-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(notification):user can mark all notification as read
[finishes #167727473]
- Loading branch information
Showing
7 changed files
with
144 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,33 @@ | ||
import models from '../db/models'; | ||
|
||
const { Notification } = models; | ||
|
||
|
||
/* eslint-disable */ | ||
export default class NotificationContoller { | ||
static markAsRead(req, res) { | ||
|
||
|
||
Notification.update( { read: true },{where: { receiver_id: req.currentUser.id },attributes: ['read']}) | ||
.then((data) => { | ||
if (data) { | ||
return res.status(200).json({ | ||
status: 'success', | ||
data:data[1], | ||
message: 'All Notification marked as read' | ||
}); | ||
} | ||
return res.status(404).json({ | ||
status: 'error', | ||
error: 'No notification found' | ||
}); | ||
}) | ||
.catch((err) => { | ||
res.status(500).json({ | ||
status: 'error', | ||
message: err.message, | ||
info: 'Internal Server Error', | ||
}); | ||
}); | ||
} | ||
} |
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,11 @@ | ||
import express from 'express'; | ||
import Notification from '../../controllers/notification.controller'; | ||
import auth from '../../middlewares/auth'; | ||
|
||
|
||
const router = express.Router(); | ||
|
||
|
||
router.get('/mark-read', auth.verifyUserToken, Notification.markAsRead); | ||
|
||
export default router; |
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,89 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import sinon from 'sinon'; | ||
import app from '../index'; | ||
import models from '../db/models' | ||
|
||
|
||
const {Notification} = models; | ||
let userToken = ''; | ||
chai.use(chaiHttp); | ||
chai.should(); | ||
const { expect } = chai; | ||
|
||
before(() => { | ||
it('it should login user', (done) => { | ||
chai | ||
.request(app) | ||
.post('/api/v1/auth/signin') | ||
.send({ | ||
email: 'jane_doe@email.com', | ||
password: 'asdfghjkl', | ||
}) | ||
.end((err, res) => { | ||
userToken = res.body.data.token; | ||
res.body.should.have.property('status').to.equals('success'); | ||
res.body.should.have.property('data').to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('UNIT TESTS FOR NOTIFICATION', () => { | ||
describe('/POST REQUEST', () => { | ||
it('it should mark all notification as read ', (done) => { | ||
chai | ||
.request(app) | ||
.get('/api/v1/mark-read') | ||
.set('authorization', `Bearer ${userToken}`) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.should.be.an('object'); | ||
res.body.should.have.property('status').to.equals('success'); | ||
res.body.should.have | ||
.property('message') | ||
.to.equals('All Notification marked as read'); | ||
|
||
done(); | ||
}); | ||
}); | ||
it('it should not mark all notification as read ', (done) => { | ||
const stub = sinon.stub(Notification, 'update').returns(new Promise((resolve,reject) => { | ||
resolve(null); | ||
})) | ||
chai | ||
.request(app) | ||
.get('/api/v1/mark-read') | ||
.set('authorization', `Bearer ${userToken}`) | ||
.end((err, res) => { | ||
stub.restore(); | ||
res.should.have.status(404); | ||
res.body.should.be.an('object'); | ||
res.body.should.have.property('status').to.equals('error'); | ||
res.body.should.have | ||
.property('error') | ||
.to.equals('No notification found'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
it('it should not mark all notification for internal server error 500', (done) => { | ||
const stub = sinon.stub(Notification, 'update').throws(new Error()) | ||
chai.request(app) | ||
.get('/api/v1/mark-read') | ||
.set('authorization', `Bearer ${userToken}`) | ||
.end((err, res) => { | ||
stub.restore(); | ||
expect(res).to.have.status(500); | ||
expect(res.body).to.have.keys('status','error'); | ||
expect(res.body.status).to.deep.equal('error'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
|
||
|