Skip to content

Commit

Permalink
fix(article & users): fix bugs in both features
Browse files Browse the repository at this point in the history
- fix hashpassword bug in articles feature
- add restriction to length of description in articles
  • Loading branch information
thislekan committed Apr 17, 2019
1 parent 6237594 commit ae65ee6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/controllers/usersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UsersController {
const { body } = request;

try {
const user = await User.create(body, { raw: true });
const user = await User.create(body);
const role = await models.Role.findOne({ where: { name: 'user' } });
await user.setRole(role);
const token = await generateToken({ user });
Expand Down
4 changes: 4 additions & 0 deletions server/middlewares/articlesMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export default class AriclesMiddleware {
return Response.send(res, STATUS.BAD_REQUEST, [], 'category cannot be empty', false);
}

if (description.length > 255) {
return Response.send(res, STATUS.BAD_REQUEST, [], 'description can only be 255 characters maximum', false);
}

try {
const foundArticle = await articleHelpers.findArticleByAuthorId(authorId, title);
if (foundArticle && foundArticle.title === title) {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/middlewares/articlesMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ describe('API endpoint: /api/articles (Middleware test)', () => {
});
});

describe('POST: /api/v1/articles', () => {
describe('create an article with a lengthy description', () => {
it('Should return an error', (done) => {
const article = { ...dummyArticle };
article.description = 'After the success of Peloton’s stationary bike — it has sold hundreds of thousands, though the company won’t provide specifics — Peloton is aggressively expanding to become a full-body, full-service fitness and technology company, and it’s forcing the rest of the industry to follow suit or fall behind.';
chai
.request(app)
.post('/api/v1/articles')
.send(article)
.set({ Authorization: `Bearer ${dummyUser.token}` })
.end((err, res) => {
expect(res).to.have.status(BAD_REQUEST);
expect(res.body).to.be.an('object');
expect(res.body).to.haveOwnProperty('code').to.equal(BAD_REQUEST);
expect(res.body.message).to.equal('description can only be 255 characters maximum');
done();
});
});
});
});

describe('POST: /api/v1/articles', () => {
describe('create an article with a description of numbers', () => {
it('Should return an error', (done) => {
Expand Down

0 comments on commit ae65ee6

Please sign in to comment.