@@ -495,21 +495,77 @@ describe('HTTP request handler', () => {
495
495
assert . deepStrictEqual ( stats , [
496
496
{
497
497
day : '2024-01-11' ,
498
- tested : 20 ,
499
- indexMajorityFound : 10 ,
500
- indexed : 6 ,
501
- indexedHttp : 4 ,
502
- retrievalMajorityFound : 5 ,
503
- retrievable : 2
498
+ tested : '20' ,
499
+ indexMajorityFound : '10' ,
500
+ indexed : '6' ,
501
+ indexedHttp : '4' ,
502
+ retrievalMajorityFound : '5' ,
503
+ retrievable : '2'
504
504
} ,
505
505
{
506
506
day : '2024-01-12' ,
507
- tested : 30 ,
508
- indexMajorityFound : 7 ,
509
- indexed : 7 ,
510
- indexedHttp : 7 ,
511
- retrievalMajorityFound : 3 ,
512
- retrievable : 3
507
+ tested : '30' ,
508
+ indexMajorityFound : '7' ,
509
+ indexed : '7' ,
510
+ indexedHttp : '7' ,
511
+ retrievalMajorityFound : '3' ,
512
+ retrievable : '3'
513
+ }
514
+ ] )
515
+ } )
516
+
517
+ it ( 'aggregates stats over miners' , async ( ) => {
518
+ await givenDailyDealStats ( pgPools . evaluate , { day : '2024-01-11' , minerId : 'f1aa' , tested : 10 } )
519
+ await givenDailyDealStats ( pgPools . evaluate , { day : '2024-01-11' , minerId : 'f1bb' , tested : 20 } )
520
+ await givenDailyDealStats ( pgPools . evaluate , { day : '2024-01-12' , minerId : 'f1aa' , tested : 30 } )
521
+ await givenDailyDealStats ( pgPools . evaluate , { day : '2024-01-12' , minerId : 'f1bb' , tested : 40 } )
522
+
523
+ const res = await fetch (
524
+ new URL (
525
+ '/deals/daily?from=2024-01-11&to=2024-01-12' ,
526
+ baseUrl
527
+ ) , {
528
+ redirect : 'manual'
529
+ }
530
+ )
531
+ await assertResponseStatus ( res , 200 )
532
+ const stats = /** @type {any[] } */ ( await res . json ( ) )
533
+ assert . deepStrictEqual ( stats . map ( ( { day, tested } ) => ( { day, tested } ) ) , [
534
+ {
535
+ day : '2024-01-11' ,
536
+ tested : String ( 10 + 20 )
537
+ } ,
538
+ {
539
+ day : '2024-01-12' ,
540
+ tested : String ( 30 + 40 )
541
+ }
542
+ ] )
543
+ } )
544
+
545
+ it ( 'aggregates stats over clients' , async ( ) => {
546
+ await givenDailyDealStats ( pgPools . evaluate , { day : '2024-01-11' , clientId : 'f1aa' , tested : 10 } )
547
+ await givenDailyDealStats ( pgPools . evaluate , { day : '2024-01-11' , clientId : 'f1bb' , tested : 20 } )
548
+ await givenDailyDealStats ( pgPools . evaluate , { day : '2024-01-12' , clientId : 'f1aa' , tested : 30 } )
549
+ await givenDailyDealStats ( pgPools . evaluate , { day : '2024-01-12' , minerId : 'f1bb' , tested : 40 } )
550
+
551
+ const res = await fetch (
552
+ new URL (
553
+ '/deals/daily?from=2024-01-11&to=2024-01-12' ,
554
+ baseUrl
555
+ ) , {
556
+ redirect : 'manual'
557
+ }
558
+ )
559
+ await assertResponseStatus ( res , 200 )
560
+ const stats = /** @type {any[] } */ ( await res . json ( ) )
561
+ assert . deepStrictEqual ( stats . map ( ( { day, tested } ) => ( { day, tested } ) ) , [
562
+ {
563
+ day : '2024-01-11' ,
564
+ tested : String ( 10 + 20 )
565
+ } ,
566
+ {
567
+ day : '2024-01-12' ,
568
+ tested : String ( 30 + 40 )
513
569
}
514
570
] )
515
571
} )
@@ -617,10 +673,10 @@ const givenRetrievalStats = async (pgPool, { day, minerId, total, successful })
617
673
* clientId?: string;
618
674
* tested: number;
619
675
* indexMajorityFound?: number;
620
- * indexed: number;
676
+ * indexed? : number;
621
677
* indexedHttp?: number;
622
678
* retrievalMajorityFound?: number;
623
- * retrievable: number;
679
+ * retrievable? : number;
624
680
* }} stats
625
681
*/
626
682
const givenDailyDealStats = async ( pgPool , {
@@ -634,6 +690,13 @@ const givenDailyDealStats = async (pgPool, {
634
690
retrievalMajorityFound,
635
691
retrievable
636
692
} ) => {
693
+ indexed ??= tested
694
+ indexedHttp ??= indexed
695
+ indexMajorityFound ??= indexed
696
+
697
+ retrievable ??= tested
698
+ retrievalMajorityFound ??= retrievable
699
+
637
700
await pgPool . query ( `
638
701
INSERT INTO daily_deals (
639
702
day,
@@ -651,10 +714,10 @@ const givenDailyDealStats = async (pgPool, {
651
714
minerId ?? 'f1miner' ,
652
715
clientId ?? 'f1client' ,
653
716
tested ,
654
- indexMajorityFound ?? indexed ,
717
+ indexMajorityFound ,
655
718
indexed ,
656
- indexedHttp ?? indexed ,
657
- retrievalMajorityFound ?? retrievable ,
719
+ indexedHttp ,
720
+ retrievalMajorityFound ,
658
721
retrievable
659
722
] )
660
723
}
0 commit comments