@@ -4,7 +4,7 @@ import _xhrMock from 'xhr-mock';
4
4
import { Crypto } from "@peculiar/webcrypto" ;
5
5
import Evolv from '../index.js' ;
6
6
import Store , { EFFECTIVE_GENOME_UPDATED } from '../store.js' ;
7
- import Context , { CONTEXT_INITIALIZED , CONTEXT_CHANGED } from '../context.js' ;
7
+ import Context , { CONTEXT_INITIALIZED , CONTEXT_CHANGED , CONFIRMATIONS_KEY , INTERNAL_CONFIRMATIONS_KEY } from '../context.js' ;
8
8
import { waitFor , emit } from '../waitforit.js' ;
9
9
import base64 from '../ponyfills/base64.js' ;
10
10
import { buildOptions } from '../build-options.js' ;
@@ -439,12 +439,42 @@ describe('Evolv client integration tests', () => {
439
439
440
440
await validateClient ( evolv , options , uid ) ;
441
441
442
- const confirmations = evolv . context . get ( 'experiments.confirmations' ) ;
442
+ const confirmations = evolv . context . get ( CONFIRMATIONS_KEY ) ;
443
443
expect ( confirmations . length ) . to . equal ( 1 ) ;
444
444
expect ( confirmations [ 0 ] . cid ) . to . equal ( '0cf8ffcedea2:0f39849197' ) ;
445
445
} ) ;
446
446
447
447
448
+ it ( 'should only confirm once when evaluating a context for confirmations' , async ( ) => {
449
+ xhrMock . get ( `${ endpoint } v${ version } /${ environment } /${ uid } /configuration.json` , ( _req , res ) => {
450
+ return res . status ( 200 ) . body ( JSON . stringify ( {
451
+ _published : 1584475383.3865728 ,
452
+ _client : {
453
+ browser : 'chrome' ,
454
+ platform : 'windows'
455
+ } ,
456
+ _experiments : experiments
457
+ } ) ) ;
458
+ } ) ;
459
+
460
+ xhrMock . get ( `${ endpoint } v${ version } /${ environment } /${ uid } /allocations` , ( _req , res ) => {
461
+ return res . status ( 200 ) . body ( JSON . stringify ( allocations ) ) ;
462
+ } ) ;
463
+
464
+ const options = {
465
+ environment,
466
+ endpoint,
467
+ version
468
+ } ;
469
+ const evolv = new Evolv ( options ) ;
470
+ const confirmedSpy = chai . spy ( ) ;
471
+ evolv . on ( Evolv . CONFIRMED , confirmedSpy ) ;
472
+
473
+ await validateClient ( evolv , options , uid ) ;
474
+
475
+ expect ( confirmedSpy ) . to . have . been . called . exactly ( 1 ) ;
476
+ } ) ;
477
+
448
478
it ( 'should put in internal confirmations if the user is internal' , async ( ) => {
449
479
xhrMock . get ( `${ endpoint } v${ version } /${ environment } /${ uid } /configuration.json` , ( _req , res ) => {
450
480
return res . status ( 200 ) . body ( JSON . stringify ( {
@@ -471,12 +501,43 @@ describe('Evolv client integration tests', () => {
471
501
472
502
await validateClient ( evolv , options , uid ) ;
473
503
474
- expect ( evolv . context . get ( 'experiments.confirmations' ) ) . to . be . undefined ;
475
- const internalConfirmations = evolv . context . get ( 'experiments.confirmationsInternal' ) ;
504
+ expect ( evolv . context . get ( CONFIRMATIONS_KEY ) ) . to . be . undefined ;
505
+ const internalConfirmations = evolv . context . get ( INTERNAL_CONFIRMATIONS_KEY ) ;
476
506
expect ( internalConfirmations . length ) . to . equal ( 1 ) ;
477
507
expect ( internalConfirmations [ 0 ] . cid ) . to . equal ( '0cf8ffcedea2:0f39849197' ) ;
478
508
} ) ;
479
509
510
+ it ( 'should only confirm once when evaluating a context for internal confirmations' , async ( ) => {
511
+ xhrMock . get ( `${ endpoint } v${ version } /${ environment } /${ uid } /configuration.json` , ( _req , res ) => {
512
+ return res . status ( 200 ) . body ( JSON . stringify ( {
513
+ _internal_user : true ,
514
+ _published : 1584475383.3865728 ,
515
+ _client : {
516
+ browser : 'chrome' ,
517
+ platform : 'windows'
518
+ } ,
519
+ _experiments : experiments
520
+ } ) ) ;
521
+ } ) ;
522
+
523
+ xhrMock . get ( `${ endpoint } v${ version } /${ environment } /${ uid } /allocations` , ( _req , res ) => {
524
+ return res . status ( 200 ) . body ( JSON . stringify ( allocations ) ) ;
525
+ } ) ;
526
+
527
+ const options = {
528
+ environment,
529
+ endpoint,
530
+ version
531
+ } ;
532
+ const evolv = new Evolv ( options ) ;
533
+ const confirmedSpy = chai . spy ( ) ;
534
+ evolv . on ( Evolv . CONFIRMED , confirmedSpy ) ;
535
+
536
+ await validateClient ( evolv , options , uid ) ;
537
+
538
+ expect ( confirmedSpy ) . to . have . been . called . exactly ( 1 ) ;
539
+ } ) ;
540
+
480
541
it ( 'should load variants and reevaluate context correctly with authentication' , async ( ) => {
481
542
const id = 'mine' ;
482
543
const secret = 'yep, lunch' ;
@@ -675,7 +736,7 @@ describe('Evolv client integration tests', () => {
675
736
expect ( messages [ 6 ] ) . to . be . a . message ( "context.value.added" , "user_attributes.country" , "usa" ) ;
676
737
expect ( messages [ 7 ] ) . to . be . a . message ( "context.value.changed" , "keys.active" , [ "web.ab8numq2j.am94yhwo2" ] ) ;
677
738
expect ( messages [ 8 ] ) . to . be . a . message ( "context.value.changed" , "variants.active" , [ "web.ab8numq2j.am94yhwo2:1486101989" ] ) ;
678
- expect ( messages [ 9 ] ) . to . be . a . messageWithLength ( "context.value.added" , "experiments.confirmations" , 1 ) ;
739
+ expect ( messages [ 9 ] ) . to . be . a . messageWithLength ( "context.value.added" , CONFIRMATIONS_KEY , 1 ) ;
679
740
expect ( messages [ 9 ] . payload . value [ 0 ] . cid ) . to . equal ( "0cf8ffcedea2:0f39849197" )
680
741
expect ( messages [ 10 ] ) . to . be . a . messageWithLength ( "context.value.added" , "events" , 1 ) ;
681
742
expect ( messages [ 10 ] . payload . value [ 0 ] . type ) . to . equal ( "lunch-time" )
@@ -823,7 +884,7 @@ describe('Evolv client integration tests', () => {
823
884
824
885
expect ( messages [ 9 ] ) . to . be . a . messageWithLength ( "context.value.added" , "confirmations" , 1 ) ;
825
886
expect ( messages [ 9 ] . payload . value [ 0 ] . cid ) . to . equal ( "0cf8ffcedea2:0f39849197" )
826
- expect ( messages [ 10 ] ) . to . be . a . messageWithLength ( "context.value.added" , "experiments.confirmations" , 1 ) ;
887
+ expect ( messages [ 10 ] ) . to . be . a . messageWithLength ( "context.value.added" , CONFIRMATIONS_KEY , 1 ) ;
827
888
expect ( messages [ 10 ] . payload . value [ 0 ] . cid ) . to . equal ( "0cf8ffcedea2:0f39849197" )
828
889
expect ( messages [ 11 ] ) . to . be . a . messageWithLength ( "context.value.added" , "events" , 1 ) ;
829
890
expect ( messages [ 11 ] . payload . value [ 0 ] . type ) . to . equal ( "lunch-time" )
@@ -1170,7 +1231,7 @@ describe('Evolv client unit tests', () => {
1170
1231
1171
1232
waitFor ( context , Evolv . CONFIRMED , ( ) => {
1172
1233
try {
1173
- const confirmations = context . get ( 'experiments.confirmations' ) ;
1234
+ const confirmations = context . get ( CONFIRMATIONS_KEY ) ;
1174
1235
expect ( confirmations . length ) . to . be . equal ( 1 ) ;
1175
1236
expect ( confirmations [ 0 ] . cid ) . to . be . equal ( '5678' ) ;
1176
1237
done ( ) ;
@@ -1196,7 +1257,7 @@ describe('Evolv client unit tests', () => {
1196
1257
1197
1258
waitFor ( context , Evolv . CONFIRMED , ( ) => {
1198
1259
try {
1199
- const confirmations = context . get ( 'experiments.confirmations' ) ;
1260
+ const confirmations = context . get ( CONFIRMATIONS_KEY ) ;
1200
1261
expect ( confirmations . length ) . to . be . equal ( 1 ) ;
1201
1262
expect ( confirmations [ 0 ] . cid ) . to . be . equal ( '5678' ) ;
1202
1263
done ( ) ;
0 commit comments