Skip to content

Commit 9988930

Browse files
author
John Gilbert
committed
add-eb-global-support
1 parent 96b49e0 commit 9988930

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

src/sinks/eventbridge.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,17 @@ export const publishToEventBridge = ({ // eslint-disable-line import/prefer-defa
4242
} : undefined,
4343
});
4444

45-
const toPublishRequest = (batchUow) => {
46-
const Entries = batchUow.batch
47-
.filter((uow) => uow[publishRequestEntryField])
48-
.map((uow) => uow[publishRequestEntryField]);
49-
50-
return {
51-
...batchUow,
52-
[publishRequestField]: endpointId ? /* istanbul ignore next */ {
53-
Entries,
45+
const toPublishRequest = (batchUow) => ({
46+
...batchUow,
47+
[publishRequestField]: {
48+
Entries: batchUow.batch
49+
.filter((uow) => uow[publishRequestEntryField])
50+
.map((uow) => uow[publishRequestEntryField]),
51+
...(endpointId && {
5452
EndpointId: endpointId,
55-
} : {
56-
Entries,
57-
},
58-
};
59-
};
53+
}),
54+
},
55+
});
6056

6157
const putEvents = (batchUow) => {
6258
if (!batchUow[publishRequestField].Entries.length) {

test/unit/sinks/eventbridge.test.js

+44
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,48 @@ describe('sinks/eventbridge.js', () => {
249249
})
250250
.done(done);
251251
});
252+
253+
it('should publish to global endpoint', (done) => {
254+
sinon.stub(Connector.prototype, 'putEvents').resolves({ FailedEntryCount: 0 });
255+
256+
const uows = [{
257+
event: {
258+
id: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
259+
type: 'p1',
260+
partitionKey: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
261+
},
262+
}];
263+
264+
_(uows)
265+
.through(publish({ busName: 'b1', debug: (msg, v) => console.log(msg, v), endpointId: 'ep1' }))
266+
.collect()
267+
.tap((collected) => {
268+
// console.log(JSON.stringify(collected, null, 2));
269+
270+
expect(collected.length).to.equal(1);
271+
expect(collected[0].publishRequest).to.deep.equal({
272+
EndpointId: 'ep1',
273+
Entries: [{
274+
EventBusName: 'b1',
275+
Source: 'custom',
276+
DetailType: 'p1',
277+
Detail: JSON.stringify({
278+
id: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
279+
type: 'p1',
280+
partitionKey: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
281+
tags: {
282+
account: 'undefined',
283+
region: 'us-west-2',
284+
stage: 'undefined',
285+
source: 'undefined',
286+
functionname: 'undefined',
287+
pipeline: 'undefined',
288+
skip: true,
289+
},
290+
}),
291+
}],
292+
});
293+
})
294+
.done(done);
295+
});
252296
});

0 commit comments

Comments
 (0)