-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2997-include only notification service
- Loading branch information
1 parent
e7df823
commit 91b5429
Showing
9 changed files
with
130 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
import express from 'express'; | ||
import NotificationsController from '../controllers/notifications.controllers'; | ||
import { nonEmptyString, validateInputs } from '../utils/validation.utils'; | ||
import { body } from 'express-validator'; | ||
|
||
const notificationsRouter = express.Router(); | ||
|
||
notificationsRouter.post('/task-deadlines', NotificationsController.sendDailySlackNotifications); | ||
notificationsRouter.post( | ||
'/send/users', | ||
nonEmptyString(body('text')), | ||
nonEmptyString(body('iconName')), | ||
body('userIds').isArray(), | ||
nonEmptyString(body('userIds.*')), | ||
validateInputs, | ||
NotificationsController.sendNotificationToUsers | ||
); | ||
|
||
export default notificationsRouter; |
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,59 @@ | ||
import { Organization } from '@prisma/client'; | ||
import { createTestOrganization, createTestUser, resetUsers } from '../test-utils'; | ||
import { batmanAppAdmin, supermanAdmin } from '../test-data/users.test-data'; | ||
import { NotFoundException } from '../../src/utils/errors.utils'; | ||
import prisma from '../../src/prisma/prisma'; | ||
import NotificationService from '../../src/services/notifications.services'; | ||
|
||
describe('Notifications Tests', () => { | ||
let orgId: string; | ||
let organization: Organization; | ||
beforeEach(async () => { | ||
organization = await createTestOrganization(); | ||
orgId = organization.organizationId; | ||
}); | ||
|
||
afterEach(async () => { | ||
await resetUsers(); | ||
}); | ||
|
||
describe('Send Notification', () => { | ||
it('fails on invalid user id', async () => { | ||
await expect( | ||
async () => | ||
await NotificationService.sendNotifcationToUsers( | ||
'test notification', | ||
'star', | ||
['1', '2'], | ||
organization.organizationId | ||
) | ||
).rejects.toThrow(new NotFoundException('User', '1')); | ||
}); | ||
|
||
it('Succeeds and sends notification to user', async () => { | ||
const testBatman = await createTestUser(batmanAppAdmin, orgId); | ||
const testSuperman = await createTestUser(supermanAdmin, orgId); | ||
await NotificationService.sendNotifcationToUsers( | ||
'test notification', | ||
'star', | ||
[testBatman.userId, testSuperman.userId], | ||
organization.organizationId | ||
); | ||
|
||
const batmanWithNotifications = await prisma.user.findUnique({ | ||
where: { userId: testBatman.userId }, | ||
include: { unreadNotifications: true } | ||
}); | ||
|
||
const supermanWithNotifications = await prisma.user.findUnique({ | ||
where: { userId: testBatman.userId }, | ||
include: { unreadNotifications: true } | ||
}); | ||
|
||
expect(batmanWithNotifications?.unreadNotifications).toHaveLength(1); | ||
expect(batmanWithNotifications?.unreadNotifications[0].text).toBe('test notification'); | ||
expect(supermanWithNotifications?.unreadNotifications).toHaveLength(1); | ||
expect(supermanWithNotifications?.unreadNotifications[0].text).toBe('test notification'); | ||
}); | ||
}); | ||
}); |
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