@@ -26,7 +26,7 @@ describe('letter-stream-forwarder Lambda', () => {
2626 eventName : 'MODIFY' ,
2727 dynamodb : {
2828 Keys : { id : { S : '123' } } ,
29- OldImage : { status : { S : 'PENDING' } } ,
29+ OldImage : { status : { S : 'PENDING' } , id : { S : '123' } } ,
3030 NewImage : { status : { S : 'ACCEPTED' } , id : { S : '123' } } ,
3131 } ,
3232 } ,
@@ -46,14 +46,70 @@ describe('letter-stream-forwarder Lambda', () => {
4646 ) ;
4747 } ) ;
4848
49- it ( 'does not forward if status did not change' , async ( ) => {
49+
50+ it ( 'forwards to Kinesis if a reason code is added' , async ( ) => {
51+ const event : DynamoDBStreamEvent = {
52+ Records : [
53+ {
54+ eventName : 'MODIFY' ,
55+ dynamodb : {
56+ Keys : { id : { S : '123' } } ,
57+ OldImage : { status : { S : 'PENDING' } , id : { S : '123' } } ,
58+ NewImage : { status : { S : 'PENDING' } , id : { S : '123' } , reasonCode : { S : 'r1' } } ,
59+ } ,
60+ } ,
61+ ] ,
62+ } ;
63+
64+ const handler = createHandler ( mockedDeps ) ;
65+ await handler ( event , mockDeep < Context > ( ) , jest . fn ( ) ) ;
66+
67+ expect ( mockedDeps . kinesisClient . send ) . toHaveBeenCalledWith (
68+ expect . objectContaining ( {
69+ input : expect . objectContaining ( {
70+ StreamName : 'test-stream' ,
71+ PartitionKey : '123' ,
72+ } ) ,
73+ } )
74+ ) ;
75+ } ) ;
76+
77+
78+ it ( 'forwards to Kinesis if a reason code is changed' , async ( ) => {
79+ const event : DynamoDBStreamEvent = {
80+ Records : [
81+ {
82+ eventName : 'MODIFY' ,
83+ dynamodb : {
84+ Keys : { id : { S : '123' } } ,
85+ OldImage : { status : { S : 'PENDING' } , id : { S : '123' } , reasonCode : { S : 'r1' } } ,
86+ NewImage : { status : { S : 'PENDING' } , id : { S : '123' } , reasonCode : { S : 'r2' } } ,
87+ } ,
88+ } ,
89+ ] ,
90+ } ;
91+
92+ const handler = createHandler ( mockedDeps ) ;
93+ await handler ( event , mockDeep < Context > ( ) , jest . fn ( ) ) ;
94+
95+ expect ( mockedDeps . kinesisClient . send ) . toHaveBeenCalledWith (
96+ expect . objectContaining ( {
97+ input : expect . objectContaining ( {
98+ StreamName : 'test-stream' ,
99+ PartitionKey : '123' ,
100+ } ) ,
101+ } )
102+ ) ;
103+ } ) ;
104+
105+ it ( 'does not forward if neither status nor reason code changed' , async ( ) => {
50106 const event : DynamoDBStreamEvent = {
51107 Records : [
52108 {
53109 eventName : 'MODIFY' ,
54110 dynamodb : {
55111 Keys : { id : { S : '123' } } ,
56- OldImage : { status : { S : 'PENDING' } } ,
112+ OldImage : { status : { S : 'PENDING' } , id : { S : '123' } } ,
57113 NewImage : { status : { S : 'PENDING' } , id : { S : '123' } } ,
58114 } ,
59115 } ,
0 commit comments