Skip to content

Commit

Permalink
fix: handle conflict check for pacts where the interactions are missi…
Browse files Browse the repository at this point in the history
…ng in one or the other
  • Loading branch information
bethesque committed Nov 11, 2021
1 parent 1aaea9a commit 71844f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/pact_broker/pacts/merger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ module Merger
def conflict? original_json, additional_json
original, additional = [original_json, additional_json].map{|str| JSON.parse(str, PACT_PARSING_OPTIONS) }

additional["interactions"].any? do |new_interaction|
original["interactions"].any? do |original_interaction|
same_description_and_state?(original_interaction, new_interaction) &&
!same_request_properties?(original_interaction["request"], new_interaction["request"])
if original["interactions"].nil? || additional["interactions"].nil?
true
else
additional["interactions"].any? do |new_interaction|
original["interactions"].any? do |original_interaction|
same_description_and_state?(original_interaction, new_interaction) &&
!same_request_properties?(original_interaction["request"], new_interaction["request"])
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/pact_broker/pacts/merger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ def merge_pacts(a, b, return_hash = true)
pact_to_compare["interactions"][0]["request"]["headers"].delete("Content-Type")
expect(compare_pacts(example_pact, pact_to_compare)).to eq true
end

it "returns true if the existing pact has no interactions and the new one does" do
example_pact["interactions"] = nil
expect(compare_pacts(example_pact, pact_to_compare)).to eq true
end

it "returns true if the new pact has no interactions and the existing one does" do
pact_to_compare["interactions"] = nil
expect(compare_pacts(example_pact, pact_to_compare)).to eq true
end
end

def compare_pacts(a, b)
Expand Down

0 comments on commit 71844f0

Please sign in to comment.