Merge branch 'legal-boilerplate' into 'develop'
[akkoma] / test / captcha_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.CaptchaTest do
6 use ExUnit.Case
7
8 import Tesla.Mock
9
10 alias Pleroma.Captcha.Kocaptcha
11
12 @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
13
14 describe "Kocaptcha" do
15 setup do
16 ets_name = Kocaptcha.Ets
17 ^ets_name = :ets.new(ets_name, @ets_options)
18
19 mock(fn
20 %{method: :get, url: "https://captcha.kotobank.ch/new"} ->
21 json(%{
22 md5: "63615261b77f5354fb8c4e4986477555",
23 token: "afa1815e14e29355e6c8f6b143a39fa2",
24 url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
25 })
26 end)
27
28 :ok
29 end
30
31 test "new and validate" do
32 assert Kocaptcha.new() == %{
33 type: :kocaptcha,
34 token: "afa1815e14e29355e6c8f6b143a39fa2",
35 url: "https://captcha.kotobank.ch/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
36 }
37
38 assert Kocaptcha.validate(
39 "afa1815e14e29355e6c8f6b143a39fa2",
40 "7oEy8c"
41 )
42 end
43 end
44 end