Skip to content

Commit

Permalink
chore(purifier.spec.ts): remove unnecessary comments and improve code…
Browse files Browse the repository at this point in the history
… readability

feat(purifier.spec.ts): add test case to check for duplicate operation names when loading queries
  • Loading branch information
danil-iglu committed Sep 18, 2024
1 parent 8a183a9 commit 0e768ca
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/__tests__/purifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ describe('GraphQLQueryPurifier', () => {
mockRes.status = jest.fn().mockReturnThis();
mockRes.send = jest.fn();

// Mock the necessary functions
(fs.watch as jest.Mock).mockImplementation((path, options, callback) => {
// Simulate file change
callback('change', 'test.gql');
return { close: jest.fn() };
});
Expand Down Expand Up @@ -100,4 +98,44 @@ describe('GraphQLQueryPurifier', () => {
expect(mockReq.body.query).toBe('{ __typename }');
expect(mockNext).toHaveBeenCalled();
});

test('should throw error for duplicate operation names when loading queries', () => {
(glob.sync as jest.Mock).mockReturnValue([
'./graphql/queries/findMyJobs1.gql',
'./graphql/queries/findMyJobs2.gql',
]);

(fs.readFileSync as jest.Mock).mockReturnValueOnce(`
query FindMyJobs {
data: findJobs {
id
createdAt
job {
id
title
}
}
}
`).mockReturnValueOnce(`
query FindMyJobs {
data: findJobs {
id
createdAt
deletedAt
job {
id
title
company {
name
}
}
}
}
`);

expect(() => {
// @ts-ignore
purifier.loadQueries();
}).toThrowError('Duplicate operation name detected: FindMyJobs.');
});
});

0 comments on commit 0e768ca

Please sign in to comment.