From 8e3d3a5efa059e3ecbc46a97fe22d2f067bcee77 Mon Sep 17 00:00:00 2001 From: Aanshi Lahoti Date: Mon, 20 Jan 2025 01:30:24 +0530 Subject: [PATCH] chore: mixpanel test cases --- .../integrations/Mixpanel/browser.test.js | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/packages/analytics-js-integrations/__tests__/integrations/Mixpanel/browser.test.js b/packages/analytics-js-integrations/__tests__/integrations/Mixpanel/browser.test.js index c8fb19346..fa065c2b4 100644 --- a/packages/analytics-js-integrations/__tests__/integrations/Mixpanel/browser.test.js +++ b/packages/analytics-js-integrations/__tests__/integrations/Mixpanel/browser.test.js @@ -375,3 +375,99 @@ describe('Page tests', () => { } }); }); + +describe('Group tests', () => { + beforeEach(() => { + window.mixpanel = []; + }); + let mixpanel; + test('should log an error when userId is not defined for group call', () => { + mixpanel = new Mixpanel( + { + groupKeySettings: true, + }, + { logLevel: 'debug' }, + ); + mixpanel.init(); + try { + mixpanel.group({ + message: { + name: 'Doc', + userId: null, + properties: { category: 'Integration' }, + }, + }); + } catch (error) { + expect(error).toEqual('valid userId is required for group'); + } + }); + + test('should log an error when groupId is not defined for group call', () => { + mixpanel = new Mixpanel( + { + groupKeySettings: true, + }, + { logLevel: 'debug' }, + ); + mixpanel.init(); + try { + mixpanel.group({ + message: { + name: 'Doc', + groupId: null, + properties: { category: 'Integration' }, + }, + }); + } catch (error) { + expect(error).toEqual('valid groupId is required for group'); + } + }); +}); + +describe('Alias tests', () => { + beforeEach(() => { + window.mixpanel = []; + }); + let mixpanel; + test('should log an error when previousId is not defined for alias call', () => { + mixpanel = new Mixpanel( + { + identityMergeApi: 'original', + }, + { logLevel: 'debug' }, + ); + mixpanel.init(); + try { + mixpanel.alias({ + message: { + name: 'Doc', + previousId: null, + properties: { category: 'Integration' }, + }, + }); + } catch (error) { + expect(error).toEqual('valid previousId is required for group'); + } + }); + + test('should log an error when userId is not defined for alias call', () => { + mixpanel = new Mixpanel( + { + identityMergeApi: 'original', + }, + { logLevel: 'debug' }, + ); + mixpanel.init(); + try { + mixpanel.alias({ + message: { + name: 'Doc', + userId: null, + properties: { category: 'Integration' }, + }, + }); + } catch (error) { + expect(error).toEqual('valid userId is required for group'); + } + }); +});