-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write characterisation tests for the new read model
- Loading branch information
Daniel Haarhoff
committed
May 26, 2024
1 parent
3c2b36a
commit 57133a4
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {faker} from '@faker-js/faker'; | ||
import {DomainEvent} from '../../../src/types'; | ||
import {TestFramework, initTestFramework} from '../test-framework'; | ||
import {NonEmptyString, UUID} from 'io-ts-types'; | ||
import {getAll} from '../../../src/read-models/equipment/get-all'; | ||
|
||
describe('get-all', () => { | ||
let events: ReadonlyArray<DomainEvent>; | ||
let framework: TestFramework; | ||
beforeEach(async () => { | ||
framework = await initTestFramework(); | ||
}); | ||
|
||
describe('when equipment is added to existing area', () => { | ||
const createArea = { | ||
id: faker.string.uuid() as UUID, | ||
name: faker.company.buzzNoun() as NonEmptyString, | ||
description: faker.company.buzzPhrase(), | ||
}; | ||
const addEquipment = { | ||
id: faker.string.uuid() as UUID, | ||
name: faker.company.buzzNoun() as NonEmptyString, | ||
areaId: createArea.id, | ||
}; | ||
beforeEach(async () => { | ||
await framework.commands.area.create(createArea); | ||
await framework.commands.equipment.add(addEquipment); | ||
events = await framework.getAllEvents(); | ||
}); | ||
|
||
it('returns the equipment with the area name', () => { | ||
const allEquipment = getAll(events); | ||
expect(allEquipment[0].id).toStrictEqual(addEquipment.id); | ||
expect(allEquipment[0].areaName).toStrictEqual(createArea.name); | ||
}); | ||
}); | ||
|
||
describe('when equipment is added to non-existant area', () => { | ||
const addEquipment = { | ||
id: faker.string.uuid() as UUID, | ||
name: faker.company.buzzNoun() as NonEmptyString, | ||
areaId: faker.string.uuid() as UUID, | ||
}; | ||
beforeEach(async () => { | ||
await framework.commands.equipment.add(addEquipment); | ||
events = await framework.getAllEvents(); | ||
}); | ||
|
||
it('omits the equipment', () => { | ||
const allEquipment = getAll(events); | ||
expect(allEquipment).toHaveLength(0); | ||
}); | ||
}); | ||
}); |