import { ContentsquareModule } from '../../core/nativeModules'; import { identify, optIn, optOut, resetIdentity, sendUserIdentifier, } from '../../privacy/csqPrivacy'; jest.mock('../../core/nativeModules', () => ({ ContentsquareModule: { optIn: jest.fn(), optOut: jest.fn(), identify: jest.fn(), resetIdentity: jest.fn(), sendUserIdentifier: jest.fn(), }, })); describe('CSQ User Privacy Functions', () => { beforeEach(() => { jest.clearAllMocks(); }); describe('optIn', () => { it('should call ContentsquareModule.optIn', () => { optIn(); expect(ContentsquareModule.optIn).toHaveBeenCalledTimes(1); }); }); describe('optOut', () => { it('should call ContentsquareModule.optOut', () => { optOut(); expect(ContentsquareModule.optOut).toHaveBeenCalledTimes(1); }); }); describe('identify', () => { it('should call ContentsquareModule.identify with correct identity', () => { const testIdentity = 'test-identity'; identify(testIdentity); expect(ContentsquareModule.identify).toHaveBeenCalledTimes(1); expect(ContentsquareModule.identify).toHaveBeenCalledWith(testIdentity); }); }); describe('resetIdentity', () => { it('should call ContentsquareModule.resetIdentity', () => { resetIdentity(); expect(ContentsquareModule.resetIdentity).toHaveBeenCalledTimes(1); }); }); describe('sendUserIdentifier', () => { it('should call ContentsquareModule.sendUserIdentifier with correct user identifier', () => { const testUserIdentifier = 'test-user-identifier'; sendUserIdentifier(testUserIdentifier); expect(ContentsquareModule.sendUserIdentifier).toHaveBeenCalledTimes(1); expect(ContentsquareModule.sendUserIdentifier).toHaveBeenCalledWith( testUserIdentifier ); }); }); it('should log an error for a non-string user identifier', () => { console.error = jest.fn(); // Mock console.error const invalidUserId = 123; sendUserIdentifier(invalidUserId as any); expect(console.error).toHaveBeenCalledWith( 'The User Identifier must be of string data type.' ); expect(ContentsquareModule.sendUserIdentifier).not.toHaveBeenCalled(); }); });