@@ -8,16 +8,32 @@ jest.mock('../../src/integrations/github/service', () => require('../__mocks__/g
88// eslint-disable-next-line @typescript-eslint/no-var-requires
99import { deleteInstallationMock , GitHubService } from '../__mocks__/github-service' ;
1010
11+ jest . mock ( '../../src/mongo' , ( ) => ( {
12+ databases : {
13+ events : {
14+ createCollection : jest . fn ( ) ,
15+ } ,
16+ } ,
17+ } ) ) ;
18+
19+ jest . mock ( '../../src/utils/telegram' , ( ) => ( {
20+ sendMessage : jest . fn ( ) ,
21+ } ) ) ;
22+
1123// @ts -expect-error - CommonJS module, TypeScript can't infer types properly
1224import projectResolverModule from '../../src/resolvers/project' ;
1325
26+ // eslint-disable-next-line @typescript-eslint/no-var-requires
27+ const mongoMock = require ( '../../src/mongo' ) ;
28+
1429/**
1530 * Type assertion for CommonJS module
1631 */
1732const projectResolver = projectResolverModule as {
1833 Mutation : {
1934 disconnectTaskManager : ( ...args : unknown [ ] ) => Promise < unknown > ;
2035 updateTaskManagerSettings : ( ...args : unknown [ ] ) => Promise < unknown > ;
36+ createProject : ( ...args : unknown [ ] ) => Promise < unknown > ;
2137 } ;
2238 Query : {
2339 project : ( ...args : unknown [ ] ) => Promise < unknown > ;
@@ -518,3 +534,71 @@ describe('Project Resolver - Task Manager Mutations', () => {
518534 } ) ;
519535 } ) ;
520536} ) ;
537+
538+ describe ( 'Project Resolver - createProject' , ( ) => {
539+ beforeEach ( ( ) => {
540+ jest . clearAllMocks ( ) ;
541+ } ) ;
542+
543+ it ( 'should create a timestamp index on the repetitions collection' , async ( ) => {
544+ const projectId = new ObjectId ( ) ;
545+
546+ const eventsCollectionMock = { createIndex : jest . fn ( ) . mockResolvedValue ( undefined ) } ;
547+ const repetitionsCollectionMock = { createIndex : jest . fn ( ) . mockResolvedValue ( undefined ) } ;
548+ const dailyEventsCollectionMock = { createIndex : jest . fn ( ) . mockResolvedValue ( undefined ) } ;
549+
550+ mongoMock . databases . events . createCollection . mockImplementation ( ( name : string ) => {
551+ if ( name . startsWith ( 'events:' ) ) {
552+ return Promise . resolve ( eventsCollectionMock ) ;
553+ }
554+ if ( name . startsWith ( 'repetitions:' ) ) {
555+ return Promise . resolve ( repetitionsCollectionMock ) ;
556+ }
557+ if ( name . startsWith ( 'dailyEvents:' ) ) {
558+ return Promise . resolve ( dailyEventsCollectionMock ) ;
559+ }
560+ return Promise . reject ( new Error ( `Unexpected collection name: ${ name } ` ) ) ;
561+ } ) ;
562+
563+ const mockProject = {
564+ _id : projectId ,
565+ createNotificationsRule : jest . fn ( ) . mockResolvedValue ( undefined ) ,
566+ } ;
567+
568+ const mockProjectsFactory = {
569+ create : jest . fn ( ) . mockResolvedValue ( mockProject ) ,
570+ findById : jest . fn ( ) . mockResolvedValue ( mockProject ) ,
571+ } ;
572+
573+ const mockWorkspacesFactory = {
574+ findById : jest . fn ( ) . mockResolvedValue ( { _id : new ObjectId ( ) , name : 'Test Workspace' } ) ,
575+ } ;
576+
577+ const mockUsersFactory = {
578+ findById : jest . fn ( ) . mockResolvedValue ( { email : 'test@example.com' } ) ,
579+ } ;
580+
581+ const context = {
582+ user : { id : new ObjectId ( ) . toString ( ) } ,
583+ factories : {
584+ workspacesFactory : mockWorkspacesFactory as any ,
585+ projectsFactory : mockProjectsFactory as any ,
586+ usersFactory : mockUsersFactory as any ,
587+ plansFactory : { } as any ,
588+ businessOperationsFactory : { } as any ,
589+ releasesFactory : { } as any ,
590+ } ,
591+ } ;
592+
593+ await projectResolver . Mutation . createProject (
594+ { } ,
595+ { workspaceId : new ObjectId ( ) . toString ( ) , name : 'Test Project' , image : '' } ,
596+ context
597+ ) ;
598+
599+ expect ( repetitionsCollectionMock . createIndex ) . toHaveBeenCalledWith (
600+ { timestamp : 1 } ,
601+ { name : 'timestamp' , sparse : true }
602+ ) ;
603+ } ) ;
604+ } ) ;
0 commit comments