@@ -2,12 +2,17 @@ import 'mocha';
22import { expect } from 'chai' ;
33import sinon from 'sinon' ;
44import _ from 'highland' ;
5-
5+ import { v4 } from 'uuid' ;
66import { publishToEventBridge as publish } from '../../../src/sinks/eventbridge' ;
77
88import Connector from '../../../src/connectors/eventbridge' ;
99
1010describe ( 'sinks/eventbridge.js' , ( ) => {
11+ const origBatchSize = process . env . BATCH_SIZE ;
12+ afterEach ( ( ) => {
13+ // set back to state specified in package.json
14+ process . env . BATCH_SIZE = origBatchSize ;
15+ } ) ;
1116 afterEach ( sinon . restore ) ;
1217
1318 it ( 'should batch and publish' , ( done ) => {
@@ -89,6 +94,36 @@ describe('sinks/eventbridge.js', () => {
8994 . done ( done ) ;
9095 } ) ;
9196
97+ it ( 'should batch and publish, multiple' , ( done ) => {
98+ process . env . BATCH_SIZE = 100 ;
99+ sinon . stub ( Connector . prototype , 'putEvents' ) . resolves ( { FailedEntryCount : 0 } ) ;
100+
101+ const uows = [ ] ;
102+ for ( let i = 1 ; i <= 15 ; i += 1 ) {
103+ const id = v4 ( ) ;
104+ uows . push ( {
105+ event : {
106+ id,
107+ type : `p${ i } ` ,
108+ partitionKey : id ,
109+ } ,
110+ } ) ;
111+ }
112+
113+ _ ( uows )
114+ . through ( publish ( { busName : 'b1' , debug : ( msg , v ) => console . log ( msg , v ) , metricsEnabled : true } ) )
115+ . collect ( )
116+ . tap ( ( collected ) => {
117+ // console.log(JSON.stringify(collected, null, 2));
118+
119+ expect ( collected . length ) . to . equal ( 15 ) ;
120+ collected . forEach ( ( c ) => {
121+ expect ( c . publishRequest . Entries . length < 11 ) . to . be . true ;
122+ } ) ;
123+ } )
124+ . done ( done ) ;
125+ } ) ;
126+
92127 it ( 'should not publish' , ( done ) => {
93128 const uows = [ {
94129 } ] ;
0 commit comments