Skip to content

Commit

Permalink
feat(publish test result): allow json test results to be published wi…
Browse files Browse the repository at this point in the history
…th the verification result
  • Loading branch information
bethesque committed Nov 12, 2017
1 parent 10a6eb9 commit 528034c
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 2 deletions.
7 changes: 7 additions & 0 deletions db/migrations/20171112_add_test_results.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/pact_broker/api/decorators/verification_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
{
Expand Down
2 changes: 2 additions & 0 deletions lib/pact_broker/domain/verification.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pact_broker/db'
require 'pact_broker/repositories/helpers'
require 'json'

module PactBroker

Expand All @@ -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
Expand Down
57 changes: 57 additions & 0 deletions script/foo-bar-verification.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
5 changes: 5 additions & 0 deletions script/publish-verification.sh
Original file line number Diff line number Diff line change
@@ -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}
5 changes: 5 additions & 0 deletions spec/features/publish_verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion spec/fixtures/verification.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"success": true,
"providerApplicationVersion": "4.5.6"
"providerApplicationVersion": "4.5.6",
"testResults": {
"some": "results"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/pact_broker/domain/verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 528034c

Please sign in to comment.