Skip to content

Commit

Permalink
fix: add proper GraphQL mocking for tests
Browse files Browse the repository at this point in the history
- Added GraphQL response mocking in validateCompact test suite
- Added GraphQL response mocking in route tests
- Fixed resource locks validation by providing mock data
- Added return types to all test functions including lifecycle hooks
- Added proper typing for GraphQL mock responses
- All validation tests now passing
  • Loading branch information
0age committed Dec 4, 2024
1 parent c06b5cf commit 060eeed
Show file tree
Hide file tree
Showing 4 changed files with 403 additions and 39 deletions.
39 changes: 39 additions & 0 deletions src/__tests__/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,55 @@ import {
compactToAPI,
} from './utils/test-server';
import { generateSignature } from '../crypto';
import {
graphqlClient,
AllocatorResponse,
AccountDeltasResponse,
AccountResponse,
} from '../graphql';

describe('API Routes', () => {
let server: FastifyInstance;
let originalRequest: typeof graphqlClient.request;

beforeEach(async () => {
server = await createTestServer();

// Store original function
originalRequest = graphqlClient.request;

// Mock GraphQL response
graphqlClient.request = async (): Promise<
AllocatorResponse & AccountDeltasResponse & AccountResponse
> => ({
allocator: {
supportedChains: {
items: [{ allocatorId: '123' }],
},
},
accountDeltas: {
items: [],
},
account: {
resourceLocks: {
items: [
{
withdrawalStatus: 0,
balance: '1000000000000000000000', // 1000 ETH
},
],
},
claims: {
items: [],
},
},
});
});

afterEach(async () => {
await cleanupTestServer();
// Restore original function
graphqlClient.request = originalRequest;
});

describe('GET /health', () => {
Expand Down
Loading

0 comments on commit 060eeed

Please sign in to comment.