Packages

A simple hCaptcha package for Elixir applications, provides verification and templates for rendering forms with the hCaptcha widget

Current section

Files

Jump to
hcaptcha lib hcaptcha http mock_http_client.ex
Raw

lib/hcaptcha/http/mock_http_client.ex

defmodule Hcaptcha.Http.MockClient do
@moduledoc """
A mock HTTP client used for testing.
"""
alias Hcaptcha.Http
def request_verification(body, options \\ [])
def request_verification(
"response=valid_response&secret=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe" =
body,
options
) do
send(self(), {:request_verification, body, options})
{:ok,
%{
"success" => true,
"challenge_ts" => "timestamp",
"hostname" => "localhost"
}}
end
def request_verification(
"response=invalid_response&secret=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe" =
body,
options
) do
send(self(), {:request_verification, body, options})
{:error, [:"invalid-input-response"]}
end
# every other match is a pass through to the real client
def request_verification(body, options) do
send(self(), {:request_verification, body, options})
Http.request_verification(body, options)
end
end