Skip to content

Commit 9121de8

Browse files
authored
Merge pull request #84 from jcortega/master
fix(eventbridge): multiple-integration integration test and validation
2 parents 69867e5 + ccc50f7 commit 9121de8

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

__tests__/integration/eventbridge/multiple-integrations/service/serverless.yml

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ custom:
4646
eventBusName: { Ref: 'YourBus' }
4747
source: mySourceName
4848
cors: true
49+
# set value of detail, detailType and source as bodyParam
50+
- eventbridge:
51+
path: /eventbridge5
52+
method: post
53+
eventBusName: { Ref: 'YourBus' }
54+
source:
55+
bodyParam: data.source
56+
detailType:
57+
bodyParam: data.detailType
58+
detail:
59+
bodyParam: data.detail
60+
cors: true
4961

5062
resources:
5163
Resources:

__tests__/integration/eventbridge/multiple-integrations/tests.js

+21
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,25 @@ describe('Multiple EventBridge Proxy Integrations Test', () => {
7878
expect(body).to.have.own.property('FailedEntryCount')
7979
expect(body.FailedEntryCount).to.equal(0)
8080
})
81+
82+
it('should get correct response from eventbridge proxy endpoints with bodyParams', async () => {
83+
const testEndpoint = `${endpoint}/eventbridge5`
84+
const response = await fetch(testEndpoint, {
85+
method: 'POST',
86+
headers: { 'Content-Type': 'application/json' },
87+
body: JSON.stringify({
88+
data: {
89+
detail: `{"data": "data for event bus"}`,
90+
detailType: `myDetailType`,
91+
source: `mySource`
92+
}
93+
})
94+
})
95+
expect(response.headers.get('access-control-allow-origin')).to.deep.equal('*')
96+
expect(response.status).to.be.equal(200)
97+
const body = await response.json()
98+
expect(body).to.have.own.property('Entries')
99+
expect(body).to.have.own.property('FailedEntryCount')
100+
expect(body.FailedEntryCount).to.equal(0)
101+
})
81102
})

lib/apiGateway/schema.js

+33-6
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,49 @@ const dynamodbDefaultKeyScheme = Joi.object()
163163
)
164164
)
165165

166+
// EventBridge source parameter
167+
const eventBridgeSource = Joi.alternatives().try([
168+
Joi.string(),
169+
Joi.object()
170+
.keys({
171+
pathParam: Joi.string(),
172+
queryStringParam: Joi.string(),
173+
bodyParam: Joi.string()
174+
})
175+
.xor('pathParam', 'queryStringParam', 'bodyParam')
176+
.error(
177+
customErrorBuilder(
178+
'object.xor',
179+
'key must contain "pathParam" or "queryStringParam" or "bodyParam" and only one'
180+
)
181+
)
182+
])
183+
166184
// EventBridge detailType parameter
167-
const detailType = Joi.alternatives().try([
185+
const eventBridgeDetailType = Joi.alternatives().try([
168186
Joi.string(),
169187
Joi.object()
170188
.keys({
171189
pathParam: Joi.string(),
172-
queryStringParam: Joi.string()
190+
queryStringParam: Joi.string(),
191+
bodyParam: Joi.string()
173192
})
174-
.xor('pathParam', 'queryStringParam')
193+
.xor('pathParam', 'queryStringParam', 'bodyParam')
175194
.error(
176195
customErrorBuilder(
177196
'object.xor',
178-
'key must contain "pathParam" or "queryStringParam and only one'
197+
'key must contain "pathParam" or "queryStringParam" or "bodyParam" and only one'
179198
)
180199
)
181200
])
182201

202+
// EventBridge source parameter
203+
const eventBridgeDetail = Joi.alternatives().try([
204+
Joi.object().keys({
205+
bodyParam: Joi.string()
206+
})
207+
])
208+
183209
const request = Joi.object({
184210
template: Joi.object().required()
185211
})
@@ -238,8 +264,9 @@ const proxiesSchemas = {
238264
eventbridge: Joi.object({
239265
eventbridge: proxy.append({
240266
eventBusName: stringOrRef.required(),
241-
source: stringOrRef.required(),
242-
detailType
267+
source: eventBridgeSource.required(),
268+
detailType: eventBridgeDetailType,
269+
detail: eventBridgeDetail
243270
})
244271
})
245272
}

0 commit comments

Comments
 (0)