Skip to content

Commit 894682f

Browse files
test: added multiple proxies s3 int test
1 parent 05760c5 commit 894682f

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
service: multiple-s3-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+
- s3:
15+
path: /s3
16+
method: post
17+
action: PutObject
18+
bucket:
19+
Ref: S3Bucket
20+
key: my-test-object.json # static key
21+
cors: true
22+
23+
- s3:
24+
path: /s3/{key} # path param
25+
method: get
26+
action: GetObject
27+
bucket:
28+
Ref: S3Bucket
29+
key:
30+
pathParam: key
31+
cors: true
32+
33+
- s3:
34+
path: /s3
35+
method: delete
36+
action: DeleteObject
37+
bucket:
38+
Ref: S3Bucket
39+
key:
40+
queryStringParam: key # query string param
41+
cors: true
42+
43+
resources:
44+
Resources:
45+
S3Bucket:
46+
Type: 'AWS::S3::Bucket'
47+
48+
Outputs:
49+
S3BucketName:
50+
Value:
51+
Ref: S3Bucket
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict'
2+
3+
const expect = require('chai').expect
4+
const fetch = require('node-fetch')
5+
const {
6+
deployWithRandomStage,
7+
removeService,
8+
getS3Object,
9+
deleteS3Object
10+
} = require('../../../utils')
11+
12+
describe('Multiple S3 Proxies Integration Test', () => {
13+
let endpoint
14+
let stage
15+
let bucket
16+
const config = '__tests__/integration/s3/multiple-integrations/service/serverless.yml'
17+
const key = 'my-test-object.json'
18+
19+
beforeAll(async () => {
20+
const result = await deployWithRandomStage(config)
21+
22+
stage = result.stage
23+
endpoint = result.endpoint
24+
bucket = result.outputs.S3BucketName
25+
})
26+
27+
afterAll(async () => {
28+
await deleteS3Object(bucket, key)
29+
removeService(stage, config)
30+
})
31+
32+
it('should get correct response from s3 put endpoint', async () => {
33+
const putEndpoint = `${endpoint}/s3`
34+
35+
const putResponse = await fetch(putEndpoint, {
36+
method: 'POST',
37+
headers: { 'Content-Type': 'application/json' },
38+
body: JSON.stringify({ message: 'test' })
39+
})
40+
expect(putResponse.headers.get('access-control-allow-origin')).to.deep.equal('*')
41+
expect(putResponse.status).to.be.equal(200)
42+
43+
const uploadedObject = await getS3Object(bucket, key)
44+
expect(uploadedObject.toString()).to.equal(JSON.stringify({ message: 'test' }))
45+
})
46+
47+
it('should get correct response from s3 get endpoint', async () => {
48+
const getEndpoint = `${endpoint}/s3/${key}`
49+
50+
const getResponse = await fetch(getEndpoint, {
51+
method: 'GET',
52+
headers: { Accept: 'application/json' }
53+
})
54+
expect(getResponse.headers.get('access-control-allow-origin')).to.deep.equal('*')
55+
expect(getResponse.status).to.be.equal(200)
56+
57+
const body = await getResponse.json()
58+
expect(body).to.deep.equal({ message: 'test' })
59+
})
60+
61+
it('should get correct response from s3 delete endpoint', async () => {
62+
const deleteEndpoint = `${endpoint}/s3?key=${key}`
63+
64+
const deleteResponse = await fetch(deleteEndpoint, {
65+
method: 'DELETE'
66+
})
67+
expect(deleteResponse.status).to.be.equal(200)
68+
})
69+
})

0 commit comments

Comments
 (0)