Skip to content

Commit

Permalink
test: add test for static method
Browse files Browse the repository at this point in the history
  • Loading branch information
mantariksh committed Nov 19, 2020
1 parent 82f4469 commit 78b5e9d
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion tests/unit/backend/models/login.server.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import moment from 'moment-timezone'
import mongoose from 'mongoose'

import getLoginModel from 'src/app/models/login.server.model'
import { AuthType, IFormSchema, ILogin, IUserSchema } from 'src/types'
import {
AuthType,
IFormSchema,
ILogin,
IPopulatedForm,
IUserSchema,
} from 'src/types'

import dbHandler from '../helpers/jest-db'

Expand Down Expand Up @@ -114,6 +120,43 @@ describe('login.server.model', () => {
})

describe('Statics', () => {
describe('addLoginFromForm', () => {
const adminId = new ObjectId()
const formId = new ObjectId()
const agencyId = new ObjectId()
const mockEsrvcId = 'esrvcid'
const mockAuthType = 'SP'

it('should save the correct form data', async () => {
const fullForm = ({
_id: formId,
admin: {
_id: adminId,
agency: {
_id: agencyId,
},
},
authType: mockAuthType,
esrvcId: mockEsrvcId,
} as unknown) as IPopulatedForm

const saved = await LoginModel.addLoginFromForm(fullForm)
const found = await LoginModel.findOne({ form: formId })
// Returned document should match
expect(saved.form).toEqual(formId)
expect(saved.admin).toEqual(adminId)
expect(saved.agency).toEqual(agencyId)
expect(saved.authType).toBe(mockAuthType)
expect(saved.esrvcId).toBe(mockEsrvcId)
// Found document should match
expect(found!.form).toEqual(formId)
expect(found!.admin).toEqual(adminId)
expect(found!.agency).toEqual(agencyId)
expect(found!.authType).toBe(mockAuthType)
expect(found!.esrvcId).toBe(mockEsrvcId)
})
})

describe('aggregateLoginStats', () => {
const VALID_ESRVC_ID = 'MOCK-ESRVC-ID'
const CURR_MOMENT = moment()
Expand Down

0 comments on commit 78b5e9d

Please sign in to comment.