Skip to content

Commit 4b9953c

Browse files
committed
test: Add tests for checking call of findMany and count
1 parent 1f0cb5f commit 4b9953c

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/__tests__/paginationResolver-test.js

+72
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { preparePaginationResolver } from '../paginationResolver';
88
const { GraphQLInt } = graphql;
99

1010
describe('paginationResolver', () => {
11+
const spyFindManyResolve = jest.spyOn(userTypeComposer.getResolver('findMany'), 'resolve');
12+
const spyCountResolve = jest.spyOn(userTypeComposer.getResolver('count'), 'resolve');
1113
const paginationResolver = preparePaginationResolver(userTypeComposer, {
1214
countResolverName: 'count',
1315
findResolverName: 'findMany',
@@ -252,6 +254,41 @@ describe('paginationResolver', () => {
252254
});
253255

254256
describe('filter tests with resolve', () => {
257+
it('should pass `filter` arg to `findResolverfindMany` and `count` resolvers', async () => {
258+
spyFindManyResolve.mockClear();
259+
spyCountResolve.mockClear();
260+
await paginationResolver.resolve({
261+
args: {
262+
filter: {
263+
gender: 'm',
264+
},
265+
},
266+
projection: {
267+
count: true,
268+
items: {
269+
name: true,
270+
},
271+
},
272+
});
273+
expect(spyFindManyResolve.mock.calls).toEqual([
274+
[
275+
{
276+
args: { filter: { gender: 'm' }, limit: 6 },
277+
projection: { count: true, items: { name: true }, name: true },
278+
},
279+
],
280+
]);
281+
expect(spyCountResolve.mock.calls).toEqual([
282+
[
283+
{
284+
args: { filter: { gender: 'm' } },
285+
projection: { count: true, items: { name: true } },
286+
rawQuery: undefined,
287+
},
288+
],
289+
]);
290+
});
291+
255292
it('should add additional filtering', async () => {
256293
const result = await paginationResolver.resolve({
257294
args: {
@@ -284,6 +321,41 @@ describe('paginationResolver', () => {
284321
});
285322
});
286323

324+
describe('sort tests with resolve', () => {
325+
it('should pass `sort` arg to `findResolverfindMany` but not to `count` resolvers', async () => {
326+
spyFindManyResolve.mockClear();
327+
spyCountResolve.mockClear();
328+
await paginationResolver.resolve({
329+
args: {
330+
sort: { _id: 1 },
331+
},
332+
projection: {
333+
count: true,
334+
items: {
335+
name: true,
336+
},
337+
},
338+
});
339+
expect(spyFindManyResolve.mock.calls).toEqual([
340+
[
341+
{
342+
args: { limit: 6, sort: { _id: 1 } },
343+
projection: { count: true, items: { name: true }, name: true },
344+
},
345+
],
346+
]);
347+
expect(spyCountResolve.mock.calls).toEqual([
348+
[
349+
{
350+
args: { filter: {} },
351+
projection: { count: true, items: { name: true } },
352+
rawQuery: undefined,
353+
},
354+
],
355+
]);
356+
});
357+
});
358+
287359
describe('resolver payload', () => {
288360
it('should have correct pageInfo for first page', async () => {
289361
const result = await paginationResolver.resolve({

0 commit comments

Comments
 (0)