docbrown/spec/services/authentication/providers_spec.rb
Fernando Valverde c74121b0c0
Forem passport (cont) (#14759)
* Initial forem omniauth strategy setup work

* Finish basic raw proof of concept

* Some playing around

* use OAuth payloads + PASSPORT_OAUTH_URL for local dev

* Use FeatureFlag for Forem Passport Auth

* Working on tests

* Fix tests 🤞🏼 & some cleanup

* Use correct namespace within lib directory (match class namespace)

* Test to ensure Forem Passport auth is restricted by FeatureFlag

* Add broadcast + work on tests

* Update spec/lib/data_update_scripts/insert_forem_connect_broadcast_message_spec.rb

Co-authored-by: Michael Kohl <citizen428@forem.com>

* Hash format

* Schema cleanup + inline comments

* Use temprorary Heroku domain

* More cleanup

* Missed one

* Back to passport.forem.com

* Require correct path in lib

* Apply suggestions from code review

Co-authored-by: Michael Kohl <citizen428@forem.com>

* Use with_indifferent_access for symbol hash access in Forem strategy

Co-authored-by: benhalpern <bendhalpern@gmail.com>
Co-authored-by: Michael Kohl <citizen428@forem.com>
2021-09-30 06:47:45 -06:00

59 lines
1.8 KiB
Ruby

require "rails_helper"
RSpec.describe Authentication::Providers, type: :service do
describe ".get!" do
it "raises an exception if a provider is not available" do
expect do
described_class.get!(:unknown)
end.to raise_error(Authentication::Errors::ProviderNotFound)
end
it "raises an exception if a provider is available but not enabled" do
allow(Settings::Authentication).to receive(:providers).and_return(%w[github])
expect do
described_class.get!(:twitter)
end.to raise_error(Authentication::Errors::ProviderNotEnabled)
end
it "loads the correct provider class" do
allow(Settings::Authentication).to receive(:providers).and_return(described_class.available)
is_subclass_of = (
described_class.get!(:twitter) < Authentication::Providers::Provider
)
expect(is_subclass_of).to be(true)
end
end
describe ".available" do
it "lists the available providers" do
available_providers = %i[apple facebook forem github twitter]
expect(described_class.available).to eq(available_providers)
end
end
describe ".enabled" do
context "when one of the available providers is disabled" do
it "only lists those that remain enabled" do
allow(Settings::Authentication).to receive(:providers).and_return(%w[github])
expect(described_class.enabled).to eq(%i[github])
end
end
end
describe ".enabled?" do
it "returns true if a provider is enabled" do
allow(Settings::Authentication).to receive(:providers).and_return(%w[github])
expect(described_class.enabled?(:github)).to be(true)
end
it "returns false if a provider is not enabled" do
allow(Settings::Authentication).to receive(:providers).and_return(%w[twitter])
expect(described_class.enabled?(:github)).to be(false)
end
end
end