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 3feb7ca
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 234 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
12 changes: 6 additions & 6 deletions src/app/modules/user/__tests__/user.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ describe('user.controller', () => {
MOCK_REQ.body.userId,
MOCK_REQ.body.contact,
)
expect(MockPostmanSmsService.sendAdminContactOtp).toHaveBeenCalledWith(
MOCK_REQ.body.contact,
expectedOtp,
MOCK_REQ.body.userId,
'MOCK_IP',
)
expect(MockPostmanSmsService.sendAdminContactOtp).toHaveBeenCalledWith({
recipientPhoneNumber: MOCK_REQ.body.contact,
otp: expectedOtp,
userId: MOCK_REQ.body.userId,
senderIp: 'MOCK_IP',
})
expect(mockRes.sendStatus).toHaveBeenCalledWith(200)
})

Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export const _handleContactSendOtp: ControllerHandler<

// Step 2: No error, send verification OTP to contact.
const otp = createResult.value
const sendOtpResult = await PostmanSmsService.sendAdminContactOtp(
contact,
const sendOtpResult = await PostmanSmsService.sendAdminContactOtp({
recipientPhoneNumber: contact,
otp,
userId,
senderIp,
)
})

// Error sending OTP.
if (sendOtpResult.isErr()) {
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 3feb7ca

Please sign in to comment.