From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- .../api/notifications/comments-notifications.ts | 46 +++++++------------ .../api/notifications/moderation-notifications.ts | 51 ++++++++-------------- .../tests/api/notifications/notifications-api.ts | 11 +++-- .../tests/api/notifications/user-notifications.ts | 19 ++++---- 4 files changed, 48 insertions(+), 79 deletions(-) (limited to 'server/tests/api/notifications') diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index 62569f810..a74b38e8a 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -10,7 +10,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - uploadVideo, waitJobs } from '@shared/extra-utils' import { UserNotification } from '@shared/models' @@ -53,8 +52,7 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification after a comment on another video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id @@ -66,8 +64,7 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification if I comment my own video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' }) const commentId = created.id @@ -81,8 +78,7 @@ describe('Test comments notifications', function () { await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id @@ -96,8 +92,7 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a local comment on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id @@ -109,8 +104,7 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a remote comment on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) await waitJobs(servers) @@ -128,8 +122,7 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a local reply on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) @@ -142,8 +135,7 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a remote reply on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) await waitJobs(servers) { @@ -169,8 +161,7 @@ describe('Test comments notifications', function () { it('Should convert markdown in comment to html', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'cool video' } }) await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText }) @@ -199,8 +190,7 @@ describe('Test comments notifications', function () { it('Should not send a new mention comment notification if I mention the video owner', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) @@ -211,8 +201,7 @@ describe('Test comments notifications', function () { it('Should not send a new mention comment notification if I mention myself', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) @@ -225,8 +214,7 @@ describe('Test comments notifications', function () { await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) @@ -239,8 +227,7 @@ describe('Test comments notifications', function () { it('Should not send a new mention notification if the remote account mention a local account', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) await waitJobs(servers) const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) @@ -252,8 +239,7 @@ describe('Test comments notifications', function () { it('Should send a new mention notification after local comments', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) @@ -269,8 +255,7 @@ describe('Test comments notifications', function () { it('Should send a new mention notification after remote comments', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) await waitJobs(servers) @@ -301,8 +286,7 @@ describe('Test comments notifications', function () { it('Should convert markdown in comment to html', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' }) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 0269124c5..91a2b4fa5 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -17,12 +17,10 @@ import { checkVideoAutoBlacklistForModerators, checkVideoIsPublished, cleanupTests, - getVideoIdFromUUID, MockInstancesIndex, MockSmtpServer, prepareNotificationsTest, ServerInfo, - uploadVideo, wait, waitJobs } from '@shared/extra-utils' @@ -64,8 +62,7 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' }) @@ -77,12 +74,11 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await waitJobs(servers) - const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) + const videoId = await servers[1].videosCommand.getId({ uuid: video.uuid }) await servers[1].abusesCommand.report({ videoId, reason: 'super reason' }) await waitJobs(servers) @@ -93,8 +89,7 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) const comment = await servers[0].commentsCommand.createThread({ token: userAccessToken, videoId: video.id, @@ -113,8 +108,7 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await servers[0].commentsCommand.createThread({ token: userAccessToken, @@ -150,7 +144,7 @@ describe('Test moderation notifications', function () { const username = 'user' + new Date().getTime() const tmpToken = await servers[0].usersCommand.generateUserAndToken(username) - await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) + await servers[0].videosCommand.upload({ token: tmpToken, attributes: { name: 'super video' } }) await waitJobs(servers) @@ -175,8 +169,7 @@ describe('Test moderation notifications', function () { } const name = 'abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) abuseId = body.abuse.id @@ -223,8 +216,7 @@ describe('Test moderation notifications', function () { } const name = 'abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) { const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) @@ -294,8 +286,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await servers[0].blacklistCommand.add({ videoId: uuid }) @@ -307,8 +298,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await servers[0].blacklistCommand.add({ videoId: uuid }) @@ -497,8 +487,8 @@ describe('Test moderation notifications', function () { this.timeout(40000) videoName = 'video with auto-blacklist ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) - videoUUID = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: videoName } }) + videoUUID = uuid await waitJobs(servers) await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') @@ -544,17 +534,16 @@ describe('Test moderation notifications', function () { const name = 'video with auto-blacklist and future schedule ' + buildUUID() - const data = { + const attributes = { name, privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) await servers[0].blacklistCommand.remove({ videoId: uuid }) @@ -577,17 +566,16 @@ describe('Test moderation notifications', function () { const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() - const data = { + const attributes = { name, privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) await wait(6000) await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') @@ -601,8 +589,7 @@ describe('Test moderation notifications', function () { const name = 'video without auto-blacklist ' + buildUUID() // admin with blacklist right will not be auto-blacklisted - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name } }) await waitJobs(servers) await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index f33d8e64d..41e1b8015 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -10,7 +10,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - uploadRandomVideo, waitJobs } from '@shared/extra-utils' import { UserNotification, UserNotificationSettingValue } from '@shared/models' @@ -35,7 +34,7 @@ describe('Test notifications API', function () { await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { - await uploadRandomVideo(server, false) + await server.videosCommand.randomUpload({ wait: false }) } await waitJobs([ server ]) @@ -112,7 +111,7 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, uuid } = await server.videosCommand.randomUpload() const check = { web: true, mail: true } await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') @@ -131,7 +130,7 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, uuid } = await server.videosCommand.randomUpload() { const check = { mail: true, web: false } @@ -157,7 +156,7 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, uuid } = await server.videosCommand.randomUpload() { const check = { mail: false, web: true } @@ -188,7 +187,7 @@ describe('Test notifications API', function () { ) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, uuid } = await server.videosCommand.randomUpload() await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 465349fb9..4db8c1576 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -14,7 +14,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - updateVideo, uploadRandomVideoOnServers, wait, waitJobs @@ -99,7 +98,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) @@ -118,7 +117,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) @@ -137,7 +136,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) @@ -154,7 +153,7 @@ describe('Test user notifications', function () { await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') - await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) + await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') @@ -168,7 +167,7 @@ describe('Test user notifications', function () { await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') - await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) + await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') @@ -180,7 +179,7 @@ describe('Test user notifications', function () { const data = { privacy: VideoPrivacy.PRIVATE } const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) - await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) + await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') }) @@ -191,7 +190,7 @@ describe('Test user notifications', function () { const data = { privacy: VideoPrivacy.PRIVATE } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) - await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) + await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') @@ -295,7 +294,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) @@ -313,7 +312,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) -- cgit v1.2.3