Skip to content

Commit 96fc594

Browse files
committed
add explicit test for base64 mode, but expect json otherwise
1 parent 07d34e5 commit 96fc594

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tests/test.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,8 @@
9898
}
9999

100100
function getRequestData(request, keyPath) {
101-
var data = decodeURIComponent(request.requestBody.match(/data=([^&]+)/)[1]);
102101
try {
103-
data = atob(data);
104-
} catch (err) {
105-
// plain json?
106-
}
107-
try {
108-
data = JSON.parse(data);
102+
var data = JSON.parse(decodeURIComponent(request.requestBody.match(/data=([^&]+)/)[1]));
109103
(keyPath || []).forEach(function(key) {
110104
data = data[key];
111105
});
@@ -3932,6 +3926,15 @@
39323926
);
39333927
});
39343928
}
3929+
3930+
test("tracking can be configured to use base64 encoding", 3, function() {
3931+
mixpanel.test.set_config({api_payload_format: 'base64'});
3932+
mixpanel.test.track('test', {foo: 'bar'});
3933+
same(this.requests.length, 1, "track should have fired off a request");
3934+
var data = JSON.parse(atob(decodeURIComponent(this.requests[0].requestBody.match(/data=([^&]+)/)[1])));
3935+
same(data.event, 'test');
3936+
same(data.properties.foo, 'bar');
3937+
});
39353938
}
39363939

39373940
if (USE_XHR && window.localStorage) {

0 commit comments

Comments
 (0)