import { ContentsquareModule } from '../../core/nativeModules'; import { getUserId, optIn, optOut, sendUserIdentifier, } from '../../privacy/user'; jest.mock('../../core/nativeModules', () => ({ ContentsquareModule: { getUserId: jest.fn(), optIn: jest.fn(), optOut: jest.fn(), sendUserIdentifier: jest.fn(), }, })); describe('User Privacy Functions', () => { beforeEach(() => { jest.clearAllMocks(); }); describe('getUserId', () => { it('should call ContentsquareModule.getUserId with the correct callback', () => { const mockCallback = jest.fn(); getUserId(mockCallback); expect(ContentsquareModule.getUserId).toHaveBeenCalledWith(mockCallback); expect(ContentsquareModule.getUserId).toHaveBeenCalledTimes(1); }); }); 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('sendUserIdentifier', () => { it('should call ContentsquareModule.sendUserIdentifier with a valid string', () => { const validUserId = 'user123'; sendUserIdentifier(validUserId); expect(ContentsquareModule.sendUserIdentifier).toHaveBeenCalledWith( validUserId ); expect(ContentsquareModule.sendUserIdentifier).toHaveBeenCalledTimes(1); }); 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(); }); }); });