diff --git a/lib/pact_broker/pacts/merger.rb b/lib/pact_broker/pacts/merger.rb index 84a99c74a..8a82b6d1b 100644 --- a/lib/pact_broker/pacts/merger.rb +++ b/lib/pact_broker/pacts/merger.rb @@ -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 diff --git a/spec/lib/pact_broker/pacts/merger_spec.rb b/spec/lib/pact_broker/pacts/merger_spec.rb index ca0a248ab..f87123bb3 100644 --- a/spec/lib/pact_broker/pacts/merger_spec.rb +++ b/spec/lib/pact_broker/pacts/merger_spec.rb @@ -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)