@@ -2,13 +2,15 @@ import {
22 DUMMY_ONESIGNAL_ID ,
33 DUMMY_PUSH_TOKEN ,
44} from '__test__/support/constants' ;
5+ import Log from 'src/shared/libraries/Log' ;
56import { IDManager } from 'src/shared/managers/IDManager' ;
67import { TestEnvironment } from '../../__test__/support/environment/TestEnvironment' ;
78import UserChangeEvent from '../page/models/UserChangeEvent' ;
89import { Subscription } from '../shared/models/Subscription' ;
10+ import User from './User' ;
911import UserNamespace from './UserNamespace' ;
1012
11- vi . mock ( '../shared/libraries/Log ') ;
13+ const errorSpy = vi . spyOn ( Log , 'error' ) . mockImplementation ( ( ) => ' ') ;
1214
1315describe ( 'UserNamespace' , ( ) => {
1416 let userNamespace : UserNamespace ;
@@ -427,4 +429,32 @@ describe('UserNamespace', () => {
427429 expect ( customNamespace . PushSubscription ) . toBeDefined ( ) ;
428430 } ) ;
429431 } ) ;
432+
433+ describe ( 'Custom Events' , ( ) => {
434+ test ( 'should call track event' , ( ) => {
435+ const trackEventSpy = vi . spyOn ( User . prototype , 'trackEvent' ) ;
436+ const name = 'test_event' ;
437+ const properties = {
438+ test_property : 'test_value' ,
439+ } ;
440+
441+ // should validate properties
442+ // @ts -expect-error - mock invalid argument
443+ userNamespace . trackEvent ( name , 123 ) ;
444+ expect ( errorSpy ) . toHaveBeenCalledWith (
445+ 'Custom event properties must be a JSON-serializable object' ,
446+ ) ;
447+
448+ // big ints can't be serialized
449+ userNamespace . trackEvent ( name , {
450+ data : 10n ,
451+ } ) ;
452+ expect ( errorSpy ) . toHaveBeenCalledWith (
453+ 'Custom event properties must be a JSON-serializable object' ,
454+ ) ;
455+
456+ userNamespace . trackEvent ( name , properties ) ;
457+ expect ( trackEventSpy ) . toHaveBeenCalledWith ( name , properties ) ;
458+ } ) ;
459+ } ) ;
430460} ) ;
0 commit comments