Skip to content

Commit cde7460

Browse files
committed
Fix cypress tests following user wizard changes
1 parent ca84e3a commit cde7460

27 files changed

+938
-654
lines changed

backend/internal/user.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import internalAuditLog from "./audit-log.js";
99
import internalToken from "./token.js";
1010

1111
const omissions = () => {
12-
return ["is_deleted"];
12+
return ["is_deleted", "permissions.id", "permissions.user_id", "permissions.created_on", "permissions.modified_on"];
1313
};
1414

1515
const DEFAULT_AVATAR = gravatar.url("admin@example.com", { default: "mm" });
@@ -250,6 +250,14 @@ const internalUser = {
250250
});
251251
},
252252

253+
deleteAll: async () => {
254+
await userModel
255+
.query()
256+
.patch({
257+
is_deleted: 1,
258+
});
259+
},
260+
253261
/**
254262
* This will only count the users
255263
*

backend/lib/config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ const isPostgres = () => {
199199
*/
200200
const isDebugMode = () => !!process.env.DEBUG;
201201

202+
/**
203+
* Are we running in CI?
204+
*
205+
* @returns {boolean}
206+
*/
207+
const isCI = () => process.env.CI === 'true' && process.env.DEBUG === 'true';
208+
202209
/**
203210
* Returns a public key
204211
*
@@ -234,4 +241,4 @@ const useLetsencryptServer = () => {
234241
return null;
235242
};
236243

237-
export { configHas, configGet, isSqlite, isMysql, isPostgres, isDebugMode, getPrivateKey, getPublicKey, useLetsencryptStaging, useLetsencryptServer };
244+
export { isCI, configHas, configGet, isSqlite, isMysql, isPostgres, isDebugMode, getPrivateKey, getPublicKey, useLetsencryptStaging, useLetsencryptServer };

backend/lib/error.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ const errs = {
1414
Error.captureStackTrace(this, this.constructor);
1515
this.name = this.constructor.name;
1616
this.previous = previous;
17-
this.message = `Item Not Found - ${id}`;
17+
this.message = "Not Found";
18+
if (id) {
19+
this.message = `Not Found - ${id}`;
20+
}
1821
this.public = true;
1922
this.status = 404;
2023
},

backend/routes/audit-log.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import express from "express";
22
import internalAuditLog from "../internal/audit-log.js";
33
import jwtdecode from "../lib/express/jwt-decode.js";
44
import validator from "../lib/validator/index.js";
5+
import { express as logger } from "../logger.js";
56

67
const router = express.Router({
78
caseSensitive: true,
@@ -24,31 +25,31 @@ router
2425
*
2526
* Retrieve all logs
2627
*/
27-
.get((req, res, next) => {
28-
validator(
29-
{
30-
additionalProperties: false,
31-
properties: {
32-
expand: {
33-
$ref: "common#/properties/expand",
34-
},
35-
query: {
36-
$ref: "common#/properties/query",
28+
.get(async (req, res, next) => {
29+
try {
30+
const data = await validator(
31+
{
32+
additionalProperties: false,
33+
properties: {
34+
expand: {
35+
$ref: "common#/properties/expand",
36+
},
37+
query: {
38+
$ref: "common#/properties/query",
39+
},
3740
},
3841
},
39-
},
40-
{
41-
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
42-
query: typeof req.query.query === "string" ? req.query.query : null,
43-
},
44-
)
45-
.then((data) => {
46-
return internalAuditLog.getAll(res.locals.access, data.expand, data.query);
47-
})
48-
.then((rows) => {
49-
res.status(200).send(rows);
50-
})
51-
.catch(next);
42+
{
43+
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
44+
query: typeof req.query.query === "string" ? req.query.query : null,
45+
},
46+
);
47+
const rows = await internalAuditLog.getAll(res.locals.access, data.expand, data.query);
48+
res.status(200).send(rows);
49+
} catch (err) {
50+
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
51+
next(err);
52+
}
5253
});
5354

5455
export default router;

backend/routes/nginx/access_lists.js

Lines changed: 80 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import internalAccessList from "../../internal/access-list.js";
33
import jwtdecode from "../../lib/express/jwt-decode.js";
44
import apiValidator from "../../lib/validator/api.js";
55
import validator from "../../lib/validator/index.js";
6+
import { express as logger } from "../../logger.js";
67
import { getValidationSchema } from "../../schema/index.js";
78

89
const router = express.Router({
@@ -26,47 +27,47 @@ router
2627
*
2728
* Retrieve all access-lists
2829
*/
29-
.get((req, res, next) => {
30-
validator(
31-
{
32-
additionalProperties: false,
33-
properties: {
34-
expand: {
35-
$ref: "common#/properties/expand",
36-
},
37-
query: {
38-
$ref: "common#/properties/query",
30+
.get(async (req, res, next) => {
31+
try {
32+
const data = await validator(
33+
{
34+
additionalProperties: false,
35+
properties: {
36+
expand: {
37+
$ref: "common#/properties/expand",
38+
},
39+
query: {
40+
$ref: "common#/properties/query",
41+
},
3942
},
4043
},
41-
},
42-
{
43-
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
44-
query: typeof req.query.query === "string" ? req.query.query : null,
45-
},
46-
)
47-
.then((data) => {
48-
return internalAccessList.getAll(res.locals.access, data.expand, data.query);
49-
})
50-
.then((rows) => {
51-
res.status(200).send(rows);
52-
})
53-
.catch(next);
44+
{
45+
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
46+
query: typeof req.query.query === "string" ? req.query.query : null,
47+
},
48+
);
49+
const rows = await internalAccessList.getAll(res.locals.access, data.expand, data.query);
50+
res.status(200).send(rows);
51+
} catch (err) {
52+
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
53+
next(err);
54+
}
5455
})
5556

5657
/**
5758
* POST /api/nginx/access-lists
5859
*
5960
* Create a new access-list
6061
*/
61-
.post((req, res, next) => {
62-
apiValidator(getValidationSchema("/nginx/access-lists", "post"), req.body)
63-
.then((payload) => {
64-
return internalAccessList.create(res.locals.access, payload);
65-
})
66-
.then((result) => {
67-
res.status(201).send(result);
68-
})
69-
.catch(next);
62+
.post(async (req, res, next) => {
63+
try {
64+
const payload = await apiValidator(getValidationSchema("/nginx/access-lists", "post"), req.body);
65+
const result = await internalAccessList.create(res.locals.access, payload);
66+
res.status(201).send(result);
67+
} catch (err) {
68+
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
69+
next(err);
70+
}
7071
});
7172

7273
/**
@@ -86,66 +87,69 @@ router
8687
*
8788
* Retrieve a specific access-list
8889
*/
89-
.get((req, res, next) => {
90-
validator(
91-
{
92-
required: ["list_id"],
93-
additionalProperties: false,
94-
properties: {
95-
list_id: {
96-
$ref: "common#/properties/id",
97-
},
98-
expand: {
99-
$ref: "common#/properties/expand",
90+
.get(async (req, res, next) => {
91+
try {
92+
const data = await validator(
93+
{
94+
required: ["list_id"],
95+
additionalProperties: false,
96+
properties: {
97+
list_id: {
98+
$ref: "common#/properties/id",
99+
},
100+
expand: {
101+
$ref: "common#/properties/expand",
102+
},
100103
},
101104
},
102-
},
103-
{
104-
list_id: req.params.list_id,
105-
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
106-
},
107-
)
108-
.then((data) => {
109-
return internalAccessList.get(res.locals.access, {
110-
id: Number.parseInt(data.list_id, 10),
111-
expand: data.expand,
112-
});
113-
})
114-
.then((row) => {
115-
res.status(200).send(row);
116-
})
117-
.catch(next);
105+
{
106+
list_id: req.params.list_id,
107+
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
108+
},
109+
);
110+
const row = await internalAccessList.get(res.locals.access, {
111+
id: Number.parseInt(data.list_id, 10),
112+
expand: data.expand,
113+
});
114+
res.status(200).send(row);
115+
} catch (err) {
116+
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
117+
next(err);
118+
}
118119
})
119120

120121
/**
121122
* PUT /api/nginx/access-lists/123
122123
*
123124
* Update and existing access-list
124125
*/
125-
.put((req, res, next) => {
126-
apiValidator(getValidationSchema("/nginx/access-lists/{listID}", "put"), req.body)
127-
.then((payload) => {
128-
payload.id = Number.parseInt(req.params.list_id, 10);
129-
return internalAccessList.update(res.locals.access, payload);
130-
})
131-
.then((result) => {
132-
res.status(200).send(result);
133-
})
134-
.catch(next);
126+
.put(async (req, res, next) => {
127+
try {
128+
const payload = await apiValidator(getValidationSchema("/nginx/access-lists/{listID}", "put"), req.body);
129+
payload.id = Number.parseInt(req.params.list_id, 10);
130+
const result = await internalAccessList.update(res.locals.access, payload);
131+
res.status(200).send(result);
132+
} catch (err) {
133+
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
134+
next(err);
135+
}
135136
})
136137

137138
/**
138139
* DELETE /api/nginx/access-lists/123
139140
*
140141
* Delete and existing access-list
141142
*/
142-
.delete((req, res, next) => {
143-
internalAccessList
144-
.delete(res.locals.access, { id: Number.parseInt(req.params.list_id, 10) })
145-
.then((result) => {
146-
res.status(200).send(result);
147-
})
148-
.catch(next);
143+
.delete(async (req, res, next) => {
144+
try {
145+
const result = await internalAccessList.delete(res.locals.access, {
146+
id: Number.parseInt(req.params.list_id, 10),
147+
});
148+
res.status(200).send(result);
149+
} catch (err) {
150+
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
151+
next(err);
152+
}
149153
});
150154

151155
export default router;

0 commit comments

Comments
 (0)