Skip to content

Commit

Permalink
Write characterisation tests for the new read model
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Haarhoff committed May 26, 2024
1 parent 3c2b36a commit 57133a4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/read-models/equipment/get-all.test.ts
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);
});
});
});

0 comments on commit 57133a4

Please sign in to comment.