Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions wts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@
confirmed_user.wallet do |wallet|
list = wallet.txns
list.reverse! if params[:sort] && params[:sort] == 'desc'
if params[:limit]

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.

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.

limit = params[:limit].to_i
raise WTS::UserError, "E207: The 'limit' parameter must be a positive integer" if limit <= 0

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.

Error code E207 is already taken by front/front_upwork.rb:26, which raises WTS::UserError on a different condition (You have to work in Zerocracy in order to cash out to UpWork). Reusing the same code on a new failure path breaks the contract that callers and operators rely on to identify which user-facing error fired. Pick the next free code in the sequence; E227 appears to be the next unused slot after E226 in objects/ops.rb.

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}")
Expand Down
Loading