-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(manual-payments): Add payment resolver, and filter by customer e…
…xternal_id
- Loading branch information
1 parent
00781e2
commit 385f811
Showing
7 changed files
with
219 additions
and
20 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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
class PaymentResolver < Resolvers::BaseResolver | ||
include AuthenticableApiUser | ||
include RequiredOrganization | ||
|
||
REQUIRED_PERMISSION = 'payments:view' | ||
|
||
description 'Query a single Payment' | ||
|
||
argument :id, ID, required: true, description: 'Uniq ID of the payment' | ||
|
||
type Types::Payments::Object, null: true | ||
|
||
def resolve(id:) | ||
Payment.for_organization(current_organization).find(id) | ||
rescue ActiveRecord::RecordNotFound | ||
not_found_error(resource: 'payment') | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Resolvers::PaymentResolver, type: :graphql do | ||
let(:required_permission) { 'payments:view' } | ||
|
||
let(:query) do | ||
<<~GQL | ||
query($id: ID!) { | ||
payment(id: $id) { | ||
id | ||
} | ||
} | ||
GQL | ||
end | ||
|
||
let(:membership) { create(:membership) } | ||
let(:organization) { membership.organization } | ||
let(:customer) { create(:customer, organization:) } | ||
let(:invoice) { create(:invoice, customer:, organization:, fees_amount_cents: 10) } | ||
let(:payment) { create(:payment, payable: invoice) } | ||
|
||
before { payment } | ||
|
||
it_behaves_like 'requires current user' | ||
it_behaves_like 'requires current organization' | ||
it_behaves_like 'requires permission', 'payments:view' | ||
|
||
it 'returns a single payment' do | ||
result = execute_graphql( | ||
current_user: membership.user, | ||
current_organization: organization, | ||
permissions: required_permission, | ||
query:, | ||
variables: { | ||
id: payment.id | ||
} | ||
) | ||
|
||
data = result['data']['payment'] | ||
|
||
expect(data['id']).to eq(payment.id) | ||
end | ||
|
||
context 'when payment is not found' do | ||
it 'returns an error' do | ||
result = execute_graphql( | ||
current_user: membership.user, | ||
current_organization: invoice.organization, | ||
permissions: required_permission, | ||
query:, | ||
variables: { | ||
id: 'foo' | ||
} | ||
) | ||
|
||
expect_graphql_error(result:, message: 'Resource not found') | ||
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