Skip to content

Commit

Permalink
feat(manual-payments): Add more resolver specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad committed Jan 24, 2025
1 parent b4fee07 commit 07af881
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/queries/invoices_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ def with_positive_due_amount(scope)
positive_due_amount = ActiveModel::Type::Boolean.new.cast(filters.positive_due_amount)

if positive_due_amount
scope = scope.where("total_amount_cents - total_paid_amount_cents > 0")
scope.where("total_amount_cents - total_paid_amount_cents > 0")
else
scope.where("total_amount_cents - total_paid_amount_cents <= 0")
end
scope
end

def with_partially_paid(scope)
Expand Down
111 changes: 111 additions & 0 deletions spec/graphql/resolvers/invoices_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,117 @@
end
end

context 'when filtering by partially paid' do
let(:invoice_third) do
create(
:invoice,
customer: customer_first,
organization:,
total_amount_cents: 1000,
total_paid_amount_cents: 10
)
end

let(:query) do
<<~GQL
query {
invoices(limit: 5, partiallyPaid: true) {
collection { id }
metadata { currentPage, totalCount }
}
}
GQL
end

before do
invoice_third
end

it 'returns all partially paid invoices' do
result = execute_graphql(
current_user: membership.user,
current_organization: organization,
permissions: required_permission,
query:
)

invoices_response = result['data']['invoices']

aggregate_failures do
expect(invoices_response['collection'].count).to eq(1)
expect(invoices_response['collection'].first['id']).to eq(invoice_third.id)

expect(invoices_response['metadata']['currentPage']).to eq(1)
expect(invoices_response['metadata']['totalCount']).to eq(1)
end
end
end

context 'when filtering by positive due amount' do
let(:invoice_third) do
create(
:invoice,
customer: customer_first,
organization:,
total_amount_cents: 1000,
total_paid_amount_cents: 10
)
end

let(:query) do
<<~GQL
query {
invoices(limit: 5, positiveDueAmount: #{positive_due_amount}) {
collection { id }
metadata { currentPage, totalCount }
}
}
GQL
end

let(:result) do
execute_graphql(
current_user: membership.user,
current_organization: organization,
permissions: required_permission,
query:
)
end

before do
invoice_third
end

context 'when the flag is set to true' do
let(:positive_due_amount) { true }

it 'returns all invoices with due amount is greater than 0' do
invoices_response = result['data']['invoices']

expect(invoices_response['collection'].count).to eq(1)
expect(invoices_response['collection'].first['id']).to eq(invoice_third.id)

expect(invoices_response['metadata']['currentPage']).to eq(1)
expect(invoices_response['metadata']['totalCount']).to eq(1)
end
end

context 'when the flag is set to false' do
let(:positive_due_amount) { false }

it 'returns all invoices with due amount is 0' do
invoices_response = result['data']['invoices']

expect(invoices_response['collection'].count).to eq(2)

expect(invoices_response['collection'].map { _1['id'] }).to contain_exactly(invoice_first.id, invoice_second.id)

expect(invoices_response['metadata']['currentPage']).to eq(1)
expect(invoices_response['metadata']['totalCount']).to eq(2)
end
end
end

context 'when filtering by issuing date' do
let(:invoice_third) do
create(
Expand Down

0 comments on commit 07af881

Please sign in to comment.