Skip to content

Commit

Permalink
fix: correctly handle new test results format when merging test resul…
Browse files Browse the repository at this point in the history
…ts with pact contents
  • Loading branch information
bethesque committed Aug 12, 2020
1 parent df95f64 commit b35ab71
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/pact_broker/pacts/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions spec/lib/pact_broker/pacts/content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b35ab71

Please sign in to comment.