Skip to content

Commit

Permalink
fix: correct logic for finding latest verification for revised pacts
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 3, 2018
1 parent 0704772 commit 8fb28ee
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
3 changes: 1 addition & 2 deletions lib/pact_broker/domain/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def verification_number number

def tag tag_name
filter = name_like(Sequel.qualify(:tags, :name), tag_name)
join(:pact_publications, {pact_version_id: :pact_version_id})
.join(:tags, {version_id: :consumer_version_id}).where(filter)
join(:tags, { version_id: :consumer_version_id }).where(filter)
end

def untagged
Expand Down
6 changes: 3 additions & 3 deletions lib/pact_broker/verifications/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ def find_latest_verification_for_tags consumer_name, provider_name, consumer_ver
query = PactBroker::Verifications::AllVerifications
.select_all_qualified
.join(:versions, {Sequel[:provider_versions][:id] => Sequel[view_name][:provider_version_id]}, {table_alias: :provider_versions})
.join(:all_pact_publications, { Sequel[view_name][:pact_version_id] => Sequel[:all_pact_publications][:pact_version_id] })
.join(:latest_pact_publications_by_consumer_versions, { Sequel[view_name][:pact_version_id] => Sequel[:latest_pact_publications_by_consumer_versions][:pact_version_id] })
.consumer(consumer_name)
.provider(provider_name)
.tag(consumer_version_tag)
.provider_version_tag(provider_version_tag)

query.reverse_order(
Sequel[:all_pact_publications][:consumer_version_order],
Sequel[:all_pact_publications][:revision_number],
Sequel[:latest_pact_publications_by_consumer_versions][:consumer_version_order],
Sequel[:latest_pact_publications_by_consumer_versions][:revision_number],
Sequel[:provider_versions][:order],
Sequel[view_name][:execution_date]
).limit(1).single_record
Expand Down
61 changes: 44 additions & 17 deletions spec/lib/pact_broker/verifications/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,53 @@ module Verifications
end

describe "find_latest_verification_for_tags" do
before do
TestDataBuilder.new
.create_pact_with_hierarchy("Foo", "1", "Bar")
.create_consumer_version_tag("feat-x")
.create_verification(provider_version: "5")
.use_provider_version("5")
.create_provider_version_tag("feat-y")
.create_verification(provider_version: "6", number: 2)
.use_provider_version("6")
.create_provider_version_tag("feat-y")
.create_verification(provider_version: "7", number: 3)
.create_consumer_version("2")
.create_pact
.create_verification(provider_version: "8")
context "with no revisions" do
before do
TestDataBuilder.new
.create_pact_with_hierarchy("Foo", "1", "Bar")
.create_consumer_version_tag("feat-x")
.create_verification(provider_version: "5")
.use_provider_version("5")
.create_provider_version_tag("feat-y")
.create_verification(provider_version: "6", number: 2)
.use_provider_version("6")
.create_provider_version_tag("feat-y")
.create_verification(provider_version: "7", number: 3)
.create_consumer_version("2")
.create_pact
.create_verification(provider_version: "8")
end

subject { Repository.new.find_latest_verification_for_tags("Foo", "Bar", "feat-x", "feat-y") }

it "returns the latest verification for a pact with the given consumer tag, by a provider version with the given provider tag" do
expect(subject.provider_version_number).to eq "6"
end
end

subject { Repository.new.find_latest_verification_for_tags("Foo", "Bar", "feat-x", "feat-y") }
context "when a verification exists for a pact revision that was then overwritten by a new revision of the pact" do
let(:content_1) { { content: 1 }.to_json }
let(:content_2) { { content: 2 }.to_json }

before do
TestDataBuilder.new
.create_pact_with_hierarchy("Foo", "1", "Bar", content_1)
.create_consumer_version_tag("develop")
.create_verification(provider_version: "5", number: 1, tag_name: "develop", comment: "not this because pact revised")
.create_verification(provider_version: "6", number: 2, tag_name: "develop", comment: "not this because pact revised")
.revise_pact(content_2)
.create_verification(provider_version: "1", number: 1, tag_name: "develop", comment: "not this because later one exists")
.create_verification(provider_version: "2", number: 2, tag_name: "develop", comment: "this one!")
.create_consumer_version("2")
.create_pact(json_content: content_1)
end

subject { Repository.new.find_latest_verification_for_tags("Foo", "Bar", "develop", "develop") }

it "returns the latest verification for a pact with the given consumer tag, by a provider version with the given provider tag" do
expect(subject.provider_version_number).to eq "6"
it "returns the latest verification " do
expect(subject.provider_version_number).to eq "2"
expect(subject.number).to eq 2
end
end
end
end
Expand Down

0 comments on commit 8fb28ee

Please sign in to comment.