@@ -160,45 +160,58 @@ describe('get all events', () => {
160160 } ) ;
161161
162162 describe ( 'getAllEventsByTypes' , ( ) => {
163- it ( 'returns events matching either requested type' , async ( ) => {
164- const firstMatchingEvent = arbitraryMemberNumberLinkedToEmailEvent ( ) ;
165- const nonMatchingEvent = arbitraryEquipmentTrainingQuizResultEvent ( ) ;
166- const secondMatchingEvent = arbitraryEquipmentTrainingSheetRegisteredEvent ( ) ;
163+ const memberLinkedEvent = arbitraryMemberNumberLinkedToEmailEvent ( ) ;
164+ const equipmentTrainingQuizResult = arbitraryEquipmentTrainingQuizResultEvent ( ) ;
165+ const trainingSheetRegisteredEvent = arbitraryEquipmentTrainingSheetRegisteredEvent ( ) ;
167166
168- await persistEvent ( firstMatchingEvent ) ;
169- await persistEvent ( nonMatchingEvent ) ;
170- await persistEvent ( secondMatchingEvent ) ;
167+ beforeEach ( async ( ) => {
168+ await persistEvent ( memberLinkedEvent ) ;
169+ await persistEvent ( equipmentTrainingQuizResult ) ;
170+ await persistEvent ( trainingSheetRegisteredEvent ) ;
171+ } ) ;
171172
173+ it ( 'returns events matching either requested type' , async ( ) => {
172174 expect (
173175 await initalisedGetAllEventsByTypes (
174176 'MemberNumberLinkedToEmail' ,
175177 'EquipmentTrainingSheetRegistered'
176178 )
177179 ) . toStrictEqual ( [
178- firstMatchingEvent ,
179- secondMatchingEvent ,
180+ memberLinkedEvent ,
181+ trainingSheetRegisteredEvent ,
180182 ] ) ;
181183 } ) ;
182184
183185 it ( 'returns EquipmentTrainingQuizResult events when one of the requested types matches' , async ( ) => {
184- const equipmentTrainingQuizResult =
185- arbitraryEquipmentTrainingQuizResultEvent ( ) ;
186- const matchingEvent = arbitraryEquipmentTrainingSheetRegisteredEvent ( ) ;
187- const nonMatchingEvent = arbitraryMemberNumberLinkedToEmailEvent ( ) ;
188-
189- await persistEvent ( equipmentTrainingQuizResult ) ;
190- await persistEvent ( matchingEvent ) ;
191- await persistEvent ( nonMatchingEvent ) ;
192-
193186 expect (
194187 await initalisedGetAllEventsByTypes (
195188 'EquipmentTrainingQuizResult' ,
196189 'EquipmentTrainingSheetRegistered'
197190 )
198191 ) . toStrictEqual ( [
199192 equipmentTrainingQuizResult ,
200- matchingEvent ,
193+ trainingSheetRegisteredEvent ,
201194 ] ) ;
202195 } ) ;
196+
197+ describe ( 'exclude an event' , ( ) => {
198+ const excludedBy : number = faker . number . int ( ) ;
199+ const excludedByReason : string = faker . company . catchPhrase ( ) ;
200+
201+ beforeEach ( async ( ) => {
202+ const eventId = ( await dbClient . execute ( 'SELECT id FROM events WHERE event_type = ?' , [ trainingSheetRegisteredEvent . type ] ) ) . rows [ 0 ] [ 'id' ] ! as string ;
203+ await unPersistEvent ( eventId , excludedBy , excludedByReason )
204+ } ) ;
205+ it ( 'returns only events of the requested type excluding the excluded event' , async ( ) => {
206+ expect (
207+ await initalisedGetAllEventsByTypes (
208+ 'MemberNumberLinkedToEmail' ,
209+ 'EquipmentTrainingSheetRegistered'
210+ )
211+ ) . toStrictEqual ( [
212+ memberLinkedEvent ,
213+ ] ) ;
214+ } ) ;
215+ } ) ;
203216 } ) ;
204217} ) ;
0 commit comments