@@ -22,12 +22,19 @@ describe("NextPage", () => {
22
22
} ) ;
23
23
24
24
describe ( "#serverlessFunction" , ( ) => {
25
- it ( "should return function http event path /" , ( ) => {
25
+ it ( "should have http GET event with path /" , ( ) => {
26
26
const { events } = page . serverlessFunction . indexPage ;
27
27
28
- expect ( events ) . toHaveLength ( 1 ) ;
29
-
30
28
const httpEvent = events [ 0 ] . http ;
29
+ expect ( httpEvent . method ) . toEqual ( "get" ) ;
30
+ expect ( httpEvent . path ) . toEqual ( "/" ) ;
31
+ } ) ;
32
+
33
+ it ( "should have http HEAD event with path /" , ( ) => {
34
+ const { events } = page . serverlessFunction . indexPage ;
35
+
36
+ const httpEvent = events [ 1 ] . http ;
37
+ expect ( httpEvent . method ) . toEqual ( "head" ) ;
31
38
expect ( httpEvent . path ) . toEqual ( "/" ) ;
32
39
} ) ;
33
40
} ) ;
@@ -47,13 +54,27 @@ describe("NextPage", () => {
47
54
expect ( page . serverlessFunction . notFoundErrorPage ) . toBeDefined ( ) ;
48
55
} ) ;
49
56
50
- it ( "should return function http event path /{proxy+}" , ( ) => {
57
+ it ( "should return two events" , ( ) => {
58
+ const { events } = page . serverlessFunction . notFoundErrorPage ;
59
+ expect ( events ) . toHaveLength ( 2 ) ;
60
+ } ) ;
61
+
62
+ it ( "should return http event path /{proxy+} with GET method" , ( ) => {
51
63
const { events } = page . serverlessFunction . notFoundErrorPage ;
52
64
53
- expect ( events ) . toHaveLength ( 1 ) ;
65
+ const httpGet = events [ 0 ] . http ;
54
66
55
- const httpEvent = events [ 0 ] . http ;
56
- expect ( httpEvent . path ) . toEqual ( "/{proxy+}" ) ;
67
+ expect ( httpGet . path ) . toEqual ( "/{proxy+}" ) ;
68
+ expect ( httpGet . method ) . toEqual ( "get" ) ;
69
+ } ) ;
70
+
71
+ it ( "should return http event path /{proxy+} with HEAD method" , ( ) => {
72
+ const { events } = page . serverlessFunction . notFoundErrorPage ;
73
+
74
+ const httpHead = events [ 1 ] . http ;
75
+
76
+ expect ( httpHead . path ) . toEqual ( "/{proxy+}" ) ;
77
+ expect ( httpHead . method ) . toEqual ( "head" ) ;
57
78
} ) ;
58
79
} ) ;
59
80
} ) ;
@@ -71,12 +92,15 @@ describe("NextPage", () => {
71
92
it ( "should have URI path matching subdirectories" , ( ) => {
72
93
const { events } = page . serverlessFunction . fridgesPage ;
73
94
74
- expect ( events ) . toHaveLength ( 1 ) ;
95
+ expect ( events ) . toHaveLength ( 2 ) ;
75
96
76
- const httpEvent = events [ 0 ] . http ;
97
+ const httpGet = events [ 0 ] . http ;
98
+ const httpHead = events [ 1 ] . http ;
77
99
78
- expect ( httpEvent . path ) . toEqual ( "categories/fridge/fridges" ) ;
79
- expect ( httpEvent . method ) . toEqual ( "get" ) ;
100
+ expect ( httpGet . path ) . toEqual ( "categories/fridge/fridges" ) ;
101
+ expect ( httpGet . method ) . toEqual ( "get" ) ;
102
+ expect ( httpHead . path ) . toEqual ( "categories/fridge/fridges" ) ;
103
+ expect ( httpHead . method ) . toEqual ( "head" ) ;
80
104
} ) ;
81
105
} ) ;
82
106
} ) ;
@@ -167,54 +191,105 @@ describe("NextPage", () => {
167
191
expect ( handler ) . toEqual ( `${ buildDir } /admin.render` ) ;
168
192
} ) ;
169
193
170
- it ( "should return function http event " , ( ) => {
194
+ it ( "should return 2 http events " , ( ) => {
171
195
const { events } = page . serverlessFunction . adminPage ;
196
+ expect ( events ) . toHaveLength ( 2 ) ;
197
+ } ) ;
172
198
173
- expect ( events ) . toHaveLength ( 1 ) ;
199
+ it ( "should return function http GET event" , ( ) => {
200
+ const { events } = page . serverlessFunction . adminPage ;
174
201
175
202
const httpEvent = events [ 0 ] . http ;
176
203
177
204
expect ( httpEvent . path ) . toEqual ( "admin" ) ;
178
205
expect ( httpEvent . method ) . toEqual ( "get" ) ;
179
206
} ) ;
180
207
181
- it ( "should override serverlessFunction with provided pageConfig" , ( ) => {
182
- const serverlessFunctionOverrides = { foo : "bar" } ;
183
-
184
- const pageWithCustomConfig = new NextPage (
185
- pagePath ,
186
- serverlessFunctionOverrides
187
- ) ;
188
-
189
- expect ( pageWithCustomConfig . serverlessFunction . adminPage . foo ) . toBe (
190
- "bar"
191
- ) ;
192
- } ) ;
193
-
194
- it ( "should NOT change handler with provided pageConfig" , ( ) => {
195
- const serverlessFunctionOverrides = { handler : "invalid/handler" } ;
208
+ it ( "should return function http HEAD event" , ( ) => {
209
+ const { events } = page . serverlessFunction . adminPage ;
196
210
197
- const pageWithCustomConfig = new NextPage (
198
- pagePath ,
199
- serverlessFunctionOverrides
200
- ) ;
211
+ const httpEvent = events [ 1 ] . http ;
201
212
202
- expect ( pageWithCustomConfig . serverlessFunction . adminPage . handler ) . toBe (
203
- pageWithCustomConfig . pageHandler
204
- ) ;
213
+ expect ( httpEvent . path ) . toEqual ( "admin" ) ;
214
+ expect ( httpEvent . method ) . toEqual ( "head" ) ;
205
215
} ) ;
206
216
207
- it ( "should NOT change runtime with provided pageConfig" , ( ) => {
208
- const serverlessFunctionOverrides = { runtime : "python2.7" } ;
209
-
210
- const pageWithCustomConfig = new NextPage (
211
- pagePath ,
212
- serverlessFunctionOverrides
213
- ) ;
214
-
215
- expect ( pageWithCustomConfig . serverlessFunction . adminPage . runtime ) . toBe (
216
- undefined
217
- ) ;
217
+ describe ( "When pageConfig override is provided" , ( ) => {
218
+ it ( "should create identical HEAD route for custom GET route" , ( ) => {
219
+ const serverlessFunctionOverrides = {
220
+ events : [
221
+ {
222
+ http : {
223
+ path : "admin/{id}" ,
224
+ request : {
225
+ parameters : {
226
+ id : true
227
+ }
228
+ }
229
+ }
230
+ }
231
+ ]
232
+ } ;
233
+
234
+ const pageWithCustomConfig = new NextPage (
235
+ pagePath ,
236
+ serverlessFunctionOverrides
237
+ ) ;
238
+
239
+ const { events } = pageWithCustomConfig . serverlessFunction . adminPage ;
240
+ expect ( events ) . toHaveLength ( 2 ) ;
241
+
242
+ const httpGet = events [ 0 ] . http ;
243
+ const httpHead = events [ 1 ] . http ;
244
+
245
+ expect ( httpGet . method ) . toBe ( "get" ) ;
246
+ expect ( httpHead . method ) . toBe ( "head" ) ;
247
+
248
+ expect ( httpGet . path ) . toBe ( "admin/{id}" ) ;
249
+ expect ( httpHead . path ) . toBe ( "admin/{id}" ) ;
250
+
251
+ expect ( httpGet . request . parameters . id ) . toBe ( true ) ;
252
+ expect ( httpHead . request . parameters . id ) . toBe ( true ) ;
253
+ } ) ;
254
+
255
+ it ( "should override serverlessFunction with provided pageConfig" , ( ) => {
256
+ const serverlessFunctionOverrides = { foo : "bar" } ;
257
+
258
+ const pageWithCustomConfig = new NextPage (
259
+ pagePath ,
260
+ serverlessFunctionOverrides
261
+ ) ;
262
+
263
+ expect ( pageWithCustomConfig . serverlessFunction . adminPage . foo ) . toBe (
264
+ "bar"
265
+ ) ;
266
+ } ) ;
267
+
268
+ it ( "should NOT change handler with provided pageConfig" , ( ) => {
269
+ const serverlessFunctionOverrides = { handler : "invalid/handler" } ;
270
+
271
+ const pageWithCustomConfig = new NextPage (
272
+ pagePath ,
273
+ serverlessFunctionOverrides
274
+ ) ;
275
+
276
+ expect (
277
+ pageWithCustomConfig . serverlessFunction . adminPage . handler
278
+ ) . toBe ( pageWithCustomConfig . pageHandler ) ;
279
+ } ) ;
280
+
281
+ it ( "should NOT change runtime with provided pageConfig" , ( ) => {
282
+ const serverlessFunctionOverrides = { runtime : "python2.7" } ;
283
+
284
+ const pageWithCustomConfig = new NextPage (
285
+ pagePath ,
286
+ serverlessFunctionOverrides
287
+ ) ;
288
+
289
+ expect (
290
+ pageWithCustomConfig . serverlessFunction . adminPage . runtime
291
+ ) . toBe ( undefined ) ;
292
+ } ) ;
218
293
} ) ;
219
294
} ) ;
220
295
} ) ;
0 commit comments