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