-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard api): include verification tags
- Loading branch information
Showing
14 changed files
with
234 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Sequel.migration do | ||
change do | ||
# the provider version order of the latest verification for each consumer/provider/tag | ||
create_view(:latest_tagged_verification_provider_version_orders, | ||
" | ||
select m.consumer_id, m.provider_id, t.name as tag_name, max(m.provider_version_order) as latest_provider_version_order | ||
from latest_matrix m | ||
inner join tags t | ||
on m.provider_version_id = t.version_id | ||
where m.provider_version_order is not null | ||
group by m.consumer_id, m.provider_id, t.name | ||
" | ||
) | ||
|
||
=begin | ||
The tags for which the given verification is the latest of that tag | ||
Imagine that: | ||
provider v1 has verification | ||
has tag dev | ||
has tag prod <- latest | ||
provider v2 has verification | ||
has tag dev <-latest | ||
provider v3 has tag dev | ||
This table would contain the prod tag row for the v1 verification | ||
This table would contain the dev tag row for the v2 verification | ||
=end | ||
create_view(:latest_verification_tags, | ||
" | ||
select t.*, m.verification_id | ||
from latest_matrix m | ||
inner join latest_tagged_verification_provider_version_orders l | ||
on m.consumer_id = l.consumer_id | ||
and m.provider_id = l.provider_id | ||
and m.provider_version_order = l.latest_provider_version_order | ||
inner join tags t | ||
on l.tag_name = t.name | ||
and m.provider_version_id = t.version_id | ||
" | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'pact_broker/db' | ||
require 'pact_broker/repositories/helpers' | ||
|
||
module PactBroker | ||
module Tags | ||
# The tag associated with the latest verification for a given tag | ||
class LatestVerificationTag < Sequel::Model | ||
|
||
dataset_module do | ||
include PactBroker::Repositories::Helpers | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
spec/migrations/20180123_create_latest_verification_tags_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
describe 'latest tagged verifications', migration: true do | ||
before do | ||
PactBroker::Database.migrate(20180123) | ||
end | ||
|
||
let(:now) { DateTime.new(2018, 2, 2) } | ||
let!(:consumer) { create(:pacticipants, {name: 'C', created_at: now, updated_at: now}) } | ||
let!(:provider) { create(:pacticipants, {name: 'P', created_at: now, updated_at: now}) } | ||
let!(:consumer_version_1) { create(:versions, {number: '1', order: 1, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) } | ||
let!(:consumer_version_2) { create(:versions, {number: '2', order: 2, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) } | ||
|
||
let!(:provider_version_1) { create(:versions, {number: '1', order: 1, pacticipant_id: provider[:id], created_at: now, updated_at: now}) } | ||
let!(:provider_version_2) { create(:versions, {number: '2', order: 2, pacticipant_id: provider[:id], created_at: now, updated_at: now}) } | ||
let!(:provider_version_3) { create(:versions, {number: '3', order: 3, pacticipant_id: provider[:id], created_at: now, updated_at: now}) } | ||
|
||
let!(:provider_version_1_prod_tag) { create(:tags, {version_id: provider_version_1[:id], name: 'prod', created_at: now, updated_at: now}, nil) } | ||
let!(:provider_version_1_dev_tag) { create(:tags, {version_id: provider_version_1[:id], name: 'dev', created_at: now, updated_at: now}, nil) } | ||
let!(:provider_version_2_dev_tag) { create(:tags, {version_id: provider_version_2[:id], name: 'dev', created_at: now, updated_at: now}, nil) } | ||
|
||
let!(:pact_version_1) { create(:pact_versions, {content: {some: 'json'}.to_json, sha: '1', consumer_id: consumer[:id], provider_id: provider[:id], created_at: now}) } | ||
let!(:pact_version_2) { create(:pact_versions, {content: {some: 'json other'}.to_json, sha: '2', consumer_id: consumer[:id], provider_id: provider[:id], created_at: now}) } | ||
#let!(:pact_version_3) { create(:pact_versions, {content: {some: 'json more'}.to_json, sha: '3', consumer_id: consumer[:id], provider_id: provider[:id], created_at: now}) } | ||
let!(:pact_publication_1) do | ||
create(:pact_publications, { | ||
consumer_version_id: consumer_version_1[:id], | ||
provider_id: provider[:id], | ||
revision_number: 1, | ||
pact_version_id: pact_version_1[:id], | ||
created_at: now | ||
}) | ||
end | ||
|
||
let!(:pact_publication_2) do | ||
create(:pact_publications, { | ||
consumer_version_id: consumer_version_2[:id], | ||
provider_id: provider[:id], | ||
revision_number: 1, | ||
pact_version_id: pact_version_2[:id], | ||
created_at: now | ||
}) | ||
end | ||
|
||
# provider v1 | ||
let!(:verification_1) do | ||
create(:verifications, { | ||
number: 1, | ||
success: true, | ||
provider_version_id: provider_version_1[:id], | ||
pact_version_id: pact_version_1[:id], | ||
execution_date: now, | ||
created_at: now | ||
}) | ||
end | ||
|
||
# provider v2 | ||
let!(:verification_2) do | ||
create(:verifications, { | ||
number: 2, | ||
success: true, | ||
provider_version_id: provider_version_2[:id], | ||
pact_version_id: pact_version_1[:id], | ||
execution_date: now, | ||
created_at: now | ||
}) | ||
end | ||
|
||
# provider v2 | ||
let!(:verification_3) do | ||
create(:verifications, { | ||
number: 3, | ||
success: true, | ||
provider_version_id: provider_version_2[:id], | ||
pact_version_id: pact_version_1[:id], | ||
execution_date: now, | ||
created_at: now | ||
}) | ||
end | ||
|
||
it "includes the tag rows for which the related verification is the latest of that tag" do | ||
rows = database[:latest_verification_tags].all | ||
expect(rows).to contain_hash(verification_id: verification_1[:id], name: 'prod') | ||
expect(rows).to contain_hash(verification_id: verification_3[:id], name: 'dev') | ||
expect(rows.size).to eq 2 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters