-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
test_amplitude-js_v4.x.x.js
224 lines (172 loc) · 5.09 KB
/
test_amplitude-js_v4.x.x.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// @flow
/* eslint-disable no-unused-vars, no-undef, no-console */
import amplitude, { Identify, Revenue } from 'amplitude-js';
import type { AmplitudeClient } from 'amplitude-js';
/**
* Common instances
*/
const client = amplitude.getInstance();
const identify = new Identify();
const revenue = new Revenue();
const callback = (responseCode: number, responseBody: string) => void 0;
/**
* ALL THE TESTS START FROM HERE
*/
function getInstanceTest() {
(amplitude.getInstance(): AmplitudeClient);
(amplitude.getInstance('name'): AmplitudeClient);
// $ExpectError: getInstance only accepts strings
amplitude.getInstance(5);
// $ExpectError: getInstance only accepts strings
amplitude.getInstance(new Date());
}
function identifyTests() {
//* constructor
(new Identify(): Identify);
const i: Identify = new Identify();
//* add
i.add('foo', 1);
i.add('bar', -10);
// $ExpectError: add requies a name as first parameter
i.add(15, 21);
// $ExpectError: add requies a number as second parameter
i.add('foo', 'bar');
//* append
i.append('foo', 1);
i.append('foo', [1]);
i.append('foo', 'bar');
i.append('foo', ['bar']);
i.append('foo', [1, 'bar']);
//* prepend
i.prepend('foo', 1);
i.prepend('foo', [1]);
i.prepend('foo', 'bar');
i.prepend('foo', ['bar']);
i.prepend('foo', [1, 'bar']);
//* set
i.set('foo', 1);
i.set('foo', [1]);
i.set('foo', 'bar');
i.set('foo', ['bar']);
i.set('foo', [1, 'bar']);
i.set('foo', {});
i.set('foo', { foo: 1 });
i.set('foo', { foo: [1] });
i.set('foo', { foo: 'foo' });
i.set('foo', { foo: ['foo'] });
i.set('foo', { foo: [1, 'foo'] });
//* setOnce
i.setOnce('foo', 1);
i.setOnce('foo', [1]);
i.setOnce('foo', 'bar');
i.setOnce('foo', ['bar']);
i.setOnce('foo', [1, 'bar']);
i.setOnce('foo', {});
i.setOnce('foo', { foo: 1 });
i.setOnce('foo', { foo: [1] });
i.setOnce('foo', { foo: 'foo' });
i.setOnce('foo', { foo: ['foo'] });
i.setOnce('foo', { foo: [1, 'foo'] });
//* unset
i.unset('foo');
}
function revenueTests() {
//* constructor
(new Revenue(): Revenue);
const r: Revenue = new Revenue();
//* setProductId
r.setProductId('pid');
// $ExpectError: setProductId only accepts strings
r.setProductId(5);
// $ExpectError: setProductId only accepts strings
r.setProductId();
//* setQuantity
r.setQuantity(5);
r.setQuantity();
// $ExpectError: setProductId only accepts numbers
r.setQuantity('foo');
//* setPrice
r.setPrice(15);
// $ExpectError: setPrice only accepts numbers
r.setPrice();
// $ExpectError: setPrice only accepts numbers
r.setPrice('foo');
//* setRevenueType
r.setRevenueType('cost');
// $ExpectError: setRevenueType only accepts strings
r.setRevenueType(5);
// $ExpectError: setRevenueType only accepts strings
r.setRevenueType();
//* setEventProperties
// $ExpectError: setEventProperties requires arguments
r.setEventProperties();
r.setEventProperties({});
r.setEventProperties({ foo: 1 });
r.setEventProperties({ foo: [1] });
r.setEventProperties({ foo: 'foo' });
r.setEventProperties({ foo: ['foo'] });
r.setEventProperties({ foo: [1, 'foo'] });
}
function amplitudeClientTests() {
const client: AmplitudeClient = amplitude.getInstance();
//* Identify
(client.Identify: typeof Identify);
//* Revenue
(client.Revenue: typeof Revenue);
//* init
client.init('key');
client.init('key', 'uid');
client.init('key', null, { batchEvents: false });
client.init('key', 'uid', null, function(c: AmplitudeClient) {});
//* isNewSession
(client.isNewSession(): boolean);
//* getSessionId
(client.getSessionId(): number);
//* setDomain
client.setDomain('foo');
//* setUserId
client.setUserId('uid');
client.setUserId(null);
//* setGroup
client.setGroup('orgId', '15');
client.setGroup('sport', ['soccer', 'tennis']);
//* setOptOut
client.setOptOut(true);
client.setOptOut(false);
//* regenerateDeviceId
client.regenerateDeviceId();
//* setDeviceId
client.setDeviceId('uid');
//* setUserProperties
// $ExpectError: setUserProperties requires arguments
r.setUserProperties();
r.setUserProperties({});
r.setUserProperties({ foo: 1 });
r.setUserProperties({ foo: [1] });
r.setUserProperties({ foo: 'foo' });
r.setUserProperties({ foo: ['foo'] });
r.setUserProperties({ foo: [1, 'foo'] });
//* clearUserProperties
r.clearUserProperties();
//* identify
r.identify(identify);
r.identify(identify, callback);
//* setVersionName
r.setVersionName('vname');
//* logEvent
r.logEvent('event');
r.logEvent('event', { foo: 1 });
r.logEvent('event', null, callback);
//* logEventWithTimestamp
r.logEventWithTimestamp('event');
r.logEventWithTimestamp('event', { foo: 1 });
r.logEventWithTimestamp('event', null, Date.now());
r.logEventWithTimestamp('event', null, null, callback);
//* logEventWithGroups
r.logEventWithGroups('event');
r.logEventWithGroups('event', { foo: 1 });
r.logEventWithGroups('event', null, { orgId: 'some-org-id' });
r.logEventWithGroups('event', null, null, callback);
//* logRevenueV2
r.logRevenueV2(revenue);
}