-
Notifications
You must be signed in to change notification settings - Fork 2
#293 support limit query param in /txns.json #517
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,6 +258,11 @@ | |
| confirmed_user.wallet do |wallet| | ||
| list = wallet.txns | ||
| list.reverse! if params[:sort] && params[:sort] == 'desc' | ||
| if params[:limit] | ||
| limit = params[:limit].to_i | ||
| raise WTS::UserError, "E207: The 'limit' parameter must be a positive integer" if limit <= 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error code E207 is already taken by front/front_upwork.rb:26, which raises WTS::UserError on a different condition ( |
||
| list = list.first(limit) | ||
| end | ||
| JSON.pretty_generate( | ||
| list.map do |t| | ||
| t.to_json.merge(tid: t.amount.negative? ? "#{wallet.id}:#{t.id}" : "#{t.bnf}:#{t.id}") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new limit branch is not exercised by any test. The smoke test in test/test_wts.rb only hits /txns.json without a parameter, so a regression in the parse, the bound check, or the first(limit) slice would land silently. Add a case that calls /txns.json?limit=1 and asserts the response is a JSON array of length at most one, and a case that asserts a 4xx response for limit=0 or a negative value so the new WTS::UserError is covered.