This repository has been archived by the owner on Jul 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the function in middleware to check for unread notfications created notification controller created route for created seeders to test the functionalit added tests for the functions added swagger documentation [ Finishes #170947565 ]
- Loading branch information
Showing
14 changed files
with
173 additions
and
43 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module.exports = { | ||
up: (queryInterface) => queryInterface.bulkInsert( | ||
'Notifications', [ | ||
{ | ||
id: '51j74d57-1910-4f50-9h15-b23740331od5', | ||
status: 'unread', | ||
recieverEmail: 'jdev@andela.com', | ||
recieverId: '79660e6f-4b7d-4g21-81re-74f54jk91c8a', | ||
content: 'Your trip to Gisenyi on 2020-02-01 has been approved', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
{ | ||
id: '01q74d57-1995-h45h-592f-b23740331od5', | ||
status: 'read', | ||
recieverEmail: 'jdev@andela.com', | ||
recieverId: '79660e6f-4b7d-4g21-81re-74f54jk91c8a', | ||
content: 'You have been assign Jamie Jules as your manager', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
{ | ||
id: '91q74d57-1695-h40h-590f-b25b4063tod5', | ||
status: 'unread', | ||
recieverEmail: 'jeanne@andela.com', | ||
recieverId: '79660e6f-4b7d-4g21-81re-74f54e9e1c8a', | ||
content: 'You have been assign Jamie Jules as your manager', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
},], | ||
{}, | ||
), | ||
down: (queryInterface) => queryInterface.bulkDelete('Notifications', 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,23 @@ | ||
/** | ||
* @swagger | ||
* /api/v1/notifications/all-as-read: | ||
* patch: | ||
* security: | ||
* - bearerAuth: [] | ||
* tags: | ||
* - Notifications | ||
* name: markAllNotificationsAsRead | ||
* summary: enables a user to mark all as read | ||
* produces: | ||
* - application/json | ||
* parameters: | ||
* - name: token | ||
* in: header | ||
* responses: | ||
* '200': | ||
* description: all unread notifications marked as read. | ||
* '404': | ||
* description: no unread notifications. | ||
* '500': | ||
* description: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import app from '../index'; | ||
|
||
const { expect } = chai; | ||
chai.use(chaiHttp); | ||
let token; | ||
|
||
describe('MARK ALL AS READ TESTS', () => { | ||
before((done) => { | ||
chai | ||
.request(app) | ||
.post('/api/v1/auth/login') | ||
.send({ | ||
email: 'jdev@andela.com', | ||
password: 'Bien@BAR789' | ||
}) | ||
.end((err, res) => { | ||
token = res.body.data; | ||
done(); | ||
}); | ||
}); | ||
it('should return all notfications marked as read', (done) => { | ||
chai | ||
.request(app) | ||
.patch('/api/v1/notifications/all-as-read') | ||
.set('token', token) | ||
.end((err, res) => { | ||
expect(res.status).to.equal(200); | ||
expect(res.body.message).to.equal('all unread notifications marked as read'); | ||
done(); | ||
}); | ||
}); | ||
it('should return no unread notifications', (done) => { | ||
chai | ||
.request(app) | ||
.patch('/api/v1/notifications/all-as-read') | ||
.set('token', token) | ||
.end((err, res) => { | ||
// console.log(res.body); | ||
expect(res.status).to.equal(404); | ||
expect(res.body.error).to.equal('no unread notifications'); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,16 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import db from '../../models'; | ||
|
||
|
||
const { expect } = chai; | ||
chai.use(chaiHttp); | ||
|
||
describe('NOTIFICATION UNIT TESTS', () => { | ||
it('should return unread notifications of user', async () => { | ||
const unreadNotifications = await db.Notifications.findAll({ | ||
where: { recieverId: '79660e6f-4b7d-4g21-81re-74f54jk91c8a', status: 'unread' } | ||
}); | ||
expect(unreadNotifications).to.be.an('array'); | ||
}); | ||
}); |