Browse Source

CLDC-4332: Add tests

pull/3305/head
samyou-softwire 3 weeks ago
parent
commit
9fc6482020
  1. 1
      app/services/feature_toggle.rb
  2. 47
      spec/models/user_spec.rb

1
app/services/feature_toggle.rb

@ -39,6 +39,5 @@ class FeatureToggle
# if nil this feature will be disabled # if nil this feature will be disabled
def self.support_organisation_allow_list def self.support_organisation_allow_list
return [1] if Rails.env.production? return [1] if Rails.env.production?
return [1] if Rails.env.development?
end end
end end

47
spec/models/user_spec.rb

@ -540,6 +540,53 @@ RSpec.describe User, type: :model do
.to raise_error(ActiveRecord::RecordInvalid, error_message) .to raise_error(ActiveRecord::RecordInvalid, error_message)
end end
end end
describe "#support_user_is_in_correct_organisation" do
let(:organisation) { create(:organisation) }
context "when the user is not a support user" do
let(:user) { build(:user, :data_coordinator, organisation:) }
it "is valid regardless of the allow list" do
allow(FeatureToggle).to receive(:support_organisation_allow_list).and_return([999])
expect(user).to be_valid
end
end
context "when the user is a support user" do
let(:user) { build(:user, :support, organisation:) }
context "and the allow list is nil" do
before do
allow(FeatureToggle).to receive(:support_organisation_allow_list).and_return(nil)
end
it "is valid" do
expect(user).to be_valid
end
end
context "and the organisation is in the allow list" do
before do
allow(FeatureToggle).to receive(:support_organisation_allow_list).and_return([organisation.id])
end
it "is valid" do
expect(user).to be_valid
end
end
context "and the organisation is not in the allow list" do
before do
allow(FeatureToggle).to receive(:support_organisation_allow_list).and_return([organisation.id + 1])
end
it "is not valid" do
expect(user).not_to be_valid
end
end
end
end
end end
describe "delete" do describe "delete" do

Loading…
Cancel
Save