Merge branch 'develop' into fix/formatter-ignore-html-chars
[akkoma] / test / captcha_test.exs
1 defmodule Pleroma.CaptchaTest do
2 use ExUnit.Case
3
4 import Tesla.Mock
5
6 alias Pleroma.Captcha.Kocaptcha
7
8 @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
9
10 describe "Kocaptcha" do
11 setup do
12 ets_name = Kocaptcha.Ets
13 ^ets_name = :ets.new(ets_name, @ets_options)
14
15 mock(fn
16 %{method: :get, url: "https://captcha.kotobank.ch/new"} ->
17 json(%{
18 md5: "63615261b77f5354fb8c4e4986477555",
19 token: "afa1815e14e29355e6c8f6b143a39fa2",
20 url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
21 })
22 end)
23
24 :ok
25 end
26
27 test "new and validate" do
28 assert Kocaptcha.new() == %{
29 type: :kocaptcha,
30 token: "afa1815e14e29355e6c8f6b143a39fa2",
31 url: "https://captcha.kotobank.ch/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
32 }
33
34 assert Kocaptcha.validate(
35 "afa1815e14e29355e6c8f6b143a39fa2",
36 "7oEy8c"
37 )
38 end
39 end
40 end