My questions appear to be duplicates of other questions on stackoverflow. I tried every single solution, but none of them worked.
I have a sns lambda function which return void. I want to throw an error if the orderId does not exist.
When run the test suite. I am getting this error:
Matcher error: received value must be a function
Received has value: undefined
Here is my function
const parseOrdersFromSns = (event: SNSEvent): Payload[] => {
try {
return event.Records.flatMap((r) => JSON.parse(r.Sns.Message));
} catch (error) {
Log.error("New order from SNS failed at parsing orders", { event }, error);
return [];
}
};
export const handlerFn = async (event: SNSEvent): Promise<void> => {
const orders = parseOrdersFromSns(event);
if (orders.length === 0) return;
const existingOrders = await Promise.all(
orders.map(
async (o) => await findOrderStateNode(tagOrderStateId(o.orderId))
)
);
console.log({ orders });
if (!existingOrders) {
orders.forEach((o) => {
throw new Error(
`Failed to get exisiting order with this orderId: ${o.orderId}`
);
});
// other code staff if there is existing order
}
};
Here is my test suite function where I am passing random orderId which is not legit. So, I am expecting error.
describe('Making an order by random uuid', () => {
integrationTest('should throw an error', async () => {
const order = {
orderId: '90073f29-d0df-4eca-b93d-ba1cce0d950a',
roundName,
startTime,
}
const event = {
Records: [
{
Sns: {
Message: JSON.stringify([order]),
},
},
],
} as SNSEvent
// snsListen is my lambda function
expect(await snsListen(event)).toThrowError(
`Failed to get exisiting order with this orderId: ${order.orderId}`,
)
})
})