Skip to content

Commit

Permalink
Merge db7c89f into 5cd8022
Browse files Browse the repository at this point in the history
  • Loading branch information
Makwe-O committed Feb 1, 2019
2 parents 5cd8022 + db7c89f commit 1f90048
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 17 deletions.
36 changes: 30 additions & 6 deletions server/controllers/followController.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ class FollowContoller {
Util.sendInAppNotification([userToBeFollowed], notification.message);
}

return response(res, 201, 'success', `You are now following ${userToBeFollowed.fullName}`);
return response(
res,
201,
'success',
`You are now following ${userToBeFollowed.fullName}`
);
} catch (error) {
response(res, 500, 'failure', error.name);
}
Expand Down Expand Up @@ -120,7 +125,12 @@ class FollowContoller {
});

if (!userUnfollow) {
return response(res, 400, 'failure', `You are not following ${user.userName}`);
return response(
res,
400,
'failure',
`You are not following ${user.userName}`
);
}

userUnfollow.destroy();
Expand Down Expand Up @@ -164,7 +174,7 @@ class FollowContoller {
});

if (followers.length === 0) {
return response(res, 200, 'success', 'You currenly have no followers');
return response(res, 200, 'success', 'User currenly has no followers');
}

const payload = {
Expand All @@ -174,7 +184,14 @@ class FollowContoller {
}
};

response(res, 200, 'success', 'Followers returned successfully', null, payload);
response(
res,
200,
'success',
'Followers returned successfully',
null,
payload
);
} catch (error) {
response(res, 500, 'failure', error.name);
}
Expand Down Expand Up @@ -215,7 +232,7 @@ class FollowContoller {
});

if (following.length === 0) {
return response(res, 200, 'success', 'You are not following anyone');
return response(res, 200, 'success', 'User currently has no following');
}
const payload = {
following: following.map(followingUser => followingUser.followedUser),
Expand All @@ -224,7 +241,14 @@ class FollowContoller {
}
};

response(res, 200, 'success', 'Following returned successfully', null, payload);
response(
res,
200,
'success',
'Following returned successfully',
null,
payload
);
} catch (error) {
response(res, 500, 'failure', error.name);
}
Expand Down
44 changes: 33 additions & 11 deletions server/test/controllers/follow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ describe('Follow Model', () => {

describe('Get followers', () => {
it("Should get show proper error message when getting the followers of users that don't exist", async () => {
const response = await chai.request(app).get('/api/v1/users/jesseinitjesseinit/followers');
const response = await chai
.request(app)
.get('/api/v1/users/jesseinitjesseinit/followers');

expect(response.status).to.eqls(404);
expect(response.body.status).to.eqls('failure');
Expand All @@ -98,7 +100,9 @@ describe('Follow Model', () => {
});

it('Should get show proper message when getting the followers of users that have followers', async () => {
const response = await chai.request(app).get('/api/v1/users/kabir/followers');
const response = await chai
.request(app)
.get('/api/v1/users/kabir/followers');

expect(response.status).to.eqls(200);
expect(response.body.status).to.eqls('success');
Expand All @@ -107,19 +111,25 @@ describe('Follow Model', () => {
});

it('Should get show proper message when user does not have any followers', async () => {
const response = await chai.request(app).get('/api/v1/users/jesseinit/followers');
const response = await chai
.request(app)
.get('/api/v1/users/jesseinit/followers');

expect(response.status).to.eqls(200);
expect(response.body.status).to.eqls('success');
expect(response.body.data.message).to.eqls('Followers returned successfully');
expect(response.body.data.message).to.eqls(
'Followers returned successfully'
);
expect(response.body.data.statusCode).to.eqls(200);
});

it('Should get handle unexpected errors when trying to get the followers of a user', async () => {
const stub = sinon
.stub(Follow, 'findAll')
.callsFake(() => Promise.reject(new Error('Internal Server Error')));
const response = await chai.request(app).get('/api/v1/users/kabir/followers');
const response = await chai
.request(app)
.get('/api/v1/users/kabir/followers');

expect(response.status).to.eqls(500);
expect(response.body.status).to.eqls('failure');
Expand All @@ -130,7 +140,9 @@ describe('Follow Model', () => {

describe('Get following', () => {
it("Should get show proper error message when getting the following of users that don't exist", async () => {
const response = await chai.request(app).get('/api/v1/users/jesseinitjesseinit/following');
const response = await chai
.request(app)
.get('/api/v1/users/jesseinitjesseinit/following');

expect(response.status).to.eqls(404);
expect(response.body.status).to.eqls('failure');
Expand All @@ -139,7 +151,9 @@ describe('Follow Model', () => {
});

it('Should get show proper message when getting the followers of users that have following', async () => {
const response = await chai.request(app).get('/api/v1/users/jesseinit/following');
const response = await chai
.request(app)
.get('/api/v1/users/jesseinit/following');

expect(response.status).to.eqls(200);
expect(response.body.status).to.eqls('success');
Expand All @@ -148,19 +162,25 @@ describe('Follow Model', () => {
});

it('Should get show proper message when user is not following any other user', async () => {
const response = await chai.request(app).get('/api/v1/users/kabir/following');
const response = await chai
.request(app)
.get('/api/v1/users/kabir/following');

expect(response.status).to.eqls(200);
expect(response.body.status).to.eqls('success');
expect(response.body.data.message).to.eqls('You are not following anyone');
expect(response.body.data.message).to.eqls(
'User currently has no following'
);
expect(response.body.data.statusCode).to.eqls(200);
});

it('Should get handle unexpected errors when trying to get the following of a user', async () => {
const stub = sinon
.stub(Follow, 'findAll')
.callsFake(() => Promise.reject(new Error('Internal Server Error')));
const response = await chai.request(app).get('/api/v1/users/jesseinit/following');
const response = await chai
.request(app)
.get('/api/v1/users/jesseinit/following');

expect(response.status).to.eqls(500);
expect(response.body.status).to.eqls('failure');
Expand Down Expand Up @@ -202,7 +222,9 @@ describe('Follow Model', () => {

expect(response.status).to.eqls(400);
expect(response.body.status).to.eqls('failure');
expect(response.body.data.message).to.eqls('You cannot unfollow yourself');
expect(response.body.data.message).to.eqls(
'You cannot unfollow yourself'
);
expect(response.body.data.statusCode).to.eqls(400);
});

Expand Down

0 comments on commit 1f90048

Please sign in to comment.