This repository has been archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 419
/
endpoint-test.js
65 lines (60 loc) · 2.6 KB
/
endpoint-test.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
var vows = require("vows"),
assert = require("assert"),
http = require("http"),
test = require("./test"),
endpoint = require("../lib/cube/server/endpoint");
var suite = vows.describe("endpoint");
var file = "lib/cube/client/semicolon.js",
port = ++test.port,
server = http.createServer(endpoint.file(file, file));
server.listen(port, "127.0.0.1");
suite.addBatch({
"file": {
"GET": {
topic: test.request({method: "GET", port: port}),
"the status should be 200": function(response) {
assert.equal(response.statusCode, 200);
},
"the expected headers should be set": function(response) {
assert.equal(response.headers["content-type"], "text/javascript;charset=utf-8");
assert.equal(response.headers["content-length"], 2);
assert.ok(new Date(response.headers["date"]) > Date.UTC(2011, 0, 1));
assert.ok(new Date(response.headers["last-modified"]) > Date.UTC(2011, 0, 1));
},
"the expected content should be returned": function(response) {
assert.equal(response.body, ";;");
}
},
"GET If-Modified-Since": {
topic: test.request({method: "GET", port: port, headers: {"if-modified-since": new Date(2101, 0, 1).toUTCString()}}),
"the status should be 304": function(response) {
assert.equal(response.statusCode, 304);
},
"the expected headers should be set": function(response) {
assert.equal(response.headers["content-type"], "text/javascript;charset=utf-8");
assert.ok(!("Content-Length" in response.headers));
assert.ok(new Date(response.headers["date"]) > Date.UTC(2011, 0, 1));
assert.ok(new Date(response.headers["last-modified"]) > Date.UTC(2011, 0, 1));
},
"no content should be returned": function(response) {
assert.equal(response.body, "");
}
},
"HEAD": {
topic: test.request({method: "HEAD", port: port, headers: {"if-modified-since": new Date(2001, 0, 1).toUTCString()}}),
"the status should be 200": function(response) {
assert.equal(response.statusCode, 200);
},
"the expected headers should be set": function(response) {
assert.equal(response.headers["content-type"], "text/javascript;charset=utf-8");
assert.ok(!("Content-Length" in response.headers));
assert.ok(new Date(response.headers["date"]) > Date.UTC(2011, 0, 1));
assert.ok(new Date(response.headers["last-modified"]) > Date.UTC(2011, 0, 1));
},
"no content should be returned": function(response) {
assert.equal(response.body, "");
}
}
}
});
suite.export(module);