File tree Expand file tree Collapse file tree 1 file changed +40
-2
lines changed
Expand file tree Collapse file tree 1 file changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -19,9 +19,7 @@ describe('GraphQLQueryPurifier', () => {
1919 mockRes . status = jest . fn ( ) . mockReturnThis ( ) ;
2020 mockRes . send = jest . fn ( ) ;
2121
22- // Mock the necessary functions
2322 ( fs . watch as jest . Mock ) . mockImplementation ( ( path , options , callback ) => {
24- // Simulate file change
2523 callback ( 'change' , 'test.gql' ) ;
2624 return { close : jest . fn ( ) } ;
2725 } ) ;
@@ -100,4 +98,44 @@ describe('GraphQLQueryPurifier', () => {
10098 expect ( mockReq . body . query ) . toBe ( '{ __typename }' ) ;
10199 expect ( mockNext ) . toHaveBeenCalled ( ) ;
102100 } ) ;
101+
102+ test ( 'should throw error for duplicate operation names when loading queries' , ( ) => {
103+ ( glob . sync as jest . Mock ) . mockReturnValue ( [
104+ './graphql/queries/findMyJobs1.gql' ,
105+ './graphql/queries/findMyJobs2.gql' ,
106+ ] ) ;
107+
108+ ( fs . readFileSync as jest . Mock ) . mockReturnValueOnce ( `
109+ query FindMyJobs {
110+ data: findJobs {
111+ id
112+ createdAt
113+ job {
114+ id
115+ title
116+ }
117+ }
118+ }
119+ ` ) . mockReturnValueOnce ( `
120+ query FindMyJobs {
121+ data: findJobs {
122+ id
123+ createdAt
124+ deletedAt
125+ job {
126+ id
127+ title
128+ company {
129+ name
130+ }
131+ }
132+ }
133+ }
134+ ` ) ;
135+
136+ expect ( ( ) => {
137+ // @ts -ignore
138+ purifier . loadQueries ( ) ;
139+ } ) . toThrowError ( 'Duplicate operation name detected: FindMyJobs.' ) ;
140+ } ) ;
103141} ) ;
You can’t perform that action at this time.
0 commit comments