@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
80 lines • 3.38 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const mixpanel = tslib_1.__importStar(require("mixpanel-browser"));
const mixpanel_service_1 = require("./mixpanel-service");
const types_1 = require("./types");
const logger_1 = require("./utils/logger");
const config = {
thoughtSpotHost: 'https://10.87.89.232',
authType: types_1.AuthType.None,
};
jest.mock('mixpanel-browser', () => ({
__esModule: true,
init: jest.fn().mockReturnThis(),
identify: jest.fn(),
track: jest.fn(),
register_once: jest.fn(),
}));
describe('Unit test for mixpanel', () => {
afterEach(() => {
jest.clearAllMocks();
});
test('initMixpanel and test upload event', () => {
const sessionInfo = {
mixpanelToken: 'abc123',
userGUID: '12345',
isPublicUser: false,
};
(0, mixpanel_service_1.initMixpanel)(sessionInfo);
expect(mixpanel.init).toHaveBeenCalledWith(sessionInfo.mixpanelToken, undefined, 'tsEmbed');
expect(mixpanel.identify).toHaveBeenCalledWith(sessionInfo.userGUID);
(0, mixpanel_service_1.uploadMixpanelEvent)(mixpanel_service_1.MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
authType: config.authType,
host: config.thoughtSpotHost,
});
expect(mixpanel.track).toHaveBeenCalled();
});
test('initMixpanel on public cluster', () => {
const sessionInfo = {
mixpanelToken: 'newToken',
isPublicUser: true,
userGUID: 'newUser',
clusterId: 'newClusterId',
clusterName: 'newClusterName',
releaseVersion: 'newReleaseVersion',
};
(0, mixpanel_service_1.initMixpanel)(sessionInfo);
expect(mixpanel.init).toHaveBeenCalledWith(sessionInfo.mixpanelToken, undefined, 'tsEmbed');
expect(mixpanel.register_once).toHaveBeenCalledWith({
clusterId: sessionInfo.clusterId,
clusterName: sessionInfo.clusterName,
releaseVersion: sessionInfo.releaseVersion,
hostAppUrl: 'localhost',
});
expect(mixpanel.identify).not.toHaveBeenCalledWith(sessionInfo.userGUID);
});
test('when not init, should queue events and flush on init', () => {
(0, mixpanel_service_1.testResetMixpanel)();
(0, mixpanel_service_1.uploadMixpanelEvent)(mixpanel_service_1.MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
authType: config.authType,
host: config.thoughtSpotHost,
});
(0, mixpanel_service_1.uploadMixpanelEvent)(mixpanel_service_1.MIXPANEL_EVENT.VISUAL_SDK_TRIGGER);
expect(mixpanel.track).not.toHaveBeenCalled();
const sessionInfo = {
mixpanelToken: 'abc123',
userGUID: '12345',
isPublicUser: false,
};
(0, mixpanel_service_1.initMixpanel)(sessionInfo);
expect(mixpanel.track).toHaveBeenCalledTimes(2);
});
test('init mixpanel with no mixpanel token', () => {
jest.spyOn(logger_1.logger, 'error').mockReturnValueOnce(true);
(0, mixpanel_service_1.initMixpanel)({ test: 'dummy' });
expect(logger_1.logger.error).toHaveBeenCalled();
expect(mixpanel.register_once).not.toHaveBeenCalled();
});
});
//# sourceMappingURL=mixpanel-service.spec.js.map
;