pact_broker 1.18.0 → 2.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -9
- data/DEVELOPER_DOCUMENTATION.md +53 -0
- data/README.md +13 -13
- data/db/migrations/23_create_pact_contents_table.rb +19 -0
- data/db/migrations/24_populate_pact_contents.rb +9 -0
- data/db/migrations/25_populate_pact_contents_pacticipants.rb +7 -0
- data/db/migrations/26_make_pc_pacticipants_mandatory.rb +8 -0
- data/db/migrations/27_create_pact_publications.rb +18 -0
- data/db/migrations/28_populate_pact_publications.rb +13 -0
- data/db/migrations/29_recreate_all_pacts.rb +16 -0
- data/db/migrations/30_drop_pacts.rb +8 -0
- data/db/migrations/31_drop_pact_version_contents.rb +5 -0
- data/db/migrations/32_rename_pact_contents.rb +5 -0
- data/db/migrations/33_recreate_all_pacts.rb +52 -0
- data/db/migrations/34_recreate_latest_tagged_pacts.rb +23 -0
- data/db/migrations/35_create_verifications.rb +15 -0
- data/db/migrations/36_create_latest_verifications.rb +14 -0
- data/db/pact_broker_database.sqlite3 +0 -0
- data/lib/pact_broker/api.rb +25 -10
- data/lib/pact_broker/api/contracts/verification_contract.rb +41 -0
- data/lib/pact_broker/api/decorators/pact_decorator.rb +7 -0
- data/lib/pact_broker/api/decorators/pact_version_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/representable_pact.rb +4 -3
- data/lib/pact_broker/api/decorators/timestamps.rb +1 -1
- data/lib/pact_broker/api/decorators/verification_decorator.rb +30 -0
- data/lib/pact_broker/api/decorators/verifications_decorator.rb +21 -0
- data/lib/pact_broker/api/decorators/version_decorator.rb +14 -0
- data/lib/pact_broker/api/decorators/versions_decorator.rb +1 -1
- data/lib/pact_broker/api/pact_broker_urls.rb +41 -2
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +1 -1
- data/lib/pact_broker/api/resources/base_resource.rb +11 -2
- data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +39 -0
- data/lib/pact_broker/api/resources/pacticipants.rb +1 -1
- data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
- data/lib/pact_broker/api/resources/verifications.rb +67 -0
- data/lib/pact_broker/api/resources/versions.rb +1 -1
- data/lib/pact_broker/api/resources/webhooks.rb +1 -1
- data/lib/pact_broker/app.rb +0 -2
- data/lib/pact_broker/configuration.rb +1 -4
- data/lib/pact_broker/doc/views/latest-verifications.markdown +7 -0
- data/lib/pact_broker/doc/views/publish-verification.markdown +14 -0
- data/lib/pact_broker/domain.rb +1 -1
- data/lib/pact_broker/domain/order_versions.rb +5 -15
- data/lib/pact_broker/domain/pact.rb +10 -2
- data/lib/pact_broker/domain/relationship.rb +31 -4
- data/lib/pact_broker/domain/verification.rb +77 -0
- data/lib/pact_broker/domain/version.rb +6 -1
- data/lib/pact_broker/domain/webhook.rb +1 -0
- data/lib/pact_broker/domain/webhook_request.rb +4 -6
- data/lib/pact_broker/locale/en.yml +2 -1
- data/lib/pact_broker/logging.rb +0 -4
- data/lib/pact_broker/pacticipants/repository.rb +1 -2
- data/lib/pact_broker/pacticipants/service.rb +11 -5
- data/lib/pact_broker/pacts/all_pact_publications.rb +96 -0
- data/lib/pact_broker/pacts/all_pacts.rb +4 -89
- data/lib/pact_broker/pacts/diff.rb +2 -2
- data/lib/pact_broker/pacts/latest_pact_publications.rb +11 -0
- data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +11 -0
- data/lib/pact_broker/pacts/latest_pacts.rb +1 -0
- data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +11 -0
- data/lib/pact_broker/pacts/pact_params.rb +11 -1
- data/lib/pact_broker/pacts/pact_publication.rb +50 -0
- data/lib/pact_broker/pacts/pact_version.rb +39 -0
- data/lib/pact_broker/pacts/repository.rb +46 -36
- data/lib/pact_broker/pacts/service.rb +2 -2
- data/lib/pact_broker/repositories.rb +5 -0
- data/lib/pact_broker/services.rb +5 -0
- data/lib/pact_broker/ui/view_models/relationship.rb +38 -0
- data/lib/pact_broker/ui/views/relationships/show.haml +9 -0
- data/lib/pact_broker/verifications/repository.rb +45 -0
- data/lib/pact_broker/verifications/service.rb +40 -0
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/parse_semantic_version.rb +9 -6
- data/lib/pact_broker/webhooks/service.rb +8 -9
- data/lib/pact_broker/webhooks/webhook.rb +1 -1
- data/pact_broker.gemspec +3 -4
- data/pact_broker_client-pact_broker.json +4 -4
- data/script/publish.sh +2 -2
- data/script/record_verification.sh +3 -0
- data/spec/features/delete_pact_spec.rb +1 -1
- data/spec/features/get_verifications_for_consumer_version_spec.rb +33 -0
- data/spec/features/publish_verification_spec.rb +28 -0
- data/spec/fixtures/a_consumer-a_provider-2.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-3.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-conflict.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-merged.json +2 -2
- data/spec/fixtures/a_consumer-a_provider.json +1 -1
- data/spec/fixtures/consumer-provider.json +1 -1
- data/spec/fixtures/renderer_pact.json +1 -1
- data/spec/fixtures/verification.json +4 -0
- data/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +91 -0
- data/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb +0 -18
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +6 -2
- data/spec/lib/pact_broker/api/decorators/pact_version_decorator_spec.rb +0 -3
- data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +61 -0
- data/spec/lib/pact_broker/api/decorators/verifications_decorator_spec.rb +42 -0
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +4 -0
- data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/latest_verifications_for_consumer_version_spec.rb +68 -0
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/pacticipants_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +92 -0
- data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +1 -1
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +10 -30
- data/spec/lib/pact_broker/domain/verification_spec.rb +41 -0
- data/spec/lib/pact_broker/domain/version_spec.rb +26 -0
- data/spec/lib/pact_broker/domain/webhook_request_spec.rb +1 -3
- data/spec/lib/pact_broker/pacticipants/repository_spec.rb +0 -16
- data/spec/lib/pact_broker/pacticipants/service_spec.rb +4 -3
- data/spec/lib/pact_broker/pacts/pact_params_spec.rb +14 -1
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +50 -0
- data/spec/lib/pact_broker/pacts/repository_spec.rb +85 -36
- data/spec/lib/pact_broker/ui/view_models/relationship_spec.rb +48 -2
- data/spec/lib/pact_broker/verifications/repository_spec.rb +92 -0
- data/spec/lib/pact_broker/verifications/service_spec.rb +61 -0
- data/spec/lib/pact_broker/versions/parse_semantic_version_spec.rb +39 -0
- data/spec/lib/pact_broker/webhooks/service_spec.rb +3 -40
- data/spec/migrations/23_pact_versions_spec.rb +95 -0
- data/spec/migrations/24_populate_pact_contents_spec.rb +48 -0
- data/spec/migrations/34_latest_tagged_pacts_spec.rb +108 -0
- data/spec/migrations/34_pact_revisions_spec.rb +106 -0
- data/spec/support/database_cleaner.rb +8 -4
- data/spec/support/provider_state_builder.rb +22 -8
- metadata +81 -36
- data/lib/pact_broker/pacts/database_model.rb +0 -35
- data/lib/pact_broker/pacts/latest_tagged_pacts.rb +0 -11
- data/lib/pact_broker/pacts/pact_version_content.rb +0 -11
- data/lib/pact_broker/webhooks/job.rb +0 -46
- data/script/foo-bar.json +0 -22
- data/script/publish-new.sh +0 -7
- data/script/recreate-pg-db.sh +0 -7
- data/spec/lib/pact_broker/webhooks/job_spec.rb +0 -67
@@ -8,7 +8,7 @@
|
|
8
8
|
"interactions": [
|
9
9
|
{
|
10
10
|
"description" : "a request for something",
|
11
|
-
"
|
11
|
+
"provider_state": null,
|
12
12
|
"request": {
|
13
13
|
"method": "get",
|
14
14
|
"path" : "/something"
|
@@ -20,7 +20,7 @@
|
|
20
20
|
},
|
21
21
|
{
|
22
22
|
"description" : "another request for something",
|
23
|
-
"
|
23
|
+
"provider_state": null,
|
24
24
|
"request": {
|
25
25
|
"method": "get",
|
26
26
|
"path" : "/something_else"
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'pact_broker/api/contracts/verification_contract'
|
2
|
+
require 'pact_broker/api/decorators/verification_decorator'
|
3
|
+
require 'pact_broker/domain/verification'
|
4
|
+
|
5
|
+
module PactBroker
|
6
|
+
module Api
|
7
|
+
module Contracts
|
8
|
+
describe VerificationContract do
|
9
|
+
|
10
|
+
subject { VerificationContract.new(verification) }
|
11
|
+
let(:verification) { PactBroker::Domain::Verification.new }
|
12
|
+
let(:valid_params) { {success: success, providerApplicationVersion: provider_version, buildUrl: build_url} }
|
13
|
+
let(:params) { valid_params }
|
14
|
+
|
15
|
+
|
16
|
+
let(:success) { true }
|
17
|
+
let(:provider_version) { "4.5.6" }
|
18
|
+
let(:build_url) { 'http://foo' }
|
19
|
+
|
20
|
+
def modify hash, options
|
21
|
+
hash.delete(options.fetch(:without))
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "errors" do
|
26
|
+
|
27
|
+
before do
|
28
|
+
subject.validate(params)
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with valid fields" do
|
32
|
+
its(:errors) { is_expected.to be_empty }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with no success property" do
|
36
|
+
let(:success) { nil }
|
37
|
+
|
38
|
+
it "has an error" do
|
39
|
+
expect(subject.errors[:success]).to include(match("blank"))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when success is a non-boolean string" do
|
44
|
+
let(:success) { "foo" }
|
45
|
+
it "has an error" do
|
46
|
+
expect(subject.errors[:success]).to include(match("boolean"))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when buildUrl is not a URL" do
|
51
|
+
let(:build_url) { "foo bar" }
|
52
|
+
it "has an error" do
|
53
|
+
expect(subject.errors[:build_url]).to include(match("URL"))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when buildUrl is nil" do
|
58
|
+
let(:build_url) { nil }
|
59
|
+
its(:errors) { is_expected.to be_empty }
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when the buildURL is not present" do
|
63
|
+
let(:params) { modify valid_params, without: :buildUrl }
|
64
|
+
its(:errors) { is_expected.to be_empty }
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when the providerApplicationVersion is not present" do
|
68
|
+
let(:params) { modify valid_params, without: :providerApplicationVersion }
|
69
|
+
it "has an error" do
|
70
|
+
expect(subject.errors[:provider_version]).to include(match("can't be blank"))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when the providerApplicationVersion is blank" do
|
75
|
+
let(:provider_version) { " " }
|
76
|
+
it "has an error" do
|
77
|
+
expect(subject.errors[:provider_version]).to include(match("can't be blank"))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when the providerApplicationVersion is not a semantic version" do
|
82
|
+
let(:provider_version) { "#" }
|
83
|
+
it "has an error" do
|
84
|
+
expect(subject.errors[:provider_version]).to include(match("#.*cannot be parsed"))
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -18,24 +18,6 @@ module PactBroker
|
|
18
18
|
expect(subject[:createdAt]).to_not be_nil
|
19
19
|
end
|
20
20
|
|
21
|
-
context "when the updatedAt is the same as the createdAt" do
|
22
|
-
it "does not include the updatedAt date" do
|
23
|
-
expect(subject[:updatedAt]).to be_nil
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when the updatedAt is not the same as the createdAt" do
|
28
|
-
let(:pact) do
|
29
|
-
pact = ProviderStateBuilder.new.create_pact_with_hierarchy 'Consumer', '1.2.3', 'Provider'
|
30
|
-
pact.updated_at = pact.created_at + 1
|
31
|
-
RepresentablePact.new(pact)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "includes the updatedAt date" do
|
35
|
-
expect(subject[:updatedAt]).to_not be_nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
21
|
end
|
40
22
|
end
|
41
23
|
end
|
@@ -20,15 +20,15 @@ module PactBroker
|
|
20
20
|
|
21
21
|
let(:base_url) { 'http://example.org' }
|
22
22
|
let(:created_at) { Time.new(2014, 3, 4) }
|
23
|
-
let(:updated_at) { Time.new(2014, 3, 5) }
|
24
23
|
let(:pact) { double('pact',
|
25
24
|
content_hash: content_hash,
|
26
25
|
created_at: created_at,
|
27
|
-
updated_at: updated_at,
|
28
26
|
consumer: consumer,
|
29
27
|
provider: provider,
|
30
28
|
consumer_version: consumer_version,
|
31
29
|
consumer_version_number: '1234',
|
30
|
+
pact_version_sha: '9999',
|
31
|
+
revision_number: 2,
|
32
32
|
name: 'A Pact'
|
33
33
|
)}
|
34
34
|
let(:consumer) { instance_double(PactBroker::Domain::Pacticipant, name: 'A Consumer')}
|
@@ -90,6 +90,10 @@ module PactBroker
|
|
90
90
|
expect(subject[:_links][:'pb:pact-versions'][:href]).to eq "http://example.org/pacts/provider/A%20Provider/consumer/A%20Consumer/versions"
|
91
91
|
end
|
92
92
|
|
93
|
+
it "includes a link to publish a verification" do
|
94
|
+
expect(subject[:_links][:'pb:publish-verification'][:href]).to match %r{http://example.org/.*/verifications}
|
95
|
+
end
|
96
|
+
|
93
97
|
it "includes a curie" do
|
94
98
|
expect(subject[:_links][:curies]).to eq [{ name: "pb", href: "http://example.org/doc/{rel}", templated: true }]
|
95
99
|
end
|
@@ -20,11 +20,9 @@ module PactBroker
|
|
20
20
|
|
21
21
|
let(:base_url) { 'http://example.org' }
|
22
22
|
let(:created_at) { Time.new(2014, 3, 4) }
|
23
|
-
let(:updated_at) { Time.new(2014, 3, 5) }
|
24
23
|
let(:pact) { double('pact',
|
25
24
|
json_content: json_content,
|
26
25
|
created_at: created_at,
|
27
|
-
updated_at: updated_at,
|
28
26
|
consumer: consumer,
|
29
27
|
provider: provider,
|
30
28
|
consumer_version: consumer_version,
|
@@ -53,7 +51,6 @@ module PactBroker
|
|
53
51
|
|
54
52
|
it "includes timestamps" do
|
55
53
|
expect(subject[:createdAt]).to_not be_nil
|
56
|
-
expect(subject[:updatedAt]).to_not be_nil
|
57
54
|
end
|
58
55
|
|
59
56
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'pact_broker/api/decorators/verification_decorator'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Api
|
5
|
+
module Decorators
|
6
|
+
describe VerificationDecorator do
|
7
|
+
|
8
|
+
let(:verification) do
|
9
|
+
instance_double('PactBroker::Domain::Verification',
|
10
|
+
number: 1,
|
11
|
+
success: true,
|
12
|
+
provider_version: "4.5.6",
|
13
|
+
provider_name: 'Provider',
|
14
|
+
consumer_name: 'Consumer',
|
15
|
+
build_url: 'http://build-url',
|
16
|
+
pact_version: pact_version,
|
17
|
+
latest_pact_publication: pact_publication)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:pact_version) do
|
21
|
+
instance_double('PactBroker::Pacts::PactVersion',
|
22
|
+
sha: '1234'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:pact_publication) do
|
27
|
+
instance_double('PactBroker::Pacts::PactPublication',
|
28
|
+
name: 'A name',
|
29
|
+
provider_name: 'Provider',
|
30
|
+
consumer_name: 'Consumer',
|
31
|
+
consumer_version_number: '1.2.3'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:options) { { user_options: { base_url: 'http://example.org' } } }
|
36
|
+
|
37
|
+
subject { JSON.parse VerificationDecorator.new(verification).to_json(options), symbolize_names: true }
|
38
|
+
|
39
|
+
it "includes the success status" do
|
40
|
+
expect(subject[:success]).to eq true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "includes the provider version" do
|
44
|
+
expect(subject[:providerApplicationVersion]).to eq "4.5.6"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "includes the build URL" do
|
48
|
+
expect(subject[:buildUrl]).to eq "http://build-url"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "includes a link to itself" do
|
52
|
+
expect(subject[:_links][:self][:href]).to match %r{http://example.org/.*/verifications/1}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "includes a link to its pact" do
|
56
|
+
expect(subject[:_links][:'pb:pact-version'][:href]).to match %r{http://example.org/pacts/}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'pact_broker/api/decorators/verifications_decorator'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Api
|
5
|
+
module Decorators
|
6
|
+
describe VerificationsDecorator do
|
7
|
+
let(:verifications) { [verification] }
|
8
|
+
let(:verification) do
|
9
|
+
instance_double("PactBroker::Domain::Verification",
|
10
|
+
success: true, number: 1,
|
11
|
+
provider_version: '4.5.6',
|
12
|
+
build_url: 'http://some-build',
|
13
|
+
latest_pact_publication: pact,
|
14
|
+
provider_name: 'provider',
|
15
|
+
consumer_name: 'consumer',
|
16
|
+
pact_version: pact_version,
|
17
|
+
latest_pact_publication: pact)
|
18
|
+
end
|
19
|
+
let(:pact_version) do
|
20
|
+
instance_double("PactBroker::Pacts::PactVersion", sha: '1234', name: 'Name')
|
21
|
+
end
|
22
|
+
let(:pact) { instance_double("PactBroker::Domain::Pact", name: "Some pact", consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "1.2.3") }
|
23
|
+
let(:options) { {base_url: 'http://example.org', consumer_name: "Foo", consumer_version_number: "1.2.3", resource_url: "http://self"} }
|
24
|
+
|
25
|
+
subject { JSON.parse VerificationsDecorator.new(verifications).to_json(user_options: options), symbolize_names: true }
|
26
|
+
|
27
|
+
it "includes a list of verifications" do
|
28
|
+
expect(subject[:_embedded][:verifications]).to be_instance_of(Array)
|
29
|
+
expect(subject[:_embedded][:verifications].size).to eq 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it "includes a title" do
|
33
|
+
expect(subject[:_links][:self][:title]).to eq "Latest verifications for consumer Foo version 1.2.3"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "includes a link to itself" do
|
37
|
+
expect(subject[:_links][:self][:href]).to eq "http://self"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -43,6 +43,10 @@ module PactBroker
|
|
43
43
|
expect(subject[:_embedded][:tags].first[:name]).to eq "prod"
|
44
44
|
end
|
45
45
|
|
46
|
+
it "includes a link to the latest verifications for the pacts for this version" do
|
47
|
+
expect(subject[:_links][:'pb:latest-verifications'][:href]).to match(%r{http://.*/verifications/latest})
|
48
|
+
end
|
49
|
+
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
@@ -19,7 +19,7 @@ module PactBroker
|
|
19
19
|
let(:provider) { double('provider', name: 'Provider')}
|
20
20
|
let(:created_at) { DateTime.new(2014, 02, 27) }
|
21
21
|
let(:json_content) { load_fixture('renderer_pact.json') }
|
22
|
-
let(:pact) { double('pact', json_content: json_content,
|
22
|
+
let(:pact) { double('pact', json_content: json_content, consumer_version_number: '1.2.3', consumer: consumer, provider: provider, created_at: created_at)}
|
23
23
|
let(:pact_url) { '/pact/url' }
|
24
24
|
|
25
25
|
before do
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'pact_broker/api/resources/latest_verifications_for_consumer_version'
|
2
|
+
require 'pact_broker/versions/service'
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
module Api
|
6
|
+
module Resources
|
7
|
+
|
8
|
+
describe LatestVerificationsForConsumerVersion do
|
9
|
+
describe "GET" do
|
10
|
+
let(:url) { '/pacts/consumer/Consumer/versions/1.2.3/verifications/latest' }
|
11
|
+
let(:response_body) { JSON.parse(subject.body, {symbolize_names: true}) }
|
12
|
+
let(:version) { double(:version) }
|
13
|
+
|
14
|
+
subject { get url; last_response }
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(PactBroker::Versions::Service).to receive(:find_by_pacticipant_name_and_number).and_return(version)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "looks up the consumer version" do
|
21
|
+
expect(PactBroker::Versions::Service).to receive(:find_by_pacticipant_name_and_number).with(hash_including(pacticipant_name: 'Consumer', pacticipant_version_number: '1.2.3'))
|
22
|
+
subject
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when the consumer version exists" do
|
26
|
+
let(:decorator) { double(:decorator, to_json: json) }
|
27
|
+
let(:verifications) { double(:verifications) }
|
28
|
+
let(:json) { {some: 'json'}.to_json }
|
29
|
+
|
30
|
+
before do
|
31
|
+
allow(PactBroker::Api::Decorators::VerificationsDecorator).to receive(:new).and_return(decorator)
|
32
|
+
allow(PactBroker::Verifications::Service).to receive(:find_latest_verifications_for_consumer_version).and_return(verifications)
|
33
|
+
end
|
34
|
+
|
35
|
+
it { is_expected.to be_a_hal_json_success_response }
|
36
|
+
|
37
|
+
it "finds the latest verifications for the consumer version" do
|
38
|
+
expect(PactBroker::Verifications::Service).to receive(:find_latest_verifications_for_consumer_version).with(hash_including(consumer_name: 'Consumer', consumer_version_number: '1.2.3'))
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
|
42
|
+
it "serialises the verifications" do
|
43
|
+
expect(PactBroker::Api::Decorators::VerificationsDecorator).to receive(:new).with(verifications)
|
44
|
+
expect(decorator).to receive(:to_json) do | args |
|
45
|
+
expect(args[:user_options][:consumer_name]).to eq 'Consumer'
|
46
|
+
expect(args[:user_options][:consumer_version_number]).to eq '1.2.3'
|
47
|
+
expect(args[:user_options][:resource_url]).to include(url)
|
48
|
+
expect(args[:user_options][:base_url]).to eq "http://example.org"
|
49
|
+
end
|
50
|
+
subject
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns the serialised verifications in the response" do
|
54
|
+
expect(subject.body).to eq(json)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the consumer version does not exist" do
|
59
|
+
let(:version) { nil }
|
60
|
+
|
61
|
+
it { is_expected.to be_a_404_response }
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|