Skip to content

fix(customer): Fix array parameters in GET /api/v1/customers #3862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025

Conversation

groyoh
Copy link
Contributor

@groyoh groyoh commented Jun 24, 2025

Context

While testing the GET /api/v1/customers endpoint, I noticed that the documentation mentions account_type and billing_entity_codes parameters as arrays, but document them without the trailing [] brackets. This was different from other endpoints such as the subscription one.

So I tested the endpoint with ?billing_entity_codes=hooli&billing_entity_codes=gan and ?billing_entity_codes=hooli,gan and it returned a 500 error.

Using ?billing_entity_codes[]=hooli&billing_entity_codes[]=gan did work though. So it turned out to be a documentation issue, along with a missing sanitization on the parameter. The fix for the doc can be found here: getlago/lago-openapi#388.

Description

I fixed the sanitization on the billing_entity_codes parameter and then added a test to ensure it does not return a 500 error without the trailing [] brackets.

When doing so, I noticed that passing multiple identical billing entity codes did return a 404 error instead of a 200 one. So I fixed this as well along with a test.

Below are the outputs of the tests without the fixes:

1) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter
Failure/Error: return not_found_error(resource: "billing_entity") if params[:billing_entity_codes].present? && billing_entities.count != params[:billing_entity_codes].count

ArgumentError:
  wrong number of arguments (given 0, expected 1+)

2) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity
Got 1 failure and 1 other error:

2.1) Failure/Error: expect(response).to have_http_status(:ok)
       expected the response to have status code :ok (200) but it was :not_found (404)
     # ./spec/requests/api/v1/customers_controller_spec.rb:434:in 'block (5 levels) in <top (required)>'
     # ...
     # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'

2.2) Failure/Error: expect(json[:customers].count).to eq(1)

     NoMethodError:
       undefined method 'count' for nil
     # ./spec/requests/api/v1/customers_controller_spec.rb:435:in 'block (5 levels) in <top (required)>'
     # ....
     # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'

51/51 |================================================ 100 ================================================>| Time: 00:00:02

Finished in 2.7 seconds (files took 2.47 seconds to load)
51 examples, 2 failures

Failed examples:

rspec ./spec/requests/api/v1/customers_controller_spec.rb:419 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter
rspec ./spec/requests/api/v1/customers_controller_spec.rb:431 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity

