From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/api/moderation/abuses.ts | 57 ++++++------ .../tests/api/moderation/blocklist-notification.ts | 16 +--- server/tests/api/moderation/blocklist.ts | 100 +++++++++------------ server/tests/api/moderation/video-blacklist.ts | 92 +++++++++---------- 4 files changed, 118 insertions(+), 147 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index a7119263c..7574b8f4a 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -7,13 +7,8 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideoIdFromUUID, - getVideosList, - removeVideo, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' @@ -47,28 +42,30 @@ describe('Test abuses', function () { this.timeout(50000) // Upload some videos on each servers - const video1Attributes = { - name: 'my super name for server 1', - description: 'my super description for server 1' + { + const attributes = { + name: 'my super name for server 1', + description: 'my super description for server 1' + } + await servers[0].videosCommand.upload({ attributes }) } - await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) - const video2Attributes = { - name: 'my super name for server 2', - description: 'my super description for server 2' + { + const attributes = { + name: 'my super name for server 2', + description: 'my super description for server 2' + } + await servers[1].videosCommand.upload({ attributes }) } - await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) - const res = await getVideosList(servers[0].url) - const videos = res.body.data - - expect(videos.length).to.equal(2) + const { data } = await servers[0].videosCommand.list() + expect(data.length).to.equal(2) - servers[0].video = videos.find(video => video.name === 'my super name for server 1') - servers[1].video = videos.find(video => video.name === 'my super name for server 2') + servers[0].video = data.find(video => video.name === 'my super name for server 1') + servers[1].video = data.find(video => video.name === 'my super name for server 2') }) it('Should not have abuses', async function () { @@ -130,7 +127,7 @@ describe('Test abuses', function () { this.timeout(10000) const reason = 'my super bad reason 2' - const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) + const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) await commands[0].report({ videoId, reason }) // We wait requests propagation @@ -203,7 +200,7 @@ describe('Test abuses', function () { this.timeout(10000) { - const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) + const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid }) await commands[1].report({ videoId, reason: 'will mute this' }) await waitJobs(servers) @@ -255,7 +252,7 @@ describe('Test abuses', function () { it('Should keep the video abuse when deleting the video', async function () { this.timeout(10000) - await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) + await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid }) await waitJobs(servers) @@ -279,12 +276,12 @@ describe('Test abuses', function () { const userAccessToken = await servers[0].loginCommand.getAccessToken(user) // upload a third video via this user - const video3Attributes = { + const attributes = { name: 'my second super name for server 1', description: 'my second super description for server 1' } - const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) - const video3Id = resUpload.body.video.id + const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) + const video3Id = id // resume with the test const reason3 = 'my super bad reason 3' @@ -394,7 +391,7 @@ describe('Test abuses', function () { async function getComment (server: ServerInfo, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' - ? await getVideoIdFromUUID(server.url, videoIdArg) + ? await server.videosCommand.getId({ uuid: videoIdArg }) : videoIdArg const { data } = await server.commentsCommand.listThreads({ videoId }) @@ -405,8 +402,8 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) - servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) + servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' }) + servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' }) await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) @@ -604,7 +601,7 @@ describe('Test abuses', function () { await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) const token = await servers[1].usersCommand.generateUserAndToken('user_2') - await uploadVideo(servers[1].url, token, { name: 'super video' }) + await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } }) await waitJobs(servers) }) @@ -766,7 +763,7 @@ describe('Test abuses', function () { await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) - const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) + const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) }) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index b44bcb012..92a0ec681 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,15 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '@shared/extra-utils' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' const expect = chai.expect @@ -44,8 +36,8 @@ describe('Test blocklist', function () { await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) { - const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } }) + videoUUID = uuid await waitJobs(servers) } @@ -83,7 +75,7 @@ describe('Test blocklist', function () { }) userToken1 = await servers[0].loginCommand.getAccessToken(user) - await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) + await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index c253b5c11..3c3b2d6fd 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -8,28 +8,23 @@ import { CommentsCommand, doubleFollow, flushAndRunMultipleServers, - getVideosList, - getVideosListWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' -import { UserNotificationType, Video } from '@shared/models' +import { UserNotificationType } from '@shared/models' const expect = chai.expect async function checkAllVideos (server: ServerInfo, token: string) { { - const res = await getVideosListWithToken(server.url, token) - - expect(res.body.data).to.have.lengthOf(5) + const { data } = await server.videosCommand.listWithToken({ token }) + expect(data).to.have.lengthOf(5) } { - const res = await getVideosList(server.url) - - expect(res.body.data).to.have.lengthOf(5) + const { data } = await server.videosCommand.list() + expect(data).to.have.lengthOf(5) } } @@ -93,7 +88,7 @@ describe('Test blocklist', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) userToken1 = await servers[0].loginCommand.getAccessToken(user) - await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) + await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { @@ -108,22 +103,22 @@ describe('Test blocklist', function () { await servers[1].usersCommand.create({ username: user.username, password: user.password }) userToken2 = await servers[1].loginCommand.getAccessToken(user) - await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) + await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } }) } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) - videoUUID1 = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) + videoUUID1 = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) - videoUUID2 = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) + videoUUID2 = uuid } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) - videoUUID3 = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) + videoUUID3 = uuid } await doubleFollow(servers[0], servers[1]) @@ -164,12 +159,11 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).to.be.undefined }) @@ -178,12 +172,11 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v = videos.find(v => v.name === 'video user 1') + const v = data.find(v => v.name === 'video user 1') expect(v).to.be.undefined }) @@ -313,12 +306,10 @@ describe('Test blocklist', function () { }) it('Should display its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() + expect(data).to.have.lengthOf(4) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) - - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).not.to.be.undefined }) @@ -387,13 +378,12 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v1 = videos.find(v => v.name === 'video user 2') - const v2 = videos.find(v => v.name === 'video server 2') + const v1 = data.find(v => v.name === 'video user 2') + const v2 = data.find(v => v.name === 'video server 2') expect(v1).to.be.undefined expect(v2).to.be.undefined @@ -498,12 +488,11 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) + const { data } = await servers[0].videosCommand.listWithToken({ token }) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).to.be.undefined } }) @@ -514,12 +503,11 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) + const { data } = await servers[0].videosCommand.listWithToken({ token }) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v = videos.find(v => v.name === 'video user 1') + const v = data.find(v => v.name === 'video user 1') expect(v).to.be.undefined } }) @@ -593,12 +581,10 @@ describe('Test blocklist', function () { it('Should display its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + const { data } = await servers[0].videosCommand.listWithToken({ token }) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).not.to.be.undefined } }) @@ -652,15 +638,17 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res1 = await getVideosList(servers[0].url) - const res2 = await getVideosListWithToken(servers[0].url, token) + const requests = [ + servers[0].videosCommand.list(), + servers[0].videosCommand.listWithToken({ token }) + ] - for (const res of [ res1, res2 ]) { - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + for (const req of requests) { + const { data } = await req + expect(data).to.have.lengthOf(3) - const v1 = videos.find(v => v.name === 'video user 2') - const v2 = videos.find(v => v.name === 'video server 2') + const v1 = data.find(v => v.name === 'video user 2') + const v2 = data.find(v => v.name === 'video server 2') expect(v1).to.be.undefined expect(v2).to.be.undefined diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index ef25cfb8e..2f2e678e7 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -8,15 +8,11 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideos, - getVideosList, ImportsCommand, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, waitJobs } from '@shared/extra-utils' import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' @@ -29,10 +25,9 @@ describe('Test video blacklist', function () { let command: BlacklistCommand async function blacklistVideosOnServer (server: ServerInfo) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - for (const video of videos) { + for (const video of data) { await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) } } @@ -50,8 +45,8 @@ describe('Test video blacklist', function () { await doubleFollow(servers[0], servers[1]) // Upload 2 videos on server 2 - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) + await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } }) + await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } }) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) @@ -66,11 +61,11 @@ describe('Test video blacklist', function () { it('Should not have the video blacklisted in videos list/search on server 1', async function () { { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data.length).to.equal(0) } { @@ -84,11 +79,11 @@ describe('Test video blacklist', function () { it('Should have the blacklisted video in videos list/search on server 2', async function () { { - const res = await getVideosList(servers[1].url) + const { total, data } = await servers[1].videosCommand.list() - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(2) + expect(total).to.equal(2) + expect(data).to.be.an('array') + expect(data.length).to.equal(2) } { @@ -186,12 +181,12 @@ describe('Test video blacklist', function () { it('Should display blacklisted videos', async function () { await blacklistVideosOnServer(servers[1]) - const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) + const { total, data } = await servers[1].videosCommand.listMyVideos() - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + expect(total).to.equal(2) + expect(data).to.have.lengthOf(2) - for (const video of res.body.data) { + for (const video of data) { expect(video.blacklisted).to.be.true expect(video.blacklistedReason).to.equal('super reason') } @@ -203,10 +198,10 @@ describe('Test video blacklist', function () { let blacklist = [] it('Should not have any video in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data.length).to.equal(0) }) it('Should remove a video from the blacklist on server 1', async function () { @@ -220,15 +215,14 @@ describe('Test video blacklist', function () { }) it('Should have the ex-blacklisted video in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(1) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) - expect(videos[0].name).to.equal(videoToRemove.video.name) - expect(videos[0].id).to.equal(videoToRemove.video.id) + expect(data[0].name).to.equal(videoToRemove.video.name) + expect(data[0].id).to.equal(videoToRemove.video.id) }) it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { @@ -250,12 +244,12 @@ describe('Test video blacklist', function () { this.timeout(10000) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) - video3UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } }) + video3UUID = uuid } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) - video4UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } }) + video4UUID = uuid } await waitJobs(servers) @@ -269,13 +263,13 @@ describe('Test video blacklist', function () { await waitJobs(servers) { - const res = await getVideosList(servers[0].url) - expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined + const { data } = await servers[0].videosCommand.list() + expect(data.find(v => v.uuid === video3UUID)).to.be.undefined } { - const res = await getVideosList(servers[1].url) - expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined + const { data } = await servers[1].videosCommand.list() + expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined } }) @@ -287,21 +281,21 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) it('Should have the video unfederated even after an Update AP message', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) + await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) @@ -324,8 +318,8 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined } }) @@ -383,7 +377,7 @@ describe('Test video blacklist', function () { }) it('Should auto blacklist a video on upload', async function () { - await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) + await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(1) @@ -419,7 +413,7 @@ describe('Test video blacklist', function () { }) it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { - await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) + await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) -- cgit v1.2.3