-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
164796905-feature: Implement article reporting
Complete implementation of article reporting [#164796905]
- Loading branch information
1 parent
978f95b
commit aefdd57
Showing
13 changed files
with
234 additions
and
44 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
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 |
---|---|---|
@@ -1,23 +1,25 @@ | ||
export default { | ||
up: queryInterface => queryInterface.bulkInsert( | ||
'report', | ||
'article_reports', | ||
[ | ||
{ | ||
id: '979eaa2e-5b8f-4103-8192-4639afae2bb9', | ||
articleId: '979eaa2e-5b8f-4103-8192-4639afae2ba8', | ||
description: 'Plagiarism by Sanusi', | ||
reporterId: '979eaa2e-5b8f-4103-8192-4639afae2ba9', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
{ | ||
id: '979eaa2e-5b8f-4103-8192-4639afae2bb8', | ||
articleId: '979eaa2e-5b8f-4103-8192-4639afae2ba7', | ||
description: 'Plagiarism by Micah', | ||
reporterId: '979eaa2e-5b8f-4103-8192-4639afae2ba9', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
], | ||
{} | ||
), | ||
down: queryInterface => queryInterface.bulkDelete('report', null, {}), | ||
down: queryInterface => queryInterface.bulkDelete('article_reports', null, {}), | ||
}; |
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,71 @@ | ||
import 'chai/register-should'; | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import { startServer } from '../../src/server'; | ||
import Auth from '../../src/middlewares/authenticator'; | ||
|
||
const user = { | ||
id: '979eaa2e-5b8f-4103-8192-4639afae2ba8', | ||
fullName: 'Martins Aloba', | ||
role: 'admin', | ||
username: 'martinsaloba' | ||
}; | ||
|
||
chai.use(chaiHttp); | ||
|
||
describe('Article Report API test', () => { | ||
let app = null; | ||
let agent = null; | ||
beforeEach(async () => { | ||
app = await startServer(6000); | ||
agent = chai.request(app); | ||
}); | ||
afterEach(async () => { | ||
app = null; | ||
agent = null; | ||
}); | ||
it('should report an article', (done) => { | ||
agent | ||
.post('/api/v1/articles/979eaa2e-5b8f-4103-8192-4639afae2ba8/reports') | ||
.set({ Authorization: Auth.generateToken(user) }) | ||
.send({ description: 'article contains plagiarized content', category: 'plagiarism' }) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
res.should.have.status(200); | ||
res.body.status.should.equal('success'); | ||
res.body.data.description.should.equal('article contains plagiarized content'); | ||
res.body.data.reportCategory.should.equal('plagiarism'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return a database error for an article that doesn\'t exist', (done) => { | ||
agent | ||
.post('/api/v1/articles/979eaa2e-5b8f-4103-8192-4639afae2ba/reports') | ||
.set({ Authorization: Auth.generateToken(user) }) | ||
.send({ description: 'article contains plagiarized content', category: 'plagiarism' }) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
res.should.have.status(500); | ||
res.body.should.have.property('message'); | ||
res.body.status.should.equal('error'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return an error for an invalid request body', (done) => { | ||
agent | ||
.post('/api/v1/articles/979eaa2e-5b8f-4103-8192-4639afae2ba/reports') | ||
.set({ Authorization: Auth.generateToken(user) }) | ||
.send({ category: 'plagiarism' }) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
res.should.have.status(400); | ||
res.body.status.should.equal('fail'); | ||
res.body.should.have.property('data'); | ||
res.body.data.should.be.an('object'); | ||
res.body.data.description.should.equal('Please supply a description of your report'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.