While testing the `GET /api/v1/customers` endpoint, I noticed that [the documentation](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/customers.yaml#L36-L58) mentions `account_type` and `billing_entity_codes` parameters as arrays, but document them without the trailing `[]` brackets. This was different from other endpoints such as [the subscription one](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/subscriptions.yaml#L54-L68).

So I tested the endpoint with `?billing_entity_codes=hooli&billing_entity_codes=gan` and `?billing_entity_codes=hooli,gan` and it returned a 500 error.

Using `?billing_entity_codes[]=hooli&billing_entity_codes[]=gan` did work though. So it turned out to be a documentation issue, along with a missing sanitization on the parameter.

I fixed the sanitization on the `billing_entity_codes` parameter and then added a test to ensure it does not return a 500 error without the trailing `[]` brackets.

When doing so, I noticed that passing multiple identical billing entity codes did return a 404 error instead of a 200 one. So I fixed this as well along with a test.

Below are the outputs of the tests without the fixes:

```
1) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter
Failure/Error: return not_found_error(resource: "billing_entity") if params[:billing_entity_codes].present? && billing_entities.count != params[:billing_entity_codes].count

ArgumentError:
  wrong number of arguments (given 0, expected 1+)

2) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity
Got 1 failure and 1 other error:

2.1) Failure/Error: expect(response).to have_http_status(:ok)
       expected the response to have status code :ok (200) but it was :not_found (404)
     # ./spec/requests/api/v1/customers_controller_spec.rb:434:in 'block (5 levels) in <top (required)>'
     # ...
     # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'

2.2) Failure/Error: expect(json[:customers].count).to eq(1)

     NoMethodError:
       undefined method 'count' for nil
     # ./spec/requests/api/v1/customers_controller_spec.rb:435:in 'block (5 levels) in <top (required)>'
     # ....
     # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'

51/51 |================================================ 100 ================================================>| Time: 00:00:02

Finished in 2.7 seconds (files took 2.47 seconds to load)
51 examples, 2 failures

Failed examples:

rspec ./spec/requests/api/v1/customers_controller_spec.rb:419 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter
rspec ./spec/requests/api/v1/customers_controller_spec.rb:431 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity
```
@groyoh groyoh merged commit c7daca4 into main Jun 25, 2025
14 checks passed
@groyoh groyoh deleted the fix/get-customers branch June 25, 2025 13:16
diegocharles pushed a commit that referenced this pull request Jun 30, 2025
## Context

While testing the `GET /api/v1/customers` endpoint, I noticed that [the documentation](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/customers.yaml#L36-L58) mentions `account_type` and `billing_entity_codes` parameters as arrays, but document them without the trailing `[]` brackets. This was different from other endpoints such as [the subscription one](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/subscriptions.yaml#L54-L68).

So I tested the endpoint with `?billing_entity_codes=hooli&billing_entity_codes=gan` and `?billing_entity_codes=hooli,gan` and it returned a 500 error.

Using `?billing_entity_codes[]=hooli&billing_entity_codes[]=gan` did work though. So it turned out to be a documentation issue, along with a missing sanitization on the parameter. The fix for the doc can be found here: getlago/lago-openapi#388.

## Description

I fixed the sanitization on the `billing_entity_codes` parameter and then added a test to ensure it does not return a 500 error without the trailing `[]` brackets.

When doing so, I noticed that passing multiple identical billing entity codes did return a 404 error instead of a 200 one. So I fixed this as well along with a test.

Below are the outputs of the tests without the fixes:

```
1) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter
Failure/Error: return not_found_error(resource: "billing_entity") if params[:billing_entity_codes].present? && billing_entities.count != params[:billing_entity_codes].count

ArgumentError:
  wrong number of arguments (given 0, expected 1+)

2) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity
Got 1 failure and 1 other error:

2.1) Failure/Error: expect(response).to have_http_status(:ok)
       expected the response to have status code :ok (200) but it was :not_found (404)
     # ./spec/requests/api/v1/customers_controller_spec.rb:434:in 'block (5 levels) in <top (required)>'
     # ...
     # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'

2.2) Failure/Error: expect(json[:customers].count).to eq(1)

     NoMethodError:
       undefined method 'count' for nil
     # ./spec/requests/api/v1/customers_controller_spec.rb:435:in 'block (5 levels) in <top (required)>'
     # ....
     # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'

Finished in 2.7 seconds (files took 2.47 seconds to load)
51 examples, 2 failures

Failed examples:

rspec ./spec/requests/api/v1/customers_controller_spec.rb:419 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter
rspec ./spec/requests/api/v1/customers_controller_spec.rb:431 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity
```
diegocharles pushed a commit that referenced this pull request Jul 11, 2025
## Context

While testing the `GET /api/v1/customers` endpoint, I noticed that [the documentation](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/customers.yaml#L36-L58) mentions `account_type` and `billing_entity_codes` parameters as arrays, but document them without the trailing `[]` brackets. This was different from other endpoints such as [the subscription one](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/subscriptions.yaml#L54-L68).

So I tested the endpoint with `?billing_entity_codes=hooli&billing_entity_codes=gan` and `?billing_entity_codes=hooli,gan` and it returned a 500 error.

Using `?billing_entity_codes[]=hooli&billing_entity_codes[]=gan` did work though. So it turned out to be a documentation issue, along with a missing sanitization on the parameter. The fix for the doc can be found here: getlago/lago-openapi#388.

## Description

I fixed the sanitization on the `billing_entity_codes` parameter and then added a test to ensure it does not return a 500 error without the trailing `[]` brackets.

When doing so, I noticed that passing multiple identical billing entity codes did return a 404 error instead of a 200 one. So I fixed this as well along with a test.

Below are the outputs of the tests without the fixes:

```
1) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter
Failure/Error: return not_found_error(resource: "billing_entity") if params[:billing_entity_codes].present? && billing_entities.count != params[:billing_entity_codes].count

ArgumentError:
  wrong number of arguments (given 0, expected 1+)

2) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity
Got 1 failure and 1 other error:

2.1) Failure/Error: expect(response).to have_http_status(:ok)
       expected the response to have status code :ok (200) but it was :not_found (404)
     # ./spec/requests/api/v1/customers_controller_spec.rb:434:in 'block (5 levels) in <top (required)>'
     # ...
     # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'

2.2) Failure/Error: expect(json[:customers].count).to eq(1)

     NoMethodError:
       undefined method 'count' for nil
     # ./spec/requests/api/v1/customers_controller_spec.rb:435:in 'block (5 levels) in <top (required)>'
     # ....
     # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'

Finished in 2.7 seconds (files took 2.47 seconds to load)
51 examples, 2 failures

Failed examples:

rspec ./spec/requests/api/v1/customers_controller_spec.rb:419 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter
rspec ./spec/requests/api/v1/customers_controller_spec.rb:431 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity
```
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.

3 participants