-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
54 lines (43 loc) · 1.22 KB
/
test.js
File metadata and controls
54 lines (43 loc) · 1.22 KB
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
const tape = require("tape");
const jsonist = require("jsonist");
const PORT = (process.env.PORT =
process.env.PORT || require("get-PORT-sync")());
const server = require("./server");
const urlBase = `http://localhost:${PORT}`;
tape("should respond hello", t => {
jsonist.get(urlBase, (err, body) => {
if (err) t.error(err);
t.equal(body.msg, "hello");
t.end();
});
});
tape("should respond user-agent", t => {
const opts = { headers: { "User-Agent": "tape" } };
jsonist.get(`${urlBase}/user-agent`, opts, (err, body) => {
if (err) t.error(err);
t.equal(body.ua, "tape");
t.end();
});
});
tape("should respond b64", t => {
jsonist.get(`${urlBase}/b64/hello`, (err, body) => {
if (err) t.error(err);
t.equal(body.b64, "aGVsbG8=");
t.end();
});
});
tape('should respond repetitive-word', (t) => {
const data = {
text: 'I felt happy because I saw the others were happy and because I knew I should feel happy, but I wasn’t really happy.'
}
jsonist.post(`${urlBase}/repetitive-word`, data, (err, body) => {
if (err) t.error(err)
t.equal(body[0].count, 4)
t.equal(body[0].word, 'happy')
t.end()
})
})
tape("cleanup", function(t) {
server.close();
t.end();
});