Skip to content

Commit

Permalink
feat: add version details of the implementation that verified a Pact (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
uglyog authored Sep 15, 2021
1 parent 2499a45 commit 021a869
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
6 changes: 6 additions & 0 deletions db/migrations/20210915_add_verified_by_to_verification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sequel.migration do
change do
add_column(:verifications, :verified_by_implementation, String)
add_column(:verifications, :verified_by_version, String)
end
end
4 changes: 4 additions & 0 deletions lib/pact_broker/api/decorators/verification_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class TagDecorator < BaseDecorator
property :execution_date, as: :verificationDate
property :build_url, as: :buildUrl
property :test_results, as: :testResults
nested :verifiedBy do
property :verified_by_implementation, as: :implementation
property :verified_by_version, as: :version
end

link :self do | options |
{
Expand Down
3 changes: 3 additions & 0 deletions lib/pact_broker/verifications/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def next_number
verification_repository.next_number
end

# TODO use a decorator instead of passing in params, srsly, Beth
# verified_pacts is an array of SelectedPact objects
def create next_verification_number, params, verified_pacts, event_context
first_verified_pact = verified_pacts.first
Expand All @@ -37,6 +38,8 @@ def create next_verification_number, params, verified_pacts, event_context
verification.wip = params.fetch("wip")
verification.pact_pending = params.fetch("pending")
verification.number = next_verification_number
verification.verified_by_implementation = params.dig("verifiedBy", "implementation")
verification.verified_by_version = params.dig("verifiedBy", "version")
verification.consumer_version_selector_hashes = event_context[:consumer_version_selectors]
pact_version = pact_repository.find_pact_version(first_verified_pact.consumer, first_verified_pact.provider, first_verified_pact.pact_version_sha)
verification = verification_repository.create(verification, provider_version_number, pact_version)
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/verification.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"providerApplicationVersion": "4.5.6",
"testResults": {
"some": "results"
},
"verifiedBy": {
"implementation" : "Ruby",
"version": "1234"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ module Decorators
pact_version_sha: "1234",
latest_pact_publication: pact_publication,
execution_date: DateTime.now,
provider_version_tags: provider_version_tags)
provider_version_tags: provider_version_tags,
verified_by_implementation: "Ruby",
verified_by_version: "1234")
end

let(:pact_publication) do
Expand Down Expand Up @@ -67,6 +69,11 @@ module Decorators
it "includes a link to the triggered webhooks" do
expect(subject[:_links][:'pb:triggered-webhooks'][:href]).to eq "http://triggered-webhooks"
end

it "includes the framework that did the verification" do
expect(subject[:verifiedBy][:implementation]).to eq "Ruby"
expect(subject[:verifiedBy][:version]).to eq "1234"
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module Decorators
latest_pact_publication: pact,
test_results: nil,
execution_date: DateTime.now,
provider_version_tags: provider_version_tags)
provider_version_tags: provider_version_tags,
verified_by_implementation: "Ruby",
verified_by_version: "1234")
end

let(:pact_version) do
Expand Down
18 changes: 16 additions & 2 deletions spec/lib/pact_broker/verifications/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ module Verifications

let(:event_context) { { some: "data", consumer_version_selectors: [{ foo: "bar" }] } }
let(:expected_event_context) { { some: "data", provider_version_tags: ["dev"] } }
let(:params) { { "success" => success, "providerApplicationVersion" => "4.5.6", "wip" => true, "pending" => is_pending, "testResults" => { "some" => "results" }} }
let(:params) do
{
"success" => success,
"providerApplicationVersion" => "4.5.6",
"wip" => true,
"pending" => is_pending,
"testResults" => { "some" => "results" },
"verifiedBy" => {
"implementation" => "Ruby",
"version" => "1234"
}
}
end
let(:is_pending) { true }
let(:success) { true }
let(:pact) do
Expand All @@ -34,7 +46,7 @@ module Verifications
let(:create_verification) { subject.create 3, params, selected_pacts, event_context }

it "logs the creation" do
expect(logger).to receive(:info).with(/.*verification.*3/, payload: {"providerApplicationVersion"=>"4.5.6", "success"=>true, "wip"=>true, "pending" => is_pending})
expect(logger).to receive(:info).with(/.*verification.*3/, payload: hash_including("providerApplicationVersion"=>"4.5.6", "success"=>true, "wip"=>true, "pending" => is_pending))
create_verification
end

Expand All @@ -47,6 +59,8 @@ module Verifications
expect(verification.test_results).to eq "some" => "results"
expect(verification.consumer_version_selector_hashes).to eq [{ foo: "bar" }]
expect(verification.tag_names).to eq ["dev"]
expect(verification.verified_by_implementation).to eq "Ruby"
expect(verification.verified_by_version).to eq "1234"
end

it "sets the pact content for the verification" do
Expand Down

0 comments on commit 021a869

Please sign in to comment.