pact_broker 2.31.0 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/db/migrations/20190509_create_version_sequence.rb +8 -0
- data/db/migrations/20190510_set_version_sequence.rb +9 -0
- data/db/migrations/20190511_create_integrations_view.rb +19 -0
- data/db/migrations/20190523_add_enabled_column_to_webhooks.rb +5 -0
- data/db/migrations/20190524_set_webhooks_enabled.rb +10 -0
- data/db/migrations/20190525_add_description_column_to_webhooks.rb +5 -0
- data/lib/pact_broker/api.rb +3 -0
- data/lib/pact_broker/api/decorators/base_decorator.rb +0 -3
- data/lib/pact_broker/api/decorators/integration_decorator.rb +40 -0
- data/lib/pact_broker/api/decorators/integrations_decorator.rb +19 -0
- data/lib/pact_broker/api/decorators/pact_decorator.rb +1 -1
- data/lib/pact_broker/api/decorators/pact_details_decorator.rb +1 -6
- data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +12 -0
- data/lib/pact_broker/api/decorators/verifiable_pacts_decorator.rb +20 -0
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +5 -1
- data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/webhooks_decorator.rb +2 -2
- data/lib/pact_broker/api/pact_broker_urls.rb +37 -3
- data/lib/pact_broker/api/resources/base_resource.rb +4 -0
- data/lib/pact_broker/api/resources/dashboard.rb +1 -1
- data/lib/pact_broker/api/resources/integrations.rb +10 -2
- data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +8 -14
- data/lib/pact_broker/api/resources/pact.rb +15 -3
- data/lib/pact_broker/api/resources/verification.rb +0 -2
- data/lib/pact_broker/api/resources/verifications.rb +18 -1
- data/lib/pact_broker/api/resources/webhook.rb +1 -1
- data/lib/pact_broker/api/resources/webhook_execution.rb +18 -9
- data/lib/pact_broker/app.rb +10 -11
- data/lib/pact_broker/db.rb +2 -2
- data/lib/pact_broker/db/data_migrations/helpers.rb +11 -0
- data/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb +29 -0
- data/lib/pact_broker/db/data_migrations/set_webhooks_enabled.rb +17 -0
- data/lib/pact_broker/db/migrate_data.rb +2 -0
- data/lib/pact_broker/db/seed_example_data.rb +6 -3
- data/lib/pact_broker/domain/order_versions.rb +14 -1
- data/lib/pact_broker/domain/verification.rb +4 -0
- data/lib/pact_broker/domain/webhook.rb +13 -3
- data/lib/pact_broker/domain/webhook_request.rb +3 -2
- data/lib/pact_broker/index/service.rb +3 -0
- data/lib/pact_broker/integrations/integration.rb +10 -0
- data/lib/pact_broker/integrations/service.rb +5 -0
- data/lib/pact_broker/matrix/parse_query.rb +2 -0
- data/lib/pact_broker/matrix/row.rb +8 -0
- data/lib/pact_broker/matrix/service.rb +1 -2
- data/lib/pact_broker/pacts/service.rb +16 -9
- data/lib/pact_broker/test/test_data_builder.rb +6 -2
- data/lib/pact_broker/verifications/sequence.rb +0 -2
- data/lib/pact_broker/verifications/service.rb +10 -2
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/sequence.rb +38 -0
- data/lib/pact_broker/webhooks/job.rb +19 -7
- data/lib/pact_broker/webhooks/render.rb +30 -13
- data/lib/pact_broker/webhooks/repository.rb +3 -4
- data/lib/pact_broker/webhooks/service.rb +60 -34
- data/lib/pact_broker/webhooks/trigger_service.rb +6 -6
- data/lib/pact_broker/webhooks/webhook.rb +9 -1
- data/lib/pact_broker/webhooks/webhook_request_template.rb +11 -7
- data/lib/rack/pact_broker/database_transaction.rb +6 -2
- data/script/publish-new.sh +23 -1
- data/script/publish.sh +13 -4
- data/script/seed.rb +53 -52
- data/spec/features/create_webhook_spec.rb +2 -0
- data/spec/features/execute_webhook_spec.rb +4 -3
- data/spec/features/get_integrations_spec.rb +17 -0
- data/spec/features/get_pacts_to_verify_spec.rb +7 -3
- data/spec/features/publish_verification_spec.rb +8 -1
- data/spec/features/update_webhook_spec.rb +47 -0
- data/spec/integration/webhooks/certificate_spec.rb +1 -1
- data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +12 -0
- data/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb +82 -0
- data/spec/lib/pact_broker/api/decorators/integrations_decorator_spec.rb +29 -0
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +12 -4
- data/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb +30 -0
- data/spec/lib/pact_broker/api/decorators/verifiable_pacts_decorator_spec.rb +29 -0
- data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +20 -1
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +0 -4
- data/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +5 -4
- data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +64 -1
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +0 -3
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +40 -10
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +13 -3
- data/spec/lib/pact_broker/app_spec.rb +28 -4
- data/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb +68 -0
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +1 -4
- data/spec/lib/pact_broker/domain/webhook_spec.rb +10 -6
- data/spec/lib/pact_broker/matrix/parse_query_spec.rb +15 -7
- data/spec/lib/pact_broker/pacts/service_spec.rb +13 -5
- data/spec/lib/pact_broker/verifications/service_spec.rb +15 -3
- data/spec/lib/pact_broker/versions/repository_spec.rb +1 -1
- data/spec/lib/pact_broker/webhooks/job_spec.rb +52 -15
- data/spec/lib/pact_broker/webhooks/render_spec.rb +28 -7
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +23 -32
- data/spec/lib/pact_broker/webhooks/service_spec.rb +186 -62
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +6 -5
- data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +12 -5
- data/spec/lib/rack/pact_broker/database_transaction_spec.rb +10 -0
- data/spec/lib/rack/pact_broker/ui_request_filter_spec.rb +9 -0
- data/spec/migrations/23_pact_versions_spec.rb +7 -1
- data/spec/support/database_cleaner.rb +11 -1
- data/spec/support/metadata_test_server.rb +40 -0
- data/spec/support/verification_job.rb +34 -0
- data/spec/support/webhook_endpoint_middleware.rb +22 -0
- metadata +37 -2
@@ -5,25 +5,29 @@ require 'pact_broker/verifications/service'
|
|
5
5
|
|
6
6
|
module PactBroker
|
7
7
|
module Api
|
8
|
-
|
9
8
|
module Resources
|
10
|
-
|
11
9
|
describe Verifications do
|
12
|
-
|
13
10
|
describe "post" do
|
14
|
-
|
15
|
-
let(:
|
16
|
-
let(:
|
17
|
-
|
18
|
-
|
11
|
+
let(:url) { "/pacts/provider/Provider/consumer/Consumer/pact-version/1234/metadata/abcd/verification-results" }
|
12
|
+
let(:request_body) { { some: 'params' }.to_json }
|
13
|
+
let(:rack_env) do
|
14
|
+
{ 'CONTENT_TYPE' => 'application/json', 'pactbroker.database_connector' => database_connector }
|
15
|
+
end
|
16
|
+
let(:response_body) { JSON.parse(subject.body, symbolize_names: true) }
|
17
|
+
let(:database_connector) { double('database_connector' )}
|
19
18
|
let(:verification) { double(PactBroker::Domain::Verification) }
|
20
19
|
let(:errors_empty) { true }
|
20
|
+
let(:parsed_metadata) { { the: 'metadata' } }
|
21
|
+
let(:base_url) { "http://example.org" }
|
21
22
|
|
22
23
|
before do
|
23
24
|
allow(PactBroker::Verifications::Service).to receive(:create).and_return(verification)
|
24
25
|
allow(PactBroker::Verifications::Service).to receive(:errors).and_return(double(:errors, messages: ['errors'], empty?: errors_empty))
|
26
|
+
allow(PactBrokerUrls).to receive(:parse_webhook_metadata).and_return(parsed_metadata)
|
25
27
|
end
|
26
28
|
|
29
|
+
subject { post url, request_body, rack_env; last_response }
|
30
|
+
|
27
31
|
it "looks up the specified pact" do
|
28
32
|
allow(Pacts::Service).to receive(:find_pact).with(instance_of(PactBroker::Pacts::PactParams))
|
29
33
|
end
|
@@ -39,7 +43,13 @@ module PactBroker
|
|
39
43
|
end
|
40
44
|
|
41
45
|
context "when the pact exists" do
|
42
|
-
let(:pact)
|
46
|
+
let(:pact) do
|
47
|
+
instance_double("PactBroker::Domain::Pact",
|
48
|
+
provider_name: 'Provider',
|
49
|
+
consumer_name: 'Consumer',
|
50
|
+
pact_version_sha: '1234'
|
51
|
+
)
|
52
|
+
end
|
43
53
|
let(:next_verification_number) { "2" }
|
44
54
|
let(:serialised_verification) { {some: 'verification'}.to_json }
|
45
55
|
let(:decorator) { instance_double('PactBroker::Api::Decorators::VerificationDecorator', to_json: serialised_verification) }
|
@@ -48,6 +58,12 @@ module PactBroker
|
|
48
58
|
allow(Pacts::Service).to receive(:find_pact).and_return(pact)
|
49
59
|
allow(PactBroker::Verifications::Service).to receive(:next_number).and_return(next_verification_number)
|
50
60
|
allow(PactBroker::Api::Decorators::VerificationDecorator).to receive(:new).and_return(decorator)
|
61
|
+
allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return('some-boolean')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "parses the webhook metadata" do
|
65
|
+
expect(PactBrokerUrls).to receive(:parse_webhook_metadata).with("abcd")
|
66
|
+
subject
|
51
67
|
end
|
52
68
|
|
53
69
|
it "returns a 201" do
|
@@ -59,7 +75,21 @@ module PactBroker
|
|
59
75
|
end
|
60
76
|
|
61
77
|
it "stores the verification in the database" do
|
62
|
-
expect(PactBroker::Verifications::Service).to receive(:create).with(
|
78
|
+
expect(PactBroker::Verifications::Service).to receive(:create).with(
|
79
|
+
next_verification_number,
|
80
|
+
hash_including('some' => 'params'),
|
81
|
+
pact,
|
82
|
+
{
|
83
|
+
execution_options: {
|
84
|
+
show_response: 'some-boolean'
|
85
|
+
},
|
86
|
+
webhook_context: {
|
87
|
+
the: 'metadata',
|
88
|
+
base_url: base_url,
|
89
|
+
},
|
90
|
+
database_connector: database_connector
|
91
|
+
}
|
92
|
+
)
|
63
93
|
subject
|
64
94
|
end
|
65
95
|
|
@@ -33,6 +33,16 @@ module PactBroker
|
|
33
33
|
let(:pact) { instance_double("PactBroker::Domain::Pact") }
|
34
34
|
let(:consumer_name) { "foo" }
|
35
35
|
let(:provider_name) { "bar" }
|
36
|
+
let(:webhook_options) do
|
37
|
+
{
|
38
|
+
execution_options: {
|
39
|
+
show_response: false,
|
40
|
+
},
|
41
|
+
webhook_context: {
|
42
|
+
base_url: "http://example.org"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
end
|
36
46
|
|
37
47
|
before do
|
38
48
|
allow(PactBroker::Webhooks::Service).to receive(:test_execution).and_return(execution_result)
|
@@ -40,7 +50,7 @@ module PactBroker
|
|
40
50
|
end
|
41
51
|
|
42
52
|
it "executes the webhook" do
|
43
|
-
expect(PactBroker::Webhooks::Service).to receive(:test_execution).with(webhook)
|
53
|
+
expect(PactBroker::Webhooks::Service).to receive(:test_execution).with(webhook, webhook_options)
|
44
54
|
subject
|
45
55
|
end
|
46
56
|
|
@@ -65,9 +75,9 @@ module PactBroker
|
|
65
75
|
context "when execution is not successful" do
|
66
76
|
let(:success) { false }
|
67
77
|
|
68
|
-
it "returns a
|
78
|
+
it "returns a 200 JSON response" do
|
69
79
|
subject
|
70
|
-
expect(last_response.status).to eq
|
80
|
+
expect(last_response.status).to eq 200
|
71
81
|
end
|
72
82
|
|
73
83
|
it "includes the execution result JSON in the body" do
|
@@ -66,13 +66,15 @@ module PactBroker
|
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "use_custom_ui" do
|
69
|
+
before do
|
70
|
+
app.use_custom_ui(custom_ui)
|
71
|
+
get "/", nil, { "HTTP_ACCEPT" => "text/html" }
|
72
|
+
end
|
73
|
+
|
69
74
|
context "when the UI returns a non 404 response" do
|
70
75
|
let(:custom_ui) { double('ui', call: [200, {}, ["hello"]]) }
|
71
76
|
|
72
77
|
it "returns the given page" do
|
73
|
-
app.use_custom_ui(custom_ui)
|
74
|
-
|
75
|
-
get "/", nil, { "HTTP_ACCEPT" => "text/html" }
|
76
78
|
expect(last_response.body).to eq "hello"
|
77
79
|
end
|
78
80
|
end
|
@@ -81,12 +83,34 @@ module PactBroker
|
|
81
83
|
let(:custom_ui) { double('ui', call: [404, {}, []]) }
|
82
84
|
|
83
85
|
it "passes on the call to the rest of the app" do
|
84
|
-
get "/", nil, { "HTTP_ACCEPT" => "text/html" }
|
85
86
|
expect(last_response.status).to eq 200
|
86
87
|
end
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
91
|
+
describe "use_custom_api" do
|
92
|
+
before do
|
93
|
+
app.use_custom_api(custom_api)
|
94
|
+
get "/", nil, { "HTTP_ACCEPT" => "application/hal+json" }
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when the API returns a non 404 response" do
|
98
|
+
let(:custom_api) { double('api', call: [200, {}, ["hello"]]) }
|
99
|
+
|
100
|
+
it "returns the given resource" do
|
101
|
+
expect(last_response.body).to eq "hello"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when the custom API returns a 404 response" do
|
106
|
+
let(:custom_api) { double('api', call: [404, {}, []]) }
|
107
|
+
|
108
|
+
it "passes on the call to the rest of the app" do
|
109
|
+
expect(last_response.body).to_not eq "hello"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
90
114
|
describe "use_xxx_auth" do
|
91
115
|
class TestAuth
|
92
116
|
def initialize app, *args, &block
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'pact_broker/db/data_migrations/set_latest_version_sequence_value'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module DB
|
5
|
+
module DataMigrations
|
6
|
+
describe SetLatestVersionSequenceValue, data_migration: true do
|
7
|
+
include MigrationHelpers
|
8
|
+
|
9
|
+
describe ".call" do
|
10
|
+
before (:all) do
|
11
|
+
PactBroker::Database.migrate(20190509)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:now) { DateTime.new(2018, 2, 2) }
|
15
|
+
|
16
|
+
subject { SetLatestVersionSequenceValue.call(database) }
|
17
|
+
|
18
|
+
context "when there is no sequence value set" do
|
19
|
+
context "when there are no versions" do
|
20
|
+
it "initializes the sequence value - this is required at start up each time in case someone has changed the ordering configuration (date vs semantic)" do
|
21
|
+
subject
|
22
|
+
expect(database[:version_sequence_number].first[:value]).to eq 100
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when there are pre-existing versions" do
|
27
|
+
let!(:consumer) { create(:pacticipants, {name: 'Consumer', created_at: now, updated_at: now}) }
|
28
|
+
let!(:consumer_version) { create(:versions, {number: '1.2.3', order: 1, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) }
|
29
|
+
let!(:consumer_version) { create(:versions, {number: '1.2.5', order: 3, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) }
|
30
|
+
|
31
|
+
it "initializes the sequence value to the max version order with a margin of error" do
|
32
|
+
subject
|
33
|
+
expect(database[:version_sequence_number].first[:value]).to eq 103
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when a value already exists and it is already higher than the max_order" do
|
39
|
+
before do
|
40
|
+
database[:version_sequence_number].insert(value: 5)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "does not update the value" do
|
44
|
+
subject
|
45
|
+
expect(database[:version_sequence_number].first[:value]).to eq 5
|
46
|
+
expect(database[:version_sequence_number].count).to eq 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when a value already exists and it not higher than the max_order" do
|
51
|
+
before do
|
52
|
+
database[:version_sequence_number].insert(value: 3)
|
53
|
+
end
|
54
|
+
|
55
|
+
let!(:consumer) { create(:pacticipants, {name: 'Consumer', created_at: now, updated_at: now}) }
|
56
|
+
let!(:consumer_version) { create(:versions, {number: '1.2.3', order: 1, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) }
|
57
|
+
let!(:consumer_version) { create(:versions, {number: '1.2.5', order: 3, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) }
|
58
|
+
|
59
|
+
it "updates the value" do
|
60
|
+
subject
|
61
|
+
expect(database[:version_sequence_number].first[:value]).to eq 103
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -24,7 +24,7 @@ describe PactBroker::Domain::OrderVersions do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
context "when order_versions_by_date is true (
|
27
|
+
context "when order_versions_by_date is true (recommended)" do
|
28
28
|
before do
|
29
29
|
allow(PactBroker.configuration).to receive(:order_versions_by_date).and_return(true)
|
30
30
|
end
|
@@ -69,7 +69,6 @@ describe PactBroker::Domain::OrderVersions do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
context "when the new version is considered to be earlier than the previous latest version" do
|
72
|
-
|
73
72
|
before do
|
74
73
|
Sequel::Model.db[:versions].where(number: '2').update(number: 'z')
|
75
74
|
Sequel::Model.db[:versions].where(number: '3').update(number: 'a')
|
@@ -80,8 +79,6 @@ describe PactBroker::Domain::OrderVersions do
|
|
80
79
|
PactBroker::Domain::Version.create(number: '2', pacticipant_id: consumer.id)
|
81
80
|
expect(ordered_versions).to eq(['1', 'z', 'a', '2', '4'])
|
82
81
|
end
|
83
|
-
|
84
82
|
end
|
85
83
|
end
|
86
|
-
|
87
84
|
end
|
@@ -8,8 +8,9 @@ module PactBroker
|
|
8
8
|
let(:request_template) { instance_double(PactBroker::Webhooks::WebhookRequestTemplate, build: request)}
|
9
9
|
let(:request) { instance_double(PactBroker::Domain::WebhookRequest, execute: result) }
|
10
10
|
let(:result) { double('result') }
|
11
|
-
let(:
|
12
|
-
let(:
|
11
|
+
let(:webhook_context) { { some: 'things' } }
|
12
|
+
let(:execution_options) { { other: 'options' } }
|
13
|
+
let(:options) { { webhook_context: webhook_context, execution_options: execution_options } }
|
13
14
|
let(:pact) { double('pact') }
|
14
15
|
let(:verification) { double('verification') }
|
15
16
|
let(:logger) { double('logger').as_null_object }
|
@@ -20,8 +21,8 @@ module PactBroker
|
|
20
21
|
|
21
22
|
subject(:webhook) { Webhook.new(request: request_template, consumer: consumer, provider: provider) }
|
22
23
|
|
23
|
-
describe "
|
24
|
-
subject { webhook.
|
24
|
+
describe "scope_description" do
|
25
|
+
subject { webhook.scope_description }
|
25
26
|
|
26
27
|
context "with a consumer and provider" do
|
27
28
|
it { is_expected.to eq "A webhook for the pact between Consumer and Provider" }
|
@@ -55,12 +56,15 @@ module PactBroker
|
|
55
56
|
let(:execute) { subject.execute pact, verification, options }
|
56
57
|
|
57
58
|
it "builds the request" do
|
58
|
-
expect(request_template).to receive(:build).with(
|
59
|
+
expect(request_template).to receive(:build).with(
|
60
|
+
pact: pact,
|
61
|
+
verification: verification,
|
62
|
+
webhook_context: webhook_context)
|
59
63
|
execute
|
60
64
|
end
|
61
65
|
|
62
66
|
it "executes the request" do
|
63
|
-
expect(request).to receive(:execute).with(
|
67
|
+
expect(request).to receive(:execute).with(execution_options)
|
64
68
|
execute
|
65
69
|
end
|
66
70
|
|
@@ -39,22 +39,22 @@ module PactBroker
|
|
39
39
|
context "with no options specified" do
|
40
40
|
let(:query) { "" }
|
41
41
|
|
42
|
-
it "
|
43
|
-
expect(subject.last).to eq(
|
42
|
+
it "sets the defaults" do
|
43
|
+
expect(subject.last).to eq(limit: "100")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
context "with just one status specified" do
|
48
48
|
let(:query) { "success=true" }
|
49
49
|
it "extracts the one status" do
|
50
|
-
expect(subject.last).to
|
50
|
+
expect(subject.last).to include success: [true]
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
context "with an array of statuses" do
|
55
55
|
let(:query) { "success[]=true&success[]=false&success[]=" }
|
56
56
|
it "extracts the statuses" do
|
57
|
-
expect(subject.last).to
|
57
|
+
expect(subject.last).to include success: [true, false, nil]
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,7 +62,7 @@ module PactBroker
|
|
62
62
|
let(:query) { "success[]=&foo=bar" }
|
63
63
|
|
64
64
|
it "sets an array with a nil success" do
|
65
|
-
expect(subject.last).to
|
65
|
+
expect(subject.last).to include success: [nil]
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -70,7 +70,7 @@ module PactBroker
|
|
70
70
|
let(:query) { "success=&foo=bar" }
|
71
71
|
|
72
72
|
it "sets an array with a nil success" do
|
73
|
-
expect(subject.last).to
|
73
|
+
expect(subject.last).to include success: [nil]
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -86,7 +86,7 @@ module PactBroker
|
|
86
86
|
let(:query) { "q[][pacticipant]=Foo&latest=true" }
|
87
87
|
|
88
88
|
it "returns options with latest true" do
|
89
|
-
expect(subject.last).to
|
89
|
+
expect(subject.last).to include latest: true
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -105,6 +105,14 @@ module PactBroker
|
|
105
105
|
expect(subject.first).to eq [{ pacticipant_name: 'Foo', tag: 'prod' }]
|
106
106
|
end
|
107
107
|
end
|
108
|
+
|
109
|
+
context "when a limit is specified" do
|
110
|
+
let(:query) { "limit=200" }
|
111
|
+
|
112
|
+
it "sets the limit" do
|
113
|
+
expect(subject.last[:limit]).to eq "200"
|
114
|
+
end
|
115
|
+
end
|
108
116
|
end
|
109
117
|
end
|
110
118
|
end
|
@@ -33,7 +33,7 @@ module PactBroker
|
|
33
33
|
let(:provider) { double('provider', id: 2) }
|
34
34
|
let(:version) { double('version', id: 3, pacticipant_id: 1) }
|
35
35
|
let(:existing_pact) { nil }
|
36
|
-
let(:new_pact) { double('new_pact', json_content: json_content) }
|
36
|
+
let(:new_pact) { double('new_pact', consumer_version_tag_names: %[dev], json_content: json_content) }
|
37
37
|
let(:json_content) { { the: "contract" }.to_json }
|
38
38
|
let(:json_content_with_ids) { { the: "contract with ids" }.to_json }
|
39
39
|
let(:previous_pacts) { [] }
|
@@ -47,6 +47,8 @@ module PactBroker
|
|
47
47
|
end
|
48
48
|
let(:content) { double('content') }
|
49
49
|
let(:content_with_interaction_ids) { double('content_with_interaction_ids', to_json: json_content_with_ids) }
|
50
|
+
let(:webhook_options) { { the: 'options'} }
|
51
|
+
let(:outgoing_webhook_options) { { the: 'options', webhook_context: { consumer_version_tags: %[dev] }} }
|
50
52
|
|
51
53
|
before do
|
52
54
|
allow(Content).to receive(:from_json).and_return(content)
|
@@ -54,7 +56,7 @@ module PactBroker
|
|
54
56
|
allow(PactBroker::Pacts::GenerateSha).to receive(:call).and_call_original
|
55
57
|
end
|
56
58
|
|
57
|
-
subject { Service.create_or_update_pact(params) }
|
59
|
+
subject { Service.create_or_update_pact(params, webhook_options) }
|
58
60
|
|
59
61
|
context "when no pact exists with the same params" do
|
60
62
|
it "creates the sha before adding the interaction ids" do
|
@@ -69,13 +71,19 @@ module PactBroker
|
|
69
71
|
end
|
70
72
|
|
71
73
|
it "triggers webhooks" do
|
72
|
-
expect(webhook_trigger_service).to receive(:trigger_webhooks_for_new_pact).with(new_pact)
|
74
|
+
expect(webhook_trigger_service).to receive(:trigger_webhooks_for_new_pact).with(new_pact, outgoing_webhook_options)
|
73
75
|
subject
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
79
|
context "when a pact exists with the same params" do
|
78
|
-
let(:existing_pact)
|
80
|
+
let(:existing_pact) do
|
81
|
+
double('existing_pact',
|
82
|
+
id: 4,
|
83
|
+
consumer_version_tag_names: %[dev],
|
84
|
+
json_content: { the: "contract" }.to_json
|
85
|
+
)
|
86
|
+
end
|
79
87
|
|
80
88
|
it "creates the sha before adding the interaction ids" do
|
81
89
|
expect(PactBroker::Pacts::GenerateSha).to receive(:call).ordered
|
@@ -89,7 +97,7 @@ module PactBroker
|
|
89
97
|
end
|
90
98
|
|
91
99
|
it "triggers webhooks" do
|
92
|
-
expect(webhook_trigger_service).to receive(:trigger_webhooks_for_updated_pact).with(existing_pact, new_pact)
|
100
|
+
expect(webhook_trigger_service).to receive(:trigger_webhooks_for_updated_pact).with(existing_pact, new_pact, outgoing_webhook_options)
|
93
101
|
subject
|
94
102
|
end
|
95
103
|
end
|