Skip to content

Commit

Permalink
[feature 162171026] Implement follow user functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
edogbosunny committed Dec 13, 2018
1 parent 079c118 commit 46ca428
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 4 deletions.
6 changes: 3 additions & 3 deletions controllers/FollowersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class FollowersController {
// console.log(following);
if (following.length === 0) {
const payload = {
message: 'You have no followers'
message: 'You have no followers following you'
};
return StatusResponse.conflict(res, payload);
return StatusResponse.success(res, payload);
}
return res.status(200).send({
message: following
Expand All @@ -124,7 +124,7 @@ class FollowersController {
const { followingId } = req.params;
const { userId } = res.locals.user;
const verifyFollowerUsernameAndId = await FollowersModelQuery
.findFollowingByUsernameAndId(followingId, userId);
.findFollowingById(followingId, userId);
if (!verifyFollowerUsernameAndId) {
return res.send({ message: 'you are not following this user' });
}
Expand Down
11 changes: 10 additions & 1 deletion seeders/20181211173050-users-seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ export default {
createdAt: new Date(),
updatedAt: new Date(),
roleId: 3,
}], {}),
},
{
email: 'usertest@heimdal.com',
password: '$2y$08$pAT7OB/WXBR2bHlnIWsNieFTOHCxuSL73sCHJdvUNe7s7uCAcavy2',
emailVerification: true,
createdAt: new Date(),
updatedAt: new Date(),
roleId: 3,
}
], {}),

down: (queryInterface, Sequelize) => {
/*
Expand Down
6 changes: 6 additions & 0 deletions seeders/20181212033227-profiles-seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export default {
createdAt: new Date(),
updatedAt: new Date(),
userId: 5,
},
{
username: 'user1',
createdAt: new Date(),
updatedAt: new Date(),
userId: 6,
}], {}),

down: (queryInterface, Sequelize) => {
Expand Down
84 changes: 84 additions & 0 deletions test/follows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import chai from 'chai';
import chaiHttp from 'chai-http';
import db from '../models';
import app from '../index';
import getToken from '../helpers/getToken';

const { users } = db;
chai.use(chaiHttp);

chai.use(chaiHttp);
chai.should();

describe('Test To Follow, Unfollow user, View Followes, and view following', async () => {
let token;
// let id;
let user;
before(async () => {
const userInfo = {
username: 'sunny',
password: 'sunny12345',
email: 'sunny@gmail.com'
};
user = await users.create(userInfo);
token = getToken(user.id, user.username);
// ({ id } = user);
});

describe('Test to login an existing user', () => {
it('should return 200 on following a user', async () => {
const res = await chai
.request(app)
.post('/api/v1/users/2/follow')
.set('access-token', token);
res.status.should.equal(200);
res.body.should.have.a('object');
res.body.should.have.property('message');
});
it('should return 200 on getting all followers', async () => {
const res = await chai
.request(app)
.get('/api/v1/users/follow')
.set('access-token', token);
res.status.should.equal(200);
res.body.should.have.a('object');
res.body.should.have.property('message');
});

it('should return 200 on getting all users following you', async () => {
const res = await chai
.request(app)
.get('/api/v1/users/following')
.set('access-token', token);
res.status.should.equal(200);
res.body.should.have.a('object');
res.body.should.have.property('message');
});

it('should return 200 on unfollowing a users', async () => {
const res = await chai
.request(app)
.post('/api/v1/users/2/unfollow')
.set('access-token', token);
res.status.should.equal(200);
res.body.should.have.a('object');
console.log(res.body);
res.body.should.have.property('message');
});
// it('should return 200 on successful update of article', async () => {
// const res = await chai
// .request(app)
// .put('/api/v1/articles/this-is-trd-post-title-u87ddsa')
// .set('access-token', userToken)
// .send({
// title: 'This is a title',
// description: 'This is a description',
// body: ' his is a powerful article'
// });
// res.status.should.equal(200);
// res.body.should.have.a('object');
// res.body.should.have.property('message');
// res.body.message.should.equal('Article updated successfully');
// });
});
});

0 comments on commit 46ca428

Please sign in to comment.