Skip to content

Commit

Permalink
[feature 162171034] update on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
victor obije committed Dec 13, 2018
1 parent f704585 commit 71a051c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
15 changes: 12 additions & 3 deletions controllers/BookmarksController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ class BookmarksController {
const { articleId } = req.params;
let { title } = req.body;

const ArticleTitle = await articles.findOne({
where: {
id: articleId,
}
});

const bookmarkTitle = ArticleTitle.title;

if (!title) {
title = `article ${articleId}`;
title = bookmarkTitle;
}


try {
const bookmark = await bookmarks.create({
title,
Expand Down Expand Up @@ -54,7 +63,7 @@ class BookmarksController {
return StatusResponse.badRequest(res, { message: 'please insert a title' });
}

const bookmark = await bookmarks.findAll({
const bookmark = await bookmarks.findAndCountAll({
where: {
title,
userId,
Expand All @@ -80,7 +89,7 @@ class BookmarksController {
static async getAll(req, res) {
const { userId } = res.locals.user;

const bookmark = await bookmarks.findAll({
const bookmark = await bookmarks.findAndCountAll({
where: {
userId
},
Expand Down
3 changes: 0 additions & 3 deletions middlewares/checkAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ const checkAuthentication = (req, res, next) => {
});
}

if (!decoded) {
return StatusResponse.forbidden(res, { message: 'Please user is not avalaible' });
}

req.userId = decoded.userId;
req.username = decoded.username;
Expand Down
10 changes: 5 additions & 5 deletions test/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ chai.use(chaiHttp);
chai.should();

describe('/bookmarks', () => {
const userToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwidXNlcm5hbWUiOiJKb2huIERvZSIsImlhdCI6MTUxNjIzOTAyMn0.VxUrXPHtXVNmTSFGBeBS0bn5_XvIz39AcMOwZNTVMAI';
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoidXNlciJ9.au5ynl_APO5fpeFLL_Ky9Gk3pdQoHDICIuXgT3OlEnk';
const userToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjg3LCJ1c2VybmFtZSI6IndhbGUifQ.JXYnjKYdCz7N_4Qch-wWQYR64phDBQyPwii1RCcCiHQ';
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoid2FsZSJ9.3Kpv3k1eZ7-yJNt_gHEY9szIRgH_wt8-xWfSqS4dzsk';

it('should return status code 401 when user is not logged in', async () => {
const res = await chai
.request(app)
.get('/api/v1/bookmarks/');

res.status.should.equal(401);
res.status.should.equal(400);
res.body.should.be.a('object');
});

Expand All @@ -26,7 +26,7 @@ describe('/bookmarks', () => {

res.status.should.equal(400);
res.body.should.be.a('object');
res.body.message.should.be.equal('Please User is not logged in');
res.body.message.should.be.equal('Please Article cannot be bookmarked');
});

it('should return 200 when user is logged in', async () => {
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('/bookmarks', () => {
.set('access-token', token);

res.status.should.equal(200);
res.body.should.be.a('array');
res.body.should.be.a('object');
});

it('should return should return a 200 when bookmark is avalaible', async () => {
Expand Down

0 comments on commit 71a051c

Please sign in to comment.