Skip to content

Commit 0a9afff

Browse files
committed
update tests
1 parent 717191c commit 0a9afff

File tree

7 files changed

+71
-15
lines changed

7 files changed

+71
-15
lines changed

tests/integration/kinesis/tests.js renamed to __tests__/integration/kinesis/tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const expect = require('chai').expect
44
const fetch = require('node-fetch')
55
const { deployService, removeService, getApiGatewayEndpoint } = require('./../../utils')
66

7-
describe('AWS - API Gateway Integration Test', () => {
7+
describe('Kinesis Proxy Integration Test', () => {
88
let endpoint
99
let stackName
1010
let stage
11-
const config = 'tests/integration/kinesis/service/serverless.yml'
11+
const config = '__tests__/integration/kinesis/service/serverless.yml'
1212

1313
beforeAll(async () => {
1414
stage = Math.random()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
service: sqs-proxy
2+
3+
provider:
4+
name: aws
5+
runtime: nodejs10.x
6+
7+
plugins:
8+
localPath: './../'
9+
modules:
10+
- serverless-apigateway-service-proxy
11+
12+
custom:
13+
apiGatewayServiceProxies:
14+
- sqs:
15+
path: /sqs
16+
method: post
17+
queueName: {"Fn::GetAtt":[ "SQSQueue", "QueueName" ]}
18+
cors: true
19+
20+
resources:
21+
Resources:
22+
SQSQueue:
23+
Type: "AWS::SQS::Queue"

__tests__/integration/sqs/tests.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict'
2+
3+
const expect = require('chai').expect
4+
const fetch = require('node-fetch')
5+
const { deployService, removeService, getApiGatewayEndpoint } = require('./../../utils')
6+
7+
describe('SQS Proxy Integration Test', () => {
8+
let endpoint
9+
let stackName
10+
let stage
11+
const config = '__tests__/integration/sqs/service/serverless.yml'
12+
13+
beforeAll(async () => {
14+
stage = Math.random()
15+
.toString(32)
16+
.substring(2)
17+
stackName = 'sqs-proxy-' + stage
18+
deployService(stage, config)
19+
endpoint = await getApiGatewayEndpoint(stackName)
20+
})
21+
22+
afterAll(() => {
23+
removeService(stage, config)
24+
})
25+
26+
it('should get correct response from sqs proxy endpoint', async () => {
27+
const testEndpoint = `${endpoint}/sqs`
28+
29+
const response = await fetch(testEndpoint, {
30+
method: 'POST',
31+
headers: { 'Content-Type': 'application/json' },
32+
body: JSON.stringify({ message: 'testtest' })
33+
})
34+
expect(response.headers.get('access-control-allow-origin')).to.deep.equal('*')
35+
expect(response.status).to.be.equal(200)
36+
const body = await response.json()
37+
expect(body.SendMessageResponse.SendMessageResult).to.have.own.property(
38+
'MD5OfMessageAttributes'
39+
)
40+
expect(body.SendMessageResponse.SendMessageResult).to.have.own.property('MD5OfMessageBody')
41+
expect(body.SendMessageResponse.SendMessageResult).to.have.own.property('MessageId')
42+
expect(body.SendMessageResponse.SendMessageResult).to.have.own.property('SequenceNumber')
43+
expect(body.SendMessageResponse.ResponseMetadata).to.have.own.property('RequestId')
44+
})
45+
})
File renamed without changes.

tests/utils.js renamed to __tests__/utils.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
.OutputValue
1414
return endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]
1515
},
16+
1617
deployService(stage, config) {
1718
execSync(`npx serverless deploy --stage ${stage} --config ${config}`, {
1819
stdio: 'inherit'
@@ -21,9 +22,5 @@ module.exports = {
2122

2223
removeService(stage, config) {
2324
execSync(`npx serverless remove --stage ${stage} --config ${config}`, { stdio: 'inherit' })
24-
},
25-
26-
async sleep(second) {
27-
await new Promise((r) => setTimeout(r, second))
2825
}
2926
}

package.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
"git add"
1717
]
1818
},
19-
"jest": {
20-
"setupFilesAfterEnv": [
21-
"<rootDir>/tests/setup-tests.js"
22-
],
23-
"testEnvironment": "node",
24-
"testRegex": "(\\.|/)(tests)\\.js$",
25-
"testRunner": "jest-circus/runner",
26-
"useStderr": true
27-
},
2819
"dependencies": {
2920
"serverless": "^1.48.2"
3021
},

0 commit comments

Comments
 (0)