|
| 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