Skip to content

Commit

Permalink
feat: rename writeMode to onConflict for contract publishing endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 29, 2021
1 parent b74d8b7 commit 26a4e35
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/contracts/publish_contracts_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/pact_broker/contracts/contract_to_publish.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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?
specification == "pact"
end

def merge?
write_mode == "merge"
on_conflict == "merge"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/doc/views/index/publish-contracts.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -38,7 +38,7 @@ The previous tag and pact endpoints are still supported, however, future feature
"specification": "pact",
"contentType": "application/json",
"content": "<base64 encoded JSON pact>",
"writeMode": "overwrite"
"onConflict": "overwrite"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion spec/features/publish_pact_all_in_one_approval_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:specification => "pact",
:contentType => "application/json",
:content => encoded_contract,
:writeMode => "overwrite",
:onConflict => "overwrite",
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion spec/features/publish_pact_all_in_one_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:specification => "pact",
:contentType => "application/json",
:content => encoded_contract,
:writeMode => "overwrite",
:onConflict => "overwrite",
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"specification": "pact",
"contentType": "application/json",
"content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=",
"writeMode": "overwrite"
"onConflict": "overwrite"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"specification": "pact",
"contentType": "application/json",
"content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=",
"writeMode": "overwrite"
"onConflict": "overwrite"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"specification": "pact",
"contentType": "application/json",
"content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=",
"writeMode": "overwrite"
"onConflict": "overwrite"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"specification": "pact",
"contentType": "application/json",
"content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=",
"writeMode": "overwrite"
"onConflict": "overwrite"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"specification": "pact",
"contentType": "application/json",
"content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbXX0=",
"writeMode": "overwrite"
"onConflict": "overwrite"
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/pact_broker/contracts/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +23,7 @@ module Contracts
provider_name: "Bar",
decoded_content: decoded_contract,
specification: "pact",
write_mode: write_mode
on_conflict: on_conflict
)
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 26a4e35

Please sign in to comment.