diff --git a/db/migrations/20171112_add_test_results.rb b/db/migrations/20171112_add_test_results.rb new file mode 100644 index 000000000..36c3922c3 --- /dev/null +++ b/db/migrations/20171112_add_test_results.rb @@ -0,0 +1,7 @@ +require_relative 'migration_helper' + +Sequel.migration do + change do + add_column(:verifications, :test_results, PactBroker::MigrationHelper.large_text_type) + end +end diff --git a/lib/pact_broker/api/decorators/verification_decorator.rb b/lib/pact_broker/api/decorators/verification_decorator.rb index 43e622d56..d21b2cb2c 100644 --- a/lib/pact_broker/api/decorators/verification_decorator.rb +++ b/lib/pact_broker/api/decorators/verification_decorator.rb @@ -10,6 +10,7 @@ class VerificationDecorator < BaseDecorator property :success property :execution_date, as: :verificationDate property :build_url, as: :buildUrl + property :test_results, as: :testResults link :self do | options | { diff --git a/lib/pact_broker/domain/verification.rb b/lib/pact_broker/domain/verification.rb index 3fc7b65ad..cc47dd93c 100644 --- a/lib/pact_broker/domain/verification.rb +++ b/lib/pact_broker/domain/verification.rb @@ -1,5 +1,6 @@ require 'pact_broker/db' require 'pact_broker/repositories/helpers' +require 'json' module PactBroker @@ -9,6 +10,7 @@ class Verification < Sequel::Model set_primary_key :id associate(:many_to_one, :pact_version, class: "PactBroker::Pacts::PactVersion", key: :pact_version_id, primary_key: :id) associate(:many_to_one, :provider_version, class: "PactBroker::Domain::Version", key: :provider_version_id, primary_key: :id) + plugin :serialization, :json, :test_results def before_create super diff --git a/script/foo-bar-verification.json b/script/foo-bar-verification.json new file mode 100644 index 000000000..998ef14a3 --- /dev/null +++ b/script/foo-bar-verification.json @@ -0,0 +1,57 @@ +{ + "success": true, + "providerApplicationVersion": "1.0.0", + "testResults": { + "examples": [ + { + "description": "has status code 200", + "file_path": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb", + "full_description": "Verifying a pact between me and they Greeting with GET / returns a response which has status code 200", + "id": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb[1:1:1:1:1]", + "line_number": 122, + "pending_message": null, + "run_time": 0.111762, + "status": "passed" + }, + { + "description": "has a matching body", + "file_path": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb", + "full_description": "Verifying a pact between me and they Greeting with GET / returns a response which has a matching body", + "id": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb[1:1:1:1:3]", + "line_number": 139, + "pending_message": null, + "run_time": 0.000235, + "status": "passed" + }, + { + "description": "has status code 200", + "file_path": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb", + "full_description": "Verifying a pact between me and they Given There is a greeting Provider state success with GET /somestate returns a response which has status code 200", + "id": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb[1:2:1:1:1:1]", + "line_number": 122, + "pending_message": null, + "run_time": 0.006892, + "status": "passed" + }, + { + "description": "has a matching body", + "file_path": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb", + "full_description": "Verifying a pact between me and they Given There is a greeting Provider state success with GET /somestate returns a response which has a matching body", + "id": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb[1:2:1:1:1:3]", + "line_number": 139, + "pending_message": null, + "run_time": 0.000176, + "status": "passed" + } + ], + "summary": { + "duration": 0.123096, + "errors_outside_of_examples_count": 0, + "example_count": 4, + "failure_count": 0, + "pending_count": 0 + }, + "summary_line": "4 examples, 0 failures", + "version": "3.7.0" + } +} \ No newline at end of file diff --git a/script/publish-verification.sh b/script/publish-verification.sh new file mode 100755 index 000000000..a4258e42c --- /dev/null +++ b/script/publish-verification.sh @@ -0,0 +1,5 @@ +BASE_URL="http://localhost:9292" + +response_body=$(curl ${BASE_URL}/pacts/provider/Bar/consumer/Foo/latest) +verification_url=$(echo "${response_body}" | ruby -e "require 'json'; puts JSON.parse(ARGF.read)['_links']['pb:publish-verification-results']['href']") +curl -XPOST -H 'Content-Type: application/json' -d@script/foo-bar-verification.json ${verification_url} diff --git a/spec/features/publish_verification_spec.rb b/spec/features/publish_verification_spec.rb index ebcada7c4..f449721f0 100644 --- a/spec/features/publish_verification_spec.rb +++ b/spec/features/publish_verification_spec.rb @@ -33,6 +33,11 @@ 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 diff --git a/spec/fixtures/verification.json b/spec/fixtures/verification.json index 15d37c452..38d4501b6 100644 --- a/spec/fixtures/verification.json +++ b/spec/fixtures/verification.json @@ -1,4 +1,7 @@ { "success": true, - "providerApplicationVersion": "4.5.6" + "providerApplicationVersion": "4.5.6", + "testResults": { + "some": "results" + } } 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 9497361a0..bc1886793 100644 --- a/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb @@ -12,6 +12,7 @@ module Decorators provider_version_number: "4.5.6", provider_name: 'Provider', consumer_name: 'Consumer', + test_results: { 'arbitrary' => 'json' }, build_url: 'http://build-url', pact_version_sha: '1234', latest_pact_publication: pact_publication, @@ -39,6 +40,10 @@ module Decorators expect(subject[:providerApplicationVersion]).to eq "4.5.6" end + it "includes the test results" do + expect(subject[:testResults]).to eq(arbitrary: 'json') + end + it "includes the build URL" do expect(subject[:buildUrl]).to eq "http://build-url" end diff --git a/spec/lib/pact_broker/domain/verification_spec.rb b/spec/lib/pact_broker/domain/verification_spec.rb index b476ae4ad..c06fd9b6f 100644 --- a/spec/lib/pact_broker/domain/verification_spec.rb +++ b/spec/lib/pact_broker/domain/verification_spec.rb @@ -5,6 +5,19 @@ module PactBroker module Domain describe Verification do + describe "#save" do + let!(:verification) do + TestDataBuilder.new + .create_pact_with_hierarchy("A", "1", "B") + .create_verification(test_results: {'some' => 'thing'}) + .and_return(:verification) + end + + it "saves and loads the test_results" do + expect(Verification.find(id: verification.id).test_results).to eq({ 'some' => 'thing' }) + end + end + describe "#consumer" do let!(:consumer) do TestDataBuilder.new diff --git a/spec/support/test_data_builder.rb b/spec/support/test_data_builder.rb index db22aaad4..a7ba8c74f 100644 --- a/spec/support/test_data_builder.rb +++ b/spec/support/test_data_builder.rb @@ -238,7 +238,7 @@ def create_deprecated_webhook_execution params = {} def create_verification parameters = {} provider_version_number = parameters[:provider_version] || '4.5.6' - default_parameters = {success: true, number: 1} + default_parameters = {success: true, number: 1, test_results: {some: 'results'}} parameters = default_parameters.merge(parameters) parameters.delete(:provider_version) verification = PactBroker::Domain::Verification.new(parameters)