forked from pact-foundation/pact_broker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(matrix): add validation errors to matrix resource
- Loading branch information
Showing
7 changed files
with
139 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'pact_broker/api/resources/matrix' | ||
require 'pact_broker/matrix/service' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe Matrix do | ||
before do | ||
allow(PactBroker::Matrix::Service).to receive(:validate_selectors).and_return(error_messages) | ||
end | ||
|
||
let(:td) { TestDataBuilder.new } | ||
let(:path) { "/matrix" } | ||
let(:json_response_body) { JSON.parse(subject.body, symbolize_names: true) } | ||
let(:params) { { selectors: ['Foo/version/1', 'Bar/version/2'] } } | ||
let(:error_messages) { [] } | ||
|
||
subject { get path, params, {'Content-Type' => 'application/hal+json'}; last_response } | ||
|
||
it "validates the selectors" do | ||
expect(PactBroker::Matrix::Service).to receive(:validate_selectors).with(['Foo/version/1', 'Bar/version/2']) | ||
subject | ||
end | ||
|
||
context "when a validation error occurs" do | ||
let(:error_messages) { ['foo'] } | ||
it "returns a 400 status" do | ||
expect(subject.status).to eq 400 | ||
end | ||
|
||
it "returns error messages" do | ||
expect(json_response_body[:errors]).to eq ['foo'] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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,42 @@ | ||
require 'pact_broker/matrix/service' | ||
|
||
module PactBroker | ||
module Matrix | ||
describe Service do | ||
describe "validate_selectors" do | ||
let(:td) { TestDataBuilder.new } | ||
|
||
subject { Service.validate_selectors(selectors) } | ||
|
||
context "when a selector format is invalid" do | ||
let(:selectors) { ["Foo/1"] } | ||
|
||
it "returns error messages" do | ||
expect(subject.first).to eq "Invalid version selector 'Foo/1'. Format must be <pacticipant_name>/version/<version>" | ||
end | ||
end | ||
|
||
context "when one or more of the selectors does not match any known version" do | ||
before do | ||
td.create_pacticipant("Foo") | ||
end | ||
|
||
let(:selectors) { ["Foo/version/1"] } | ||
|
||
it "returns error messages" do | ||
expect(subject.first).to eq "No pact or verification found for Foo/version/1" | ||
end | ||
end | ||
|
||
context "when the pacticipant does not exist" do | ||
let(:selectors) { ["Foo/version/1"] } | ||
|
||
it "returns error messages" do | ||
expect(subject.first).to eq "Pacticipant 'Foo' not found" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
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