Skip to content

test: cover economy stats and wallet mutation resolvers - #35

Open
mojobeeping wants to merge 3 commits into
AuthorPrime:mainfrom
mojobeeping:mojobeep/economy-stats-test
Open

test: cover economy stats and wallet mutation resolvers#35
mojobeeping wants to merge 3 commits into
AuthorPrime:mainfrom
mojobeeping:mojobeep/economy-stats-test

Conversation

@mojobeeping

@mojobeeping mojobeeping commented Jun 7, 2026

Copy link
Copy Markdown

Summary

Adds focused Vitest coverage for two GraphQL resolver areas:

  • tests/graphql/economy-stats.test.ts
    • maps aggregate DB rows into the public economy stats shape
    • covers zero/default fallback behavior when aggregate rows are missing
  • tests/graphql/wallet-mutations.test.ts
    • covers authenticated addWallet insertion payloads and default isPrimary behavior
    • covers unauthenticated addWallet rejection
    • covers syncWalletBalance updating the sync timestamp and returning the updated row

Both files use mocked DB chains, so they do not require Postgres or external services.

Relates to #8.

Validation

Passed:

npm test -- --run tests/graphql/economy-stats.test.ts tests/graphql/wallet-mutations.test.ts
npm test -- --run
git diff --check

Result: 2 test files passed, 5 tests passed.

Previously attempted:

npm run build

The build currently fails on existing project-level TypeScript/config issues unrelated to these test files, including database/schema/agents.ts self-reference typing, rootDir mismatch for database/**/*, src/graphql/resolvers.ts query 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/graphql/economy-stats.test.ts Outdated
[{ total: 12, sovereign: 3, active: 9 }],
[{ completedToday: 4, completedTotal: 27 }],
]);
const resolvers = createResolvers(db as never);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
const resolvers = createResolvers(db as never);
const resolvers = createResolvers(db as any);

Comment thread tests/graphql/economy-stats.test.ts Outdated
Comment on lines +24 to +34
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,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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,
});

Comment thread tests/graphql/economy-stats.test.ts Outdated

it('returns zeroed public stats when aggregate rows are missing', async () => {
const db = createSelectMock([[], []]);
const resolvers = createResolvers(db as never);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
const resolvers = createResolvers(db as never);
const resolvers = createResolvers(db as any);

@mojobeeping mojobeeping changed the title test: cover economy stats resolver test: cover economy stats and wallet mutation resolvers Jun 7, 2026
@mojobeeping

Copy link
Copy Markdown
Author

Addressed the automated review feedback in f91b0fb: switched the economyStats populated-case assertion to toEqual and replaced the local test mock as never casts with as any. Re-ran npm test -- --run tests/graphql/economy-stats.test.ts tests/graphql/wallet-mutations.test.ts, npm test -- --run, and git diff --check; all pass.

@mojobeeping mojobeeping mentioned this pull request Jun 7, 2026
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant