forked from facg3/JokeGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
48 lines (38 loc) · 1.23 KB
/
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
const test = require('tape');
const shot = require('shot');
const router = require('./src/router');
const fs = require('fs');
test("Initialize", (t)=> {
let num = 2;
t.equal(num, 2, "Should return 2");
t.end();
});
var index = fs.readFile(process.cwd()+'/'+'public/index.html','UTF-8' ,(err,contentFile) =>{
if(err){
process.stdout.write('The file doesn\'t exist')
}else{
index=contentFile;
}
});
// Home Route
test('Home route', (t) => {
shot.inject(router, { method: 'get', url: '/' }, (res) => {
t.equal(res.statusCode, 200, 'should respond with status code of 200');
t.equal(res.payload,index, 'should return an html document');
t.end();
})
})
test("Unknown Pages", (t)=>{
shot.inject(router, {method:"get", url:"/this_is_just_a_random_url"}, res=>{
t.equal(res.statusCode, 404, "Should return a status code of 404")
t.equal(res.payload, 'PAGE NOT FOUND!!!!!!!!!!', "Should handle unknown pages.");
t.end();
});
});
test("Retrieving Jokes", t=>{
shot.inject(router, {method:"get", url:"/getjoke"}, res=>{
t.equal(res.statusCode, 200, 'should respond with status code of 200');
t.equal(typeof res.payload, "string", "Should respond with a joke as a string");
t.end();
})
})