Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: uninstall sinon and ts-mock-imports (forreal) #1611

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 0 additions & 105 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
"proxyquire": "^2.1.3",
"regenerator": "^0.14.4",
"rimraf": "^3.0.2",
"sinon": "^10.0.0",
"stylelint": "^13.12.0",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^21.0.0",
Expand All @@ -244,7 +243,6 @@
"ts-essentials": "^7.0.1",
"ts-jest": "^26.5.4",
"ts-loader": "^7.0.5",
"ts-mock-imports": "^1.3.3",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6",
"type-fest": "^0.20.2",
Expand Down
10 changes: 4 additions & 6 deletions src/app/modules/auth/__tests__/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { ObjectId } from 'bson-ext'
import mongoose from 'mongoose'
import { err, errAsync, ok, okAsync } from 'neverthrow'
import { mocked } from 'ts-jest/utils'
import { ImportMock } from 'ts-mock-imports'

import getTokenModel from 'src/app/models/token.server.model'
import * as OtpUtils from 'src/app/utils/otp'
import { IAgencySchema, IPopulatedForm, IPopulatedUser } from 'src/types'

import dbHandler from 'tests/unit/backend/helpers/jest-db'

import * as OtpUtils from '../../../utils/otp'
import { DatabaseError } from '../../core/core.errors'
import { PermissionLevel } from '../../form/admin-form/admin-form.types'
import * as AdminFormUtils from '../../form/admin-form/admin-form.utils'
Expand All @@ -34,9 +33,6 @@ const VALID_EMAIL_DOMAIN = 'test.gov.sg'
const VALID_EMAIL = `valid@${VALID_EMAIL_DOMAIN}`
const MOCK_OTP = '123456'

// All calls to generateOtp will return MOCK_OTP.
ImportMock.mockFunction(OtpUtils, 'generateOtp', MOCK_OTP)

describe('auth.service', () => {
let defaultAgency: IAgencySchema

Expand All @@ -50,7 +46,7 @@ describe('auth.service', () => {
// Only need to clear Token collection, and ignore other collections.
beforeEach(async () => {
await dbHandler.clearCollection(TokenModel.collection.collectionName)
jest.resetAllMocks()
jest.clearAllMocks()
})

afterAll(async () => await dbHandler.closeDatabase())
Expand Down Expand Up @@ -97,6 +93,7 @@ describe('auth.service', () => {
// Arrange
// Should have no documents prior to this.
await expect(TokenModel.countDocuments()).resolves.toEqual(0)
jest.spyOn(OtpUtils, 'generateOtp').mockReturnValueOnce(MOCK_OTP)

// Act
const actualResult = await AuthService.createLoginOtp(VALID_EMAIL)
Expand Down Expand Up @@ -124,6 +121,7 @@ describe('auth.service', () => {
describe('verifyLoginOtp', () => {
it('should successfully return true and delete Token document when OTP hash matches', async () => {
// Arrange
jest.spyOn(OtpUtils, 'generateOtp').mockReturnValueOnce(MOCK_OTP)
// Add a Token document to verify against.
await AuthService.createLoginOtp(VALID_EMAIL)
await expect(TokenModel.countDocuments()).resolves.toEqual(1)
Expand Down
Loading