Skip to content

Commit

Permalink
test: fix tests with correct hcaptcha api url
Browse files Browse the repository at this point in the history
  • Loading branch information
saveman71 committed Oct 17, 2024
1 parent f091061 commit 7e54b2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions test/hcaptcha/template_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ defmodule HcaptchaTemplateTest do

test "supplying a hl in options to display/1 overrides it in the script tag" do
template_string = Hcaptcha.Template.display(hl: "en")
assert template_string =~ "https://www.google.com/hcaptcha/api.js?hl=en"
assert template_string =~ "https://js.hcaptcha.com/1/api.js?hl=en"
end

test "supplying a onload in options to display/1 adds it to the script tag" do
template_string1 = Hcaptcha.Template.display(onload: "onLoad")
template_string2 = Hcaptcha.Template.display(onload: "onLoad", hl: "en")

assert template_string1 =~
"https://www.google.com/hcaptcha/api.js?onload=onLoad&hl"
"https://js.hcaptcha.com/1/api.js?onload=onLoad&hl"

assert template_string2 =~
"https://www.google.com/hcaptcha/api.js?onload=onLoad&hl=en"
"https://js.hcaptcha.com/1/api.js?onload=onLoad&hl=en"
end

test "supplying a invisible hcaptcha on option size equal invisible" do
template_string = Hcaptcha.Template.display(size: "invisible")
assert template_string =~ "ghcaptcha.execute()"
assert template_string =~ "window.hcaptcha.execute()"

template_string = Hcaptcha.Template.display(size: "compact")
refute template_string =~ "ghcaptcha.execute()"
refute template_string =~ "window.hcaptcha.execute()"
end

test "supplying an option to change the callback even if you are using invisible hcaptcha" do
Expand Down
14 changes: 8 additions & 6 deletions test/hcaptcha_test.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
defmodule HcaptchaTest do
use ExUnit.Case, async: true

# see https://developers.google.com/hcaptcha/docs/faq#id-like-to-run-automated-tests-with-hcaptcha-v2-what-should-i-do
# see https://docs.hcaptcha.com/#integration-testing-test-keys
@hCaptcha_test_secret "0x0000000000000000000000000000000000000000"

test "When the supplied hcaptcha-response is invalid, multiple errors are returned" do
test "When the supplied hcaptcha-response is invalid, errors are returned" do
assert {:error, messages} = Hcaptcha.verify("not_valid")
assert messages == [:invalid_input_response, :invalid_input_secret]
assert messages == [:invalid_input_response]
end

test "When a valid response is supplied, a success response is returned" do
assert {:ok, %{challenge_ts: _, hostname: _}} =
Hcaptcha.verify("valid_response", secret: @hCaptcha_test_secret)
Hcaptcha.verify("10000000-aaaa-bbbb-cccc-000000000001",
secret: @hCaptcha_test_secret
)
end

test "When a valid response is supplied, an error response is returned" do
assert {:error, [:"invalid-input-response"]} =
test "When an invalid response is supplied, an error response is returned" do
assert {:error, [:invalid_input_response]} =
Hcaptcha.verify("invalid_response", secret: @hCaptcha_test_secret)
end

Expand Down

0 comments on commit 7e54b2a

Please sign in to comment.