-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsettings.test.js
More file actions
105 lines (101 loc) · 3.82 KB
/
settings.test.js
File metadata and controls
105 lines (101 loc) · 3.82 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
"use strict";
const chai = require("chai");
const chaiHttp = require("chai-http");
chai.use(chaiHttp);
const server = require("../app");
const agent = chai.request.agent(server.app);
chai.should();
const util = {
account: require("./util/account.test.util"),
auth: require("./util/auth.test.util")
};
const Constants = {
Success: require("../constants/success.constant"),
Error: require("../constants/error.constant")
};
const invalidAccount = util.account.hackerAccounts.stored.noTeam[0];
const Admin = util.account.adminAccounts.stored[0];
describe("GET settings", function() {
it("should get the current settings", function(done) {
chai.request(server.app)
.get(`/api/settings/`)
// does not have password because of to stripped json
.end(function(err, res) {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property("message");
res.body.message.should.equal(Constants.Success.SETTINGS_GET);
done();
});
});
});
describe("PATCH settings", function() {
it("should FAIL to update the settings due to lack of authentication", function(done) {
chai.request(server.app)
.patch(`/api/settings/`)
// does not have password because of to stripped json
.end(function(err, res) {
res.should.have.status(401);
res.should.be.json;
res.body.should.have.property("message");
res.body.message.should.equal(Constants.Error.AUTH_401_MESSAGE);
done();
});
});
it("should FAIL to update the settings due to lack of authorization", function(done) {
util.auth.login(agent, invalidAccount, (error) => {
if (error) {
agent.close();
return done(error);
}
return (
agent
.patch(`/api/settings/`)
.type("application/json")
.send({
openTime: new Date().toString(),
closeTime: new Date().toString(),
confirmTime: new Date().toString()
})
// does not have password because of to stripped json
.end(function(err, res) {
res.should.have.status(403);
res.should.be.json;
res.body.should.have.property("message");
res.body.message.should.equal(
Constants.Error.AUTH_403_MESSAGE
);
done();
})
);
});
});
it("should succeed to update the settings", function(done) {
util.auth.login(agent, Admin, (error) => {
if (error) {
agent.close();
return done(error);
}
return (
agent
.patch(`/api/settings/`)
.type("application/json")
.send({
openTime: new Date().toString(),
closeTime: new Date().toString(),
confirmTime: new Date().toString()
})
// does not have password because of to stripped json
.end(function(err, res) {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property("message");
res.body.message.should.equal(
Constants.Success.SETTINGS_PATCH
);
done();
})
);
});
});
});