@@ -213,6 +213,80 @@ describe('flavors/update.js', () => {
213213 } )
214214 . done ( done ) ;
215215 } ) ;
216+
217+ it ( 'should fault on error' , ( done ) => {
218+ sinon . stub ( DynamoDBConnector . prototype , 'query' ) . resolves ( [ ] ) ;
219+ sinon . stub ( DynamoDBConnector . prototype , 'batchGet' ) . resolves ( {
220+ Responses : {
221+ undefined : [ {
222+ pk : '2' ,
223+ sk : 'thing' ,
224+ discriminator : 'thing' ,
225+ name : 'thing2' ,
226+ } ] ,
227+ } ,
228+ UnprocessedKeys : { } ,
229+ } ) ;
230+ const ebStub = sinon . stub ( EventBridgeConnector . prototype , 'putEvents' ) . resolves ( { FailedEntryCount : 0 } ) ;
231+
232+ sinon . stub ( KmsConnector . prototype , 'generateDataKey' ) . resolves ( MOCK_GEN_DK_RESPONSE ) ;
233+
234+ const events = toDynamodbRecords ( [
235+ {
236+ timestamp : 1572832690 ,
237+ keys : {
238+ pk : '1' ,
239+ sk : 'thing' ,
240+ } ,
241+ newImage : {
242+ pk : '1' ,
243+ sk : 'thing' ,
244+ discriminator : 'thing' ,
245+ name : 'Thing One' ,
246+ description : 'This is thing one' ,
247+ otherThing : 'thing|2' ,
248+ ttl : 1549053422 ,
249+ timestamp : 1548967022000 ,
250+ } ,
251+ } ,
252+ ] ) ;
253+
254+ const errorRule = {
255+ id : 'error-rule' ,
256+ flavor : update ,
257+ eventType : / t h i n g - * / ,
258+ filters : [ ( ) => true ] ,
259+ toGetRequest,
260+ fks : [ 'otherThing' ] ,
261+ toUpdateRequest : ( uow ) => { throw new Error ( 'intentional fault' ) ; } ,
262+ } ;
263+
264+ initialize ( {
265+ ...initializeFrom ( [ errorRule ] ) ,
266+ } , { ...defaultOptions , AES : false } )
267+ . assemble ( fromDynamodb ( events ) , true )
268+ . collect ( )
269+ // .tap((collected) => console.log(JSON.stringify(collected, null, 2)))
270+ . tap ( ( collected ) => {
271+ expect ( collected . length ) . to . eq ( 1 ) ;
272+ expect ( collected [ 0 ] . event . err . message ) . to . eq ( 'intentional fault' ) ;
273+ expect ( ebStub ) . to . have . been . calledOnceWith ( {
274+ Entries : [ {
275+ EventBusName : 'undefined' ,
276+ Source : 'custom' ,
277+ DetailType : 'fault' ,
278+ Detail : JSON . stringify ( collected [ 0 ] . event ) ,
279+ } ] ,
280+ } , {
281+ batch : [ {
282+ event : collected [ 0 ] . event ,
283+ publishRequestEntry : collected [ 0 ] . publishRequestEntry ,
284+ } ] ,
285+ publishRequest : collected [ 0 ] . publishRequest ,
286+ } ) ;
287+ } )
288+ . done ( done ) ;
289+ } ) ;
216290} ) ;
217291
218292const toUpdateRequest = ( uow ) => ( {
0 commit comments