@@ -17,17 +17,17 @@ const ApolloServer = require("../../src/ApolloServer").ApolloServer;
1717//ApolloServerCore.convertNodeHttpToRequest.mockImplementation(() => "convertedRequest");
1818
1919describe ( "Test ApolloServer" , ( ) => {
20- it ( "should support Uploads" , ( ) => {
20+ test ( "should support Uploads" , ( ) => {
2121 const apolloServer = new ApolloServer ( { } ) ;
2222 expect ( apolloServer . supportsUploads ( ) ) . toBe ( true ) ;
2323 } ) ;
2424
25- it ( "should support subscriptions" , ( ) => {
25+ test ( "should support subscriptions" , ( ) => {
2626 const apolloServer = new ApolloServer ( { } ) ;
2727 expect ( apolloServer . supportsSubscriptions ( ) ) . toBe ( true ) ;
2828 } ) ;
2929
30- it ( "should call super graphQLServerOptions" , ( ) => {
30+ test ( "should call super graphQLServerOptions" , ( ) => {
3131 const apolloServer = new ApolloServer ( { } ) ;
3232 ApolloServerBase . prototype . graphQLServerOptions = jest . fn ( ) ;
3333
@@ -54,9 +54,10 @@ describe("Test ApolloServer", () => {
5454 const fakeRes = {
5555 $ctx : fakeCtx ,
5656 $service : fakeService ,
57+ $route : { } ,
5758 } ;
5859
59- it ( "should return 200 'pass'" , async ( ) => {
60+ test ( "should return 200 'pass'" , async ( ) => {
6061 const onHealthCheck = jest . fn ( ( ) => "Everything OK" ) ;
6162
6263 await apolloServer . handleHealthCheck ( { req : fakeReq , res : fakeRes , onHealthCheck } ) ;
@@ -75,7 +76,7 @@ describe("Test ApolloServer", () => {
7576 expect ( fakeCtx . meta . $responseType ) . toBe ( "application/health+json" ) ;
7677 } ) ;
7778
78- it ( "should return 503 'fail'" , async ( ) => {
79+ test ( "should return 503 'fail'" , async ( ) => {
7980 fakeService . sendResponse . mockClear ( ) ;
8081
8182 const onHealthCheck = jest . fn ( ( ) => Promise . reject ( new Error ( "Something wrong" ) ) ) ;
@@ -96,7 +97,7 @@ describe("Test ApolloServer", () => {
9697 expect ( fakeCtx . meta . $responseType ) . toBe ( "application/health+json" ) ;
9798 } ) ;
9899
99- it ( "should call an empty healthcheck function" , async ( ) => {
100+ test ( "should call an empty healthcheck function" , async ( ) => {
100101 fakeService . sendResponse . mockClear ( ) ;
101102 fakeCtx . meta . $responseType = "application/json" ;
102103
@@ -130,15 +131,21 @@ describe("Test ApolloServer", () => {
130131 sendResponse : jest . fn ( ) ,
131132 } ;
132133
133- let fakeReq = {
134- headers : { } ,
135- } ;
136- let fakeRes = {
137- $ctx : fakeCtx ,
138- $service : fakeService ,
139- } ;
134+ let fakeReq ;
135+ let fakeRes ;
140136
141- it ( "should handle as a request" , async ( ) => {
137+ beforeEach ( ( ) => {
138+ fakeReq = {
139+ headers : { } ,
140+ } ;
141+ fakeRes = {
142+ $ctx : fakeCtx ,
143+ $service : fakeService ,
144+ $route : { } ,
145+ } ;
146+ } ) ;
147+
148+ test ( "should handle as a request" , async ( ) => {
142149 const handler = apolloServer . createHandler ( ) ;
143150
144151 await handler ( fakeReq , fakeRes ) ;
@@ -155,7 +162,7 @@ describe("Test ApolloServer", () => {
155162 expect ( fakeService . sendResponse ) . toBeCalledWith (
156163 fakeReq ,
157164 fakeRes ,
158- "GraphQL Response Data" ,
165+ "GraphQL Response Data"
159166 ) ;
160167
161168 expect ( fakeCtx . meta . $responseType ) . toBe ( "application/json" ) ;
@@ -166,7 +173,25 @@ describe("Test ApolloServer", () => {
166173 expect ( apolloServer . createGraphQLServerOptions ) . toBeCalledWith ( fakeReq , fakeRes ) ;
167174 } ) ;
168175
169- it ( "should handle as a file upload request" , async ( ) => {
176+ test ( "should call onAfterCall function" , async ( ) => {
177+ const handler = apolloServer . createHandler ( ) ;
178+ const onAfterCall = jest . fn ( ) ;
179+ const $route = { onAfterCall } ;
180+ fakeRes . $route = $route ;
181+
182+ await handler ( fakeReq , fakeRes ) ;
183+
184+ expect ( onAfterCall ) . toHaveBeenCalledTimes ( 1 ) ;
185+ expect ( onAfterCall ) . toHaveBeenCalledWith (
186+ fakeCtx ,
187+ $route ,
188+ fakeReq ,
189+ fakeRes ,
190+ "GraphQL Response Data"
191+ ) ;
192+ } ) ;
193+
194+ test ( "should handle as a file upload request" , async ( ) => {
170195 // Clear mocks
171196 moleculerApollo . mockClear ( ) ;
172197 fakeGraphqlHandler . mockClear ( ) ;
@@ -190,7 +215,7 @@ describe("Test ApolloServer", () => {
190215 expect ( GraphqlUpload . processRequest ) . toBeCalledWith (
191216 fakeReq ,
192217 fakeRes ,
193- apolloServer . uploadsConfig ,
218+ apolloServer . uploadsConfig
194219 ) ;
195220
196221 expect ( moleculerApollo ) . toBeCalledTimes ( 1 ) ;
@@ -205,13 +230,13 @@ describe("Test ApolloServer", () => {
205230 expect ( fakeService . sendResponse ) . toBeCalledWith (
206231 fakeReq ,
207232 fakeRes ,
208- "GraphQL Response Data" ,
233+ "GraphQL Response Data"
209234 ) ;
210235
211236 expect ( fakeCtx . meta . $responseType ) . toBe ( "application/json" ) ;
212237 } ) ;
213238
214- it ( "should handle as health-check request" , async ( ) => {
239+ test ( "should handle as health-check request" , async ( ) => {
215240 // Clear mocks
216241 moleculerApollo . mockClear ( ) ;
217242 fakeGraphqlHandler . mockClear ( ) ;
@@ -241,7 +266,7 @@ describe("Test ApolloServer", () => {
241266 expect ( moleculerApollo ) . toBeCalledTimes ( 0 ) ;
242267 } ) ;
243268
244- it ( "should not handle as health-check request if disabled" , async ( ) => {
269+ test ( "should not handle as health-check request if disabled" , async ( ) => {
245270 // Clear mocks
246271 moleculerApollo . mockClear ( ) ;
247272 fakeGraphqlHandler . mockClear ( ) ;
@@ -265,7 +290,7 @@ describe("Test ApolloServer", () => {
265290 expect ( moleculerApollo ) . toBeCalledTimes ( 1 ) ;
266291 } ) ;
267292
268- it ( "should handle as playground request" , async ( ) => {
293+ test ( "should handle as playground request" , async ( ) => {
269294 // Clear mocks
270295 moleculerApollo . mockClear ( ) ;
271296 fakeService . sendResponse . mockClear ( ) ;
0 commit comments