-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: shorten length of metadata in pact URLs by using the consumer v…
…ersion id instead of number
- Loading branch information
Showing
9 changed files
with
209 additions
and
44 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
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
70 changes: 70 additions & 0 deletions
70
spec/features/publish_verification_results_and_version_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,70 @@ | ||
require 'pact_broker/domain/verification' | ||
|
||
describe "Publishing a pact verification and provider version" do | ||
let(:path) { "/pacts/provider/Provider/consumer/Consumer/pact-version/#{pact.pact_version_sha}/verification-results" } | ||
let(:verification_content) { load_fixture('verification.json') } | ||
let(:parsed_response_body) { JSON.parse(subject.body) } | ||
let(:pact) { td.pact } | ||
let(:rack_env) do | ||
{ | ||
'CONTENT_TYPE' => 'application/json', | ||
'HTTP_ACCEPT' => 'application/hal+json', | ||
'pactbroker.database_connector' => lambda { |&block| block.call } | ||
} | ||
end | ||
|
||
subject { post path, verification_content, rack_env; last_response } | ||
|
||
before do | ||
td.create_provider("Provider") | ||
.create_consumer("Consumer") | ||
.create_consumer_version("1.0.0") | ||
.create_pact | ||
.create_consumer_version("1.2.3") | ||
.create_pact | ||
.revise_pact | ||
end | ||
|
||
it "Responds with a 201 Created" do | ||
expect(subject.status).to be 201 | ||
end | ||
|
||
it "saves new verification" do | ||
expect { subject }.to change { PactBroker::Domain::Verification.count }.by(1) | ||
end | ||
|
||
it "saves the verification against the correct pact" do | ||
subject | ||
expect(PactBroker::Domain::Verification.order(:id).last.pact_version_sha).to eq pact.pact_version_sha | ||
end | ||
|
||
it "saves the test results" do | ||
subject | ||
expect(PactBroker::Domain::Verification.order(:id).last.test_results).to eq('some' => 'results') | ||
end | ||
|
||
it "returns a link to itself that can be followed" do | ||
get_verification_link = parsed_response_body['_links']['self']['href'] | ||
get get_verification_link, nil, { 'HTTP_ACCEPT' => 'application/hal+json' } | ||
expect(last_response.status).to be 200 | ||
expect(JSON.parse(subject.body)).to include JSON.parse(verification_content) | ||
end | ||
|
||
context "with a webhook configured", job: true do | ||
before do | ||
td.create_webhook( | ||
method: 'POST', | ||
url: 'http://example.org', | ||
events: [{ name: PactBroker::Webhooks::WebhookEvent::VERIFICATION_PUBLISHED }] | ||
) | ||
end | ||
let!(:request) do | ||
stub_request(:post, 'http://example.org').to_return(:status => 200) | ||
end | ||
|
||
it "executes the webhook" do | ||
subject | ||
expect(request).to have_been_made | ||
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
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,12 @@ | ||
require 'pact_broker/db' | ||
|
||
RSpec.describe "the Pact Broker migrations" do | ||
it "doesn't have any migrations with the same number" do | ||
duplicates = Dir.glob(PactBroker::DB::MIGRATIONS_DIR + "/*") | ||
.collect { |path| path.split("/").last } | ||
.select { | filename| filename =~ /^\d\d\d\d/ } | ||
.group_by{ | filename | filename.split("_").first.to_i } | ||
.select { | number, filenames | filenames.size > 1 } | ||
expect(duplicates).to eq({}) | ||
end | ||
end |