-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1530 from yeti-switch/1528-include-service-from-t…
…ransaction-resource 1528, Customer API: improve transactions API resource
- Loading branch information
Showing
3 changed files
with
91 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
38 changes: 38 additions & 0 deletions
38
spec/requests/api/rest/customer/v1/services_controller_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,38 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Api::Rest::Customer::V1::ServicesController, type: :request do | ||
include_context :json_api_customer_v1_helpers, type: :services | ||
|
||
let!(:service) { FactoryBot.create(:service, uuid: SecureRandom.uuid) } | ||
let(:json_api_request_query) { { include: :transactions } } | ||
|
||
describe 'GET /api/rest/customer/v1/services?include=transactions' do | ||
subject { get json_api_request_path, params: json_api_request_query, headers: json_api_request_headers } | ||
|
||
it 'should render records with included service' do | ||
subject | ||
|
||
expect(response_json[:errors]).to eq nil | ||
expect(response_json[:data].pluck(:id)).to match_array [service.uuid] | ||
expect(response_json[:included]).to contain_exactly( | ||
hash_including( | ||
id: service.transactions.first.uuid, | ||
type: 'transactions' | ||
) | ||
) | ||
end | ||
end | ||
|
||
describe 'GET /api/rest/customer/v1/services/{id}?include=transactions' do | ||
subject { get json_api_request_path, params: json_api_request_query, headers: json_api_request_headers } | ||
|
||
let(:json_api_request_path) { "#{super()}/#{service.uuid}" } | ||
|
||
it 'should return record with included service' do | ||
subject | ||
|
||
expect(response_json.dig(:data, :id)).to eq service.uuid | ||
expect(response_json.dig(:included)).to contain_exactly hash_including id: service.transactions.first.uuid, type: 'transactions' | ||
end | ||
end | ||
end |
51 changes: 51 additions & 0 deletions
51
spec/requests/api/rest/customer/v1/transactions_controller_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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Api::Rest::Customer::V1::TransactionsController, type: :request do | ||
include_context :json_api_customer_v1_helpers, type: :transactions | ||
|
||
let!(:service) { FactoryBot.create(:service, uuid: SecureRandom.uuid) } | ||
let(:json_api_request_query) { { include: :service } } | ||
|
||
describe 'GET /api/rest/customer/v1/transactions?include=service' do | ||
subject { get json_api_request_path, params: json_api_request_query, headers: json_api_request_headers } | ||
|
||
it 'should render records with included service' do | ||
subject | ||
|
||
expect(response_json[:errors]).to eq nil | ||
expect(response_json[:data].pluck(:id)).to match_array [service.transactions.first.uuid] | ||
expect(response_json[:included]).to contain_exactly( | ||
hash_including( | ||
id: service.uuid, | ||
type: 'services', | ||
attributes: hash_including(name: service.name) | ||
) | ||
) | ||
end | ||
end | ||
|
||
describe 'GET /api/rest/customer/v1/transactions?filter[service-id-eq]=uuid' do | ||
subject { get json_api_request_path, params: json_api_request_query, headers: json_api_request_headers } | ||
|
||
let(:json_api_request_query) { { filter: { 'service-id-eq' => service.uuid } } } | ||
|
||
it 'should filter records by UUID of service' do | ||
subject | ||
|
||
expect(response_json[:data].pluck(:id)).to contain_exactly service.transactions.first.uuid | ||
end | ||
end | ||
|
||
describe 'GET /api/rest/customer/v1/transactions/{id}?include=service' do | ||
subject { get json_api_request_path, params: json_api_request_query, headers: json_api_request_headers } | ||
|
||
let(:json_api_request_path) { "#{super()}/#{service.transactions.first.uuid}" } | ||
|
||
it 'should return record with included service' do | ||
subject | ||
|
||
expect(response_json.dig(:data, :id)).to eq service.transactions.first.uuid | ||
expect(response_json.dig(:included)).to contain_exactly hash_including id: service.uuid, type: 'services' | ||
end | ||
end | ||
end |