Skip to content

Add test coverage for usage rollups, agent aggregations, and CSV/JSON exports #46

Description

@mikewheeleer

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.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions