-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathupdateSystemSettings.test.js
More file actions
123 lines (101 loc) · 3.58 KB
/
updateSystemSettings.test.js
File metadata and controls
123 lines (101 loc) · 3.58 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
120
121
122
123
const supertest = require("supertest");
const SystemSettings = require("../../../../models/systemSettings");
const app = require("../../../../server");
const request = supertest(app);
describe("PATCH /msAdmins/settings", () => {
it("Should insert/update system settings", async () => {
//system settings from DB should be empty
await SystemSettings.deleteMany({});
const oldSettings = await SystemSettings.findOne({});
expect(oldSettings).toBeNull();
const initSettings = {
maxRequestsPerMin: 100,
defaultItemsPerPage: 30,
};
const expectedSettings = {
maxRequestsPerMin: 100,
defaultItemsPerPage: 30,
maxItemsPerPage: 50,
defaultMaxRequestsPerDay: 10000,
disableRequestLimits: false,
loggingEnabled: true,
logPageSize: 100,
};
let res = await request
.patch(`/v1/msAdmins/settings`)
.set("Authorization", `bearer ${global.superSysToken}`)
.send(initSettings);
expect(res.status).toEqual(200);
expect(expectedSettings).toMatchObject(res.body.data);
//expect new settings to be inserted in DB
const newDBSettings = await SystemSettings.findOne({});
expect(newDBSettings).toEqual(expect.objectContaining(res.body.data));
const updateSettings = {
maxRequestsPerMin: 200,
maxItemsPerPage: 20,
};
const expectedUpdateSettings = {
maxRequestsPerMin: 200,
defaultItemsPerPage: 30,
maxItemsPerPage: 20,
defaultMaxRequestsPerDay: 10000,
disableRequestLimits: false,
loggingEnabled: true,
logPageSize: 100,
};
//check for update also in same process because this is a single document collection
res = await request
.patch(`/v1/msAdmins/settings`)
.set("Authorization", `bearer ${global.superSysToken}`)
.send(updateSettings);
const updatedDBSettings = await SystemSettings.findOne({});
expect(res.status).toEqual(200);
expect(expectedUpdateSettings).toMatchObject(res.body.data);
//expect new settings to be inserted in DB
expect(updatedDBSettings).toEqual(expect.objectContaining(res.body.data));
});
it("Should return a 401 error when authorization token is unauthorized", async () => {
const url = `/v1/msAdmins/settings`;
const bearerToken = `bearer `;
const initSettings = {
maxRequestsPerMin: 100,
defaultItemsPerPage: 30,
};
const res = await request
.patch(url)
.set("Authorization", bearerToken)
.send(initSettings);
expect(res.status).toEqual(401);
expect(res.body.status).toEqual("error");
expect(res.body.data).toEqual([]);
});
it("Should return a 401 error when admin token is unauthorized", async () => {
const url = `/v1/msAdmins/settings`;
const bearerToken = `bearer ${global.sysToken}`;
const initSettings = {
maxRequestsPerMin: 100,
defaultItemsPerPage: 30,
};
const res = await request
.patch(url)
.set("Authorization", bearerToken)
.send(initSettings);
expect(res.status).toEqual(401);
expect(res.body.status).toEqual("error");
expect(res.body.data).toEqual([]);
});
it("Should return a 422 error when invalid settings are used", async () => {
const url = `/v1/msAdmins/settings`;
const bearerToken = `bearer ${global.superSysToken}`;
const initSettings = {
maxRequestsPerMin: 100,
invalidItemsPerPage: 30,
};
const res = await request
.patch(url)
.set("Authorization", bearerToken)
.send(initSettings);
expect(res.status).toEqual(422);
expect(res.body.status).toEqual("error");
});
});