Skip to content

Commit

Permalink
Mock Date to allow testing of trainedAt #59
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Haarhoff committed Aug 8, 2024
1 parent cc07c69 commit 770af7d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ module.exports = {
},
verbose: true,
reporters: ['jest-wip-reporter'],
setupFiles: ['jest-date-mock'],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"gts": "^5.2.0",
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"jest-date-mock": "^1.0.10",
"jest-wip-reporter": "^2.1.0",
"open": "^10.1.0",
"ts-jest": "^29.1.1",
Expand Down
11 changes: 10 additions & 1 deletion tests/read-models/shared-state/get-member.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as O from 'fp-ts/Option';
import {advanceTo} from 'jest-date-mock';
import {getDetails} from '../../../src/read-models/members/get';
import {EmailAddress} from '../../../src/types';
import {TestFramework, initTestFramework} from '../test-framework';
Expand Down Expand Up @@ -173,9 +174,12 @@ describe('get-via-shared-read-model', () => {
id: faker.string.uuid() as UUID,
areaId: createArea.id,
};
const trainedAt = faker.date.future();
beforeEach(async () => {
advanceTo(faker.date.past());
await framework.commands.area.create(createArea);
await framework.commands.equipment.add(createEquipment);
advanceTo(trainedAt);
await framework.commands.trainers.markTrained({
memberNumber: memberNumber as Int,
equipmentId: createEquipment.id,
Expand All @@ -189,7 +193,12 @@ describe('get-via-shared-read-model', () => {
expect(result.trainedOn[0].name).toStrictEqual(createEquipment.name);
});

it.todo('returns date they were marked as trained');
it('returns date they were marked as trained', () => {
const result = runQuery();
expect(result.trainedOn[0].trainedAt).toStrictEqual(
trainedAt.toISOString()
);
});
});
});
});

0 comments on commit 770af7d

Please sign in to comment.