I am trying to write an integration test for the body of code below, and i am actually new to writing test with JEST. Can i please get some help?...i am blocked on how to test the getClient()
method and the authorize (session_variables)
and other methods that are within the block of this code.
export default async (req: Request, res: Response) => {
const client = getClient();
try {
const {
event: { op, data, session_variables },
table,
} = req.body;
// Authorize user
authorize(session_variables);
if (
(op === 'INSERT' || op === 'UPDATE') &&
(table.name === 'tickets' || table.name === 'tasks') &&
table.schema === 'public'
) {
const { new: newData } = data;
if (table.name === 'tickets' && newData!.completedAt && newData!.code) {
const groupDetail = await getGroup(newData!.code);
if (groupDetail) {
const id = groupDetail.id;
const memberEmails = await getGroupMembers(id);
await deleteGroup(id, memberEmails);
return res.send(`error: false, messages: Group successfully deleted`);
}
} else if (
op === 'UPDATE' &&
newData!.completedAt &&
newData!.ticketCode
) {
const tasks = await fetchUncompletedTaskWithTicketCode(
client,
newData.ticketCode
);
if (tasks.length === 0) {
const groupDetail = await getGroup(newData!.ticketCode);
if (groupDetail) {
const id = groupDetail.id;
const memberEmails = await getGroupMembers(id);
await deleteGroup(id, memberEmails);
return res.send(
`error: false, messages: Group successfully deleted`
);
}
}
}
}
return res.send(`error: true, message: event ignored`);
} catch (error) {
const err: Error = error;
Sentry.captureException(err);
return res.send(`err: true, message: ${err}`);
}
};
i am expected the write an integration test for this method above.
Aucun commentaire:
Enregistrer un commentaire