X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fnotifications%2Fnotifications-api.ts;h=f194656c9f8b1eb684812e5f7b53489dd486b340;hb=aac7f4304dc7fa48869cb3f09c30383222add436;hp=41e1b801521c0281cedd70ba83c03511d29eb40a;hpb=d23dd9fbfc4d26026352c10f81d2795ceaf2908a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 41e1b8015..f194656c9 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -1,23 +1,18 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import * as chai from 'chai' +import { expect } from 'chai' import { CheckerBaseParams, checkNewVideoFromSubscription, - cleanupTests, getAllNotificationsSettings, MockSmtpServer, - prepareNotificationsTest, - ServerInfo, - waitJobs -} from '@shared/extra-utils' + prepareNotificationsTest +} from '@server/tests/shared' import { UserNotification, UserNotificationSettingValue } from '@shared/models' - -const expect = chai.expect +import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' describe('Test notifications API', function () { - let server: ServerInfo + let server: PeerTubeServer let userNotifications: UserNotification[] = [] let userToken: string let emails: object[] = [] @@ -31,26 +26,36 @@ describe('Test notifications API', function () { userNotifications = res.userNotifications server = res.servers[0] - await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) + await server.subscriptions.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { - await server.videosCommand.randomUpload({ wait: false }) + await server.videos.randomUpload({ wait: false }) } await waitJobs([ server ]) }) + describe('Notification list & count', function () { + + it('Should correctly list notifications', async function () { + const { data, total } = await server.notifications.list({ token: userToken, start: 0, count: 2 }) + + expect(data).to.have.lengthOf(2) + expect(total).to.equal(10) + }) + }) + describe('Mark as read', function () { it('Should mark as read some notifications', async function () { - const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 }) + const { data } = await server.notifications.list({ token: userToken, start: 2, count: 3 }) const ids = data.map(n => n.id) - await server.notificationsCommand.markAsRead({ token: userToken, ids }) + await server.notifications.markAsRead({ token: userToken, ids }) }) it('Should have the notifications marked as read', async function () { - const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 }) + const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10 }) expect(data[0].read).to.be.false expect(data[1].read).to.be.false @@ -61,7 +66,7 @@ describe('Test notifications API', function () { }) it('Should only list read notifications', async function () { - const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false }) + const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: false }) for (const notification of data) { expect(notification.read).to.be.true @@ -69,7 +74,7 @@ describe('Test notifications API', function () { }) it('Should only list unread notifications', async function () { - const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) + const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true }) for (const notification of data) { expect(notification.read).to.be.false @@ -77,9 +82,9 @@ describe('Test notifications API', function () { }) it('Should mark as read all notifications', async function () { - await server.notificationsCommand.markAsReadAll({ token: userToken }) + await server.notifications.markAsReadAll({ token: userToken }) - const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) + const body = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true }) expect(body.total).to.equal(0) expect(body.data).to.have.lengthOf(0) @@ -91,7 +96,7 @@ describe('Test notifications API', function () { before(() => { baseParams = { - server: server, + server, emails, socketNotifications: userNotifications, token: userToken @@ -101,78 +106,78 @@ describe('Test notifications API', function () { it('Should not have notifications', async function () { this.timeout(20000) - await server.notificationsCommand.updateMySettings({ + await server.notifications.updateMySettings({ token: userToken, settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE } }) { - const info = await server.usersCommand.getMyInfo({ token: userToken }) + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } - const { name, uuid } = await server.videosCommand.randomUpload() + const { name, shortUUID } = await server.videos.randomUpload() const check = { web: true, mail: true } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) }) it('Should only have web notifications', async function () { this.timeout(20000) - await server.notificationsCommand.updateMySettings({ + await server.notifications.updateMySettings({ token: userToken, settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB } }) { - const info = await server.usersCommand.getMyInfo({ token: userToken }) + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } - const { name, uuid } = await server.videosCommand.randomUpload() + const { name, shortUUID } = await server.videos.randomUpload() { const check = { mail: true, web: false } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) } { const check = { mail: false, web: true } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' }) } }) it('Should only have mail notifications', async function () { this.timeout(20000) - await server.notificationsCommand.updateMySettings({ + await server.notifications.updateMySettings({ token: userToken, settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL } }) { - const info = await server.usersCommand.getMyInfo({ token: userToken }) + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } - const { name, uuid } = await server.videosCommand.randomUpload() + const { name, shortUUID } = await server.videos.randomUpload() { const check = { mail: false, web: true } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) } { const check = { mail: true, web: false } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' }) } }) it('Should have email and web notifications', async function () { this.timeout(20000) - await server.notificationsCommand.updateMySettings({ + await server.notifications.updateMySettings({ token: userToken, settings: { ...getAllNotificationsSettings(), @@ -181,15 +186,15 @@ describe('Test notifications API', function () { }) { - const info = await server.usersCommand.getMyInfo({ token: userToken }) + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal( UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL ) } - const { name, uuid } = await server.videosCommand.randomUpload() + const { name, shortUUID } = await server.videos.randomUpload() - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) })