@aller/blink
Version:
A library for tracking user behaviour.
175 lines • 6.27 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var main_1 = __importDefault(require("../main"));
var config_1 = require("../config/config");
var get_mock_utils_1 = __importDefault(require("../mock/get-mock-utils"));
var jest_mock_1 = __importDefault(require("jest-mock"));
describe('Custom type intregration test', function () {
it('should send a single custom event', function () {
var mockSend = jest_mock_1.default.fn();
var blink = main_1.default({
send: mockSend,
sendDirect: mockSend,
persistState: function () { return null; },
utils: get_mock_utils_1.default,
});
// First send of a pageInit event, to set the general state
blink.pageInit({
url: 'http://some.site',
pageView: 'the-pageview-id',
referrer: 'www.sol.no',
userId: 'xavier_no',
site: 'www.kk.no',
});
blink.custom({
customDomain: 'fake-domain',
customType: 'fake-type',
customContent: 'fake-content',
customValue: 12,
time: new Date(3),
});
expect(mockSend.mock.calls[0][0]).toEqual([
{
id: 'fake-domainfake-type',
type: 'custom',
pageView: 'the-pageview-id',
referrer: 'www.sol.no',
site: 'www.kk.no',
time: new Date(3),
userId: 'xavier_no',
version: config_1.VERSION,
customDomain: 'fake-domain',
customType: 'fake-type',
customContent: 'fake-content',
customValue: 12,
},
]);
});
it('should send a single custom event even with time missing', function () {
var mockSend = jest_mock_1.default.fn();
var blink = main_1.default({
send: mockSend,
sendDirect: mockSend,
persistState: function () { return null; },
utils: get_mock_utils_1.default,
});
// First send of a pageInit event, to set the general state
blink.pageInit({
url: 'http://some.site',
pageView: 'the-pageview-id',
referrer: 'www.sol.no',
userId: 'xavier_no',
site: 'www.kk.no',
});
blink.custom({
customDomain: 'fake-domain',
customType: 'fake-type',
customContent: 'fake-content',
customValue: 12,
});
var expected = {
id: 'fake-domainfake-type',
type: 'custom',
pageView: 'the-pageview-id',
referrer: 'www.sol.no',
site: 'www.kk.no',
userId: 'xavier_no',
version: config_1.VERSION,
customDomain: 'fake-domain',
customType: 'fake-type',
customContent: 'fake-content',
customValue: 12,
time: new Date(1),
};
var expectedFields = Object.keys(expected).sort();
var fields = Object.keys(mockSend.mock.calls[0][0][0]).sort();
expect(fields).toEqual(expectedFields);
});
it('should send two separate events for two separate pages', function () {
var PAGES;
(function (PAGES) {
PAGES["FIRST"] = "FIRST_PAGE";
PAGES["SECOND"] = "SECOND_PAGE";
})(PAGES || (PAGES = {}));
var mockSend = jest_mock_1.default.fn();
var blink = main_1.default({
send: mockSend,
sendDirect: mockSend,
persistState: function () { return null; },
utils: get_mock_utils_1.default,
});
// FIRST PAGE INIT
blink.pageInit({
url: 'http://some.site',
pageView: PAGES.FIRST + "-pageview",
pageId: PAGES.FIRST,
referrer: 'www.sol.no',
userId: 'xavier_no',
site: 'www.kk.no',
});
// SECOND PAGE INIT
blink.pageInit({
url: 'http://other.site',
pageView: PAGES.SECOND + "-pageview",
pageId: PAGES.SECOND,
referrer: 'www.sol.no',
userId: 'xavier_no',
site: 'www.kk.no',
});
// FIRST PAGE CUSTOM EVENT
blink.custom({
customDomain: 'fake-domain',
customType: 'fake-type',
customContent: 'fake-content',
customValue: 12,
time: new Date(1000),
pageId: PAGES.FIRST,
});
// SECOND PAGE CUSTOM EVENT
blink.custom({
customDomain: 'second-domain',
customType: 'second-type',
customContent: 'second-content',
customValue: 42,
time: new Date(2000),
pageId: PAGES.SECOND,
});
expect(mockSend.mock.calls.length).toBe(2);
// Check first event
var firstEvent = mockSend.mock.calls[0][0][0];
expect(firstEvent).toEqual({
customContent: 'fake-content',
customDomain: 'fake-domain',
customType: 'fake-type',
customValue: 12,
userId: 'xavier_no',
pageView: 'FIRST_PAGE-pageview',
referrer: 'www.sol.no',
site: 'www.kk.no',
type: 'custom',
version: config_1.VERSION,
time: new Date(1000),
id: 'fake-domainfake-type',
});
// Check second event
var secondEvent = mockSend.mock.calls[1][0][0];
expect(secondEvent).toEqual({
customContent: 'second-content',
customDomain: 'second-domain',
customType: 'second-type',
customValue: 42,
userId: 'xavier_no',
id: 'second-domainsecond-type',
pageView: 'SECOND_PAGE-pageview',
referrer: 'www.sol.no',
site: 'www.kk.no',
time: new Date(2000),
type: 'custom',
version: config_1.VERSION,
});
});
});
//# sourceMappingURL=custom.test.js.map