Skip to content

Commit

Permalink
fix: remove test cases related to removed functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed Apr 23, 2024
1 parent 88e0b0a commit dad35ee
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 423 deletions.
2 changes: 1 addition & 1 deletion __tests__/unit/backend/helpers/jest-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const insertFormCollectionReqs = async ({
betaFlags,
apiToken,
}: {
userId?: Schema.Types.ObjectId
userId?: Types.ObjectId
mailName?: string
mailDomain?: string
shortName?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import * as SubmissionService from 'src/app/modules/submission/submission.service'
import * as SubmissionUtils from 'src/app/modules/submission/submission.utils'
import { MissingUserError } from 'src/app/modules/user/user.errors'
import { SmsLimitExceededError } from 'src/app/modules/verification/verification.errors'
import * as WorkspaceService from 'src/app/modules/workspace/workspace.service'
import {
MailGenerationError,
Expand Down Expand Up @@ -6937,9 +6936,6 @@ describe('admin-form.controller', () => {
MockAuthService.getFormAfterPermissionChecks.mockReturnValue(
okAsync(MOCK_FORM),
)
MockAdminFormService.shouldUpdateFormField.mockReturnValue(
okAsync(MOCK_FORM),
)
MockAdminFormService.updateFormField.mockReturnValue(
okAsync(MOCK_UPDATED_FIELD as FormFieldSchema),
)
Expand Down Expand Up @@ -7038,29 +7034,6 @@ describe('admin-form.controller', () => {
expect(MockAdminFormService.updateFormField).not.toHaveBeenCalled()
})

it('should return 409 when the field could not be updated due to a sms limit exceeded error', async () => {
// Arrange
MockAdminFormService.shouldUpdateFormField.mockReturnValueOnce(
errAsync(new SmsLimitExceededError()),
)
const expected = {
message:
'You have exceeded the free sms limit. Please refresh and try again.',
}
const mockRes = expressHandler.mockResponse()

// Act
await AdminFormController._handleUpdateFormField(
MOCK_REQ,
mockRes,
jest.fn(),
)

// Assert
expect(mockRes.status).toHaveBeenCalledWith(409)
expect(mockRes.json).toHaveBeenCalledWith(expected)
})

it('should return 410 when form to update form field for is already archived', async () => {
// Arrange
const mockRes = expressHandler.mockResponse()
Expand Down Expand Up @@ -7233,9 +7206,6 @@ describe('admin-form.controller', () => {
MockAuthService.getFormAfterPermissionChecks.mockReturnValue(
okAsync(MOCK_FORM),
)
MockAdminFormService.shouldUpdateFormField.mockReturnValue(
okAsync(MOCK_FORM),
)
MockAdminFormService.createFormField.mockReturnValue(
okAsync(MOCK_RETURNED_FIELD),
)
Expand Down Expand Up @@ -7345,29 +7315,6 @@ describe('admin-form.controller', () => {
expect(MockAdminFormService.createFormField).not.toHaveBeenCalled()
})

it('should return 409 when the field could not be created due to a sms limit exceeded error', async () => {
// Arrange
MockAdminFormService.shouldUpdateFormField.mockReturnValueOnce(
errAsync(new SmsLimitExceededError()),
)
const expected = {
message:
'You have exceeded the free sms limit. Please refresh and try again.',
}
const mockRes = expressHandler.mockResponse()

// Act
await AdminFormController._handleCreateFormField(
MOCK_REQ,
mockRes,
jest.fn(),
)

// Assert
expect(mockRes.status).toHaveBeenCalledWith(409)
expect(mockRes.json).toHaveBeenCalledWith(expected)
})

it('should return 410 when attempting to create a form field for an archived form', async () => {
// Arrange
const expectedErrorString = 'form gone pls'
Expand Down Expand Up @@ -7594,9 +7541,6 @@ describe('admin-form.controller', () => {
okAsync(MOCK_FORM),
)
MockAdminFormService.getFormField.mockReturnValue(ok(MOCK_FIELDS[0]))
MockAdminFormService.shouldUpdateFormField.mockReturnValue(
okAsync(MOCK_FORM),
)
MockAdminFormService.duplicateFormField.mockReturnValue(
okAsync(MOCK_DUPLICATED_FIELD),
)
Expand Down Expand Up @@ -7734,28 +7678,6 @@ describe('admin-form.controller', () => {
)
})

it('should return 409 when the field could not be duplicated due to a sms limit exceeded error', async () => {
// Arrange
MockAdminFormService.shouldUpdateFormField.mockReturnValueOnce(
errAsync(new SmsLimitExceededError()),
)
const expected = {
message:
'You have exceeded the free sms limit. Please refresh and try again.',
}
const mockRes = expressHandler.mockResponse()

// Act
await AdminFormController.handleDuplicateFormField(
MOCK_REQ,
mockRes,
jest.fn(),
)

// Assert
expect(mockRes.status).toHaveBeenCalledWith(409)
expect(mockRes.json).toHaveBeenCalledWith(expected)
})
it('should return 410 when form to duplicate form field for is already archived', async () => {
// Arrange
const mockRes = expressHandler.mockResponse()
Expand Down
111 changes: 2 additions & 109 deletions src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
} from 'src/app/modules/core/core.errors'
import { MissingUserError } from 'src/app/modules/user/user.errors'
import * as UserService from 'src/app/modules/user/user.service'
import { SmsLimitExceededError } from 'src/app/modules/verification/verification.errors'
import { TwilioCredentials } from 'src/app/services/sms/sms.types'
import { CreatePresignedPostError } from 'src/app/utils/aws-s3'
import { formatErrorRecoveryMessage } from 'src/app/utils/handle-mongo-error'
Expand Down Expand Up @@ -60,7 +59,6 @@ import {
LogicType,
SettingsUpdateDto,
} from '../../../../../../shared/types'
import { smsConfig } from '../../../../config/features/sms.config'
import * as SmsService from '../../../../services/sms/sms.service'
import {
FormNotFoundError,
Expand Down Expand Up @@ -2317,6 +2315,8 @@ describe('admin-form.service', () => {
buttonLink: 'https://some-button-link.example.com',
buttonText: 'expected button text',
paragraph: 'some paragraph',
paymentTitle: '',
paymentParagraph: '',
}

it('should return updated end page when update is successful', async () => {
Expand Down Expand Up @@ -2609,113 +2609,6 @@ describe('admin-form.service', () => {
})
})

describe('shouldUpdateFormField', () => {
const MOCK_FORM = {
admin: {
_id: new ObjectId(),
},
} as unknown as IPopulatedForm

const countSpy = jest.spyOn(SmsService, 'retrieveFreeSmsCounts')

describe('when update form field is not a BasicField.Mobile type', () => {
const MOCK_RATING_FIELD = generateDefaultField(BasicField.Rating)
it('should return the form without doing anything', async () => {
// Act
const actual = await AdminFormService.shouldUpdateFormField(
MOCK_FORM,
MOCK_RATING_FIELD,
)

// Assert
expect(actual._unsafeUnwrap()).toEqual(MOCK_FORM)
expect(countSpy).not.toHaveBeenCalled()
})
})

describe('when update form field is a BasicField.Mobile type', () => {
const MOCK_UNVERIFIABLE_MOBILE_FIELD = generateDefaultField(
BasicField.Mobile,
)
const MOCK_VERIFIABLE_MOBILE_FIELD = generateDefaultField(
BasicField.Mobile,
{ isVerifiable: true },
)

it('should return the given form when the admin is under the free sms limit', async () => {
// Arrange
countSpy.mockReturnValueOnce(okAsync(smsConfig.smsVerificationLimit))

// Act
const actual = await AdminFormService.shouldUpdateFormField(
MOCK_FORM,
MOCK_VERIFIABLE_MOBILE_FIELD,
)

// Assert
expect(actual._unsafeUnwrap()).toBe(MOCK_FORM)
})

it('should return the given form when the form is onboarded with its own credentials', async () => {
// Arrange
const MOCK_ONBOARDED_FORM = { ...MOCK_FORM, msgSrvcName: 'form a form' }

// Act
const actual = await AdminFormService.shouldUpdateFormField(
MOCK_ONBOARDED_FORM,
MOCK_VERIFIABLE_MOBILE_FIELD,
)

// Assert
expect(countSpy).not.toHaveBeenCalled()
expect(actual._unsafeUnwrap()).toEqual(MOCK_ONBOARDED_FORM)
})

it('should return the given form when mobile field is not verifiable', async () => {
// Act
const actual = await AdminFormService.shouldUpdateFormField(
MOCK_FORM,
MOCK_UNVERIFIABLE_MOBILE_FIELD,
)

// Assert
expect(countSpy).not.toHaveBeenCalled()
expect(actual._unsafeUnwrap()).toEqual(MOCK_FORM)
})

it('should return sms retrieval error when sms limit exceeded and the given form has not been onboarded', async () => {
// Arrange
countSpy.mockReturnValueOnce(
okAsync(smsConfig.smsVerificationLimit + 1),
)

// Act
const actual = await AdminFormService.shouldUpdateFormField(
MOCK_FORM,
MOCK_VERIFIABLE_MOBILE_FIELD,
)

// Assert
expect(actual._unsafeUnwrapErr()).toEqual(new SmsLimitExceededError())
})

it('should propagate any database errors encountered during retrieval', async () => {
// Arrange
const MOCK_ERROR_STRING = 'something went oopsie'
const expectedError = new DatabaseError(MOCK_ERROR_STRING)
countSpy.mockReturnValueOnce(errAsync(expectedError))

// Act
const actual = await AdminFormService.shouldUpdateFormField(
MOCK_FORM,
MOCK_VERIFIABLE_MOBILE_FIELD,
)

// Assert
expect(actual._unsafeUnwrapErr()).toBe(expectedError)
})
})
})
describe('createTwilioCredentials', () => {
const MOCK_FORM_ID = new mongoose.Types.ObjectId()
const MOCK_ADMIN_ID = new mongoose.Types.ObjectId()
Expand Down
Loading

0 comments on commit dad35ee

Please sign in to comment.