Skip to content

Commit e6cfb94

Browse files
committed
add tests
1 parent bae939c commit e6cfb94

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

lib/apiGateway/methods.test.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use strict'
2+
3+
const chai = require('chai')
4+
const Serverless = require('serverless/lib/Serverless')
5+
const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider')
6+
const ServerlessApigatewayServiceProxy = require('./../index')
7+
8+
chai.use(require('chai-as-promised'))
9+
const expect = require('chai').expect
10+
11+
describe('#getAllServiceProxies()', () => {
12+
let serverless
13+
let serverlessApigatewayServiceProxy
14+
15+
beforeEach(() => {
16+
serverless = new Serverless()
17+
serverless.servicePath = true
18+
serverless.service.service = 'apigw-service-proxy'
19+
const options = {
20+
stage: 'dev',
21+
region: 'us-east-1'
22+
}
23+
serverless.setProvider('aws', new AwsProvider(serverless))
24+
serverlessApigatewayServiceProxy = new ServerlessApigatewayServiceProxy(serverless, options)
25+
})
26+
27+
describe('#getMethodResponses()', () => {
28+
it('should return a corresponding methodResponses resource', () => {
29+
return
30+
serverlessApigatewayServiceProxy
31+
.getMethodResponses()
32+
.to.eventually.be.fulfilled.then((json) => {
33+
expect(json.Properties).to.have.property('MethodResponses')
34+
})
35+
})
36+
37+
it('should set Access-Control-Allow-Origin header when cors is true', () => {
38+
return
39+
serverlessApigatewayServiceProxy
40+
.getMethodResponses({
41+
cors: {
42+
origins: ['*', 'http://example.com']
43+
}
44+
})
45+
.to.eventually.be.fulfilled.then((json) => {
46+
expect(
47+
json.Properties.MethodResponses[0].ResponseParameters[
48+
'method.response.header.Access-Control-Allow-Origin'
49+
]
50+
).to.equal("'*,http://example.com'")
51+
52+
expect(
53+
serverlessApigatewayServiceProxy.getMethodResponses({
54+
cors: {
55+
origin: '*'
56+
}
57+
}).Properties.MethodResponses[0].ResponseParameters[
58+
'method.response.header.Access-Control-Allow-Origin'
59+
]
60+
).to.equal("'*'")
61+
})
62+
63+
return
64+
serverlessApigatewayServiceProxy
65+
.getMethodResponses({
66+
cors: {
67+
origin: '*'
68+
}
69+
})
70+
.to.eventually.be.fulfilled.then((json) => {
71+
expect(
72+
json.Properties.MethodResponses[0].ResponseParameters[
73+
'method.response.header.Access-Control-Allow-Origin'
74+
]
75+
).to.equal("'*'")
76+
})
77+
})
78+
})
79+
})

lib/utils.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const expect = require('chai').expect
4-
//const BbPromise = require('bluebird')
54
const Serverless = require('serverless/lib/Serverless')
65
const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider')
76
const ServerlessApigatewayServiceProxy = require('./index')

0 commit comments

Comments
 (0)