import { SegmentClient } from '../../analytics' ; import { getMockLogger } from '../__helpers__/mockLogger' ; import { mockPersistor } from '../__helpers__/mockPersistor' ; import { MockSegmentStore } from '../__helpers__/mockSegmentStore' ; jest . mock ( '../../uuid' ) ; jest . spyOn ( Date . prototype , 'toISOString' ) . mockReturnValue ( '2010-01-01T00:00:00.000Z' ) ; describe ( 'methods #group' , ( ) => { const store = new MockSegmentStore ( { userInfo : { userId : 'current-user-id' , anonymousId : 'very-anonymous' , } , } ) ; const clientArgs = { config : { writeKey : 'mock-write-key' , } , logger : getMockLogger ( ) , persistor : mockPersistor , store : store , } ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; } ) ; it ( 'adds the alias event correctly' , ( ) => { const client = new SegmentClient ( clientArgs ) ; jest . spyOn ( client , 'process' ) ; client . group ( 'new-group-id' , { name : 'Best Group Ever' } ) ; const expectedEvent = { groupId : 'new-group-id' , type : 'group' , traits : { name : 'Best Group Ever' , } , } ; expect ( client . process ) . toHaveBeenCalledTimes ( 1 ) ; expect ( client . process ) . toHaveBeenCalledWith ( expectedEvent ) ; } ) ; } ) ;