-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(highlight and comment on an article):highlight and comment on…
… an article user can highlight and comment on an article [finishes #166841035]
- Loading branch information
Showing
10 changed files
with
173 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,3 @@ module.exports = (sequelize, DataTypes) => { | |
}; | ||
return CommentHistory; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { body } from 'express-validator'; | ||
|
||
const highlightValidation = { | ||
validatehighlight: [ | ||
body('highlightedWord') | ||
.trim() | ||
.not().isEmpty() | ||
.withMessage('highlighted Word is required.') | ||
], | ||
validateComment: [ | ||
body('comment') | ||
.trim() | ||
.not().isEmpty() | ||
.withMessage('comment is required.') | ||
], | ||
}; | ||
|
||
export default highlightValidation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import chaiHttp from 'chai-http'; | ||
import chai, { expect } from 'chai'; | ||
|
||
import app from '../src/server'; | ||
|
||
chai.use(chaiHttp); | ||
|
||
let userToken; | ||
describe('Testing Higlight and comment Controller', () => { | ||
describe('Testing Higlight and comment controller', () => { | ||
const highlight = '/api/v1/articles/highlight/'; | ||
|
||
// SIGN IN USER TO GET TOKEN | ||
it('should login user successfully', (done) => { | ||
const user = { | ||
email: 'john.doe@andela.com', | ||
password: 'password', | ||
}; | ||
chai.request(app).post('/api/v1/auth/login') | ||
.send(user) | ||
.end((err, res) => { | ||
userToken = res.body.token; | ||
done(); | ||
}); | ||
}); | ||
|
||
const higlighted = { | ||
highlightedWord: 'survived not only', | ||
comment: 'very good' | ||
} | ||
it( | ||
'should highlight and comment if valid', | ||
async () => { | ||
const response = await chai.request(app) | ||
.post(`${highlight}article`) | ||
.set('token', userToken) | ||
.send(higlighted); | ||
expect(response).to.be.an('object'); | ||
expect(response).to.have.status(201); | ||
expect(response.body.message).to.equal(`${higlighted.highlightedWord} has been highlighted`); | ||
}, | ||
); | ||
|
||
it( | ||
'should not highlight and comment if invalid', | ||
async () => { | ||
const response = await chai.request(app) | ||
.post(`${highlight}article`) | ||
.set('token', userToken) | ||
.send({ | ||
highlightedWord: 'survived not onlysssss', | ||
comment: 'very good' | ||
}); | ||
expect(response).to.be.an('object'); | ||
expect(response).to.have.status(400); | ||
expect(response.body.message).to.equal('invalid highlighted word'); | ||
}, | ||
); | ||
|
||
it( | ||
'should not highlight and comment if no highlighted word', | ||
async () => { | ||
const response = await chai.request(app) | ||
.post(`${highlight}article`) | ||
.set('token', userToken) | ||
.send({ | ||
comment: 'very good' | ||
}); | ||
expect(response).to.be.an('object'); | ||
expect(response).to.have.status(400); | ||
expect(response.body).to.have.property('message'); | ||
}, | ||
); | ||
|
||
it( | ||
'should not highlight and comment if no comment', | ||
async () => { | ||
const response = await chai.request(app) | ||
.post(`${highlight}article`) | ||
.set('token', userToken) | ||
.send({ | ||
highlightedWord: 'survived not onlysssss', | ||
}); | ||
expect(response).to.be.an('object'); | ||
expect(response).to.have.status(400); | ||
expect(response.body).to.have.property('message'); | ||
}, | ||
); | ||
}); | ||
}); |