test: cover economy stats and wallet mutation resolvers - #35
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new test suite for the economyStats GraphQL resolver, verifying that it correctly maps aggregate database query results into the public economy stats shape and handles missing aggregate rows by returning zeroed stats. The reviewer provided feedback to improve TypeScript idiomatic usage by replacing as never type assertions with as any for partial mocks, and suggested using toEqual instead of toMatchObject for stricter assertions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| [{ total: 12, sovereign: 3, active: 9 }], | ||
| [{ completedToday: 4, completedTotal: 27 }], | ||
| ]); | ||
| const resolvers = createResolvers(db as never); |
There was a problem hiding this comment.
Using as never as a type assertion escape hatch is non-idiomatic in TypeScript. The never type represents values that should never occur. For partial mocks in tests, as any is the standard and idiomatic way to bypass type checking.
| const resolvers = createResolvers(db as never); | |
| const resolvers = createResolvers(db as any); |
| await expect(resolvers.Query.economyStats()).resolves.toMatchObject({ | ||
| totalAgents: 12, | ||
| sovereignAgents: 3, | ||
| activeAgents: 9, | ||
| tasksCompletedToday: 4, | ||
| tasksCompletedTotal: 27, | ||
| totalCirculating: '0', | ||
| dailyVolume: '0', | ||
| averageEmergenceScore: 0, | ||
| emergenceEventsToday: 0, | ||
| }); |
There was a problem hiding this comment.
For consistency and stricter assertions, use toEqual instead of toMatchObject. This ensures that the resolver does not return any unexpected extra properties beyond the defined schema.
| await expect(resolvers.Query.economyStats()).resolves.toMatchObject({ | |
| totalAgents: 12, | |
| sovereignAgents: 3, | |
| activeAgents: 9, | |
| tasksCompletedToday: 4, | |
| tasksCompletedTotal: 27, | |
| totalCirculating: '0', | |
| dailyVolume: '0', | |
| averageEmergenceScore: 0, | |
| emergenceEventsToday: 0, | |
| }); | |
| await expect(resolvers.Query.economyStats()).resolves.toEqual({ | |
| totalAgents: 12, | |
| sovereignAgents: 3, | |
| activeAgents: 9, | |
| tasksCompletedToday: 4, | |
| tasksCompletedTotal: 27, | |
| totalCirculating: '0', | |
| dailyVolume: '0', | |
| averageEmergenceScore: 0, | |
| emergenceEventsToday: 0, | |
| }); |
|
|
||
| it('returns zeroed public stats when aggregate rows are missing', async () => { | ||
| const db = createSelectMock([[], []]); | ||
| const resolvers = createResolvers(db as never); |
There was a problem hiding this comment.
Using as never as a type assertion escape hatch is non-idiomatic in TypeScript. The never type represents values that should never occur. For partial mocks in tests, as any is the standard and idiomatic way to bypass type checking.
| const resolvers = createResolvers(db as never); | |
| const resolvers = createResolvers(db as any); |
|
Addressed the automated review feedback in f91b0fb: switched the economyStats populated-case assertion to |
Summary
Adds focused Vitest coverage for two GraphQL resolver areas:
tests/graphql/economy-stats.test.tstests/graphql/wallet-mutations.test.tsaddWalletinsertion payloads and defaultisPrimarybehavioraddWalletrejectionsyncWalletBalanceupdating the sync timestamp and returning the updated rowBoth files use mocked DB chains, so they do not require Postgres or external services.
Relates to #8.
Validation
Passed:
Result: 2 test files passed, 5 tests passed.
Previously attempted:
The build currently fails on existing project-level TypeScript/config issues unrelated to these test files, including
database/schema/agents.tsself-reference typing,rootDirmismatch fordatabase/**/*,src/graphql/resolvers.tsquery result typing, and missing@as-integrations/fastify. The new test files are not referenced in those build errors.Bounty Note
Issue #8 lists an ongoing bounty of 50 sats per merged test file. This PR now adds two test files. Payout details can be provided if this PR is accepted.