-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pagination and filtering for integrations endpoint
#622 PACT-1070
- Loading branch information
Showing
14 changed files
with
243 additions
and
77 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 |
---|---|---|
|
@@ -40,3 +40,4 @@ class IntegrationDecorator < BaseDecorator | |
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,15 @@ | ||
module PactBroker | ||
module Api | ||
module Resources | ||
module FilterMethods | ||
def filter_options | ||
if request.query.has_key?("q") | ||
{ query_string: request.query["q"] } | ||
else | ||
{} | ||
end | ||
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
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 |
---|---|---|
@@ -1,17 +1,47 @@ | ||
describe "Get integrations dot file" do | ||
describe "Get integrations" do | ||
before do | ||
td.create_pact_with_hierarchy("Foo", "1", "Bar") | ||
.create_verification(provider_version: "2") | ||
td.create_consumer("Foo") | ||
.create_provider("Bar") | ||
.create_integration | ||
.create_consumer("Apple") | ||
.create_provider("Pear") | ||
.create_integration | ||
.create_consumer("Dog") | ||
.create_provider("Cat") | ||
.create_integration | ||
end | ||
|
||
let(:path) { "/integrations" } | ||
let(:response_body_hash) { JSON.parse(subject.body, symbolize_names: true) } | ||
|
||
subject { get path, nil, {"HTTP_ACCEPT" => "application/hal+json" } } | ||
let(:query) { nil } | ||
let(:response_body_hash) { JSON.parse(subject.body) } | ||
subject { get path, query, {"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) | ||
expect(response_body_hash["_embedded"]["integrations"]).to be_a(Array) | ||
end | ||
|
||
context "with pagination options" do | ||
let(:query) { { "pageSize" => "2", "pageNumber" => "1" } } | ||
|
||
it_behaves_like "a paginated response" | ||
end | ||
|
||
context "with a query string" do | ||
let(:query) { { "q" => "pp" } } | ||
|
||
it "returns only the integrations with a consumer or provider name including the given string" do | ||
expect(response_body_hash["_embedded"]["integrations"]).to contain_exactly(hash_including("consumer" => hash_including("name" => "Apple"))) | ||
end | ||
end | ||
|
||
context "as a dot file" do | ||
subject { get path, query, {"HTTP_ACCEPT" => "text/vnd.graphviz" } } | ||
|
||
it "returns a dot file" do | ||
expect(subject.body).to include "digraph" | ||
expect(subject.body).to include "Foo -> Bar" | ||
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,58 @@ | ||
require "pact_broker/api/resources/integrations" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe Integrations do | ||
describe "GET" do | ||
before do | ||
allow_any_instance_of(described_class).to receive(:integration_service).and_return(integration_service) | ||
allow(integration_service).to receive(:find_all).and_return(integrations) | ||
allow_any_instance_of(described_class).to receive(:decorator_class).and_return(decorator_class) | ||
allow_any_instance_of(described_class).to receive_message_chain(:decorator_class, :eager_load_associations).and_return(eager_load_associations) | ||
allow(PactBroker::Api::Contracts::PaginationQueryParamsSchema).to receive(:call).and_return(errors) | ||
end | ||
|
||
let(:integration_service) { class_double("PactBroker::Integrations::Service").as_stubbed_const } | ||
let(:integrations) { double("integrations") } | ||
let(:decorator_class) { double("decorator class", new: decorator) } | ||
let(:decorator) { double("decorator", to_json: json) } | ||
let(:json) { "some json" } | ||
let(:rack_headers) { { "HTTP_ACCEPT" => "application/hal+json" } } | ||
let(:eager_load_associations) { [:foo, :bar] } | ||
let(:errors) { {} } | ||
|
||
let(:path) { "/integrations" } | ||
let(:params) { { "pageNumber" => "1", "pageSize" => "2" } } | ||
|
||
subject { get(path, params, rack_headers) } | ||
|
||
it "validates the query params" do | ||
expect(PactBroker::Api::Contracts::PaginationQueryParamsSchema).to receive(:call).with(params) | ||
subject | ||
end | ||
|
||
it "finds the integrations" do | ||
allow(integration_service).to receive(:find_all).with({}, { page_number: 1, page_size: 2 }, eager_load_associations) | ||
subject | ||
end | ||
|
||
its(:status) { is_expected.to eq 200 } | ||
|
||
it "renders the integrations" do | ||
expect(decorator_class).to receive(:new).with(integrations) | ||
expect(decorator).to receive(:to_json).with(user_options: instance_of(Decorators::DecoratorContext)) | ||
expect(subject.body).to eq json | ||
end | ||
|
||
context "with invalid query params" do | ||
let(:errors) { { "some" => ["errors"]} } | ||
|
||
its(:status) { is_expected.to eq 400 } | ||
its(:body) { is_expected.to match "some.*errors" } | ||
end | ||
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
Oops, something went wrong.