Comparing version 0.3.2 to 0.4.0
@@ -27,2 +27,11 @@ // grab the Mixpanel factory | ||
// create or update a user in Mixpanel Engage without altering $last_seen | ||
// - pass option `$ignore_time: true` to prevent the $last_seen property from being updated | ||
mixpanel.people.set("billybob", { | ||
plan: "premium", | ||
games_played: 1 | ||
}, { | ||
$ignore_time: true | ||
}); | ||
// set a single property on a user | ||
@@ -29,0 +38,0 @@ mixpanel.people.set("billybob", "plan", "free"); |
@@ -0,4 +1,9 @@ | ||
0.4.0 / 2016-02-09 | ||
=================== | ||
* allow optional `modifiers` in all `people` calls for `$ignore_time`, `$ip`, | ||
and `$time` fields | ||
0.3.2 / 2015-12-10 | ||
=================== | ||
* correct `distinct_id` field in `people.delete_user` request (thanks godspeedelbow) | ||
* correct `$delete` field in `people.delete_user` request (thanks godspeedelbow) | ||
@@ -5,0 +10,0 @@ 0.3.1 / 2015-08-06 |
@@ -78,3 +78,3 @@ /* | ||
var e; | ||
if(metrics.config.verbose) { | ||
if (metrics.config.verbose) { | ||
try { | ||
@@ -97,3 +97,3 @@ var result = JSON.parse(data); | ||
}).on('error', function(e) { | ||
if(metrics.config.debug) { | ||
if (metrics.config.debug) { | ||
console.log("Got Error: " + e.message); | ||
@@ -302,3 +302,3 @@ } | ||
metrics.people = { | ||
/** people.set_once(distinct_id, prop, to, callback) | ||
/** people.set_once(distinct_id, prop, to, modifiers, callback) | ||
--- | ||
@@ -315,17 +315,28 @@ The same as people.set but in the words of mixpanel: | ||
*/ | ||
set_once: function(distinct_id, prop, to, callback) { | ||
var $set = {}, data = {}; | ||
set_once: function(distinct_id, prop, to, modifiers, callback) { | ||
var $set = {}; | ||
if (typeof(prop) === 'object') { | ||
callback = to; | ||
if (typeof(to) === 'object') { | ||
callback = modifiers; | ||
modifiers = to; | ||
} else { | ||
callback = to; | ||
} | ||
$set = prop; | ||
} else { | ||
$set[prop] = to; | ||
if (typeof(modifiers) === 'function' || !modifiers) { | ||
callback = modifiers; | ||
} | ||
} | ||
this._set(distinct_id, $set, callback, { set_once: true }); | ||
modifiers = modifiers || {}; | ||
modifiers.set_once = true; | ||
this._set(distinct_id, $set, callback, modifiers); | ||
}, | ||
/** | ||
people.set(distinct_id, prop, to, callback) | ||
people.set(distinct_id, prop, to, modifiers, callback) | ||
--- | ||
@@ -343,13 +354,21 @@ set properties on an user record in engage | ||
*/ | ||
set: function(distinct_id, prop, to, callback) { | ||
var $set = {}, data = {}; | ||
set: function(distinct_id, prop, to, modifiers, callback) { | ||
var $set = {}; | ||
if (typeof(prop) === 'object') { | ||
callback = to; | ||
if (typeof(to) === 'object') { | ||
callback = modifiers; | ||
modifiers = to; | ||
} else { | ||
callback = to; | ||
} | ||
$set = prop; | ||
} else { | ||
$set[prop] = to; | ||
if (typeof(modifiers) === 'function' || !modifiers) { | ||
callback = modifiers; | ||
} | ||
} | ||
this._set(distinct_id, $set, callback); | ||
this._set(distinct_id, $set, callback, modifiers); | ||
}, | ||
@@ -359,2 +378,3 @@ | ||
_set: function(distinct_id, $set, callback, options) { | ||
options = options || {}; | ||
var set_key = (options && options.set_once) ? "$set_once" : "$set"; | ||
@@ -378,3 +398,5 @@ | ||
if(metrics.config.debug) { | ||
data = merge_modifiers(data, options); | ||
if (metrics.config.debug) { | ||
console.log("Sending the following data to Mixpanel (Engage):"); | ||
@@ -388,3 +410,3 @@ console.log(data); | ||
/** | ||
people.increment(distinct_id, prop, to, callback) | ||
people.increment(distinct_id, prop, by, modifiers, callback) | ||
--- | ||
@@ -411,7 +433,12 @@ increment/decrement properties on an user record in engage | ||
*/ | ||
increment: function(distinct_id, prop, by, callback) { | ||
increment: function(distinct_id, prop, by, modifiers, callback) { | ||
var $add = {}; | ||
if (typeof(prop) === 'object') { | ||
callback = by; | ||
if (typeof(by) === 'object') { | ||
callback = modifiers; | ||
modifiers = by; | ||
} else { | ||
callback = by; | ||
} | ||
Object.keys(prop).forEach(function(key) { | ||
@@ -431,4 +458,16 @@ var val = prop[key]; | ||
} else { | ||
if (!by) { by = 1; } | ||
$add[prop] = by; | ||
if (typeof(by) === 'number' || !by) { | ||
by = by || 1; | ||
$add[prop] = by; | ||
if (typeof(modifiers) === 'function') { | ||
callback = modifiers; | ||
} | ||
} else if (typeof(by) === 'function') { | ||
callback = by; | ||
$add[prop] = 1; | ||
} else { | ||
callback = modifiers; | ||
modifiers = (typeof(by) === 'object') ? by : {}; | ||
$add[prop] = 1; | ||
} | ||
} | ||
@@ -442,3 +481,5 @@ | ||
if(metrics.config.debug) { | ||
data = merge_modifiers(data, modifiers); | ||
if (metrics.config.debug) { | ||
console.log("Sending the following data to Mixpanel (Engage):"); | ||
@@ -452,3 +493,3 @@ console.log(data); | ||
/** | ||
people.append(distinct_id, prop, value, callback) | ||
people.append(distinct_id, prop, value, modifiers, callback) | ||
--- | ||
@@ -468,7 +509,12 @@ Append a value to a list-valued people analytics property. | ||
*/ | ||
append: function(distinct_id, prop, value, callback) { | ||
append: function(distinct_id, prop, value, modifiers, callback) { | ||
var $append = {}; | ||
if (typeof(prop) === 'object') { | ||
callback = value; | ||
if (typeof(value) === 'object') { | ||
callback = modifiers; | ||
modifiers = value; | ||
} else { | ||
callback = value; | ||
} | ||
Object.keys(prop).forEach(function(key) { | ||
@@ -479,2 +525,5 @@ $append[key] = prop[key]; | ||
$append[prop] = value; | ||
if (typeof(modifiers) === 'function') { | ||
callback = modifiers; | ||
} | ||
} | ||
@@ -488,3 +537,5 @@ | ||
if(metrics.config.debug) { | ||
data = merge_modifiers(data, modifiers); | ||
if (metrics.config.debug) { | ||
console.log("Sending the following data to Mixpanel (Engage):"); | ||
@@ -498,3 +549,3 @@ console.log(data); | ||
/** | ||
people.track_charge(distinct_id, amount, properties, callback) | ||
people.track_charge(distinct_id, amount, properties, modifiers, callback) | ||
--- | ||
@@ -512,8 +563,17 @@ Record that you have charged the current user a certain | ||
*/ | ||
track_charge: function(distinct_id, amount, properties, callback) { | ||
var $append = {}; | ||
track_charge: function(distinct_id, amount, properties, modifiers, callback) { | ||
if (typeof(properties) === 'function' || !properties) { | ||
callback = properties; | ||
callback = properties || function() {}; | ||
properties = {}; | ||
} else { | ||
if (typeof(modifiers) === 'function' || !modifiers) { | ||
callback = modifiers || function() {}; | ||
if (properties.$ignore_time || properties.hasOwnProperty("$ip")) { | ||
modifiers = {}; | ||
Object.keys(properties).forEach(function(key) { | ||
modifiers[key] = properties[key]; | ||
delete properties[key]; | ||
}); | ||
} | ||
} | ||
} | ||
@@ -544,3 +604,5 @@ | ||
if(metrics.config.debug) { | ||
data = merge_modifiers(data, modifiers); | ||
if (metrics.config.debug) { | ||
console.log("Sending the following data to Mixpanel (Engage):"); | ||
@@ -554,3 +616,3 @@ console.log(data); | ||
/** | ||
people.clear_charges(distinct_id, callback) | ||
people.clear_charges(distinct_id, modifiers, callback) | ||
--- | ||
@@ -563,3 +625,3 @@ Clear all the current user's transactions. | ||
*/ | ||
clear_charges: function(distinct_id, callback) { | ||
clear_charges: function(distinct_id, modifiers, callback) { | ||
var data = { | ||
@@ -571,3 +633,7 @@ '$set': { '$transactions': [] }, | ||
if(metrics.config.debug) { | ||
if (typeof(modifiers) === 'function') { callback = modifiers; } | ||
data = merge_modifiers(data, modifiers); | ||
if (metrics.config.debug) { | ||
console.log("Clearing this user's charges:", distinct_id); | ||
@@ -580,3 +646,3 @@ } | ||
/** | ||
people.delete_user(distinct_id, callback) | ||
people.delete_user(distinct_id, modifiers, callback) | ||
--- | ||
@@ -589,3 +655,3 @@ delete an user record in engage | ||
*/ | ||
delete_user: function(distinct_id, callback) { | ||
delete_user: function(distinct_id, modifiers, callback) { | ||
var data = { | ||
@@ -597,3 +663,7 @@ '$delete': '', | ||
if(metrics.config.debug) { | ||
if (typeof(modifiers) === 'function') { callback = modifiers; } | ||
data = merge_modifiers(data, modifiers); | ||
if (metrics.config.debug) { | ||
console.log("Deleting the user from engage:", distinct_id); | ||
@@ -606,3 +676,3 @@ } | ||
/** | ||
people.union(distinct_id, data, callback) | ||
people.union(distinct_id, data, modifiers, callback) | ||
--- | ||
@@ -617,3 +687,3 @@ merge value(s) into a list-valued people analytics property. | ||
*/ | ||
union: function(distinct_id, data, callback) { | ||
union: function(distinct_id, data, modifiers, callback) { | ||
var $union = {}; | ||
@@ -658,2 +728,8 @@ | ||
if (typeof(modifiers) === 'function') { | ||
callback = modifiers; | ||
} | ||
data = merge_modifiers(data, modifiers); | ||
if (metrics.config.debug) { | ||
@@ -668,3 +744,3 @@ console.log("Sending the following data to Mixpanel (Engage):"); | ||
/** | ||
people.unset(distinct_id, prop, callback) | ||
people.unset(distinct_id, prop, modifiers, callback) | ||
--- | ||
@@ -679,3 +755,3 @@ delete a property on an user record in engage | ||
*/ | ||
unset: function(distinct_id, prop, callback) { | ||
unset: function(distinct_id, prop, modifiers, callback) { | ||
var $unset = []; | ||
@@ -695,3 +771,3 @@ | ||
data = { | ||
var data = { | ||
'$unset': $unset, | ||
@@ -702,3 +778,9 @@ '$token': metrics.token, | ||
if(metrics.config.debug) { | ||
if (typeof(modifiers) === 'function') { | ||
callback = modifiers; | ||
} | ||
data = merge_modifiers(data, modifiers); | ||
if (metrics.config.debug) { | ||
console.log("Sending the following data to Mixpanel (Engage):"); | ||
@@ -712,2 +794,17 @@ console.log(data); | ||
var merge_modifiers = function(data, modifiers) { | ||
if (modifiers) { | ||
if (modifiers.$ignore_time) { | ||
data.$ignore_time = modifiers.$ignore_time; | ||
} | ||
if (modifiers.hasOwnProperty("$ip")) { | ||
data.$ip = modifiers.$ip; | ||
} | ||
if (modifiers.hasOwnProperty("$time")) { | ||
data.$time = parse_time(modifiers.$time); | ||
} | ||
} | ||
return data; | ||
}; | ||
/** | ||
@@ -714,0 +811,0 @@ set_config(config) |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/mixpanel/mixpanel-node", | ||
@@ -13,0 +13,0 @@ "author": "Carl Sverre", |
@@ -46,3 +46,4 @@ Mixpanel-node | ||
plan: "premium", | ||
games_played: 1, | ||
games_played: 1 | ||
}, { | ||
$ignore_time: true | ||
@@ -49,0 +50,0 @@ }); |
var Mixpanel = require('../lib/mixpanel-node'), | ||
Sinon = require('sinon'); | ||
// shared test case | ||
var test_send_request_args = function(test, func, options) { | ||
var expected_data = { | ||
$token: this.token, | ||
$distinct_id: this.distinct_id, | ||
}; | ||
for (var k in options.expected) { | ||
expected_data[k] = options.expected[k]; | ||
} | ||
var args = [this.distinct_id].concat(options.args || []); | ||
if (options.use_modifiers) { | ||
var modifiers = {'$ignore_time': true, '$ip': '1.2.3.4', '$time': 1234567890}; | ||
for (k in modifiers) { | ||
expected_data[k] = modifiers[k]; | ||
} | ||
args.push(modifiers); | ||
} | ||
if (options.use_callback) { | ||
var callback = function() {}; | ||
args.push(callback); | ||
} | ||
this.mixpanel.people[func].apply(this.mixpanel.people, args); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people." + func + " didn't call send_request with correct arguments" | ||
); | ||
if (options.use_callback) { | ||
test.ok( | ||
this.mixpanel.send_request.args[0][2] === callback, | ||
"people.set didn't call send_request with a callback" | ||
); | ||
} | ||
test.done(); | ||
}; | ||
exports.people = { | ||
@@ -14,2 +52,4 @@ setUp: function(next) { | ||
this.test_send_request_args = test_send_request_args; | ||
next(); | ||
@@ -26,116 +66,148 @@ }, | ||
"handles set_once correctly": function(test){ | ||
var expected_data = { | ||
$set_once: { key1: 'val1' }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.mixpanel.people.set_once(this.distinct_id, 'key1', 'val1'); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.set_once calls send request with correct arguments" | ||
); | ||
test.done(); | ||
this.test_send_request_args(test, 'set_once', { | ||
args: ['key1', 'val1'], | ||
expected: {$set_once: {'key1': 'val1'}}, | ||
}); | ||
}, | ||
"calls send_request with correct endpoint and data": function(test) { | ||
var expected_data = { | ||
$set: { key1: 'val1' }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.test_send_request_args(test, 'set', { | ||
args: ['key1', 'val1'], | ||
expected: {$set: {'key1': 'val1'}}, | ||
}); | ||
}, | ||
this.mixpanel.people.set(this.distinct_id, 'key1', 'val1'); | ||
"supports being called with a property object": function(test) { | ||
this.test_send_request_args(test, 'set', { | ||
args: [{'key1': 'val1', 'key2': 'val2'}], | ||
expected: {$set: {'key1': 'val1', 'key2': 'val2'}}, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.set didn't call send_request with correct arguments" | ||
); | ||
"supports being called with a property object (set_once)": function(test) { | ||
this.test_send_request_args(test, 'set_once', { | ||
args: [{'key1': 'val1', 'key2': 'val2'}], | ||
expected: {$set_once: {'key1': 'val1', 'key2': 'val2'}}, | ||
}); | ||
}, | ||
test.done(); | ||
"supports being called with a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'set', { | ||
args: ['key1', 'val1'], | ||
expected: {$set: {'key1': 'val1'}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
"supports being called with a property object": function(test) { | ||
var prop = { key1: 'val1', key2: 'val2' }, | ||
expected_data = { | ||
$set: prop, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
"supports being called with a modifiers argument (set_once)": function(test) { | ||
this.test_send_request_args(test, 'set_once', { | ||
args: ['key1', 'val1'], | ||
expected: {$set_once: {'key1': 'val1'}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
this.mixpanel.people.set(this.distinct_id, prop); | ||
"supports being called with a properties object and a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'set', { | ||
args: [{'key1': 'val1', 'key2': 'val2'}], | ||
expected: {$set: {'key1': 'val1', 'key2': 'val2'}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.set didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
"supports being called with a properties object and a modifiers argument (set_once)": function(test) { | ||
this.test_send_request_args(test, 'set_once', { | ||
args: [{'key1': 'val1', 'key2': 'val2'}], | ||
expected: {$set_once: {'key1': 'val1', 'key2': 'val2'}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
"handles the ip property in a property object properly": function(test) { | ||
var prop = { ip: '1.2.3.4', key1: 'val1', key2: 'val2' }, | ||
expected_data = { | ||
$set: { key1: 'val1', key2: 'val2' }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id, | ||
$ip: '1.2.3.4' | ||
}; | ||
this.mixpanel.people.set(this.distinct_id, prop); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.set didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
this.test_send_request_args(test, 'set', { | ||
args: [{'ip': '1.2.3.4', 'key1': 'val1', 'key2': 'val2'}], | ||
expected: { | ||
$ip: '1.2.3.4', | ||
$set: {'key1': 'val1', 'key2': 'val2'}, | ||
}, | ||
}); | ||
}, | ||
"handles the $ignore_time property in a property object properly": function(test) { | ||
var prop = { $ignore_time: true, key1: 'val1', key2: 'val2' }, | ||
expected_data = { | ||
$set: { key1: 'val1', key2: 'val2' }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id, | ||
$ignore_time: true | ||
}; | ||
this.test_send_request_args(test, 'set', { | ||
args: [{'$ignore_time': true, 'key1': 'val1', 'key2': 'val2'}], | ||
expected: { | ||
$ignore_time: true, | ||
$set: {'key1': 'val1', 'key2': 'val2'}, | ||
}, | ||
}); | ||
}, | ||
this.mixpanel.people.set(this.distinct_id, prop); | ||
"supports being called with a callback": function(test) { | ||
this.test_send_request_args(test, 'set', { | ||
args: ['key1', 'val1'], | ||
expected: {$set: {'key1': 'val1'}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.set didn't call send_request with correct arguments" | ||
); | ||
"supports being called with a callback (set_once)": function(test) { | ||
this.test_send_request_args(test, 'set_once', { | ||
args: ['key1', 'val1'], | ||
expected: {$set_once: {'key1': 'val1'}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
test.done(); | ||
"supports being called with a properties object and a callback": function(test) { | ||
this.test_send_request_args(test, 'set', { | ||
args: [{'key1': 'val1', 'key2': 'val2'}], | ||
expected: {$set: {'key1': 'val1', 'key2': 'val2'}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
"supports a callback function": function(test) { | ||
var prop = { a: 'b' }, callback = function() { }; | ||
"supports being called with a properties object and a callback (set_once)": function(test) { | ||
this.test_send_request_args(test, 'set_once', { | ||
args: [{'key1': 'val1', 'key2': 'val2'}], | ||
expected: {$set_once: {'key1': 'val1', 'key2': 'val2'}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
this.mixpanel.people.set(this.distinct_id, prop, callback); | ||
"supports being called with a modifiers argument and a callback": function(test) { | ||
this.test_send_request_args(test, 'set', { | ||
args: ['key1', 'val1'], | ||
expected: {$set: {'key1': 'val1'}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.args[0][2] === callback, | ||
"people.set didn't call send_request with a callback" | ||
); | ||
"supports being called with a modifiers argument and a callback (set_once)": function(test) { | ||
this.test_send_request_args(test, 'set_once', { | ||
args: ['key1', 'val1'], | ||
expected: {$set_once: {'key1': 'val1'}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.done(); | ||
"supports being called with a properties object, a modifiers argument and a callback": function(test) { | ||
this.test_send_request_args(test, 'set', { | ||
args: [{'key1': 'val1', 'key2': 'val2'}], | ||
expected: {$set: {'key1': 'val1', 'key2': 'val2'}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
"supports a callback function (set_once)": function(test) { | ||
var prop = { a: 'b' }, callback = function() { }; | ||
this.mixpanel.people.set_once(this.distinct_id, prop, callback); | ||
test.ok( | ||
this.mixpanel.send_request.args[0][2] === callback, | ||
"people.set_once didn't call send_request with a callback" | ||
); | ||
test.done(); | ||
} | ||
"supports being called with a properties object, a modifiers argument and a callback (set_once)": function(test) { | ||
this.test_send_request_args(test, 'set_once', { | ||
args: [{'key1': 'val1', 'key2': 'val2'}], | ||
expected: {$set_once: {'key1': 'val1', 'key2': 'val2'}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
}, | ||
@@ -145,70 +217,93 @@ | ||
"calls send_request with correct endpoint and data": function(test) { | ||
var expected_data = { | ||
$add: { key1: 1 }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.mixpanel.people.increment(this.distinct_id, 'key1'); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.increment didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
this.test_send_request_args(test, 'increment', { | ||
args: ['key1'], | ||
expected: {$add: {'key1': 1}}, | ||
}); | ||
}, | ||
"supports incrementing key by value": function(test) { | ||
var expected_data = { | ||
$add: { key1: 2 }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.test_send_request_args(test, 'increment', { | ||
args: ['key1', 2], | ||
expected: {$add: {'key1': 2}}, | ||
}); | ||
}, | ||
this.mixpanel.people.increment(this.distinct_id, "key1", 2); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.increment didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
"supports incrementing key by value and a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'increment', { | ||
args: ['key1', 2], | ||
expected: {$add: {'key1': 2}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
"supports incrementing multiple keys": function(test) { | ||
var prop = { key1: 5, key2: -3 }, | ||
expected_data = { | ||
$add: prop, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.test_send_request_args(test, 'increment', { | ||
args: [{'key1': 5, 'key2': -3}], | ||
expected: {$add: {'key1': 5, 'key2': -3}}, | ||
}); | ||
}, | ||
this.mixpanel.people.increment(this.distinct_id, prop); | ||
"supports incrementing multiple keys and a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'increment', { | ||
args: [{'key1': 5, 'key2': -3}], | ||
expected: {$add: {'key1': 5, 'key2': -3}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.increment didn't call send_request with correct arguments" | ||
); | ||
"ignores invalid values": function(test) { | ||
this.test_send_request_args(test, 'increment', { | ||
args: [{ | ||
'key1': 'bad', | ||
'key2': 3, | ||
'key3': undefined, | ||
'key4': '5', | ||
'key5': new Date(), | ||
'key6': function() {}, | ||
}], | ||
expected: {$add: {'key2': 3, 'key4': '5'}}, | ||
}); | ||
}, | ||
test.done(); | ||
"supports being called with a callback": function(test) { | ||
this.test_send_request_args(test, 'increment', { | ||
args: ['key1'], | ||
expected: {$add: {'key1': 1}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
"ignores invalid values": function(test) { | ||
var prop = { key1: "bad", key2: 3, key3: undefined, key4: "5", key5: new Date(), key6: function(){} }, | ||
expected_data = { | ||
$add: { key2: 3, key4: '5' }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
"supports incrementing key by value with a callback": function(test) { | ||
this.test_send_request_args(test, 'increment', { | ||
args: ['key1', 2], | ||
expected: {$add: {'key1': 2}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
this.mixpanel.people.increment(this.distinct_id, prop); | ||
"supports incrementing key by value with a modifiers argument and callback": function(test) { | ||
this.test_send_request_args(test, 'increment', { | ||
args: ['key1', 2], | ||
expected: {$add: {'key1': 2}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.increment didn't call send_request with correct arguments" | ||
); | ||
"supports incrementing multiple keys with a callback": function(test) { | ||
this.test_send_request_args(test, 'increment', { | ||
args: [{'key1': 5, 'key2': -3}], | ||
expected: {$add: {'key1': 5, 'key2': -3}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
test.done(); | ||
} | ||
"supports incrementing multiple keys with a modifiers argument and callback": function(test) { | ||
this.test_send_request_args(test, 'increment', { | ||
args: [{'key1': 5, 'key2': -3}], | ||
expected: {$add: {'key1': 5, 'key2': -3}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
}, | ||
@@ -218,111 +313,136 @@ | ||
"calls send_request with correct endpoint and data": function(test) { | ||
var expected_data = { | ||
$append: { key1: 'value' }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.test_send_request_args(test, 'append', { | ||
args: ['key1', 'value'], | ||
expected: {$append: {'key1': 'value'}}, | ||
}); | ||
}, | ||
this.mixpanel.people.append(this.distinct_id, 'key1', 'value'); | ||
"supports being called with modifiers": function(test) { | ||
this.test_send_request_args(test, 'append', { | ||
args: ['key1', 'value'], | ||
expected: {$append: {'key1': 'value'}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.append didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
"supports being called with a callback": function(test) { | ||
this.test_send_request_args(test, 'append', { | ||
args: ['key1', 'value'], | ||
expected: {$append: {'key1': 'value'}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
"supports appending multiple keys with values": function(test) { | ||
var prop = { key1: 'value1', key2: 'value2' }, | ||
expected_data = { | ||
$append: prop, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.test_send_request_args(test, 'append', { | ||
args: [{'key1': 'value1', 'key2': 'value2'}], | ||
expected: {$append: {'key1': 'value1', 'key2': 'value2'}}, | ||
}); | ||
}, | ||
this.mixpanel.people.append(this.distinct_id, prop); | ||
"supports appending multiple keys with values and a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'append', { | ||
args: [{'key1': 'value1', 'key2': 'value2'}], | ||
expected: {$append: {'key1': 'value1', 'key2': 'value2'}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.append didn't call send_request with correct arguments" | ||
); | ||
"supports appending multiple keys with values and a callback": function(test) { | ||
this.test_send_request_args(test, 'append', { | ||
args: [{'key1': 'value1', 'key2': 'value2'}], | ||
expected: {$append: {'key1': 'value1', 'key2': 'value2'}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
test.done(); | ||
} | ||
"supports appending multiple keys with values with a modifiers argument and callback": function(test) { | ||
this.test_send_request_args(test, 'append', { | ||
args: [{'key1': 'value1', 'key2': 'value2'}], | ||
expected: {$append: {'key1': 'value1', 'key2': 'value2'}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
}, | ||
track_charge: { | ||
"calls send_request with correct endpoint and data": function(test) { | ||
var expected_data = { | ||
$append: { $transactions: { $amount: 50 } }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.mixpanel.people.track_charge(this.distinct_id, 50); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.track_charge didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
this.test_send_request_args(test, 'track_charge', { | ||
args: [50], | ||
expected: {$append: {$transactions: {$amount: 50}}}, | ||
}); | ||
}, | ||
"supports being called with a property object": function(test) { | ||
var time = new Date('feb 1 2012'), | ||
prop = { $time: time, isk: 'isk' }, | ||
charge = { $amount: 50, $time: time.toISOString(), isk: 'isk' }, | ||
expected_data = { | ||
$append: { $transactions: charge }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
var time = new Date('Feb 1 2012'); | ||
this.test_send_request_args(test, 'track_charge', { | ||
args: [50, {$time: time, isk: 'isk'}], | ||
expected: {$append: {$transactions: { | ||
$amount: 50, | ||
$time: time.toISOString(), | ||
isk: 'isk', | ||
}}}, | ||
}); | ||
}, | ||
this.mixpanel.people.track_charge(this.distinct_id, 50, prop); | ||
"supports being called with a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'track_charge', { | ||
args: [50], | ||
expected: {$append: {$transactions: {$amount: 50}}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.track_charge didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
"supports being called with a property object and a modifiers argument": function(test) { | ||
var time = new Date('Feb 1 2012'); | ||
this.test_send_request_args(test, 'track_charge', { | ||
args: [50, {$time: time, isk: 'isk'}], | ||
expected: {$append: {$transactions: { | ||
$amount: 50, | ||
$time: time.toISOString(), | ||
isk: 'isk', | ||
}}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
"supports being called with a callback": function(test) { | ||
var expected_data = { | ||
$append: { $transactions: { $amount: 50 } }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
var callback = function() {}; | ||
this.mixpanel.people.track_charge(this.distinct_id, 50, callback); | ||
test.ok( | ||
this.mixpanel.send_request.args[0][2] === callback, | ||
"people.track_charge didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
this.test_send_request_args(test, 'track_charge', { | ||
args: [50], | ||
expected: {$append: {$transactions: {$amount: 50}}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
"supports being called with properties and a callback": function(test) { | ||
var expected_data = { | ||
$append: { $transactions: { $amount: 50 } }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.test_send_request_args(test, 'track_charge', { | ||
args: [50, {}], | ||
expected: {$append: {$transactions: {$amount: 50}}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
var callback = function() {}; | ||
this.mixpanel.people.track_charge(this.distinct_id, 50, {}, callback); | ||
"supports being called with modifiers and a callback": function(test) { | ||
this.test_send_request_args(test, 'track_charge', { | ||
args: [50], | ||
expected: {$append: {$transactions: {$amount: 50}}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.args[0][2] === callback, | ||
"people.track_charge didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
} | ||
"supports being called with properties, modifiers and a callback": function(test) { | ||
var time = new Date('Feb 1 2012'); | ||
this.test_send_request_args(test, 'track_charge', { | ||
args: [50, {$time: time, isk: 'isk'}], | ||
expected: {$append: {$transactions: { | ||
$amount: 50, | ||
$time: time.toISOString(), | ||
isk: 'isk', | ||
}}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
}, | ||
@@ -332,17 +452,28 @@ | ||
"calls send_request with correct endpoint and data": function(test) { | ||
var expected_data = { | ||
$set: { $transactions: [] }, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.test_send_request_args(test, 'clear_charges', { | ||
expected: {$set: {$transactions: []}}, | ||
}); | ||
}, | ||
this.mixpanel.people.clear_charges(this.distinct_id); | ||
"supports being called with a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'clear_charges', { | ||
expected: {$set: {$transactions: []}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.clear_charges didn't call send_request with correct arguments" | ||
); | ||
"supports being called with a callback": function(test) { | ||
this.test_send_request_args(test, 'clear_charges', { | ||
expected: {$set: {$transactions: []}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
test.done(); | ||
} | ||
"supports being called with a modifiers argument and a callback": function(test) { | ||
this.test_send_request_args(test, 'clear_charges', { | ||
expected: {$set: {$transactions: []}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
}, | ||
@@ -352,17 +483,28 @@ | ||
"calls send_request with correct endpoint and data": function(test) { | ||
var expected_data = { | ||
$delete: '', | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.test_send_request_args(test, 'delete_user', { | ||
expected: {$delete: ''}, | ||
}); | ||
}, | ||
this.mixpanel.people.delete_user(this.distinct_id); | ||
"supports being called with a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'delete_user', { | ||
expected: {$delete: ''}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.delete_user didn't call send_request with correct arguments" | ||
); | ||
"supports being called with a callback": function(test) { | ||
this.test_send_request_args(test, 'delete_user', { | ||
expected: {$delete: ''}, | ||
use_callback: true, | ||
}); | ||
}, | ||
test.done(); | ||
} | ||
"supports being called with a modifiers argument and a callback": function(test) { | ||
this.test_send_request_args(test, 'delete_user', { | ||
expected: {$delete: ''}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
}, | ||
@@ -372,43 +514,15 @@ | ||
"calls send_request with correct endpoint and data": function(test) { | ||
this.test_send_request_args(test, 'union', { | ||
args: [{'key1': ['value1', 'value2']}], | ||
expected: {$union: {'key1': ['value1', 'value2']}}, | ||
}); | ||
}, | ||
var expected_data = { | ||
$union: {'key1': ['value1', 'value2']}, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.mixpanel.people.union(this.distinct_id, { | ||
'key1': ['value1', 'value2'] | ||
"supports being called with a scalar value": function(test) { | ||
this.test_send_request_args(test, 'union', { | ||
args: [{'key1': 'value1'}], | ||
expected: {$union: {'key1': ['value1']}}, | ||
}); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.union didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
}, | ||
"supports being called with a scalar value": function(test) { | ||
var data = { | ||
'key1': 'value1' | ||
}, | ||
expected_data = { | ||
$union: { | ||
'key1': ['value1'] | ||
}, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.mixpanel.people.union(this.distinct_id, data); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.union didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
}, | ||
"errors on other argument types": function(test) { | ||
@@ -425,6 +539,29 @@ this.mixpanel.people.union(this.distinct_id, {key1: {key: 'val'}}); | ||
); | ||
test.done(); | ||
} | ||
}, | ||
"supports being called with a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'union', { | ||
args: [{'key1': ['value1', 'value2']}], | ||
expected: {$union: {'key1': ['value1', 'value2']}}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
"supports being called with a callback": function(test) { | ||
this.test_send_request_args(test, 'union', { | ||
args: [{'key1': ['value1', 'value2']}], | ||
expected: {$union: {'key1': ['value1', 'value2']}}, | ||
use_callback: true, | ||
}); | ||
}, | ||
"supports being called with a modifiers argument and a callback": function(test) { | ||
this.test_send_request_args(test, 'union', { | ||
args: [{'key1': ['value1', 'value2']}], | ||
expected: {$union: {'key1': ['value1', 'value2']}}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
}, | ||
@@ -434,36 +571,15 @@ | ||
"calls send_request with correct endpoint and data": function(test) { | ||
this.test_send_request_args(test, 'unset', { | ||
args: ['key1'], | ||
expected: {$unset: ['key1']}, | ||
}); | ||
}, | ||
var expected_data = { | ||
$unset: ['key1'], | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.mixpanel.people.unset(this.distinct_id, 'key1'); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.unset didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
"supports being called with a property array": function(test) { | ||
this.test_send_request_args(test, 'unset', { | ||
args: [['key1', 'key2']], | ||
expected: {$unset: ['key1', 'key2']}, | ||
}); | ||
}, | ||
"supports being called with a property array": function(test) { | ||
var prop = ['key1', 'key2'], | ||
expected_data = { | ||
$unset: prop, | ||
$token: this.token, | ||
$distinct_id: this.distinct_id | ||
}; | ||
this.mixpanel.people.unset(this.distinct_id, prop); | ||
test.ok( | ||
this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), | ||
"people.unset didn't call send_request with correct arguments" | ||
); | ||
test.done(); | ||
}, | ||
"errors on other argument types": function(test) { | ||
@@ -477,8 +593,30 @@ this.mixpanel.people.unset(this.distinct_id, { key1:'val1', key2:'val2' }); | ||
); | ||
test.done(); | ||
} | ||
} | ||
}, | ||
"supports being called with a modifiers argument": function(test) { | ||
this.test_send_request_args(test, 'unset', { | ||
args: ['key1'], | ||
expected: {$unset: ['key1']}, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
"supports being called with a callback": function(test) { | ||
this.test_send_request_args(test, 'unset', { | ||
args: ['key1'], | ||
expected: {$unset: ['key1']}, | ||
use_callback: true, | ||
}); | ||
}, | ||
"supports being called with a modifiers argument and a callback": function(test) { | ||
this.test_send_request_args(test, 'unset', { | ||
args: ['key1'], | ||
expected: {$unset: ['key1']}, | ||
use_callback: true, | ||
use_modifiers: true, | ||
}); | ||
}, | ||
}, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79185
1718
186