Skip to content

Commit

Permalink
fix(metrics): correct the query for pactRevisionsPerConsumerVersion
Browse files Browse the repository at this point in the history
PACT-1606
  • Loading branch information
bethesque committed Jan 5, 2024
1 parent 9830afc commit f76b993
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/pact_broker/metrics/service.rb
Expand Up @@ -101,8 +101,8 @@ def interactions_counts
end

def pact_revision_counts
query = "select revision_count as number_of_revisions, count(consumer_version_id) as consumer_version_count
from (select consumer_version_id, count(*) as revision_count from pact_publications group by consumer_version_id) foo
query = "select revision_count as number_of_revisions, count(*) as consumer_version_count
from (select count(*) as revision_count from pact_publications group by consumer_version_id, provider_id) foo
group by revision_count
order by 1"
PactBroker::Pacts::PactPublication.db[query].all.each_with_object({}) { |row, hash| hash[row[:number_of_revisions]] = row[:consumer_version_count] }
Expand Down
7 changes: 5 additions & 2 deletions spec/lib/pact_broker/metrics/service_spec.rb
Expand Up @@ -121,20 +121,23 @@ module Service

describe "pactRevisionsPerPactPublication" do
before do
td.create_pact_with_hierarchy
td.create_pact_with_hierarchy("Foo", "1", "Bar")
.comment("this consumer version will have 3 revisions")
.revise_pact
.revise_pact
.create_consumer_version
.create_pact
.comment("this consumer version will have 1 revision")
.revise_pact
.create_pact_with_hierarchy("Foo", "1", "Bar2", td.random_json_content("Foo", "Bar2"))
.create_pact_with_hierarchy("Foo", "2", "Bar", td.random_json_content("Foo", "Bar"))
end

let(:distribution) { subject[:pactRevisionsPerConsumerVersion][:distribution] }

it "returns a distribution of pact revisions per consumer version" do
expect(distribution).to eq(2 => 1, 3 => 1)
# numberOfRevisions => countOfPactsWithThisNumberOfRevisions
expect(distribution).to eq({ 1 => 2, 2 => 1, 3 => 1 })
end
end
end
Expand Down

0 comments on commit f76b993

Please sign in to comment.