Skip to content

Commit 324eda7

Browse files
committed
More testing for caching events
1 parent 9a52842 commit 324eda7

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

tests/training-sheets/cached-sheet-data.test.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ describe('Cache sheet data', () => {
1616
const equipmentId = '326e8fda-7be8-4cd8-87d5-7cdfafebf996' as UUID;
1717
const sheetId = 'myTestingSheetId';
1818
const cacheTimestamp = new Date(2024, 1, 23, 4, 23, 45);
19+
const trainingQuizResult = {
20+
equipmentId: equipmentId,
21+
trainingSheetId: sheetId,
22+
memberNumberProvided: faker.number.int(),
23+
emailProvided: 'beans@bob.co.uk',
24+
score: 23,
25+
id: '1a3eeb99-dd7a-4f55-a018-6f5e2678fc14' as UUID,
26+
maxScore: 23,
27+
percentage: 100,
28+
timestampEpochMS: 1738623209,
29+
};
1930
let cachedData: ReadonlyArray<{
2031
cached_at: Date;
2132
sheet_id: string;
@@ -35,17 +46,7 @@ describe('Cache sheet data', () => {
3546
constructEvent('EquipmentTrainingQuizSync')({
3647
equipmentId,
3748
}),
38-
constructEvent('EquipmentTrainingQuizResult')({
39-
equipmentId: equipmentId,
40-
trainingSheetId: sheetId,
41-
memberNumberProvided: faker.number.int(),
42-
emailProvided: 'beans@bob.co.uk',
43-
score: 23,
44-
id: '1a3eeb99-dd7a-4f55-a018-6f5e2678fc14' as UUID,
45-
maxScore: 23,
46-
percentage: 100,
47-
timestampEpochMS: 1738623209,
48-
}),
49+
constructEvent('EquipmentTrainingQuizResult')(trainingQuizResult),
4950
])()
5051
);
5152
cachedData = getRightOrFail(await getCachedSheetData(db)()());
@@ -54,7 +55,14 @@ describe('Cache sheet data', () => {
5455
expect(cachedData).toHaveLength(1); // 1 sheet
5556
});
5657
it('All events cached are returned', () => {
57-
expect(getRightOrFail(cachedData[0].cached_data)).toHaveLength(2); // 2 events.
58+
const returnedCachedData = getRightOrFail(cachedData[0].cached_data);
59+
expect(returnedCachedData).toHaveLength(2); // 2 events.
60+
returnedCachedData.forEach(e =>
61+
expect(e.equipmentId).toStrictEqual(equipmentId)
62+
);
63+
expect(
64+
returnedCachedData.find(e => e.type === 'EquipmentTrainingQuizResult')!
65+
).toMatchObject(trainingQuizResult);
5866
});
5967
it('Event cache is correctly labeled', () => {
6068
expect(cachedData[0].sheet_id).toStrictEqual(sheetId);

0 commit comments

Comments
 (0)