@aller/blink
Version:
A library for tracking user behaviour.
95 lines (90 loc) • 2.43 kB
text/typescript
import prepareCustomEvent from '../prepare-custom-event';
import { VERSION } from '../../config/config';
import { BlinkEvent } from '../../types';
import { Page } from '../../selectors/get-page-state';
describe('prepareCustomEvent', () => {
it('should format properly based on state', () => {
const customDomain = 'fake-domain';
const customType = 'fake-type';
const customContent = 'content';
const customValue = 12;
const time = new Date(2);
const page: Page = {
id: 'default',
state: {
general: {
pageView: 'some-pageview-uuid',
site: 'www.dagbladet.no',
referrer: 'www.dinside.no',
userId: 'user5',
},
},
};
const expected: BlinkEvent = {
type: 'custom',
pageView: 'some-pageview-uuid',
site: 'www.dagbladet.no',
referrer: 'www.dinside.no',
userId: 'user5',
version: VERSION,
id: 'fake-domainfake-type',
customDomain: 'fake-domain',
customType: 'fake-type',
customContent: 'content',
customValue: 12,
time: new Date(2),
};
expect(
prepareCustomEvent({
page,
customDomain,
customType,
customContent,
customValue,
time,
}),
).toEqual(expected);
});
it('should work without time', () => {
const customDomain = 'fake-domain';
const customType = 'fake-type';
const customContent = 'content';
const customValue = 12;
const page: Page = {
id: 'default',
state: {
general: {
pageView: 'some-pageview-uuid',
site: 'www.dagbladet.no',
referrer: 'www.dinside.no',
userId: 'user5',
},
},
};
const expected: BlinkEvent = {
type: 'custom',
pageView: 'some-pageview-uuid',
site: 'www.dagbladet.no',
referrer: 'www.dinside.no',
userId: 'user5',
version: VERSION,
id: 'fake-domainfake-type',
customDomain: 'fake-domain',
customType: 'fake-type',
customContent: 'content',
customValue: 12,
time: new Date(1),
};
const expectedFields = Object.keys(expected).sort();
const fields = Object.keys(
prepareCustomEvent({
page,
customDomain,
customType,
customContent,
customValue,
}),
).sort();
expect(fields).toEqual(expectedFields);
});
});