-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for new XOR constraint
- Loading branch information
1 parent
3c233ac
commit 74ec584
Showing
3 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
spec/app/domain/authentication/constraints/required_exclusive_constraint_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe(Authentication::Constraints::RequiredExclusiveConstraint) do | ||
context "Given RequiredExclusiveConstraint initialized with 3 restrictions" do | ||
let(:reqx_restrictions) { %w[reqx_one reqx_two reqx_three] } | ||
let(:additional_restriction) { "additional" } | ||
let(:raised_error) { ::Errors::Authentication::Constraints::IllegalRequiredExclusiveCombination } | ||
|
||
subject(:constraint) do | ||
Authentication::Constraints::RequiredExclusiveConstraint.new(required_exclusive: reqx_restrictions) | ||
end | ||
|
||
context "when validating with no ReqX restrictions" do | ||
let(:expected_error_message) { /#{Regexp.escape(reqx_restrictions.to_s)}/ } | ||
|
||
subject do | ||
constraint.validate(resource_restrictions: [additional_restriction]) | ||
end | ||
|
||
it "raises an error" do | ||
expect { subject }.to raise_error(raised_error, expected_error_message) | ||
end | ||
end | ||
|
||
context "when validating with one ReqX restriction" do | ||
subject do | ||
constraint.validate(resource_restrictions: [reqx_restrictions.first, additional_restriction]) | ||
end | ||
|
||
it "does not raise an error" do | ||
expect { subject }.to_not raise_error | ||
end | ||
end | ||
|
||
context "when validating with many ReqX restrictions" do | ||
let(:resource_restrictions) { reqx_restrictions[1, 2] } | ||
let(:expected_error_message) { /#{Regexp.escape(resource_restrictions.to_s)}/ } | ||
|
||
subject do | ||
constraint.validate(resource_restrictions: resource_restrictions + [additional_restriction]) | ||
end | ||
|
||
it "raises an error" do | ||
expect { subject }.to raise_error(raised_error, expected_error_message) | ||
end | ||
end | ||
|
||
context "when validating with all ReqX restrictions" do | ||
let(:expected_error_message) { /#{Regexp.escape(reqx_restrictions.to_s)}/ } | ||
|
||
subject do | ||
constraint.validate(resource_restrictions: reqx_restrictions + [additional_restriction]) | ||
end | ||
|
||
it "raises an error" do | ||
expect { subject }.to raise_error(raised_error, expected_error_message) | ||
end | ||
end | ||
|
||
end | ||
end |