forked from facg3/MWM-Shop_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
43 lines (37 loc) · 1.15 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
const test = require('tape');
const shot = require('shot');
const router = require('./src/router');
const fs = require('fs');
const getData=require('./src/database/queries.js');
test('Initialize', t => {
const num = 2;
t.equal(num, 2, 'Should return 2');
t.end();
});
var index = fs.readFile(`${process.cwd()}/`+'public/login.html','UTF-8' ,(err,contentFile) => {
if (err) {
process.stdout.write(' The file doesn\'t exist');
} else {
index=contentFile;
}
});
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('test all products length' , t => {
getData.allProducts(res => {
t.equal(res.length,9, 'Data Size Should Be 9.');
t.end();
});
});