diff --git a/lib/pact_broker/pacts/content.rb b/lib/pact_broker/pacts/content.rb index a82dc272e..8b42a46f7 100644 --- a/lib/pact_broker/pacts/content.rb +++ b/lib/pact_broker/pacts/content.rb @@ -38,10 +38,17 @@ def interactions_missing_test_results end end + def with_test_results(test_results) - tests = test_results && test_results['tests'] - if tests.nil? || !tests.is_a?(Array) || tests.empty? - tests = [] + # new format + if test_results.is_a?(Array) + tests = test_results + else + # old format + tests = test_results && test_results['tests'] + if tests.nil? || !tests.is_a?(Array) || tests.empty? + tests = [] + end end new_pact_hash = pact_hash.dup @@ -130,7 +137,15 @@ def merge_verification_results(interactions, tests) end def test_is_for_interaction(interaction, test) - test.is_a?(Hash) && interaction.is_a?(Hash) && test['interactionDescription'] == interaction['description'] && test['interactionProviderState'] == interaction['providerState'] + test.is_a?(Hash) && interaction.is_a?(Hash) && ( interaction_ids_match(interaction, test) || description_and_state_match(interaction, test)) + end + + def interaction_ids_match(interaction, test) + interaction['_id'] && interaction['_id'] == test['interactionId'] + end + + def description_and_state_match(interaction, test) + test['interactionDescription'] && test['interactionDescription'] == interaction['description'] && test['interactionProviderState'] == interaction['providerState'] end end end diff --git a/spec/lib/pact_broker/pacts/content_spec.rb b/spec/lib/pact_broker/pacts/content_spec.rb index 051f2a6ab..50d9748d6 100644 --- a/spec/lib/pact_broker/pacts/content_spec.rb +++ b/spec/lib/pact_broker/pacts/content_spec.rb @@ -359,6 +359,53 @@ module Pacts expect(subject.to_hash).to eq merged_with_empty_tests end end + + context "with the new format" do + let(:test_results) do + [ + { + "interactionId" => "1", + "success "=> false + },{ + "foo" => "bar" + } + ] + end + + let(:pact_content) do + { + "interactions" => [ + { + "_id" => "1" + }, + { + "_id" => "2" + } + ] + } + end + + let(:merged) do + { + "interactions" => [ + { + "_id" => "1", + "tests" => [{ + "interactionId" => "1", + "success "=> false + }] + },{ + "_id" => "2", + "tests" => [] + } + ] + } + end + + it "merges the tests into the pact content" do + expect(subject.to_hash).to eq merged + end + end end end end