diff --git a/db/migrations/20210915_add_verified_by_to_verification.rb b/db/migrations/20210915_add_verified_by_to_verification.rb new file mode 100644 index 000000000..a0b99587d --- /dev/null +++ b/db/migrations/20210915_add_verified_by_to_verification.rb @@ -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 diff --git a/lib/pact_broker/api/decorators/verification_decorator.rb b/lib/pact_broker/api/decorators/verification_decorator.rb index 11c02f989..c83866766 100644 --- a/lib/pact_broker/api/decorators/verification_decorator.rb +++ b/lib/pact_broker/api/decorators/verification_decorator.rb @@ -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 | { diff --git a/lib/pact_broker/verifications/service.rb b/lib/pact_broker/verifications/service.rb index 91c2343fb..e14f59cba 100644 --- a/lib/pact_broker/verifications/service.rb +++ b/lib/pact_broker/verifications/service.rb @@ -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 @@ -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) diff --git a/spec/fixtures/verification.json b/spec/fixtures/verification.json index 38d4501b6..e64a3e2e8 100644 --- a/spec/fixtures/verification.json +++ b/spec/fixtures/verification.json @@ -3,5 +3,9 @@ "providerApplicationVersion": "4.5.6", "testResults": { "some": "results" + }, + "verifiedBy": { + "implementation" : "Ruby", + "version": "1234" } } diff --git a/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb index fd78a6bf9..a310c1dfb 100644 --- a/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb @@ -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 @@ -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 diff --git a/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb index e29bf7851..de05963de 100644 --- a/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb @@ -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 diff --git a/spec/lib/pact_broker/verifications/service_spec.rb b/spec/lib/pact_broker/verifications/service_spec.rb index 0320408ea..add1614b7 100644 --- a/spec/lib/pact_broker/verifications/service_spec.rb +++ b/spec/lib/pact_broker/verifications/service_spec.rb @@ -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 @@ -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 @@ -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