@@ -372,22 +372,16 @@ test('reports usage', async ({ expect }) => {
372
372
373
373
test ( 'reports usage with response cache' , async ( { expect } ) => {
374
374
let usageCount = 0 ;
375
+ const results : Array < Record < string , any > > = [ ] ;
375
376
const graphqlScope = nock ( 'http://localhost' )
376
377
. post ( '/usage' , body => {
377
378
usageCount ++ ;
378
-
379
- expect ( body . map ) . toEqual ( {
380
- f25063b60ab942d0c0d14cdd9cd3172de2e7ebc4 : {
381
- fields : [ 'Query.hi' ] ,
382
- operation : '{hi}' ,
383
- operationName : 'anonymous' ,
384
- } ,
385
- } ) ;
386
-
379
+ results . push ( body ) ;
387
380
return true ;
388
381
} )
389
382
. thrice ( )
390
383
. reply ( 200 ) ;
384
+
391
385
const yoga = createYoga ( {
392
386
schema : createSchema ( {
393
387
typeDefs : /* GraphQL */ `
@@ -458,6 +452,23 @@ test('reports usage with response cache', async ({ expect }) => {
458
452
} ) ;
459
453
graphqlScope . done ( ) ;
460
454
expect ( usageCount ) . toBe ( 3 ) ;
455
+
456
+ for ( const body of results ) {
457
+ expect ( body . operations [ 0 ] . metadata ) . toEqual ( {
458
+ client : {
459
+ name : 'brrr' ,
460
+ version : '1' ,
461
+ } ,
462
+ } ) ;
463
+
464
+ expect ( body . map ) . toEqual ( {
465
+ f25063b60ab942d0c0d14cdd9cd3172de2e7ebc4 : {
466
+ fields : [ 'Query.hi' ] ,
467
+ operation : '{hi}' ,
468
+ operationName : 'anonymous' ,
469
+ } ,
470
+ } ) ;
471
+ }
461
472
} ) ;
462
473
463
474
test ( 'does not report usage for operation that does not pass validation' , async ( { expect } ) => {
@@ -1107,10 +1118,10 @@ describe('subscription usage reporting', () => {
1107
1118
expect ( res . status ) . toBe ( 200 ) ;
1108
1119
expect ( await res . text ( ) ) . toMatchInlineSnapshot ( `
1109
1120
:
1110
-
1121
+
1111
1122
event: next
1112
1123
data: {"errors":[{"message":"Unexpected error.","locations":[{"line":1,"column":1}],"extensions":{"unexpected":true}}]}
1113
-
1124
+
1114
1125
event: complete
1115
1126
data:
1116
1127
` ) ;
0 commit comments