@@ -10,19 +10,57 @@ const path = '/foo'
10
10
const method = 'get'
11
11
const accountId = 'testid'
12
12
13
+ let shep
14
+
13
15
td . when ( fs . readJSON ( 'package.json' ) ) . thenResolve ( { name : 'bar' , shep : { } } )
14
16
td . when ( fs . writeJSON ( ) , { ignoreExtraArgs : true } ) . thenResolve ( )
15
- td . when ( load . api ( ) ) . thenResolve ( { paths : { } } )
16
17
17
- test . before ( ( ) => {
18
- const shep = require ( '../../src/index' )
19
- return shep . generateEndpoint ( { accountId, path, method } )
18
+ const functionName = 'noice-name-bro'
19
+ const generateName = td . replace ( '../../src/util/generate-name' )
20
+ td . when ( generateName ( ) , { ignoreExtraArgs : true } ) . thenResolve ( {
21
+ fullName : functionName
22
+ } )
23
+
24
+ test . before ( async ( ) => {
25
+ shep = require ( '../../src/index' )
20
26
} )
21
27
22
- test ( 'Writes a new api.json' , ( ) => {
28
+ test . beforeEach ( ( t ) => {
29
+ t . context . paths = { }
30
+
31
+ td . when ( load . api ( ) ) . thenResolve ( { paths : t . context . paths } )
32
+ } )
33
+
34
+ test ( 'Writes a new api.json file' , async ( ) => {
35
+ await shep . generateEndpoint ( { accountId, path, method } )
36
+
23
37
td . verify ( fs . writeJSON ( 'api.json' ) , { ignoreExtraArgs : true } )
24
38
} )
25
39
26
- test ( 'Generates a new function' , ( ) => {
40
+ test ( 'Generates a new function' , async ( ) => {
41
+ await shep . generateEndpoint ( { accountId, path, method } )
27
42
td . verify ( generateFunction ( td . matchers . contains ( { name : '/foo get' } ) ) )
28
43
} )
44
+
45
+ const integration = 'x-amazon-apigateway-integration'
46
+
47
+ const constructIntegrationObject = ( accountId , region ) => ( {
48
+ uri : `arn:aws:apigateway:${ region } :lambda:path/2015-03-31/functions/arn:aws:lambda:${ region } :${ accountId } :function:${ functionName } :\${stageVariables.functionAlias}/invocations` ,
49
+ passthroughBehavior : 'when_no_match' ,
50
+ httpMethod : 'POST' ,
51
+ type : 'aws_proxy'
52
+ } )
53
+
54
+ test ( 'adds a basic api path' , async ( t ) => {
55
+ const region = 'us-west-2'
56
+
57
+ await shep . generateEndpoint ( { accountId, path, method, region } )
58
+
59
+ t . deepEqual ( t . context . paths [ path ] [ method ] [ integration ] , constructIntegrationObject ( accountId , region ) )
60
+ } )
61
+
62
+ test ( 'defaults to us-east-1 region' , async ( t ) => {
63
+ await shep . generateEndpoint ( { accountId, path, method } )
64
+
65
+ t . deepEqual ( t . context . paths [ path ] [ method ] [ integration ] , constructIntegrationObject ( accountId , 'us-east-1' ) )
66
+ } )
0 commit comments