forked from nitaiaharoni1/react-restaurant-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
119 lines (103 loc) · 4.15 KB
/
Copy pathtest.js
File metadata and controls
119 lines (103 loc) · 4.15 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const request = require('supertest'),
app = require('./index'),
expect = require('chai').expect;
describe('Server Test', () => {
const PASSWORD = 'test',
EMAIL = `test${Math.random().toString(36).substring(7)}@test.com`,
ADDRESS = 'test',
HOUSE_NUM = '1',
CITY = 'test',
ZIP = '123456',
FIRST_NAME = 'Test',
LAST_NAME = 'Test',
COUNTRY = 'test';
const req = request(app);
it('should signup a new test user', async () => {
const res = await req.post(`/api/user/signup`)
.send({
email: EMAIL,
password: PASSWORD,
address: ADDRESS,
houseNum: HOUSE_NUM,
city: CITY,
zip: ZIP,
firstName: FIRST_NAME,
lastName: LAST_NAME,
country: COUNTRY,
})
.set('Accept', 'application/json');
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Signup successful');
expect(res.header['set-cookie'].length).to.equal(1);
});
it('should logout successfully', async () => {
const res = await req.post(`/api/user/logout`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Logout successful');
});
it('should login successfully', async () => {
let remember = false;
const res = await req.get(`/api/user/login/${EMAIL}/${PASSWORD}/${remember}`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Login successful');
expect(res.header['set-cookie'].length).to.equal(1);
});
it('should add new item', async () => {
let action = 'ADD',
title = 'Fried Spring Rolls';
const res = await req.post(`/api/items/${EMAIL}/${title}/${action}`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Items we\'re updated');
});
it('should add another new item', async () => {
let action = 'ADD',
title = 'Tofu Tod';
const res = await req.post(`/api/items/${EMAIL}/${title}/${action}`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Items we\'re updated');
});
it('should add a third item', async () => {
let action = 'ADD',
title = 'Gai Of Nuur Satay';
const res = await req.post(`/api/items/${EMAIL}/${title}/${action}`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Items we\'re updated');
});
it('should subtract first item', async () => {
let action = 'SUB',
title = 'Fried Spring Rolls';
const res = await req.post(`/api/items/${EMAIL}/${title}/${action}`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Items we\'re updated');
});
it('should zero second item', async () => {
let action = 'ZERO',
title = 'Tofu Tod';
const res = await req.post(`/api/items/${EMAIL}/${title}/${action}`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Items we\'re updated');
});
it('should place a new order', async () => {
const res = await req.post(`/api/order/new/${EMAIL}`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Order successfully placed');
expect(res.body.orderId).to.be.a('string');
expect(res.body.data).to.be.an('object');
});
it('should get admin data', async () => {
const res = await req.get(`/api/admin/data/admin`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('Admin data');
expect(res.body.data).to.be.an('object');
});
it('should get gallery', async () => {
const res = await req.get(`/api/gallery`);
expect(res.status).to.equal(200);
expect(res.body.images.length).to.equal(18);
});
after('should delete created user', async () => {
const res = await req.delete(`/api/user/${EMAIL}/${PASSWORD}`);
expect(res.status).to.equal(200);
expect(res.body.msg).to.equal('User was deleted successfully');
});
});