-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
170 lines (145 loc) · 4.59 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
var Analytics = require('analytics.js').constructor;
var integration = require('analytics.js-integration');
var tester = require('analytics.js-integration-tester');
var plugin = require('./');
var sandbox = require('clear-env');
describe('Customer.io', function(){
var Customerio = plugin;
var customerio;
var analytics;
var options = {
siteId: '1e5932b3d9de5078ccf9'
};
beforeEach(function(){
analytics = new Analytics;
customerio = new Customerio(options);
analytics.use(plugin);
analytics.use(tester);
analytics.add(customerio);
});
afterEach(function(){
analytics.restore();
analytics.reset();
customerio.reset();
sandbox();
});
it('should have the right settings', function(){
analytics.compare(Customerio, integration('Customer.io')
.global('_cio')
.option('siteId', ''));
});
describe('before loading', function(){
beforeEach(function(){
analytics.stub(customerio, 'load');
});
describe('#initialize', function(){
it('should create the window._cio object', function(){
analytics.assert(!window._cio);
analytics.initialize();
analytics.assert(window._cio);
});
it('should call #load', function(){
analytics.initialize();
analytics.called(customerio.load);
});
});
});
describe('loading', function(){
it('should load', function(done){
analytics.load(customerio, done);
});
});
describe('after loading', function(){
beforeEach(function(done){
analytics.once('ready', done);
analytics.initialize();
});
describe('#identify', function(){
beforeEach(function(){
analytics.stub(window._cio, 'identify');
});
it('should send an id', function(){
analytics.identify('id');
analytics.called(window._cio.identify, { id: 'id' });
});
it('should not send only traits', function(){
analytics.identify({ trait: true });
analytics.didNotCall(window._cio.identify);
});
it('should send an id and traits', function(){
analytics.identify('id', { trait: true, email: '[email protected]' });
analytics.called(window._cio.identify, { id: 'id', trait: true, email: '[email protected]' });
});
it('should convert dates to unix timestamps', function(){
var date = new Date();
analytics.identify('id', { date: date });
analytics.called(window._cio.identify, {
id: 'id',
date: Math.floor(date/1000)
});
});
it('should alias created to created_at', function(){
var date = new Date();
analytics.identify('id', { created: date });
analytics.called(window._cio.identify, {
id: 'id',
created_at: Math.floor(date/1000)
});
});
});
describe('#group', function(){
beforeEach(function(){
analytics.user().identify('id');
analytics.stub(window._cio, 'identify');
});
it('should send an id', function(){
analytics.group('id');
analytics.called(window._cio.identify, {
id: 'id',
'Group id': 'id'
});
});
it('should send traits', function(){
analytics.group({ trait: true });
analytics.called(window._cio.identify, {
id: 'id',
'Group trait': true
});
});
it('should send an id and traits', function(){
analytics.group('id', { trait: true });
analytics.called(window._cio.identify, {
id: 'id',
'Group id': 'id',
'Group trait': true
});
});
it('should convert dates to unix timestamps', function(){
var date = new Date();
analytics.group({ date: date });
analytics.called(window._cio.identify, {
id: 'id',
'Group date': Math.floor(date/1000)
});
});
});
describe('#track', function(){
beforeEach(function(){
analytics.stub(window._cio, 'track');
});
it('should send an event', function(){
analytics.track('event');
analytics.called(window._cio.track, 'event');
});
it('should send an event and properties', function(){
analytics.track('event', { property: true });
analytics.called(window._cio.track, 'event', { property: true });
});
it('should convert dates to unix timestamps', function(){
var date = new Date();
analytics.track('event', { date: date });
analytics.called(window._cio.track, 'event', { date: Math.floor(date/1000) });
});
});
});
});