Skip to content

Commit b307e5e

Browse files
committed
added identify tests
1 parent b75154b commit b307e5e

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/amplitude.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ describe('Amplitude', function() {
55
var cookie = require('../src/cookie.js');
66
var querystring = require('querystring');
77
var JSON = require('json');
8+
var Identify = require('../src/identify.js');
89
var apiKey = '000000';
910
var userId = 'user';
1011
var amplitude;
@@ -123,6 +124,64 @@ describe('Amplitude', function() {
123124
});
124125
});
125126

127+
describe('identify', function() {
128+
129+
beforeEach(function() {
130+
clock = sinon.useFakeTimers();
131+
amplitude.init(apiKey);
132+
});
133+
134+
afterEach(function() {
135+
reset();
136+
clock.restore();
137+
});
138+
139+
it('should ignore inputs that are not identify objects', function() {
140+
amplitude.identify('This is a test');
141+
assert.lengthOf(amplitude._unsentEvents, 0);
142+
assert.lengthOf(server.requests, 0);
143+
144+
amplitude.identify(150);
145+
assert.lengthOf(amplitude._unsentEvents, 0);
146+
assert.lengthOf(server.requests, 0);
147+
148+
amplitude.identify(['test']);
149+
assert.lengthOf(amplitude._unsentEvents, 0);
150+
assert.lengthOf(server.requests, 0);
151+
152+
amplitude.identify({'user_prop': true});
153+
assert.lengthOf(amplitude._unsentEvents, 0);
154+
assert.lengthOf(server.requests, 0);
155+
});
156+
157+
it('should generate an event from the identify object', function() {
158+
var identify = new Identify().set('prop1', 'value1').unset('prop2').add('prop3', 3).setOnce('prop4', true);
159+
amplitude.identify(identify);
160+
161+
assert.lengthOf(amplitude._unsentEvents, 1);
162+
assert.lengthOf(server.requests, 1);
163+
var events = JSON.parse(querystring.parse(server.requests[0].requestBody).e);
164+
assert.lengthOf(events, 1);
165+
assert.equal(events[0].event_type, '$identify');
166+
assert.deepEqual(events[0].event_properties, {});
167+
assert.deepEqual(events[0].user_properties, {
168+
'$set': {
169+
'prop1': 'value1'
170+
},
171+
'$unset': {
172+
'prop2': '-'
173+
},
174+
'$add': {
175+
'prop3': 3
176+
},
177+
'$setOnce': {
178+
'prop4': true
179+
}
180+
});
181+
});
182+
183+
});
184+
126185
describe('logEvent', function() {
127186

128187
var clock;

0 commit comments

Comments
 (0)