11import { Platforms } from '#app/models/types/global' ;
22import * as genericLabelHelpers from '../../../lib/analyticsUtils' ;
3- import { buildReverbAnalyticsModel , buildReverbEventModel } from '.' ;
3+ import {
4+ buildActivationEventModel ,
5+ buildReverbAnalyticsModel ,
6+ buildReverbEventModel ,
7+ } from '.' ;
48
59const mockAndSet = ( { name, source } , response ) => {
610 source [ name ] = jest . fn ( ) ; // eslint-disable-line no-param-reassign
@@ -16,18 +20,18 @@ const analyticsUtilFunctions = [
1620] ;
1721
1822describe ( 'atiUrl' , ( ) => {
23+ beforeEach ( ( ) => {
24+ analyticsUtilFunctions . forEach ( func => {
25+ mockAndSet ( func , func . name ) ;
26+ } ) ;
27+ } ) ;
28+
1929 afterEach ( ( ) => {
2030 jest . clearAllMocks ( ) ;
2131 } ) ;
2232
2333 describe ( 'Reverb' , ( ) => {
2434 describe ( 'buildReverbAnalyticsModel' , ( ) => {
25- beforeEach ( ( ) => {
26- analyticsUtilFunctions . forEach ( func => {
27- mockAndSet ( func , func . name ) ;
28- } ) ;
29- } ) ;
30-
3135 const input = {
3236 appName : 'news' ,
3337 campaigns : [
@@ -403,5 +407,76 @@ describe('atiUrl', () => {
403407 } ) ;
404408 } ) ;
405409 } ) ;
410+
411+ describe ( 'buildActivationEventModel' , ( ) => {
412+ const input = {
413+ pageIdentifier : 'mundo.page' ,
414+ platform : 'canonical' as unknown as Platforms ,
415+ appName : 'news-mundo' ,
416+ producerName : 'MUNDO' ,
417+ statsDestination : 'statsDestination' ,
418+ experimentName : 'dummy_experiment' ,
419+ experimentVariant : 'variant_1' ,
420+ isSignedIn : false ,
421+ hashedId : null ,
422+ } ;
423+
424+ it ( 'should return the correct Reverb page section activation event model' , ( ) => {
425+ const reverbExperimentActivationEventModel =
426+ buildActivationEventModel ( input ) ;
427+
428+ const experimentActivationEventParams = {
429+ destination : 'statsDestination' ,
430+ name : 'mundo.page' ,
431+ producer : 'MUNDO' ,
432+ additionalProperties : {
433+ type : 'AT' ,
434+ app_name : 'news-mundo' ,
435+ app_type : 'getAppType' ,
436+ } ,
437+ } ;
438+
439+ expect ( reverbExperimentActivationEventModel . params . page ) . toEqual (
440+ experimentActivationEventParams ,
441+ ) ;
442+ } ) ;
443+
444+ it ( 'should return the correct Reverb user object configuration' , ( ) => {
445+ const reverbExperimentActivationEventModel = buildActivationEventModel ( {
446+ ...input ,
447+ isSignedIn : true ,
448+ hashedId : 'hashed-id' ,
449+ } ) ;
450+
451+ expect ( reverbExperimentActivationEventModel . params . user ) . toEqual ( {
452+ isSignedIn : true ,
453+ hashedId : 'hashed-id' ,
454+ } ) ;
455+ } ) ;
456+
457+ it ( 'should return the correct Reverb event details configuration' , ( ) => {
458+ const reverbExperimentActivationEventModel =
459+ buildActivationEventModel ( input ) ;
460+
461+ expect ( reverbExperimentActivationEventModel . eventDetails ) . toEqual ( {
462+ eventName : 'activation' ,
463+ eventPublisher : 'viewability' ,
464+ event : {
465+ category : 'viewability' ,
466+ action : 'serve' ,
467+ interaction_type : 'optimizely_activation' ,
468+ spec_id : '829257ce-28c6-4bbd-8e87-bdacba05de82' ,
469+ spec_version : '1.0.1' ,
470+ } ,
471+ group : {
472+ type : 'experiment' ,
473+ name : 'optimizely' ,
474+ } ,
475+ experience : {
476+ engine_id : [ 'optimizely.dummy_experiment.variant_1' ] ,
477+ } ,
478+ } ) ;
479+ } ) ;
480+ } ) ;
406481 } ) ;
407482} ) ;
0 commit comments