Skip to content

Commit

Permalink
fix: ordering of arguments for bounce service functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin9foong committed Oct 2, 2024
1 parent 10b7952 commit c1c955c
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 225 deletions.
128 changes: 64 additions & 64 deletions src/app/modules/bounce/__tests__/bounce.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,24 +413,24 @@ describe('BounceService', () => {
).toHaveBeenCalledTimes(2)
expect(
MockedPostmanSmsService.sendBouncedSubmissionSms,
).toHaveBeenCalledWith(
testUser.email,
String(testUser._id),
form._id,
form.title,
MOCK_CONTACT.contact,
MOCK_CONTACT.email,
)
).toHaveBeenCalledWith({
adminEmail: testUser.email,
adminId: String(testUser._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: MOCK_CONTACT.contact,
recipientEmail: MOCK_CONTACT.email,
})
expect(
MockedPostmanSmsService.sendBouncedSubmissionSms,
).toHaveBeenCalledWith(
testUser.email,
String(testUser._id),
form._id,
form.title,
MOCK_CONTACT_2.contact,
MOCK_CONTACT_2.email,
)
).toHaveBeenCalledWith({
adminEmail: testUser.email,
adminId: String(testUser._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: MOCK_CONTACT_2.contact,
recipientEmail: MOCK_CONTACT_2.email,
})
expect(notifiedRecipients._unsafeUnwrap()).toEqual([
MOCK_CONTACT,
MOCK_CONTACT_2,
Expand Down Expand Up @@ -461,24 +461,24 @@ describe('BounceService', () => {
).toHaveBeenCalledTimes(2)
expect(
MockedPostmanSmsService.sendBouncedSubmissionSms,
).toHaveBeenCalledWith(
testUser.email,
String(testUser._id),
form._id,
form.title,
MOCK_CONTACT.contact,
MOCK_CONTACT.email,
)
).toHaveBeenCalledWith({
adminEmail: testUser.email,
adminId: String(testUser._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: MOCK_CONTACT.contact,
recipientEmail: MOCK_CONTACT.email,
})
expect(
MockedPostmanSmsService.sendBouncedSubmissionSms,
).toHaveBeenCalledWith(
testUser.email,
String(testUser._id),
form._id,
form.title,
MOCK_CONTACT_2.contact,
MOCK_CONTACT_2.email,
)
).toHaveBeenCalledWith({
adminEmail: testUser.email,
adminId: String(testUser._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: MOCK_CONTACT_2.contact,
recipientEmail: MOCK_CONTACT_2.email,
})
expect(notifiedRecipients._unsafeUnwrap()).toEqual([MOCK_CONTACT])
})
})
Expand Down Expand Up @@ -866,24 +866,24 @@ describe('BounceService', () => {
).toHaveBeenCalledTimes(2)
expect(
MockedPostmanSmsService.sendFormDeactivatedSms,
).toHaveBeenCalledWith(
form.admin.email,
String(form.admin._id),
form._id,
form.title,
MOCK_CONTACT.contact,
MOCK_CONTACT.email,
)
).toHaveBeenCalledWith({
adminEmail: form.admin.email,
adminId: String(form.admin._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: MOCK_CONTACT.contact,
recipientEmail: MOCK_CONTACT.email,
})
expect(
MockedPostmanSmsService.sendFormDeactivatedSms,
).toHaveBeenCalledWith(
form.admin.email,
String(form.admin._id),
form._id,
form.title,
MOCK_CONTACT_2.contact,
MOCK_CONTACT_2.email,
)
).toHaveBeenCalledWith({
adminEmail: form.admin.email,
adminId: String(form.admin._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: MOCK_CONTACT_2.contact,
recipientEmail: MOCK_CONTACT_2.email,
})
})

it('should return true even when some SMSes fail', async () => {
Expand All @@ -906,24 +906,24 @@ describe('BounceService', () => {
).toHaveBeenCalledTimes(2)
expect(
MockedPostmanSmsService.sendFormDeactivatedSms,
).toHaveBeenCalledWith(
form.admin.email,
String(form.admin._id),
form._id,
form.title,
MOCK_CONTACT.contact,
MOCK_CONTACT.email,
)
).toHaveBeenCalledWith({
adminEmail: form.admin.email,
adminId: String(form.admin._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: MOCK_CONTACT.contact,
recipientEmail: MOCK_CONTACT.email,
})
expect(
MockedPostmanSmsService.sendFormDeactivatedSms,
).toHaveBeenCalledWith(
form.admin.email,
String(form.admin._id),
form._id,
form.title,
MOCK_CONTACT_2.contact,
MOCK_CONTACT_2.email,
)
).toHaveBeenCalledWith({
adminEmail: form.admin.email,
adminId: String(form.admin._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: MOCK_CONTACT_2.contact,
recipientEmail: MOCK_CONTACT_2.email,
})
})
})
})
32 changes: 16 additions & 16 deletions src/app/modules/bounce/bounce.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ export const sendSmsBounceNotification = (
// empty array as list of recipients.
): ResultAsync<UserWithContactNumber[], never> => {
const smsResults = possibleSmsRecipients.map((recipient) =>
PostmanSmsService.sendBouncedSubmissionSms(
form.admin.email,
String(form.admin._id),
form._id,
form.title,
recipient.contact,
recipient.email,
)
PostmanSmsService.sendBouncedSubmissionSms({
adminEmail: form.admin.email,
adminId: String(form.admin._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: recipient.contact,
recipientEmail: recipient.email,
})
.map(() => recipient)
.mapErr(
(error) => new SendBounceSmsNotificationError(error, recipient.contact),
Expand Down Expand Up @@ -368,14 +368,14 @@ export const notifyAdminsOfDeactivation = (
// Best-effort attempt to send SMSes, don't propagate error upwards
): ResultAsync<true, never> => {
const smsResults = possibleSmsRecipients.map((recipient) =>
PostmanSmsService.sendFormDeactivatedSms(
form.admin.email,
String(form.admin._id),
form._id,
form.title,
recipient.contact,
recipient.email,
),
PostmanSmsService.sendFormDeactivatedSms({
adminEmail: form.admin.email,
adminId: String(form.admin._id),
formId: form._id,
formTitle: form.title,
recipientPhoneNumber: recipient.contact,
recipientEmail: recipient.email,
}),
)
return ResultAsync.combineWithAllErrors(smsResults)
.map(() => true as const)
Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/verification/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ const sendOtpForField = (
senderIp,
)
}
return PostmanSmsService.sendVerificationOtp(
recipient,
return PostmanSmsService.sendVerificationOtp({
recipientPhoneNumber: recipient,
otp,
otpPrefix,
formId,
senderIp,
)
})
})
: errAsync(new MalformedParametersError('Field id not present'))
case BasicField.Email:
Expand Down
Loading

0 comments on commit c1c955c

Please sign in to comment.