aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Harley2018-04-13 17:02:38 +0100
committerTom Harley2018-04-13 17:02:38 +0100
commit4bbf7700a53a8ddff5cbb29658fb9270e5fc1da8 (patch)
tree2f91e658a94ea91389c586727ceb8383123b321c
parentFix some tests by adding properties in projects (diff)
parentfixed template matching in test suite (diff)
downloadmedicine-4bbf7700a53a8ddff5cbb29658fb9270e5fc1da8.tar.gz
medicine-4bbf7700a53a8ddff5cbb29658fb9270e5fc1da8.zip

Merge branch ‘trh/gets’ of gitlab.cs.st-andrews.ac.uk:cs3099group-be-4/project-code into trh/gets

-rw-r--r--src/FileRouter.ts8
-rw-r--r--test/integration/protocol.routes.test.ts14
2 files changed, 14 insertions, 8 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
index 48ec9c7..b662a9c 100644
--- a/src/FileRouter.ts
+++ b/src/FileRouter.ts
@@ -257,6 +257,10 @@ const getUserProperties: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
logger.debug('Listing additional properties for a user');
+ if (res.locals.user == null) {
+ next(new RequestError(404, 'user_not_found'));
+ return;
+ }
res.locals.data = res.locals.user.properties;
next();
};
@@ -363,7 +367,9 @@ const postUsername: Middleware = async(
logger.debug('Editing user');
user.password = req.params.password;
}
- user.metadata = req.body;
+ if (req.body) {
+ user.metadata = req.body;
+ }
next();
};
diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts
index ca20da9..ebe18c2 100644
--- a/test/integration/protocol.routes.test.ts
+++ b/test/integration/protocol.routes.test.ts
@@ -170,7 +170,7 @@ describe('routes : protocol', () => {
private_user_metadata: types.anything,
public_admin_metadata: types.anything,
private_admin_metadata: types.anything
- }), 401],
+ }), 200],
// TODO types.metadata
['get', '/users/mock_user', {
username: types.string,
@@ -183,11 +183,11 @@ describe('routes : protocol', () => {
private_user_metadata: types.anything,
public_admin_metadata: types.anything,
private_admin_metadata: types.anything
- }, 401],
- ['post', '/users/mock_user', null, 401],
+ }, 200],
+ ['post', '/users/new_user', null, 200],
['get', '/users/mock_user/properties', {
data: optional(types.anything)
- }, 401],
+ }, 200],
['get', '/current_user', {
username: types.string,
privileges: array(types.string),
@@ -266,14 +266,14 @@ describe('routes : protocol', () => {
});
});
forEach(completeProtocol).it(
- '%s %s should conform to the general response protocol',
+ '%s %s should conform to the general response template',
(method: string, path: string, temp: Template, resCode: number) => {
const request: ChaiHttp.Request = method === 'get'
? chai.request(app).get(base + path)
: chai.request(app).post(base + path);
request.set('Authorization', `Bearer ${token}`);
return request.then((res: ChaiHttp.Response) => {
- match(responseTemplate, JSON.parse(res.body)).shoul.be.true;
+ expect(match(responseTemplate)(res.body)).to.be.true;
});
});
forEach(completeProtocol).it(
@@ -284,7 +284,7 @@ describe('routes : protocol', () => {
.get(base + path)
.set('Authorization', `Bearer ${token}`)
.then((res: ChaiHttp.Response) => {
- expect(match(temp)(JSON.parse(res.body))).to.be.true;
+ expect(match(temp)(res.body)).to.be.true;
});
} else {
return true;