From dd0ebb715123dfa126a82d4e4fe3a04064ae77b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 16:23:01 +0200 Subject: Introduce notifications command --- .../tests/api/notifications/notifications-api.ts | 92 +++++++++++----------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'server/tests/api/notifications/notifications-api.ts') diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 1ed98ae7a..447492c5f 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -8,14 +8,10 @@ import { cleanupTests, getAllNotificationsSettings, getMyUserInformation, - getUserNotifications, immutableAssign, - markAsReadAllNotifications, - markAsReadNotifications, MockSmtpServer, prepareNotificationsTest, ServerInfo, - updateMyNotificationSettings, uploadRandomVideo, waitJobs } from '@shared/extra-utils' @@ -26,7 +22,7 @@ const expect = chai.expect describe('Test notifications API', function () { let server: ServerInfo let userNotifications: UserNotification[] = [] - let userAccessToken: string + let userToken: string let emails: object[] = [] before(async function () { @@ -34,11 +30,11 @@ describe('Test notifications API', function () { const res = await prepareNotificationsTest(1) emails = res.emails - userAccessToken = res.userAccessToken + userToken = res.userAccessToken userNotifications = res.userNotifications server = res.servers[0] - await server.subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + server.port }) + await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { await uploadRandomVideo(server, false) @@ -50,49 +46,46 @@ describe('Test notifications API', function () { describe('Mark as read', function () { it('Should mark as read some notifications', async function () { - const res = await getUserNotifications(server.url, userAccessToken, 2, 3) - const ids = res.body.data.map(n => n.id) + const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 }) + const ids = data.map(n => n.id) - await markAsReadNotifications(server.url, userAccessToken, ids) + await server.notificationsCommand.markAsRead({ token: userToken, ids }) }) it('Should have the notifications marked as read', async function () { - const res = await getUserNotifications(server.url, userAccessToken, 0, 10) - - const notifications = res.body.data as UserNotification[] - expect(notifications[0].read).to.be.false - expect(notifications[1].read).to.be.false - expect(notifications[2].read).to.be.true - expect(notifications[3].read).to.be.true - expect(notifications[4].read).to.be.true - expect(notifications[5].read).to.be.false + const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 }) + + expect(data[0].read).to.be.false + expect(data[1].read).to.be.false + expect(data[2].read).to.be.true + expect(data[3].read).to.be.true + expect(data[4].read).to.be.true + expect(data[5].read).to.be.false }) it('Should only list read notifications', async function () { - const res = await getUserNotifications(server.url, userAccessToken, 0, 10, false) + const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false }) - const notifications = res.body.data as UserNotification[] - for (const notification of notifications) { + for (const notification of data) { expect(notification.read).to.be.true } }) it('Should only list unread notifications', async function () { - const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) + const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) - const notifications = res.body.data as UserNotification[] - for (const notification of notifications) { + for (const notification of data) { expect(notification.read).to.be.false } }) it('Should mark as read all notifications', async function () { - await markAsReadAllNotifications(server.url, userAccessToken) + await server.notificationsCommand.markAsReadAll({ token: userToken }) - const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) + const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) }) @@ -104,19 +97,20 @@ describe('Test notifications API', function () { server: server, emails, socketNotifications: userNotifications, - token: userAccessToken + token: userToken } }) it('Should not have notifications', async function () { this.timeout(20000) - await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.NONE - })) + await server.notificationsCommand.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) + const res = await getMyUserInformation(server.url, userToken) const info = res.body as User expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } @@ -130,12 +124,13 @@ describe('Test notifications API', function () { it('Should only have web notifications', async function () { this.timeout(20000) - await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.WEB - })) + await server.notificationsCommand.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) + const res = await getMyUserInformation(server.url, userToken) const info = res.body as User expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } @@ -156,12 +151,13 @@ describe('Test notifications API', function () { it('Should only have mail notifications', async function () { this.timeout(20000) - await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.EMAIL - })) + await server.notificationsCommand.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) + const res = await getMyUserInformation(server.url, userToken) const info = res.body as User expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } @@ -182,12 +178,16 @@ describe('Test notifications API', function () { it('Should have email and web notifications', async function () { this.timeout(20000) - await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL - })) + await server.notificationsCommand.updateMySettings({ + token: userToken, + settings: { + ...getAllNotificationsSettings(), + newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL + } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) + const res = await getMyUserInformation(server.url, userToken) const info = res.body as User expect(info.notificationSettings.newVideoFromSubscription).to.equal( UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL -- cgit v1.2.3