import { ContentsquareModule } from '../../core/nativeModules'; import { addEventProperties, addUserProperties, clearEventProperties, removeEventProperty, } from '../../tracking/csqPropertyTracking'; // Mock the native module jest.mock('../../core/nativeModules', () => ({ ContentsquareModule: { addEventProperties: jest.fn(), removeEventProperty: jest.fn(), clearEventProperties: jest.fn(), addUserProperties: jest.fn(), }, })); describe('Property Tracking Functions', () => { beforeEach(() => { jest.clearAllMocks(); }); describe('addEventProperties', () => { it('should call ContentsquareModule.addEventProperties with properties', () => { // Given const properties = { name: 'test', count: 101, float: 50.5, active: true, }; // When addEventProperties(properties); // Then expect(ContentsquareModule.addEventProperties).toHaveBeenCalledWith( properties ); expect(ContentsquareModule.addEventProperties).toHaveBeenCalledTimes(1); }); it('should call ContentsquareModule.addEventProperties with empty properties', () => { // Given const properties = {}; // When addEventProperties(properties); // Then expect(ContentsquareModule.addEventProperties).toHaveBeenCalledWith( properties ); expect(ContentsquareModule.addEventProperties).toHaveBeenCalledTimes(1); }); }); describe('removeEventProperty', () => { it('should call ContentsquareModule.removeEventProperty with property name', () => { // Given const propertyName = 'test_property'; // When removeEventProperty(propertyName); // Then expect(ContentsquareModule.removeEventProperty).toHaveBeenCalledWith( propertyName ); expect(ContentsquareModule.removeEventProperty).toHaveBeenCalledTimes(1); }); }); describe('clearEventProperties', () => { it('should call ContentsquareModule.clearEventProperties', () => { // When clearEventProperties(); // Then expect(ContentsquareModule.clearEventProperties).toHaveBeenCalledWith(); expect(ContentsquareModule.clearEventProperties).toHaveBeenCalledTimes(1); }); }); describe('addUserProperties', () => { it('should call ContentsquareModule.addUserProperties with properties', () => { // Given const properties = { name: 'test', count: 101, float: 50.5, active: true, }; // When addUserProperties(properties); // Then expect(ContentsquareModule.addUserProperties).toHaveBeenCalledWith( properties ); expect(ContentsquareModule.addUserProperties).toHaveBeenCalledTimes(1); }); it('should call ContentsquareModule.addUserProperties with empty properties', () => { // Given const properties = {}; // When addUserProperties(properties); // Then expect(ContentsquareModule.addUserProperties).toHaveBeenCalledWith( properties ); expect(ContentsquareModule.addUserProperties).toHaveBeenCalledTimes(1); }); }); });