@@ -8,7 +8,7 @@ import type Store from '@ember-data/store';
8
8
import type { DocumentCacheOperation , NotificationType } from '@ember-data/store' ;
9
9
import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier' ;
10
10
11
- type Counter = { count : number } ;
11
+ type Counter = { count : number ; delivered : number ; ignored : number } ;
12
12
type NotificationStorage = Map <
13
13
StableDocumentIdentifier | StableRecordIdentifier | 'document' | 'resource' ,
14
14
Map < NotificationType | DocumentCacheOperation , Counter | Map < string | symbol , Counter > >
@@ -34,7 +34,7 @@ function getCounter(
34
34
let bucketStorage = identifierStorage . get ( bucket ) ;
35
35
if ( ! bucketStorage ) {
36
36
if ( bucket === 'added' || bucket === 'removed' || bucket === 'updated' || bucket === 'state' ) {
37
- bucketStorage = { count : 0 } ;
37
+ bucketStorage = { count : 0 , delivered : 0 , ignored : 0 } ;
38
38
} else {
39
39
bucketStorage = new Map ( ) ;
40
40
}
@@ -46,7 +46,7 @@ function getCounter(
46
46
const _key = key || Symbol . for ( bucket ) ;
47
47
counter = bucketStorage . get ( _key ) ! ;
48
48
if ( ! counter ) {
49
- counter = { count : 0 } ;
49
+ counter = { count : 0 , delivered : 0 , ignored : 0 } ;
50
50
bucketStorage . set ( _key , counter ) ;
51
51
}
52
52
} else {
@@ -79,7 +79,15 @@ function setupNotifications(context: TestContext, store: Store) {
79
79
counter . count ++ ;
80
80
81
81
// @ts -expect-error TS is bad at curried overloads
82
- return originalNotify . apply ( notifications , [ identifier , bucket , key ] ) ;
82
+ const scheduled = originalNotify . apply ( notifications , [ identifier , bucket , key ] ) ;
83
+
84
+ if ( scheduled ) {
85
+ counter . delivered ++ ;
86
+ } else {
87
+ counter . ignored ++ ;
88
+ }
89
+
90
+ return scheduled ;
83
91
} ;
84
92
}
85
93
@@ -97,15 +105,16 @@ export function configureNotificationsAssert(this: TestContext, assert: Assert)
97
105
identifier : StableRecordIdentifier | StableDocumentIdentifier ,
98
106
bucket : NotificationType | DocumentCacheOperation ,
99
107
key : string | null ,
100
- count : number
108
+ count : number ,
109
+ message ?: string
101
110
) {
102
111
const counter = getCounter ( context , identifier , bucket , key ) ;
103
112
104
113
this . pushResult ( {
105
114
result : counter . count === count ,
106
115
actual : counter . count ,
107
116
expected : count ,
108
- message : `Expected ${ count } ${ bucket } notifications for ${ identifier . lid } ${ key || '' } , got ${ counter . count } ` ,
117
+ message : `${ message ? message + ' | ' : '' } Expected ${ count } ${ bucket } notifications for ${ identifier . lid } ${ key || '' } , got ${ counter . count } ` ,
109
118
} ) ;
110
119
111
120
counter . count = 0 ;
0 commit comments