Skip to content

Commit

Permalink
fixed issues in org route and added new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksraj123 committed Jul 29, 2020
1 parent f2f9821 commit ab05538
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/organisation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
32 changes: 32 additions & 0 deletions test/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'
})
.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: '[email protected]'
})
.expect(HttpStatus.UNAUTHORIZED)
})

/** Delete authenticated user profile */
test('Should delete profile of authenticated user', async () => {
await request(app)
Expand Down

0 comments on commit ab05538

Please sign in to comment.