Test the usage rollup, aggregation, and export endpoints
Description
src/index.ts exposes a family of read aggregations — GET /api/v1/agents, /agents/:agent/total, /agents/:agent/usage, /services/:serviceId/usage, /services/:serviceId/agents, /services/:serviceId/agents/top, plus usage/export.csv and usage/export.json. The CSV exporter even has custom quote-escaping. None of these are covered in src/health.test.ts. This issue adds coverage.
Requirements and context
- Repository scope:
Agentpay-Org/Agentpay-backend only.
- Seed usage across multiple agents/services and assert each rollup returns correct totals and counts.
- Test
top ordering (descending by total) and the limit clamp.
- Test the CSV exporter's escaping for values containing commas, quotes, and newlines, and the header row.
- Test the JSON export includes
exportedAt and every (agent, serviceId, total) tuple.
Suggested execution
- Fork the repo and create a branch
git checkout -b test/testing-16-rollups-exports
- Implement changes
- Write comprehensive tests in: new
src/aggregations.test.ts using supertest.
- Write code in: no production change expected unless a real bug (e.g. an export escaping flaw) is found.
- Add documentation: none beyond test descriptions.
- Add clear test titles.
- Validate security assumptions: CSV escaping prevents formula/injection via leading
=/+ if relevant.
- Test and commit
Test and commit
- Run
npm run build, npm test, and npm run lint.
- Cover edge cases: agent with no usage, service with one consumer, value needing CSV quoting.
- Include the full
npm test output in the PR description.
Example commit message
test: cover usage rollups, aggregations, and csv/json exports
Guidelines
- Minimum 95 percent test coverage for impacted modules.
- Clear, reviewer-focused documentation.
- Timeframe: 96 hours.
Community & contribution rewards
- 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
- ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.
Test the usage rollup, aggregation, and export endpoints
Description
src/index.tsexposes a family of read aggregations —GET /api/v1/agents,/agents/:agent/total,/agents/:agent/usage,/services/:serviceId/usage,/services/:serviceId/agents,/services/:serviceId/agents/top, plususage/export.csvandusage/export.json. The CSV exporter even has custom quote-escaping. None of these are covered insrc/health.test.ts. This issue adds coverage.Requirements and context
Agentpay-Org/Agentpay-backendonly.topordering (descending by total) and thelimitclamp.exportedAtand every(agent, serviceId, total)tuple.Suggested execution
git checkout -b test/testing-16-rollups-exportssrc/aggregations.test.tsusingsupertest.=/+if relevant.Test and commit
npm run build,npm test, andnpm run lint.npm testoutput in the PR description.Example commit message
test: cover usage rollups, aggregations, and csv/json exportsGuidelines
Community & contribution rewards