From 26a4e358f7a4f6a5c40e7c540ee72208b1d58534 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sat, 29 May 2021 16:55:55 +1000 Subject: [PATCH] feat: rename writeMode to onConflict for contract publishing endpoint --- lib/pact_broker/api/contracts/publish_contracts_schema.rb | 2 +- .../api/decorators/publish_contract_decorator.rb | 2 +- lib/pact_broker/contracts/contract_to_publish.rb | 8 ++++---- .../doc/views/index/publish-contracts.markdown | 4 ++-- spec/features/publish_pact_all_in_one_approval_spec.rb | 2 +- spec/features/publish_pact_all_in_one_spec.rb | 2 +- .../approvals/publish_contract_no_branch.approved.json | 2 +- .../publish_contract_nothing_exists.approved.json | 2 +- ...ish_contract_nothing_exists_with_webhook.approved.json | 2 +- ...ish_contract_verification_already_exists.approved.json | 2 +- .../publish_contract_with_validation_error.approved.json | 2 +- spec/lib/pact_broker/contracts/service_spec.rb | 8 ++++---- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/pact_broker/api/contracts/publish_contracts_schema.rb b/lib/pact_broker/api/contracts/publish_contracts_schema.rb index a2dd42682..3b45849f9 100644 --- a/lib/pact_broker/api/contracts/publish_contracts_schema.rb +++ b/lib/pact_broker/api/contracts/publish_contracts_schema.rb @@ -29,7 +29,7 @@ class PublishContractsSchema required(:content).filled(:str?) required(:contentType).filled(included_in?: ["application/json"]) required(:specification).filled(included_in?: ["pact"]) - optional(:writeMode).filled(included_in?:["overwrite", "merge"]) + optional(:onConflict).filled(included_in?:["overwrite", "merge"]) end end diff --git a/lib/pact_broker/api/decorators/publish_contract_decorator.rb b/lib/pact_broker/api/decorators/publish_contract_decorator.rb index 1bbbaf311..096ec4f34 100644 --- a/lib/pact_broker/api/decorators/publish_contract_decorator.rb +++ b/lib/pact_broker/api/decorators/publish_contract_decorator.rb @@ -12,7 +12,7 @@ class PublishContractDecorator < BaseDecorator property :specification property :content_type property :decoded_content - property :write_mode, default: "overwrite" + property :on_conflict, default: "overwrite" end end end diff --git a/lib/pact_broker/contracts/contract_to_publish.rb b/lib/pact_broker/contracts/contract_to_publish.rb index 223beaafa..f6367842d 100644 --- a/lib/pact_broker/contracts/contract_to_publish.rb +++ b/lib/pact_broker/contracts/contract_to_publish.rb @@ -1,8 +1,8 @@ module PactBroker module Contracts - ContractToPublish = Struct.new(:consumer_name, :provider_name, :decoded_content, :content_type, :specification, :write_mode) do - def self.from_hash(consumer_name: nil, provider_name: nil, decoded_content: nil, content_type: nil, specification: nil, write_mode: nil) - new(consumer_name, provider_name, decoded_content, content_type, specification, write_mode) + ContractToPublish = Struct.new(:consumer_name, :provider_name, :decoded_content, :content_type, :specification, :on_conflict) do + def self.from_hash(consumer_name: nil, provider_name: nil, decoded_content: nil, content_type: nil, specification: nil, on_conflict: nil) + new(consumer_name, provider_name, decoded_content, content_type, specification, on_conflict) end def pact? @@ -10,7 +10,7 @@ def pact? end def merge? - write_mode == "merge" + on_conflict == "merge" end end end diff --git a/lib/pact_broker/doc/views/index/publish-contracts.markdown b/lib/pact_broker/doc/views/index/publish-contracts.markdown index cd4c83d6e..41c86bf8a 100644 --- a/lib/pact_broker/doc/views/index/publish-contracts.markdown +++ b/lib/pact_broker/doc/views/index/publish-contracts.markdown @@ -20,7 +20,7 @@ The previous tag and pact endpoints are still supported, however, future feature * `specification`: currently, only contracts of type "pact" are supported, but this will be extended in the future. Required. * `contentType`: currently, only contracts with a content type of "application/json" are supported. Required. * `content`: the content of the contract. Must be Base64 encoded. Required. - * `writeMode`: Allowed values are `overwrite`|`merge`. Optional. Defaults to `overwrite`. When `merge` is specified, the interactions are merged into any pre-existing pact for the same consumer/provider/consumer version. This is required when the tests that generate pact files are split over multiple nodes. + * `onConflict`: Specifies the action to take when a contract for this consumer version already exists with different content. Allowed values are `overwrite`|`merge`. Optional. Defaults to `overwrite`. When `merge` is specified, the interactions are merged into any pre-existing pact. This is required when the tests that generate pact files are split over multiple nodes. ## Example @@ -38,7 +38,7 @@ The previous tag and pact endpoints are still supported, however, future feature "specification": "pact", "contentType": "application/json", "content": "", - "writeMode": "overwrite" + "onConflict": "overwrite" } ] } diff --git a/spec/features/publish_pact_all_in_one_approval_spec.rb b/spec/features/publish_pact_all_in_one_approval_spec.rb index 300089fc2..7adea8318 100644 --- a/spec/features/publish_pact_all_in_one_approval_spec.rb +++ b/spec/features/publish_pact_all_in_one_approval_spec.rb @@ -14,7 +14,7 @@ :specification => "pact", :contentType => "application/json", :content => encoded_contract, - :writeMode => "overwrite", + :onConflict => "overwrite", } ] } diff --git a/spec/features/publish_pact_all_in_one_spec.rb b/spec/features/publish_pact_all_in_one_spec.rb index 33dc52506..a91a03ec5 100644 --- a/spec/features/publish_pact_all_in_one_spec.rb +++ b/spec/features/publish_pact_all_in_one_spec.rb @@ -14,7 +14,7 @@ :specification => "pact", :contentType => "application/json", :content => encoded_contract, - :writeMode => "overwrite", + :onConflict => "overwrite", } ] } diff --git a/spec/fixtures/approvals/publish_contract_no_branch.approved.json b/spec/fixtures/approvals/publish_contract_no_branch.approved.json index 98c2abb3d..101951124 100644 --- a/spec/fixtures/approvals/publish_contract_no_branch.approved.json +++ b/spec/fixtures/approvals/publish_contract_no_branch.approved.json @@ -21,7 +21,7 @@ "specification": "pact", "contentType": "application/json", "content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=", - "writeMode": "overwrite" + "onConflict": "overwrite" } ] } diff --git a/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json b/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json index bf41fb2ba..4d43f43ea 100644 --- a/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +++ b/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json @@ -21,7 +21,7 @@ "specification": "pact", "contentType": "application/json", "content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=", - "writeMode": "overwrite" + "onConflict": "overwrite" } ] } diff --git a/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json b/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json index 5fa949773..f7e6f5651 100644 --- a/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +++ b/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json @@ -21,7 +21,7 @@ "specification": "pact", "contentType": "application/json", "content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=", - "writeMode": "overwrite" + "onConflict": "overwrite" } ] } diff --git a/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json b/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json index c5865d2f0..573f2bede 100644 --- a/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +++ b/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json @@ -21,7 +21,7 @@ "specification": "pact", "contentType": "application/json", "content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=", - "writeMode": "overwrite" + "onConflict": "overwrite" } ] } diff --git a/spec/fixtures/approvals/publish_contract_with_validation_error.approved.json b/spec/fixtures/approvals/publish_contract_with_validation_error.approved.json index b10cd72a7..cdc8e68a7 100644 --- a/spec/fixtures/approvals/publish_contract_with_validation_error.approved.json +++ b/spec/fixtures/approvals/publish_contract_with_validation_error.approved.json @@ -20,7 +20,7 @@ "specification": "pact", "contentType": "application/json", "content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=", - "writeMode": "overwrite" + "onConflict": "overwrite" } ] } diff --git a/spec/lib/pact_broker/contracts/service_spec.rb b/spec/lib/pact_broker/contracts/service_spec.rb index 2795b873b..62dcea298 100644 --- a/spec/lib/pact_broker/contracts/service_spec.rb +++ b/spec/lib/pact_broker/contracts/service_spec.rb @@ -14,7 +14,7 @@ module Contracts ) end - let(:write_mode) { "overwrite" } + let(:on_conflict) { "overwrite" } let(:branch) { "main" } let(:contracts) { [contract_1] } let(:contract_1) do @@ -23,7 +23,7 @@ module Contracts provider_name: "Bar", decoded_content: decoded_contract, specification: "pact", - write_mode: write_mode + on_conflict: on_conflict ) end @@ -54,7 +54,7 @@ module Contracts end context "when the write mode is merge" do - let(:write_mode) { "merge" } + let(:on_conflict) { "merge" } it "returns an info message" do expect(subject.notices.find{ |log| log.type == "success" && log.text.include?(" published ") }).to_not be nil @@ -95,7 +95,7 @@ module Contracts end context "when the write mode is merge" do - let(:write_mode) { "merge" } + let(:on_conflict) { "merge" } it "returns an info message" do expect(subject.notices.find{ |log| log.type == "success" && log.text.include?("merged") }).to_not be nil