From ab05538b3758d91e2e3bb21ce7c3060d63177b68 Mon Sep 17 00:00:00 2001 From: ksraj123 Date: Wed, 29 Jul 2020 17:42:01 +0530 Subject: [PATCH] fixed issues in org route and added new tests --- test/organisation.test.js | 6 +++--- test/user.test.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/test/organisation.test.js b/test/organisation.test.js index 12f966b..f159266 100644 --- a/test/organisation.test.js +++ b/test/organisation.test.js @@ -108,14 +108,14 @@ describe('POST /org/', () => { .set('Authorization', `Bearer ${token}`) .send(testOrg) .expect(HttpStatus.CREATED) - orgId = response.body.org._id + orgId = response.body.orgData._id /** DB must be changed **/ - const org = await Organization.findById(response.body.org._id) + const org = await Organization.findById(response.body.orgData._id) expect(org).not.toBeNull() /** Check the response **/ expect(response.body).toMatchObject({ - org: { + orgData: { isArchived: false, _id: `${orgId}`, name: `${testOrg.name}`, diff --git a/test/user.test.js b/test/user.test.js index b1fa087..f2df44a 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -185,6 +185,38 @@ test('Should not get profile for unauthenticated user', async () => { .expect(HttpStatus.UNAUTHORIZED) }) +/** Should update user profile */ +test('Should update profile or authenticated user', async () => { + await request(app) + .patch('/user/me') + .set('Authorization', `Bearer ${testUser.tokens[0].token}`) + .send({ + email: 'updated@example.com' + }) + .expect(HttpStatus.OK) +}) + +/** Should fail to make updates that are not allowed to user profile */ +test('Should be able to make only allowed updates to authenticated user', async () => { + await request(app) + .patch('/user/me') + .set('Authorization', `Bearer ${testUser.tokens[0].token}`) + .send({ + gender: 'Male' + }) + .expect(HttpStatus.BAD_REQUEST) +}) + +/** Should Fail updating profile of unauthenticate user */ +test('Should not update profile or unauthenticated user', async () => { + await request(app) + .patch('/user/me') + .send({ + email: 'updated@example.com' + }) + .expect(HttpStatus.UNAUTHORIZED) +}) + /** Delete authenticated user profile */ test('Should delete profile of authenticated user', async () => { await request(app)