Skip to content

Commit

Permalink
update tests to use db context
Browse files Browse the repository at this point in the history
  • Loading branch information
momentiris committed Jan 13, 2025
1 parent aeccbca commit 7b2dfcd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 257 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import assert from 'node:assert'

import * as applicationProfileAdapter from '../../adapters/application-profile-adapter'
import * as factory from '../factories'
import { withContext } from '../testUtils'

describe('application-profile-adapter', () => {
describe(applicationProfileAdapter.create, () => {
it('creates application profile', () =>
withContext(async (ctx) => {
const profile = await applicationProfileAdapter.create(ctx.db, {
contactCode: '1234',
const profile = await applicationProfileAdapter.create(ctx.db, '1234', {
expiresAt: new Date(),
numAdults: 1,
numChildren: 1,
housingType: 'foo',
housingType: 'RENTAL',
housingTypeDescription: 'bar',
landlord: 'baz',
housingReference: factory.applicationProfileHousingReference.build(),
})
assert(profile.ok)

Expand All @@ -29,21 +30,32 @@ describe('application-profile-adapter', () => {

it('fails if existing profile for contact code already exists', () =>
withContext(async (ctx) => {
const profile = await applicationProfileAdapter.create(ctx.db, {
contactCode: '1234',
const profile = await applicationProfileAdapter.create(ctx.db, '1234', {
expiresAt: new Date(),
numAdults: 1,
numChildren: 1,
housingType: 'RENTAL',
housingTypeDescription: 'bar',
landlord: 'baz',
housingReference: factory.applicationProfileHousingReference.build(),
})

assert(profile.ok)

const duplicate = await applicationProfileAdapter.create(ctx.db, {
contactCode: '1234',
expiresAt: new Date(),
numAdults: 1,
numChildren: 1,
})
const duplicate = await applicationProfileAdapter.create(
ctx.db,
'1234',
{
expiresAt: new Date(),
numAdults: 1,
numChildren: 1,
housingType: 'RENTAL',
housingTypeDescription: 'bar',
landlord: 'baz',
housingReference:
factory.applicationProfileHousingReference.build(),
}
)

expect(duplicate).toMatchObject({
ok: false,
Expand All @@ -64,11 +76,14 @@ describe('application-profile-adapter', () => {

it('gets application profile', () =>
withContext(async (ctx) => {
await applicationProfileAdapter.create(ctx.db, {
contactCode: '1234',
await applicationProfileAdapter.create(ctx.db, '1234', {
expiresAt: new Date(),
numAdults: 1,
numChildren: 1,
housingType: 'RENTAL',
housingTypeDescription: 'bar',
landlord: 'baz',
housingReference: factory.applicationProfileHousingReference.build(),
})

const result = await applicationProfileAdapter.getByContactCode(
Expand Down Expand Up @@ -100,6 +115,11 @@ describe('application-profile-adapter', () => {
expiresAt: new Date(),
numAdults: 1,
numChildren: 1,
housingType: 'RENTAL',
housingTypeDescription: 'bar',
landlord: 'baz',
housingReference:
factory.applicationProfileHousingReference.build(),
}
)

Expand All @@ -108,11 +128,14 @@ describe('application-profile-adapter', () => {

it('updates application profile', () =>
withContext(async (ctx) => {
const profile = await applicationProfileAdapter.create(ctx.db, {
contactCode: '1234',
expiresAt: null,
const profile = await applicationProfileAdapter.create(ctx.db, '1234', {
expiresAt: new Date(),
numAdults: 1,
numChildren: 1,
housingType: 'RENTAL',
housingTypeDescription: 'bar',
landlord: 'baz',
housingReference: factory.applicationProfileHousingReference.build(),
})

assert(profile.ok)
Expand All @@ -123,6 +146,11 @@ describe('application-profile-adapter', () => {
expiresAt: new Date(),
numAdults: 2,
numChildren: 2,
housingType: 'RENTAL',
housingTypeDescription: 'bar',
landlord: 'baz',
housingReference:
factory.applicationProfileHousingReference.build(),
}
)

Expand Down

This file was deleted.

Loading

0 comments on commit 7b2dfcd

Please sign in to comment.