From 71844f0fc37fd22cb2dbc40e746ca4bd453b9c60 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 11 Nov 2021 12:35:39 +1100 Subject: [PATCH] fix: handle conflict check for pacts where the interactions are missing in one or the other --- lib/pact_broker/pacts/merger.rb | 12 ++++++++---- spec/lib/pact_broker/pacts/merger_spec.rb | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) 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)