@@ -72,7 +72,8 @@ describe('graphQLController', () => {
7272 jest . resetAllMocks ( ) ;
7373 } ) ;
7474
75- xit ( 'should call api.send and api.receive with the correct arguments' , ( ) => {
75+ // this test was previously commented out and fails
76+ it ( 'should call api.send and api.receive with the correct arguments' , ( ) => {
7677 const url = 'https://example.com/graphql' ;
7778 const headers = [ { key : 'Content-Type' , value : 'application/json' } ] ;
7879 const cookies = [ { key : 'session_id' , value : '1234' } ] ;
@@ -123,7 +124,8 @@ describe('graphQLController', () => {
123124 ) ;
124125 } ) ;
125126
126- xit ( 'should dispatch an action with the error message if the introspection query returns an error' , ( ) => {
127+ // this test was previously commented out and fails
128+ it ( 'should dispatch an action with the error message if the introspection query returns an error' , ( ) => {
127129 const url = 'https://example.com/graphql' ;
128130 const headers = [ { key : 'Content-Type' , value : 'application/json' } ] ;
129131 const cookies = [ { key : 'session_id' , value : '1234' } ] ;
@@ -154,27 +156,28 @@ describe('graphQLController', () => {
154156 ) ;
155157 } ) ;
156158
157- // it('should send introspection query and dispatch introspectionDataChanged action', () => {
158- // const url = 'http://localhost:4000/graphql';
159- // const headers = [{ key: 'Authorization', value: 'Bearer <token>' }];
160- // const cookies = [];
161-
162- // const expectedData = { schemaSDL: 'schema sdl', clientSchema: 'client schema' };
163- // const mockIntrospectionQuery = { __schema: { types: [] } };
164- // // jest.spyOn(graphQLController, 'buildClientSchema').mockReturnValueOnce('client schema');
165- // jest.spyOn(graphQLController, 'printSchema').mockReturnValueOnce('schema sdl');
166- // jest.spyOn(graphQLController, 'introspectionDataChanged').mockReturnValueOnce('introspectionDataChanged action');
167- // jest.spyOn(api, 'receive').mockImplementationOnce((eventName, callback) => callback(mockIntrospectionQuery));
168-
169- // graphQLController.introspect(url, headers, cookies);
170-
171- // expect(api.send).toHaveBeenCalledWith('introspect', JSON.stringify({ url, headers, cookies }));
172- // // expect(graphQLController.buildClientSchema).toHaveBeenCalledWith(mockIntrospectionQuery);
173- // expect(graphQLController.buildClientSchema).toHaveBeenCalledWithTimes(1);
174- // // expect(graphQLController.printSchema).toHaveBeenCalledWith('client schema');
175- // expect(graphQLController.printSchema).toHaveBeenCalledTimes(1);
176- // expect(appDispatch).toHaveBeenCalledWith(introspectionDataChanged(expectedData));
177- // });
159+ // this test was previously commented out and fails
160+ it ( 'should send introspection query and dispatch introspectionDataChanged action' , ( ) => {
161+ const url = 'http://localhost:4000/graphql' ;
162+ const headers = [ { key : 'Authorization' , value : 'Bearer <token>' } ] ;
163+ const cookies = [ ] ;
164+
165+ const expectedData = { schemaSDL : 'schema sdl' , clientSchema : 'client schema' } ;
166+ const mockIntrospectionQuery = { __schema : { types : [ ] } } ;
167+ jest . spyOn ( graphQLController , 'buildClientSchema' ) . mockReturnValueOnce ( 'client schema' ) ;
168+ jest . spyOn ( graphQLController , 'printSchema' ) . mockReturnValueOnce ( 'schema sdl' ) ;
169+ jest . spyOn ( graphQLController , 'introspectionDataChanged' ) . mockReturnValueOnce ( 'introspectionDataChanged action' ) ;
170+ jest . spyOn ( api , 'receive' ) . mockImplementationOnce ( ( eventName , callback ) => callback ( mockIntrospectionQuery ) ) ;
171+
172+ graphQLController . introspect ( url , headers , cookies ) ;
173+
174+ expect ( api . send ) . toHaveBeenCalledWith ( 'introspect' , JSON . stringify ( { url, headers, cookies } ) ) ;
175+ expect ( graphQLController . buildClientSchema ) . toHaveBeenCalledWith ( mockIntrospectionQuery ) ;
176+ expect ( graphQLController . buildClientSchema ) . toHaveBeenCalledWithTimes ( 1 ) ;
177+ expect ( graphQLController . printSchema ) . toHaveBeenCalledWith ( 'client schema' ) ;
178+ expect ( graphQLController . printSchema ) . toHaveBeenCalledTimes ( 1 ) ;
179+ expect ( appDispatch ) . toHaveBeenCalledWith ( introspectionDataChanged ( expectedData ) ) ;
180+ } ) ;
178181 } ) ;
179182
180183 // Test cases for openGraphQLConnection
@@ -189,7 +192,7 @@ describe('graphQLController', () => {
189192 timeSent : Date . now ( ) ,
190193 } ;
191194
192- xit ( 'should initialize response data correctly' , async ( ) => {
195+ it ( 'should initialize response data correctly' , async ( ) => {
193196 await graphQLController . openGraphQLConnection ( reqResObj ) ;
194197
195198 expect ( reqResObj . response . headers ) . toEqual ( { } ) ;
@@ -240,7 +243,7 @@ describe('graphQLController', () => {
240243 /* create an array of ReqRes objects */
241244 ] ;
242245
243- xit ( 'should call runSingleGraphQLRequest with the first object in the array' , async ( ) => {
246+ it ( 'should call runSingleGraphQLRequest with the first object in the array' , async ( ) => {
244247 const runSingleGraphQLRequestSpy = jest . spyOn (
245248 graphQLController ,
246249 'runSingleGraphQLRequest'
@@ -251,17 +254,18 @@ describe('graphQLController', () => {
251254 expect ( runSingleGraphQLRequestSpy ) . toHaveBeenCalledWith ( reqResArray [ 0 ] ) ;
252255 } ) ;
253256
254- // it('should call runSingleGraphQLRequest with the next object in the array after the first object has received a response', async () => {
255- // const response = { /* create a GraphQLResponse object */ };
256- // const sendGqlToMainSpy = jest.spyOn(graphQLController, 'sendGqlToMain')
257- // .mockResolvedValue({ data: response, reqResObj: reqResArray[0] });
257+ // this test was previously commented out and fails
258+ it ( 'should call runSingleGraphQLRequest with the next object in the array after the first object has received a response' , async ( ) => {
259+ const response = { /* create a GraphQLResponse object */ } ;
260+ const sendGqlToMainSpy = jest . spyOn ( graphQLController , 'sendGqlToMain' )
261+ . mockResolvedValue ( { data : response , reqResObj : reqResArray [ 0 ] } ) ;
258262
259- // const runSingleGraphQLRequestSpy = jest.spyOn(graphQLController, 'runSingleGraphQLRequest');
263+ const runSingleGraphQLRequestSpy = jest . spyOn ( graphQLController , 'runSingleGraphQLRequest' ) ;
260264
261- // await graphQLController.openGraphQLConnectionAndRunCollection(reqResArray);
265+ await graphQLController . openGraphQLConnectionAndRunCollection ( reqResArray ) ;
262266
263- // expect(runSingleGraphQLRequestSpy).toHaveBeenCalledWith(reqResArray[1]);
264- // });
267+ expect ( runSingleGraphQLRequestSpy ) . toHaveBeenCalledWith ( reqResArray [ 1 ] ) ;
268+ } ) ;
265269 } ) ;
266270} ) ;
267271
0 commit comments