|
| 1 | +import Ninetailed from '../../../src/integrations/Ninetailed/browser'; |
| 2 | + |
| 3 | +const destinationInfo = { |
| 4 | + areTransformationsConnected: false, |
| 5 | + destinationId: 'sample-destination-id', |
| 6 | +}; |
| 7 | + |
| 8 | +describe('Ninetailed Intialization', () => { |
| 9 | + let nt; |
| 10 | + beforeEach(() => { |
| 11 | + nt = new Ninetailed({}, { loglevel: 'DEBUG' }, destinationInfo); |
| 12 | + }); |
| 13 | + afterEach(() => { |
| 14 | + jest.restoreAllMocks(); |
| 15 | + window.ninetailed = undefined; |
| 16 | + }); |
| 17 | + describe(' Is Loaded test Cases', () => { |
| 18 | + // when ninetailed is not loaded from webapp |
| 19 | + test('isLoaded should return False', () => { |
| 20 | + expect(nt.isLoaded()).toBe(false); |
| 21 | + }); |
| 22 | + // when ninetailed is loaded from webapp |
| 23 | + test('isLoaded should return True', () => { |
| 24 | + // since init call does not have any body so we are intialising the ninetailed object |
| 25 | + window.ninetailed = {}; |
| 26 | + expect(nt.isLoaded()).toBeTruthy(); |
| 27 | + }); |
| 28 | + }); |
| 29 | + describe(' Is Ready test Cases', () => { |
| 30 | + // when ninetailed is not loaded from webapp |
| 31 | + test('isReady should return False', () => { |
| 32 | + expect(nt.isReady()).toBe(false); |
| 33 | + }); |
| 34 | + // when ninetailed is loaded from webapp |
| 35 | + test('isReady should return True', () => { |
| 36 | + // since init call does not have any body so we are intialising the ninetailed object |
| 37 | + window.ninetailed = {}; |
| 38 | + expect(nt.isReady()).toBeTruthy(); |
| 39 | + }); |
| 40 | + }); |
| 41 | +}); |
| 42 | +describe('Ninetailed Event APIs', () => { |
| 43 | + beforeEach(() => { |
| 44 | + window.ninetailed = {}; |
| 45 | + }); |
| 46 | + describe('Page', () => { |
| 47 | + let nt; |
| 48 | + beforeEach(() => { |
| 49 | + nt = new Ninetailed({}, { loglevel: 'DEBUG' }, destinationInfo); |
| 50 | + window.ninetailed.page = jest.fn(); |
| 51 | + }); |
| 52 | + afterAll(() => { |
| 53 | + jest.restoreAllMocks(); |
| 54 | + }); |
| 55 | + test('send pageview with properties', () => { |
| 56 | + const properties = { |
| 57 | + category: 'test cat', |
| 58 | + path: '/test', |
| 59 | + url: 'http://localhost:8080', |
| 60 | + referrer: '', |
| 61 | + title: 'test page', |
| 62 | + testDimension: 'abc', |
| 63 | + isRudderEvents: true, |
| 64 | + }; |
| 65 | + |
| 66 | + nt.page({ |
| 67 | + message: { |
| 68 | + context: {}, |
| 69 | + properties, |
| 70 | + }, |
| 71 | + }); |
| 72 | + expect(window.ninetailed.page.mock.calls[0][0]).toEqual(properties); |
| 73 | + }); |
| 74 | + test('send pageview without properties', () => { |
| 75 | + nt.page({ |
| 76 | + message: { |
| 77 | + context: {}, |
| 78 | + }, |
| 79 | + }); |
| 80 | + expect(window.ninetailed.page.mock.calls[0][0]).toEqual(undefined); |
| 81 | + }); |
| 82 | + }); |
| 83 | + describe('Track', () => { |
| 84 | + let nt; |
| 85 | + beforeEach(() => { |
| 86 | + nt = new Ninetailed({}, { loglevel: 'DEBUG' }, destinationInfo); |
| 87 | + window.ninetailed.track = jest.fn(); |
| 88 | + }); |
| 89 | + afterAll(() => { |
| 90 | + jest.restoreAllMocks(); |
| 91 | + }); |
| 92 | + test('Testing Track Event with event', () => { |
| 93 | + const properties = { |
| 94 | + customProp: 'testProp', |
| 95 | + checkout_id: 'what is checkout id here??', |
| 96 | + event_id: 'purchaseId', |
| 97 | + order_id: 'transactionId', |
| 98 | + value: 35.0, |
| 99 | + shipping: 4.0, |
| 100 | + isRudderEvents: true, |
| 101 | + }; |
| 102 | + nt.track({ |
| 103 | + message: { |
| 104 | + context: {}, |
| 105 | + event: 'Custom', |
| 106 | + properties, |
| 107 | + }, |
| 108 | + }); |
| 109 | + expect(window.ninetailed.track.mock.calls[0][0]).toEqual('Custom'); |
| 110 | + expect(window.ninetailed.track.mock.calls[0][1]).toEqual(properties); |
| 111 | + }); |
| 112 | + test('Testing Track Event without event', () => { |
| 113 | + nt.track({ |
| 114 | + message: { |
| 115 | + context: {}, |
| 116 | + properties: {}, |
| 117 | + }, |
| 118 | + }); |
| 119 | + expect(window.ninetailed.track).not.toHaveBeenCalledWith(); |
| 120 | + }); |
| 121 | + }); |
| 122 | + describe('Identify', () => { |
| 123 | + let nt; |
| 124 | + beforeEach(() => { |
| 125 | + nt = new Ninetailed({}, { loglevel: 'DEBUG' }, destinationInfo); |
| 126 | + window.ninetailed.identify = jest.fn(); |
| 127 | + }); |
| 128 | + afterAll(() => { |
| 129 | + jest.restoreAllMocks(); |
| 130 | + }); |
| 131 | + test('Testing Identify Custom Events', () => { |
| 132 | + const traits = { |
| 133 | + |
| 134 | + isRudderEvents: true, |
| 135 | + }; |
| 136 | + nt.identify({ |
| 137 | + message: { |
| 138 | + userId: 'rudder01', |
| 139 | + context: { |
| 140 | + traits, |
| 141 | + }, |
| 142 | + }, |
| 143 | + }); |
| 144 | + expect(window.ninetailed.identify.mock.calls[0][0]).toEqual('rudder01'); |
| 145 | + expect(window.ninetailed.identify.mock.calls[0][1]).toEqual(traits); |
| 146 | + }); |
| 147 | + }); |
| 148 | +}); |
0 commit comments