DynamoDB integration subscribes to DynamoDb Stream and intercepts events. The event has the following properties:
keys
newImage
oldImage
eventName
(INSERT
,MODIFY
,REMOVE
)
You can use eventName
and compare newImage
and oldImage
to validate if the correct operation has been executed.
Basic example:
await serverlessSpyListener.waitForDynamoDBMyTable<TestData>();
You can use conditions to wait for a particular event. You can also use generic (TestData
) to strongly type the event.
await serverlessSpyListener.waitForDynamoDBMyTable<TestData>({
condition: (d) => d.keys.pk === id,
});
Validating the data with Jest would look like this:
(
await serverlessSpyListener.waitForDynamoDBMyTable<TestData>({
condition: (d) => d.keys.pk === id,
})
).toMatchObject({
eventName: 'INSERT',
newImage: data,
});
**
serverlessSpy.spy({
spyDynamoDB: false,
});
Check this test{:target="_blank"}.