X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fnotifications%2Fnotifications-api.ts;h=78864c8a04f8f9782e67c80798e14fcc63825ba3;hb=d0800f7661f13fabe7bb6f4aa0ea50764f106405;hp=1ed98ae7aba8b3f497cc21d22cb3710e3133c95f;hpb=2c27e70471120c92e0bc8c8114141fbb31ff98ac;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 1ed98ae7a..78864c8a0 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -5,28 +5,19 @@ import * as chai from 'chai' import { CheckerBaseParams, checkNewVideoFromSubscription, - cleanupTests, getAllNotificationsSettings, - getMyUserInformation, - getUserNotifications, - immutableAssign, - markAsReadAllNotifications, - markAsReadNotifications, MockSmtpServer, - prepareNotificationsTest, - ServerInfo, - updateMyNotificationSettings, - uploadRandomVideo, - waitJobs -} from '@shared/extra-utils' -import { User, UserNotification, UserNotificationSettingValue } from '@shared/models' + prepareNotificationsTest +} from '@server/tests/shared' +import { UserNotification, UserNotificationSettingValue } from '@shared/models' +import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' const expect = chai.expect describe('Test notifications API', function () { - let server: ServerInfo + let server: PeerTubeServer let userNotifications: UserNotification[] = [] - let userAccessToken: string + let userToken: string let emails: object[] = [] before(async function () { @@ -34,65 +25,72 @@ 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.subscriptions.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { - await uploadRandomVideo(server, 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 res = await getUserNotifications(server.url, userAccessToken, 2, 3) - const ids = res.body.data.map(n => n.id) + const { data } = await server.notifications.list({ token: userToken, start: 2, count: 3 }) + const ids = data.map(n => n.id) - await markAsReadNotifications(server.url, userAccessToken, ids) + await server.notifications.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.notifications.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.notifications.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.notifications.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.notifications.markAsReadAll({ token: userToken }) - const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) + const body = await server.notifications.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,99 +102,102 @@ 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.notifications.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) - const info = res.body as User + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, shortUUID } = await server.videos.randomUpload() const check = { web: true, mail: true } - await checkNewVideoFromSubscription(immutableAssign(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 updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.WEB - })) + await server.notifications.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) - const info = res.body as User + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, shortUUID } = await server.videos.randomUpload() { const check = { mail: true, web: false } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) } { const check = { mail: false, web: true } - await checkNewVideoFromSubscription(immutableAssign(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 updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.EMAIL - })) + await server.notifications.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) - const info = res.body as User + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, shortUUID } = await server.videos.randomUpload() { const check = { mail: false, web: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) } { const check = { mail: true, web: false } - await checkNewVideoFromSubscription(immutableAssign(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 updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL - })) + await server.notifications.updateMySettings({ + token: userToken, + settings: { + ...getAllNotificationsSettings(), + newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL + } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) - const info = res.body as User + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal( UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL ) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, shortUUID } = await server.videos.randomUpload() - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) })