/
http-extras-tests.js
67 lines (59 loc) · 1.78 KB
/
http-extras-tests.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
// URL prefix for tests to talk to
var _XHR_URL_PREFIX = "/http_extras_test_responder";
var url_base = function () {
if (Meteor.isServer) {
var address = WebApp.httpServer.address();
return "http://127.0.0.1:" + address.port;
} else {
return "";
}
};
var url_prefix = function () {
if (Meteor.isServer && _XHR_URL_PREFIX.indexOf("http") !== 0) {
_XHR_URL_PREFIX = url_base() + _XHR_URL_PREFIX;
}
return _XHR_URL_PREFIX;
};
testAsyncMulti("httpcall - binary", [
function(test, expect) {
// "blob" and "document" are client-only
if (Meteor.isClient) {
HTTP.call(
"GET", url_prefix() + "/binary",
{responseType: "blob"},
expect(function(error, result) {
test.isFalse(error);
test.isTrue(result);
test.equal(result.statusCode, 200);
test.instanceOf(result.content, Blob);
}));
HTTP.call(
"GET", url_prefix() + "/document",
{responseType: "document"},
expect(function(error, result) {
test.isFalse(error);
test.isTrue(result);
test.equal(result.statusCode, 200);
test.instanceOf(result.content, Document);
}));
}
HTTP.call(
"GET", url_prefix() + "/binary",
{responseType: "arraybuffer"},
expect(function(error, result) {
test.isFalse(error);
test.isTrue(result);
test.equal(result.statusCode, 200);
test.instanceOf(result.content, ArrayBuffer);
}));
HTTP.call(
"GET", url_prefix() + "/binary",
{responseType: "ejson-binary"},
expect(function(error, result) {
test.isFalse(error);
test.isTrue(result);
test.equal(result.statusCode, 200);
test.isTrue(EJSON.isBinary(result.content));
}));
}
]);