| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- import { beforeEach, describe, expect, it, vi } from 'vitest'
- const modulePath = '../../../app/js/NotificationsController.js'
- const userId = '51dc93e6fb625a261300003b'
- const notificationId = 'fb625a26f09d'
- const notificationKey = 'my-notification-key'
- describe('Notifications Controller', () => {
- let controller, notifications, stubbedNotification
- beforeEach(async () => {
- notifications = {
- addNotification: vi.fn(),
- getUserNotifications: vi.fn(),
- removeNotificationByKeyOnly: vi.fn(),
- removeNotificationId: vi.fn(),
- removeNotificationKey: vi.fn(),
- }
- vi.doMock('../../../app/js/Notifications', () => notifications)
- vi.doMock('@overleaf/metrics', () => ({
- default: {
- inc: vi.fn(),
- },
- }))
- controller = (await import(modulePath)).default
- stubbedNotification = [
- {
- key: notificationKey,
- messageOpts: 'some info',
- templateKey: 'template-key',
- },
- ]
- })
- describe('getUserNotifications', () => {
- it('should ask the notifications for the users notifications', async () => {
- notifications.getUserNotifications.mockResolvedValue(stubbedNotification)
- const req = {
- params: {
- user_id: userId,
- },
- }
- await new Promise(resolve => {
- controller.getUserNotifications(req, {
- json: result => {
- expect(result).toBe(stubbedNotification)
- expect(notifications.getUserNotifications).toHaveBeenCalledWith(
- userId
- )
- resolve()
- },
- })
- })
- })
- })
- describe('addNotification', () => {
- it('should tell the notifications to add the notification for the user', async () => {
- notifications.addNotification.mockResolvedValue()
- const req = {
- params: {
- user_id: userId,
- },
- body: stubbedNotification,
- }
- await new Promise(resolve => {
- controller.addNotification(req, {
- sendStatus: code => {
- expect(notifications.addNotification).toHaveBeenCalledWith(
- userId,
- stubbedNotification
- )
- expect(code).toBe(200)
- resolve()
- },
- })
- })
- })
- })
- describe('removeNotificationId', () => {
- it('should tell the notifications to mark the notification Id as read', async () => {
- notifications.removeNotificationId.mockResolvedValue()
- const req = {
- params: {
- user_id: userId,
- notification_id: notificationId,
- },
- }
- await new Promise(resolve => {
- controller.removeNotificationId(req, {
- sendStatus: code => {
- expect(notifications.removeNotificationId).toHaveBeenCalledWith(
- userId,
- notificationId
- )
- expect(code).toBe(200)
- resolve()
- },
- })
- })
- })
- })
- describe('removeNotificationKey', () => {
- it('should tell the notifications to mark the notification Key as read', async () => {
- notifications.removeNotificationKey.mockResolvedValue()
- const req = {
- params: {
- user_id: userId,
- },
- body: { key: notificationKey },
- }
- await new Promise(resolve => {
- controller.removeNotificationKey(req, {
- sendStatus: code => {
- expect(notifications.removeNotificationKey).toHaveBeenCalledWith(
- userId,
- notificationKey
- )
- expect(code).toBe(200)
- resolve()
- },
- })
- })
- })
- })
- describe('removeNotificationByKeyOnly', () => {
- it('should tell the notifications to mark the notification Key as read', async () => {
- notifications.removeNotificationByKeyOnly.mockResolvedValue()
- const req = {
- params: {
- key: notificationKey,
- },
- }
- await new Promise(resolve =>
- controller.removeNotificationByKeyOnly(req, {
- sendStatus: code => {
- expect(
- notifications.removeNotificationByKeyOnly
- ).toHaveBeenCalledWith(notificationKey)
- expect(code).toBe(200)
- resolve()
- },
- })
- )
- })
- })
- })
|