-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hal+json endpoint for listing integrations
- Loading branch information
Showing
9 changed files
with
164 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Sequel.migration do | ||
up do | ||
create_view(:integrations, | ||
from(:pact_publications) | ||
.select( | ||
:consumer_id, | ||
Sequel[:c][:name].as(:consumer_name), | ||
:provider_id, | ||
Sequel[:p][:name].as(:provider_name) | ||
).distinct | ||
.join(:pacticipants, {:id => :consumer_id}, {:table_alias => :c, implicit_qualifier: :pact_publications}) | ||
.join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pact_publications}) | ||
|
||
) | ||
end | ||
|
||
down do | ||
drop_view(:integrations) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require_relative 'base_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
class IntegrationDecorator < BaseDecorator | ||
property :consumer do | ||
property :name | ||
end | ||
|
||
property :provider do | ||
property :name | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require_relative 'base_decorator' | ||
require_relative 'integration_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
class IntegrationsDecorator < BaseDecorator | ||
collection :entries, as: :integrations, embedded: true, :extend => PactBroker::Api::Decorators::IntegrationDecorator | ||
|
||
link :self do | context | | ||
{ | ||
href: context[:resource_url], | ||
title: "All integrations" | ||
} | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'pact_broker/db' | ||
|
||
module PactBroker | ||
module Integrations | ||
class Integration < Sequel::Model | ||
associate(:many_to_one, :consumer, :class => "PactBroker::Domain::Pacticipant", :key => :consumer_id, :primary_key => :id) | ||
associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
describe "Get integrations dot file" do | ||
before do | ||
TestDataBuilder.new | ||
.create_pact_with_hierarchy("Foo", "1", "Bar") | ||
end | ||
|
||
let(:path) { "/integrations" } | ||
let(:response_body_hash) { JSON.parse(subject.body, symbolize_names: true) } | ||
|
||
subject { get path, nil, {'HTTP_ACCEPT' => 'application/hal+json' } } | ||
|
||
it { is_expected.to be_a_hal_json_success_response } | ||
|
||
it "returns a json body with embedded integrations" do | ||
expect(JSON.parse(subject.body)["_embedded"]["integrations"]).to be_a(Array) | ||
end | ||
end |
37 changes: 37 additions & 0 deletions
37
spec/lib/pact_broker/api/decorators/integration_decorator_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,37 @@ | ||
require 'pact_broker/api/decorators/integration_decorator' | ||
require 'pact_broker/integrations/integration' | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
describe IntegrationDecorator do | ||
let(:integration) do | ||
instance_double(PactBroker::Integrations::Integration, | ||
consumer: consumer, | ||
provider: provider | ||
) | ||
end | ||
let(:consumer) { double("consumer", name: "the consumer") } | ||
let(:provider) { double("provider", name: "the provider") } | ||
|
||
let(:expected_hash) do | ||
{ | ||
"consumer" => { | ||
"name" => "the consumer" | ||
}, | ||
"provider" => { | ||
"name" => "the provider" | ||
} | ||
} | ||
end | ||
|
||
let(:json) { IntegrationDecorator.new(integration).to_json } | ||
subject { JSON.parse(json) } | ||
|
||
it "generates a hash" do | ||
expect(subject).to match_pact expected_hash | ||
end | ||
end | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
spec/lib/pact_broker/api/decorators/integrations_decorator_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,29 @@ | ||
require 'pact_broker/api/decorators/integrations_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
describe IntegrationsDecorator do | ||
before do | ||
allow(IntegrationDecorator).to receive(:new).and_return(integration_decorator) | ||
end | ||
let(:integration_decorator) { instance_double(IntegrationDecorator).as_null_object } | ||
let(:integration) { double('integration') } | ||
let(:integrations_decorator) { IntegrationsDecorator.new([integration]) } | ||
let(:options) { { user_options: { resource_url: 'http://example.org/integrations' } } } | ||
|
||
let(:json) { integrations_decorator.to_json(options) } | ||
|
||
subject { JSON.parse(json) } | ||
|
||
it "includes a list of integrations" do | ||
expect(subject["_embedded"]["integrations"]).to be_an(Array) | ||
end | ||
|
||
it "includes a link to itself" do | ||
expect(subject["_links"]["self"]["href"]).to eq "http://example.org/integrations" | ||
end | ||
end | ||
end | ||
end | ||
end |