File tree Expand file tree Collapse file tree 7 files changed +98
-4
lines changed
tests/end-to-end/defaultResponse Expand file tree Collapse file tree 7 files changed +98
-4
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ if (env.TEST === undefined || env.TEST === "all") {
8
8
spec = [ "./src/**/*.test.js" , "tests/**/*.test.js" ]
9
9
}
10
10
11
+ if ( env . TEST === "e2e" ) {
12
+ spec = [ "tests/end-to-end/**/*.test.js" ]
13
+ }
14
+
11
15
if ( env . TEST === "unit" ) {
12
16
spec = [ "./src/**/*.test.js" , "tests/old-unit/**/*.test.js" ]
13
17
}
Original file line number Diff line number Diff line change 20
20
"prettier:fix" : " prettier --write ." ,
21
21
"test" : " mocha --require ./tests/mochaHooks.cjs" ,
22
22
"test:cov" : " NODE_OPTIONS='--experimental-loader @istanbuljs/esm-loader-hook' nyc --reporter=html npm test" ,
23
- "test:node" : " TEST=unit mocha --require ./tests/mochaHooks.cjs" ,
24
- "test:unit" : " TEST=unit mocha --require ./tests/mochaHooks.cjs"
23
+ "test:node" : " TEST=node mocha --require ./tests/mochaHooks.cjs" ,
24
+ "test:unit" : " TEST=unit mocha --require ./tests/mochaHooks.cjs" ,
25
+ "test:e2e" : " TEST=e2e mocha --require ./tests/mochaHooks.cjs"
25
26
},
26
27
"repository" : {
27
28
"type" : " git" ,
Original file line number Diff line number Diff line change @@ -654,8 +654,7 @@ export default class HttpServer {
654
654
655
655
log . debug ( `Using response '${ responseName } '` )
656
656
657
- const chosenResponse = endpoint . responses [ responseName ]
658
-
657
+ const chosenResponse = endpoint . responses ?. [ responseName ] ?? { }
659
658
/* RESPONSE PARAMETERS PROCCESSING */
660
659
661
660
const { responseParameters } = chosenResponse
Original file line number Diff line number Diff line change
1
+ import assert from "node:assert"
2
+ import { join } from "desm"
3
+ import { BASE_URL } from "../../config.js"
4
+ import { setup , teardown } from "../../_testHelpers/index.js"
5
+
6
+ describe ( "default response" , function desc ( ) {
7
+ beforeEach ( ( ) =>
8
+ setup ( {
9
+ servicePath : join ( import . meta. url , "src" ) ,
10
+ } ) ,
11
+ )
12
+
13
+ afterEach ( ( ) => teardown ( ) )
14
+
15
+ it ( "when no default response is provided" , async ( ) => {
16
+ const url = new URL ( "/dev/product_without_default" , BASE_URL )
17
+ const response = await fetch ( url )
18
+ const json = await response . json ( )
19
+
20
+ assert . deepEqual ( json , {
21
+ foo : "bar" ,
22
+ } )
23
+ } )
24
+
25
+ it ( "when default response is provided" , async ( ) => {
26
+ const url = new URL ( "/dev/product_with_default" , BASE_URL )
27
+ const response = await fetch ( url )
28
+ const json = await response . json ( )
29
+
30
+ assert . deepEqual ( json , {
31
+ foo : "bar" ,
32
+ } )
33
+ } )
34
+ } )
Original file line number Diff line number Diff line change
1
+ const { stringify } = JSON
2
+
3
+ export const hello = async ( ) => {
4
+ return {
5
+ body : stringify ( {
6
+ foo : "bar" ,
7
+ } ) ,
8
+ statusCode : 200 ,
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " module"
3
+ }
Original file line number Diff line number Diff line change
1
+ service : uncategorized-tests
2
+
3
+ frameworkVersion : " 3"
4
+
5
+ plugins :
6
+ - ../../../../src/index.js
7
+
8
+ provider :
9
+ name : aws
10
+ region : us-east-1
11
+ runtime : nodejs18.x
12
+ stage : dev
13
+ apiGateway :
14
+ minimumCompressionSize : 1024
15
+ shouldStartNameWithService : true
16
+
17
+ functions :
18
+ helloWithoutDefault :
19
+ events :
20
+ - http :
21
+ method : get
22
+ path : /product_without_default
23
+ responses :
24
+ 200 :
25
+ description : This is a success response
26
+ bodyType : Product
27
+ handler : handler.hello
28
+ helloWithDefault :
29
+ events :
30
+ - http :
31
+ method : get
32
+ path : /product_with_default
33
+ responses :
34
+ default :
35
+ description : This is a default response
36
+ bodyType : Product
37
+ 200 :
38
+ description : This is a success response
39
+ bodyType : Product
40
+ handler : handler.hello
41
+
42
+ package :
43
+ individually : true
You can’t perform that action at this time.
0 commit comments