|
| 1 | +import '../../src/env-test'; |
| 2 | + |
| 3 | +jest.mock('../../src/integrations/github/service', () => require('../__mocks__/github-service')); |
| 4 | + |
| 5 | +jest.mock('../../src/resolvers/helpers/eventsFactory', () => ({ |
| 6 | + __esModule: true, |
| 7 | + default: jest.fn(), |
| 8 | +})); |
| 9 | + |
| 10 | +// @ts-expect-error - CommonJS module, TypeScript can't infer types properly |
| 11 | +import projectResolverModule from '../../src/resolvers/project'; |
| 12 | +import getEventsFactory from '../../src/resolvers/helpers/eventsFactory'; |
| 13 | + |
| 14 | +const projectResolver = projectResolverModule as { |
| 15 | + Project: { |
| 16 | + dailyEventsPortion: (...args: unknown[]) => Promise<unknown>; |
| 17 | + }; |
| 18 | +}; |
| 19 | + |
| 20 | +describe('Project resolver dailyEventsPortion', () => { |
| 21 | + beforeEach(() => { |
| 22 | + jest.clearAllMocks(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should pass assignee filter to events factory', async () => { |
| 26 | + const findDailyEventsPortion = jest.fn().mockResolvedValue({ |
| 27 | + nextCursor: null, |
| 28 | + dailyEvents: [], |
| 29 | + }); |
| 30 | + (getEventsFactory as unknown as jest.Mock).mockReturnValue({ |
| 31 | + findDailyEventsPortion, |
| 32 | + }); |
| 33 | + |
| 34 | + const project = { _id: 'project-1' }; |
| 35 | + const args = { |
| 36 | + limit: 50, |
| 37 | + nextCursor: null, |
| 38 | + sort: 'BY_DATE', |
| 39 | + filters: { ignored: true }, |
| 40 | + search: 'TypeError', |
| 41 | + release: '1.0.0', |
| 42 | + assignee: 'user-123', |
| 43 | + }; |
| 44 | + |
| 45 | + await projectResolver.Project.dailyEventsPortion(project, args, {}); |
| 46 | + |
| 47 | + expect(findDailyEventsPortion).toHaveBeenCalledWith( |
| 48 | + 50, |
| 49 | + null, |
| 50 | + 'BY_DATE', |
| 51 | + { ignored: true }, |
| 52 | + 'TypeError', |
| 53 | + '1.0.0', |
| 54 | + 'user-123' |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should keep old call shape when assignee is not provided', async () => { |
| 59 | + const findDailyEventsPortion = jest.fn().mockResolvedValue({ |
| 60 | + nextCursor: null, |
| 61 | + dailyEvents: [], |
| 62 | + }); |
| 63 | + (getEventsFactory as unknown as jest.Mock).mockReturnValue({ |
| 64 | + findDailyEventsPortion, |
| 65 | + }); |
| 66 | + |
| 67 | + const project = { _id: 'project-1' }; |
| 68 | + const args = { |
| 69 | + limit: 10, |
| 70 | + nextCursor: null, |
| 71 | + sort: 'BY_DATE', |
| 72 | + filters: {}, |
| 73 | + search: '', |
| 74 | + release: undefined, |
| 75 | + }; |
| 76 | + |
| 77 | + await projectResolver.Project.dailyEventsPortion(project, args, {}); |
| 78 | + |
| 79 | + expect(findDailyEventsPortion).toHaveBeenCalledWith( |
| 80 | + 10, |
| 81 | + null, |
| 82 | + 'BY_DATE', |
| 83 | + {}, |
| 84 | + '', |
| 85 | + undefined, |
| 86 | + undefined |
| 87 | + ); |
| 88 | + }); |
| 89 | +}); |
0 commit comments