Skip to content

[ING-30] test: Cover currency filter on list endpoints#353

Open
aquinofb wants to merge 2 commits into
mainfrom
feat/ing-30-currency-filter
Open

[ING-30] test: Cover currency filter on list endpoints#353
aquinofb wants to merge 2 commits into
mainfrom
feat/ing-30-currency-filter

Conversation

@aquinofb

Copy link
Copy Markdown

Context

The lago-api backend exposes an optional currency query parameter on the subscriptions, wallets, and payment_requests list endpoints (getlago/lago-api#5249). The Ruby client's get_all(options = {}) already forwards arbitrary options as query parameters, so no source change is required, but the behavior was untested.

Description

Adds a when currency is given example to the #get_all specs of the subscription, wallet, and payment_request resources. Each stubs the request with the currency query string, so the example fails (WebMock raises on an unmatched request) if the option is not forwarded.

How to try locally

bundle install
bundle exec rspec spec/lago/api/resources/subscription_spec.rb spec/lago/api/resources/wallet_spec.rb spec/lago/api/resources/payment_request_spec.rb

## Context

The lago-api backend exposes a `currency` query parameter on the
subscriptions, wallets, and payment_requests list endpoints (PR #5249).
The Ruby client forwards arbitrary options as query params via get_all,
so no source change is needed, but the behavior was untested.

## Description

Add a forwarding spec for the `currency` option to the get_all examples
of the subscription, wallet, and payment_request resources. Each stubs
the request with the currency query string, so the test fails if the
option is not forwarded.
@aquinofb aquinofb self-assigned this Jun 3, 2026
@aquinofb aquinofb requested review from a team, groyoh, lovrocolic, mariohd, toommz and vincent-pochet and removed request for a team June 3, 2026 00:13
@aquinofb aquinofb marked this pull request as ready for review June 3, 2026 00:14
Comment on lines +99 to +111
context 'when currency is given' do
before do
stub_request(:get, 'https://api.getlago.com/api/v1/payment_requests?currency=EUR')
.to_return(body: payment_requests_response, status: 200)
end

it 'returns payment requests filtered by currency' do
response = resource.get_all({ currency: 'EUR' })

expect(response['payment_requests'].first['lago_id']).to eq(payment_request_id)
expect(response['meta']['current_page']).to eq(1)
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it returns the same results as the when there is no options context, I don't really see the added value of this example 🤔

## Context

Review feedback on the currency-filter spec contexts: the stubbed URL
matched on the query string, so the test failed if the param was not
forwarded, but the assertions only checked the response shape. A future
reader could not tell from the test what was being verified.

## Description

Replace the response-shape assertions with an explicit
`have_requested(...).with(query: { currency: 'EUR' })` on each of the
three resources (payment_request, subscription, wallet). The intent of
each test is now self-documenting: we are verifying the option is
serialized into the request URL.
it 'forwards the currency option as a query param' do
resource.get_all({ currency: 'EUR' })

expect(WebMock).to have_requested(:get, 'https://api.getlago.com/api/v1/payment_requests')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have to mock webmock since we're already stubbing. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants