Updated server to more fit frontend requirements
This commit is contained in:
parent
f5ad8e5f8d
commit
7ca9067533
5 changed files with 13 additions and 14 deletions
|
|
@ -13,6 +13,8 @@ async function basicAuth(req, res, next) {
|
|||
const [email, password] = Buffer.from(b64Encoded, 'base64').toString().split(':');
|
||||
if (!email || !password) return res.status(400).send(config.errorIncomplete);
|
||||
|
||||
console.log(Buffer.from(b64Encoded, 'base64').toString());
|
||||
|
||||
// Make sure that a user exists with that email
|
||||
const result = await User.findOne({
|
||||
where: { email: email },
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ async function tokenAuth(req, res, next) {
|
|||
return res.status(401).send(config.errorUnauthed);
|
||||
}
|
||||
|
||||
const user = await token.getUser();
|
||||
const user = await result.getUser();
|
||||
|
||||
if (!user) return res.status(500).send(config.errorGeneric);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,8 +29,9 @@ router.post('/audio', parseFormData, tokenAuth, SetAudio);
|
|||
router.get('/reset', RequestReset);
|
||||
router.patch('/reset/:id', ResetPassword);
|
||||
|
||||
router.get('/:userID', tokenAuth, checkKnownUser, GetUserDetails);
|
||||
router.get('/orgs', tokenAuth, GetOwnedOrgs);
|
||||
router.get('/orgs/member', tokenAuth, GetMemberOrgs);
|
||||
|
||||
router.get('/:userID', tokenAuth, checkKnownUser, GetUserDetails);
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ describe('CreateUser', function () {
|
|||
});
|
||||
});
|
||||
|
||||
test('[500] Request missing fields', async () => {
|
||||
test('[400] Request missing fields', async () => {
|
||||
await supertest(app)
|
||||
.post('/api/auth/register')
|
||||
.send()
|
||||
.expect(400, 'The request is missing required fields.')
|
||||
.set('Accept', 'text/html')
|
||||
.set('Accept', 'application/json')
|
||||
.expect('Content-Type', /text/);
|
||||
});
|
||||
|
||||
|
|
@ -90,12 +90,8 @@ describe('CreateUser', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(response.body.user).toEqual(
|
||||
expect.objectContaining(user)
|
||||
);
|
||||
expect(org.member).toEqual(
|
||||
expect.arrayContaining([expect.objectContaining(user)])
|
||||
);
|
||||
expect(response.body.user).toEqual(expect.objectContaining(user));
|
||||
expect(org.member).toEqual(expect.arrayContaining([expect.objectContaining(user)]));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -15,18 +15,18 @@ describe('SetAudio', function () {
|
|||
|
||||
test('[403] Missing token', async () => {
|
||||
await supertest(app)
|
||||
.post('/api/auth/logout')
|
||||
.post('/api/auth/audio')
|
||||
.send()
|
||||
.expect(403, 'Unauthorized user')
|
||||
.set('Accept', 'text/html')
|
||||
.expect('Content-Type', /text/);
|
||||
});
|
||||
|
||||
test('[511] Token was not found', async () => {
|
||||
test('[400] Token was not found', async () => {
|
||||
await supertest(app)
|
||||
.post('/api/auth/logout')
|
||||
.post('/api/auth/audio')
|
||||
.send({ token: 'randomString' })
|
||||
.expect(511, 'Session expired')
|
||||
.expect(400, 'Session expired')
|
||||
.set('Accept', 'text/html')
|
||||
.expect('Content-Type', /text/);
|
||||
});
|
||||
|
|
|
|||
Reference in a new issue