A platform for community discussion. Free, open, simple.
# frozen_string_literal: true
RSpec.describe ProblemCheck::HcaptchaConfiguration do
subject(:check) { described_class.new }
shared_examples "fails_problem_check" do
it do
expect(check).to have_a_problem.with_priority("high").with_message(
"There is a problem with your hCaptcha `site_key` or `secret_key` configuration",
)
end
end
shared_examples "passes_problem_check" do
it { expect(check).to be_chill_about_it }
end
context "when hCaptcha is enabled and configured as the provider" do
before do
SiteSetting.discourse_captcha_enabled = true
SiteSetting.discourse_captcha_provider = DiscourseCaptcha::CaptchaProvider::HCAPTCHA
end
describe "`hcaptcha_site_key` is not set" do
before { SiteSetting.hcaptcha_secret_key = "just a string" }
include_examples "fails_problem_check"
end
describe "`hcaptcha_secret_key` is not set" do
before { SiteSetting.hcaptcha_site_key = "just a string" }
include_examples "fails_problem_check"
end
describe "`hcaptcha_secret_key` and `hcaptcha_site_key` are not set" do
include_examples "fails_problem_check"
end
describe "`hcaptcha_secret_key` and `hcaptcha_site_key` are set" do
before do
SiteSetting.hcaptcha_secret_key = "just a string"
SiteSetting.hcaptcha_site_key = "just a string"
end
include_examples "passes_problem_check"
end
end
context "when hCaptcha is configured as the provider but disabled" do
before { SiteSetting.discourse_captcha_provider = DiscourseCaptcha::CaptchaProvider::HCAPTCHA }
describe "`hcaptcha_site_key` is not set" do
before { SiteSetting.hcaptcha_secret_key = "just a string" }
include_examples "passes_problem_check"
end
describe "`hcaptcha_secret_key` is not set" do
before { SiteSetting.hcaptcha_site_key = "just a string" }
include_examples "passes_problem_check"
end
describe "`hcaptcha_secret_key` and `hcaptcha_site_key` are not set" do
include_examples "passes_problem_check"
end
describe "`hcaptcha_secret_key` and `hcaptcha_site_key` are set" do
before do
SiteSetting.hcaptcha_secret_key = "just a string"
SiteSetting.hcaptcha_site_key = "just a string"
end
include_examples "passes_problem_check"
end
end
end