11import * as O from 'fp-ts/Option' ;
2+ import * as RA from 'fp-ts/ReadonlyArray' ;
23import { NonEmptyString , UUID } from 'io-ts-types' ;
34import { faker } from '@faker-js/faker' ;
45import * as gsheetData from '../data/google_sheet_data' ;
@@ -70,22 +71,38 @@ describe('Integration asyncApplyExternalEventSources', () => {
7071 areaId ,
7172 O . some ( gsheetData . METAL_LATHE . apiResp . spreadsheetId ! )
7273 ) ;
73- const results = await runAsyncApplyExternalEventSources ( framework ) ;
74- checkLastQuizSyncUpdated ( results ) ;
74+ const resultsAfterFirstRun =
75+ await runAsyncApplyExternalEventSources ( framework ) ;
76+
77+ const resultsAfterSecondRun =
78+ await runAsyncApplyExternalEventSources ( framework ) ;
79+
80+ expect (
81+ RA . filter ( ( e : Equipment ) => O . isSome ( e . lastQuizSync ) ) (
82+ Array . from ( resultsAfterFirstRun . equipmentAfter . values ( ) )
83+ )
84+ ) . toHaveLength ( 1 ) ; // Only update a single piece of equipment at a time.
85+
86+ expect (
87+ RA . filter ( ( e : Equipment ) => O . isSome ( e . lastQuizSync ) ) (
88+ Array . from ( resultsAfterSecondRun . equipmentAfter . values ( ) )
89+ )
90+ ) . toHaveLength ( 2 ) ; // Only update a single piece of equipment at a time.
91+
7592 checkLastQuizEventTimestamp (
7693 gsheetData . BAMBU ,
77- results . equipmentAfter . get ( bambu . id ) !
94+ resultsAfterSecondRun . equipmentAfter . get ( bambu . id ) !
7895 ) ;
7996 checkLastQuizEventTimestamp (
8097 gsheetData . METAL_LATHE ,
81- results . equipmentAfter . get ( lathe . id ) !
98+ resultsAfterSecondRun . equipmentAfter . get ( lathe . id ) !
8299 ) ;
83100
84101 // We already test the produced quiz result events above
85102 // and testing updateState is also tested elsewhere so this integration
86103 // test doesn't need to enumerate every combination it just needs to check
87104 // that generally the equipment is getting updated.
88- const bambuAfter = results . equipmentAfter . get ( bambu . id ) ! ;
105+ const bambuAfter = resultsAfterSecondRun . equipmentAfter . get ( bambu . id ) ! ;
89106 expect ( bambuAfter . orphanedPassedQuizes ) . toHaveLength ( 0 ) ;
90107 expect ( bambuAfter . membersAwaitingTraining ) . toHaveLength ( 1 ) ;
91108 expect ( bambuAfter . membersAwaitingTraining [ 0 ] . memberNumber ) . toStrictEqual (
@@ -96,7 +113,7 @@ describe('Integration asyncApplyExternalEventSources', () => {
96113 ) ;
97114
98115 // Lathe results only have a single failed entry.
99- const latheAfter = results . equipmentAfter . get ( lathe . id ) ! ;
116+ const latheAfter = resultsAfterSecondRun . equipmentAfter . get ( lathe . id ) ! ;
100117 expect ( latheAfter . orphanedPassedQuizes ) . toHaveLength ( 0 ) ;
101118 expect ( latheAfter . failedQuizAttempts ) . toHaveLength ( 1 ) ;
102119 expect ( latheAfter . failedQuizAttempts [ 0 ] ) . toMatchObject ( {
0 commit comments