55 getCachedSheetData ,
66} from '../../src/init-dependencies/google/get-cached-sheet-data' ;
77import { UUID } from 'io-ts-types' ;
8+ import * as t from 'io-ts' ;
89import { faker } from '@faker-js/faker' ;
910import { constructEvent , EventOfType } from '../../src/types/domain-event' ;
1011import { getRightOrFail } from '../helpers' ;
@@ -14,14 +15,23 @@ describe('Cache sheet data', () => {
1415 describe ( 'Cache then restore' , ( ) => {
1516 const equipmentId = '326e8fda-7be8-4cd8-87d5-7cdfafebf996' as UUID ;
1617 const sheetId = 'myTestingSheetId' ;
17- let cachedData : ReadonlyArray <
18- | EventOfType < 'EquipmentTrainingQuizResult' >
19- | EventOfType < 'EquipmentTrainingQuizSync' >
20- > ;
18+ const cacheTimestamp = new Date ( 2024 , 1 , 23 , 4 , 23 , 45 ) ;
19+ let cachedData : ReadonlyArray < {
20+ cache_entry_id : string ;
21+ cached_timestamp : Date ;
22+ sheet_id : string ;
23+ equipment_id : string ;
24+ cached_data : t . Validation <
25+ ReadonlyArray <
26+ | EventOfType < 'EquipmentTrainingQuizResult' >
27+ | EventOfType < 'EquipmentTrainingQuizSync' >
28+ >
29+ > ;
30+ } > ;
2131 beforeEach ( async ( ) => {
2232 const db = libsqlClient . createClient ( { url : ':memory:' } ) ;
2333 await ensureCachedSheetDataTableExists ( db ) ( ) ;
24- await cacheSheetData ( db ) ( new Date ( 2024 , 1 , 23 , 4 , 23 , 45 ) , sheetId , [
34+ await cacheSheetData ( db ) ( cacheTimestamp , sheetId , [
2535 constructEvent ( 'EquipmentTrainingQuizSync' ) ( {
2636 equipmentId,
2737 } ) ,
@@ -39,8 +49,16 @@ describe('Cache sheet data', () => {
3949 ] ) ( ) ;
4050 cachedData = getRightOrFail ( await getCachedSheetData ( db ) ( ) ( ) ) ;
4151 } ) ;
52+ it ( 'Each sheet is cached' , ( ) => {
53+ expect ( cachedData ) . toHaveLength ( 1 ) ; // 1 sheet
54+ } ) ;
4255 it ( 'All events cached are returned' , ( ) => {
43- expect ( cachedData ) . toHaveLength ( 2 ) ;
56+ expect ( getRightOrFail ( cachedData [ 0 ] . cached_data ) ) . toHaveLength ( 2 ) ; // 2 events.
57+ } ) ;
58+ it ( 'Event cache is correctly labeled' , ( ) => {
59+ expect ( cachedData [ 0 ] . equipment_id ) . toStrictEqual ( equipmentId ) ;
60+ expect ( cachedData [ 0 ] . sheet_id ) . toStrictEqual ( sheetId ) ;
61+ expect ( cachedData [ 0 ] . cached_timestamp ) . toStrictEqual ( cacheTimestamp ) ;
4462 } ) ;
4563 } ) ;
4664} ) ;
0 commit comments