Skip to content

Commit

Permalink
revert to 2d array for test inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkim-ogp committed Nov 22, 2024
1 parent 5d1626a commit b109a34
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions backend/src/email/routes/tests/email-transactional.routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,13 @@ describe(`${emailTransactionalRoute}/send`, () => {
})

const ccValidTests = [
[['[email protected]']],
[['[email protected]', '[email protected]']],
['[email protected]'],
['[email protected]', '[email protected]'],
JSON.stringify(['[email protected]']),
JSON.stringify([
'[email protected]',
'[email protected]',
]),
]
test.each(ccValidTests)(
'Should send email with cc from valid array or stringified array - JSON payload',
Expand All @@ -884,8 +889,10 @@ describe(`${emailTransactionalRoute}/send`, () => {
reply_to: user.email,
})

const arrayToCheck = Array.isArray(cc) ? cc : JSON.parse(cc)

expect(res.status).toBe(201)
expect(res.body.cc.sort()).toStrictEqual(cc.sort())
expect(res.body.cc.sort()).toStrictEqual(arrayToCheck.sort())
expect(mockSendEmail).toBeCalledTimes(1)
const transactionalEmail = await EmailMessageTransactional.findOne({
where: { id: res.body.id },
Expand All @@ -907,7 +914,8 @@ describe(`${emailTransactionalRoute}/send`, () => {
.spyOn(EmailService, 'sendEmail')
.mockResolvedValue(true)
// in the case where single cc is sent, stringify the cc list
const ccSend = cc.length === 1 ? JSON.stringify(cc) : cc
const ccSend =
Array.isArray(cc) && cc.length === 1 ? JSON.stringify(cc) : cc

const res = await request(app)
.post(endpoint)
Expand All @@ -919,8 +927,10 @@ describe(`${emailTransactionalRoute}/send`, () => {
.field('reply_to', validApiCall.reply_to)
.field('cc', ccSend)

const arrayToCheck = Array.isArray(cc) ? cc : JSON.parse(cc)

expect(res.status).toBe(201)
expect(res.body.cc.sort()).toStrictEqual(cc.sort())
expect(res.body.cc.sort()).toStrictEqual(arrayToCheck.sort())
expect(mockSendEmail).toBeCalledTimes(1)
const transactionalEmail = await EmailMessageTransactional.findOne({
where: { id: res.body.id },
Expand All @@ -945,7 +955,7 @@ describe(`${emailTransactionalRoute}/send`, () => {
transactionalEmail?.emailMessageTransactionalCc.map(
(item) => item.email
)
expect(transactionalCcEmails?.sort()).toStrictEqual(cc.sort())
expect(transactionalCcEmails?.sort()).toStrictEqual(arrayToCheck.sort())
}
)

Expand Down

0 comments on commit b109a34

Please sign in to comment.