Skip to content

Commit

Permalink
update tests to remove migrated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed May 29, 2024
1 parent 5a2e6eb commit fd9cfc5
Showing 1 changed file with 1 addition and 55 deletions.
56 changes: 1 addition & 55 deletions src/app/services/sms/__tests__/sms.factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ObjectId } from 'bson'
import { okAsync } from 'neverthrow'
import Twilio from 'twilio'

import { ISms } from 'src/app/config/features/sms.config'

import { createSmsFactory } from '../sms.factory'
import * as SmsService from '../sms.service'
import { BounceNotificationSmsParams, TwilioConfig } from '../sms.types'
import { TwilioConfig } from '../sms.types'

// This is hoisted and thus a const cannot be passed in.
jest.mock('twilio', () =>
Expand All @@ -24,15 +23,6 @@ const MOCKED_TWILIO = {
mocked: 'this is mocked',
} as unknown as Twilio.Twilio

const MOCK_BOUNCE_SMS_PARAMS: BounceNotificationSmsParams = {
adminEmail: '[email protected]',
adminId: new ObjectId().toHexString(),
formId: new ObjectId().toHexString(),
formTitle: 'mock form title',
recipient: '+6581234567',
recipientEmail: '[email protected]',
}

describe('sms.factory', () => {
beforeEach(() => jest.clearAllMocks())

Expand All @@ -49,28 +39,6 @@ describe('sms.factory', () => {
}
const SmsFactory = createSmsFactory(MOCK_SMS_FEATURE)

it('should call SmsService counterpart when invoking sendAdminContactOtp', async () => {
// Arrange
MockSmsService.sendAdminContactOtp.mockReturnValueOnce(okAsync(true))

const mockArguments: Parameters<typeof SmsFactory.sendAdminContactOtp> = [
'mockRecipient',
'mockOtp',
'mockFormId',
'mockSenderIp',
]

// Act
await SmsFactory.sendAdminContactOtp(...mockArguments)

// Assert
expect(MockSmsService.sendAdminContactOtp).toHaveBeenCalledTimes(1)
expect(MockSmsService.sendAdminContactOtp).toHaveBeenCalledWith(
...mockArguments,
expectedTwilioConfig,
)
})

it('should call SmsService counterpart when invoking sendVerificationOtp', async () => {
// Arrange
MockSmsService.sendVerificationOtp.mockReturnValue(okAsync(true))
Expand All @@ -93,26 +61,4 @@ describe('sms.factory', () => {
expectedTwilioConfig,
)
})

it('should call SmsService when sendFormDeactivatedSms is called', async () => {
MockSmsService.sendFormDeactivatedSms.mockReturnValue(okAsync(true))

await SmsFactory.sendFormDeactivatedSms(MOCK_BOUNCE_SMS_PARAMS)

expect(MockSmsService.sendFormDeactivatedSms).toHaveBeenCalledWith(
MOCK_BOUNCE_SMS_PARAMS,
expectedTwilioConfig,
)
})

it('should call SmsService when sendBouncedSubmissionSms is called', async () => {
MockSmsService.sendBouncedSubmissionSms.mockReturnValue(okAsync(true))

await SmsFactory.sendBouncedSubmissionSms(MOCK_BOUNCE_SMS_PARAMS)

expect(MockSmsService.sendBouncedSubmissionSms).toHaveBeenCalledWith(
MOCK_BOUNCE_SMS_PARAMS,
expectedTwilioConfig,
)
})
})

0 comments on commit fd9cfc5

Please sign in to comment.