|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const expect = require('chai').expect |
| 4 | +const fetch = require('node-fetch') |
| 5 | +const { deployWithRandomStage, removeService } = require('../../../utils') |
| 6 | + |
| 7 | +describe('Multiple EventBridge Proxy Integrations Test', () => { |
| 8 | + let endpoint |
| 9 | + let stage |
| 10 | + const config = '__tests__/integration/eventbridge/multiple-integrations/service/serverless.yml' |
| 11 | + |
| 12 | + beforeAll(async () => { |
| 13 | + const result = await deployWithRandomStage(config) |
| 14 | + stage = result.stage |
| 15 | + endpoint = result.endpoint |
| 16 | + }) |
| 17 | + |
| 18 | + afterAll(() => { |
| 19 | + removeService(stage, config) |
| 20 | + }) |
| 21 | + |
| 22 | + it('should get correct response from eventbridge proxy endpoints with static detailType and source', async () => { |
| 23 | + const testEndpoint = `${endpoint}/eventbridge1` |
| 24 | + const response = await fetch(testEndpoint, { |
| 25 | + method: 'POST', |
| 26 | + headers: { 'Content-Type': 'application/json' }, |
| 27 | + body: JSON.stringify({ message: `data for event bus` }) |
| 28 | + }) |
| 29 | + expect(response.headers.get('access-control-allow-origin')).to.deep.equal('*') |
| 30 | + expect(response.status).to.be.equal(200) |
| 31 | + const body = await response.json() |
| 32 | + expect(body).to.have.own.property('Entries') |
| 33 | + expect(body).to.have.own.property('FailedEntryCount') |
| 34 | + expect(body.FailedEntryCount).to.equal(0) |
| 35 | + }) |
| 36 | + |
| 37 | + it('should get correct response from eventbridge proxy endpoints with detailType and source as path parameters', async () => { |
| 38 | + const testEndpoint = `${endpoint}/eventbridge2/myDetailType/mySource` |
| 39 | + const response = await fetch(testEndpoint, { |
| 40 | + method: 'POST', |
| 41 | + headers: { 'Content-Type': 'application/json' }, |
| 42 | + body: JSON.stringify({ message: `data for event bus` }) |
| 43 | + }) |
| 44 | + expect(response.headers.get('access-control-allow-origin')).to.deep.equal('*') |
| 45 | + expect(response.status).to.be.equal(200) |
| 46 | + const body = await response.json() |
| 47 | + expect(body).to.have.own.property('Entries') |
| 48 | + expect(body).to.have.own.property('FailedEntryCount') |
| 49 | + expect(body.FailedEntryCount).to.equal(0) |
| 50 | + }) |
| 51 | + |
| 52 | + it('should get correct response from eventbridge proxy endpoints with detailType and source as query parameters', async () => { |
| 53 | + const testEndpoint = `${endpoint}/eventbridge3?myDetailTypeKey=myDetailTypeValue&mySourceKey=mySourceValue` |
| 54 | + const response = await fetch(testEndpoint, { |
| 55 | + method: 'POST', |
| 56 | + headers: { 'Content-Type': 'application/json' }, |
| 57 | + body: JSON.stringify({ message: `data for event bus` }) |
| 58 | + }) |
| 59 | + expect(response.headers.get('access-control-allow-origin')).to.deep.equal('*') |
| 60 | + expect(response.status).to.be.equal(200) |
| 61 | + const body = await response.json() |
| 62 | + expect(body).to.have.own.property('Entries') |
| 63 | + expect(body).to.have.own.property('FailedEntryCount') |
| 64 | + expect(body.FailedEntryCount).to.equal(0) |
| 65 | + }) |
| 66 | + |
| 67 | + it('should get correct response from eventbridge proxy endpoints without given detailType and source parameters', async () => { |
| 68 | + const testEndpoint = `${endpoint}/eventbridge4` |
| 69 | + const response = await fetch(testEndpoint, { |
| 70 | + method: 'POST', |
| 71 | + headers: { 'Content-Type': 'application/json' }, |
| 72 | + body: JSON.stringify({ message: `data for event bus` }) |
| 73 | + }) |
| 74 | + expect(response.headers.get('access-control-allow-origin')).to.deep.equal('*') |
| 75 | + expect(response.status).to.be.equal(200) |
| 76 | + const body = await response.json() |
| 77 | + expect(body).to.have.own.property('Entries') |
| 78 | + expect(body).to.have.own.property('FailedEntryCount') |
| 79 | + expect(body.FailedEntryCount).to.equal(0) |
| 80 | + }) |
| 81 | +}) |
0 commit comments