From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: [PATCH] Introduce videos command --- scripts/benchmark.ts | 11 +- server/tests/api/activitypub/cleaner.ts | 50 +- server/tests/api/activitypub/client.ts | 11 +- server/tests/api/activitypub/fetch.ts | 33 +- server/tests/api/activitypub/refresher.ts | 29 +- server/tests/api/check-params/abuses.ts | 13 +- server/tests/api/check-params/live.ts | 5 +- server/tests/api/check-params/redundancy.ts | 9 +- server/tests/api/check-params/services.ts | 14 +- server/tests/api/check-params/upload-quota.ts | 37 +- server/tests/api/check-params/users.ts | 21 +- .../tests/api/check-params/video-blacklist.ts | 34 +- .../tests/api/check-params/video-captions.ts | 8 +- .../tests/api/check-params/video-comments.ts | 13 +- .../tests/api/check-params/video-playlists.ts | 29 +- .../tests/api/check-params/videos-history.ts | 13 +- server/tests/api/check-params/videos.ts | 109 ++- server/tests/api/live/live-constraints.ts | 7 +- server/tests/api/live/live-permanent.ts | 11 +- server/tests/api/live/live-save-replay.ts | 48 +- server/tests/api/live/live-socket-messages.ts | 16 +- server/tests/api/live/live-views.ts | 18 +- server/tests/api/live/live.ts | 88 +-- server/tests/api/moderation/abuses.ts | 57 +- .../api/moderation/blocklist-notification.ts | 16 +- server/tests/api/moderation/blocklist.ts | 100 ++- .../tests/api/moderation/video-blacklist.ts | 92 ++- .../notifications/comments-notifications.ts | 46 +- .../notifications/moderation-notifications.ts | 51 +- .../api/notifications/notifications-api.ts | 11 +- .../api/notifications/user-notifications.ts | 19 +- .../tests/api/redundancy/manage-redundancy.ts | 15 +- .../api/redundancy/redundancy-constraints.ts | 8 +- server/tests/api/redundancy/redundancy.ts | 57 +- .../search-activitypub-video-channels.ts | 37 +- .../search-activitypub-video-playlists.ts | 9 +- .../api/search/search-activitypub-videos.ts | 32 +- server/tests/api/search/search-index.ts | 4 +- server/tests/api/search/search-playlists.ts | 9 +- server/tests/api/search/search-videos.ts | 42 +- server/tests/api/server/bulk.ts | 33 +- server/tests/api/server/config.ts | 11 +- server/tests/api/server/email.ts | 24 +- server/tests/api/server/follow-constraints.ts | 146 ++-- server/tests/api/server/follows.ts | 65 +- server/tests/api/server/handle-down.ts | 73 +- server/tests/api/server/jobs.ts | 5 +- server/tests/api/server/logs.ts | 23 +- server/tests/api/server/reverse-proxy.ts | 53 +- server/tests/api/server/services.ts | 19 +- server/tests/api/server/stats.ts | 15 +- server/tests/api/server/tracker.ts | 21 +- server/tests/api/users/user-subscriptions.ts | 56 +- .../tests/api/users/users-multiple-servers.ts | 34 +- server/tests/api/users/users.ts | 166 ++-- server/tests/api/videos/audio-only.ts | 20 +- server/tests/api/videos/multiple-servers.ts | 334 ++++---- server/tests/api/videos/resumable-upload.ts | 10 +- server/tests/api/videos/single-server.ts | 276 +++---- server/tests/api/videos/video-captions.ts | 8 +- .../api/videos/video-change-ownership.ts | 38 +- server/tests/api/videos/video-channels.ts | 69 +- server/tests/api/videos/video-comments.ts | 9 +- server/tests/api/videos/video-description.ts | 41 +- server/tests/api/videos/video-hls.ts | 32 +- server/tests/api/videos/video-imports.ts | 54 +- server/tests/api/videos/video-nsfw.ts | 40 +- .../api/videos/video-playlist-thumbnails.ts | 5 +- server/tests/api/videos/video-playlists.ts | 19 +- server/tests/api/videos/video-privacy.ts | 146 ++-- .../tests/api/videos/video-schedule-update.ts | 69 +- server/tests/api/videos/video-transcoder.ts | 208 +++-- server/tests/api/videos/videos-filter.ts | 20 +- server/tests/api/videos/videos-history.ts | 38 +- server/tests/api/videos/videos-overview.ts | 22 +- .../tests/api/videos/videos-views-cleaner.ts | 14 +- .../tests/cli/create-import-video-file-job.ts | 52 +- server/tests/cli/create-transcoding-job.ts | 76 +- server/tests/cli/optimize-old-videos.ts | 47 +- server/tests/cli/peertube.ts | 41 +- server/tests/cli/prune-storage.ts | 5 +- server/tests/cli/regenerate-thumbnails.ts | 33 +- server/tests/cli/update-host.ts | 29 +- server/tests/client.ts | 45 +- server/tests/external-plugins/auth-ldap.ts | 4 +- .../external-plugins/auto-block-videos.ts | 38 +- server/tests/external-plugins/auto-mute.ts | 38 +- server/tests/feeds/feeds.ts | 24 +- server/tests/misc-endpoints.ts | 17 +- server/tests/plugins/action-hooks.ts | 17 +- server/tests/plugins/filter-hooks.ts | 94 +-- server/tests/plugins/plugin-helpers.ts | 57 +- server/tests/plugins/plugin-transcoding.ts | 23 +- server/tests/plugins/video-constants.ts | 52 +- server/tools/cli.ts | 2 +- server/tools/peertube-import-videos.ts | 29 +- server/tools/peertube-upload.ts | 11 +- shared/extra-utils/miscs/webtorrent.ts | 16 +- shared/extra-utils/requests/requests.ts | 25 +- shared/extra-utils/server/servers.ts | 5 +- shared/extra-utils/shared/abstract-command.ts | 41 +- shared/extra-utils/videos/index.ts | 1 + shared/extra-utils/videos/live-command.ts | 7 +- .../extra-utils/videos/playlists-command.ts | 17 +- shared/extra-utils/videos/videos-command.ts | 583 ++++++++++++++ shared/extra-utils/videos/videos.ts | 714 +----------------- .../search/videos-common-query.model.ts | 2 + shared/models/videos/video-update.model.ts | 1 + 108 files changed, 2489 insertions(+), 3105 deletions(-) create mode 100644 shared/extra-utils/videos/videos-command.ts diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts index 272f9e8b1..d9e4a08ab 100644 --- a/scripts/benchmark.ts +++ b/scripts/benchmark.ts @@ -1,6 +1,6 @@ import * as autocannon from 'autocannon' import { writeJson } from 'fs-extra' -import { flushAndRunServer, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' +import { flushAndRunServer, killallServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { Video, VideoPrivacy } from '@shared/models' import { registerTSPaths } from '../server/helpers/register-ts-paths' @@ -197,7 +197,7 @@ async function prepare () { }) await setAccessTokensToServers([ server ]) - const videoAttributes = { + const attributes = { name: 'my super video', category: 2, nsfw: true, @@ -210,12 +210,11 @@ async function prepare () { } for (let i = 0; i < 10; i++) { - Object.assign(videoAttributes, { name: 'my super video ' + i }) - await uploadVideo(server.url, server.accessToken, videoAttributes) + await server.videosCommand.upload({ attributes: { ...attributes, name: 'my super video ' + i } }) } - const resVideos = await getVideosList(server.url) - video = resVideos.body.data.find(v => v.name === 'my super video 1') + const { data } = await server.videosCommand.list() + video = data.find(v => v.name === 'my super video 1') for (let i = 0; i < 10; i++) { const text = 'my super first comment' diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 5b08880bf..dcf758711 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -6,11 +6,8 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - rateVideo, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -49,9 +46,9 @@ describe('Test AP cleaner', function () { // Create 1 comment per video // Update 1 remote URL and 1 local URL on - videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid - videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid - videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid + videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid + videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid + videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] @@ -59,7 +56,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await rateVideo(server.url, server.accessToken, uuid, 'like') + await server.videosCommand.rate({ id: uuid, rating: 'like' }) await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) } } @@ -70,9 +67,10 @@ describe('Test AP cleaner', function () { it('Should have the correct likes', async function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const res = await getVideo(server.url, uuid) - expect(res.body.likes).to.equal(3) - expect(res.body.dislikes).to.equal(0) + const video = await server.videosCommand.get({ id: uuid }) + + expect(video.likes).to.equal(3) + expect(video.dislikes).to.equal(0) } } }) @@ -90,16 +88,16 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const res = await getVideo(servers[0].url, videoUUID1) - expect(res.body.likes).to.equal(2) - expect(res.body.dislikes).to.equal(0) + const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + expect(video.likes).to.equal(2) + expect(video.dislikes).to.equal(0) } // Did not update rates of a remote video { - const res = await getVideo(servers[0].url, videoUUID2) - expect(res.body.likes).to.equal(3) - expect(res.body.dislikes).to.equal(0) + const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + expect(video.likes).to.equal(3) + expect(video.dislikes).to.equal(0) } }) @@ -108,7 +106,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await rateVideo(server.url, server.accessToken, uuid, 'dislike') + await server.videosCommand.rate({ id: uuid, rating: 'dislike' }) } } @@ -116,9 +114,9 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const res = await getVideo(server.url, uuid) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(3) + const video = await server.videosCommand.get({ id: uuid }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(3) } } }) @@ -137,16 +135,16 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const res = await getVideo(servers[0].url, videoUUID1) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(2) + const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(2) } // Did not update rates of a remote video { - const res = await getVideo(servers[0].url, videoUUID2) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(3) + const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(3) } }) diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index e8536a214..0190df04c 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -2,8 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { VideoPlaylistPrivacy } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, @@ -11,9 +10,9 @@ import { makeActivityPubGetRequest, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideoAndGetId -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -69,7 +68,7 @@ describe('Test activitypub', function () { await setDefaultVideoChannel(servers) { - video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' }) + video = await await servers[0].videosCommand.quickUpload({ name: 'video' }) } { diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 162f3ec83..5ab4a85d7 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -2,17 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - getVideosListSort, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '../../../../shared/extra-utils' -import { Video } from '../../../../shared/models/videos' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -36,10 +26,9 @@ describe('Test ActivityPub fetcher', function () { const userAccessToken = await servers[0].loginCommand.getAccessToken(user) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) - const badVideoUUID = res.body.video.uuid - await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' }) + await servers[0].videosCommand.upload({ attributes: { name: 'video root' } }) + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'bad video root' } }) + await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'video user' } }) { const to = 'http://localhost:' + servers[0].port + '/accounts/user1' @@ -48,8 +37,8 @@ describe('Test ActivityPub fetcher', function () { } { - const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID - await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value) + const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid + await servers[0].sqlCommand.setVideoField(uuid, 'url', value) } }) @@ -60,20 +49,18 @@ describe('Test ActivityPub fetcher', function () { await waitJobs(servers) { - const res = await getVideosListSort(servers[0].url, 'createdAt') - expect(res.body.total).to.equal(3) + const { total, data } = await servers[0].videosCommand.list({ sort: 'createdAt' }) - const data: Video[] = res.body.data + expect(total).to.equal(3) expect(data[0].name).to.equal('video root') expect(data[1].name).to.equal('bad video root') expect(data[2].name).to.equal('video user') } { - const res = await getVideosListSort(servers[1].url, 'createdAt') - expect(res.body.total).to.equal(1) + const { total, data } = await servers[1].videosCommand.list({ sort: 'createdAt' }) - const data: Video[] = res.body.data + expect(total).to.equal(1) expect(data[0].name).to.equal('video root') } }) diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 5a37dbc40..5af4b1edb 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -6,14 +6,11 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -37,17 +34,17 @@ describe('Test AP refresher', function () { await setDefaultVideoChannel(servers) { - videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid - videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid - videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid + videoUUID1 = (await servers[1].videosCommand.quickUpload({ name: 'video1' })).uuid + videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'video2' })).uuid + videoUUID3 = (await servers[1].videosCommand.quickUpload({ name: 'video3' })).uuid } { - const a1 = await servers[1].usersCommand.generateUserAndToken('user1') - await uploadVideo(servers[1].url, a1, { name: 'video4' }) + const token1 = await servers[1].usersCommand.generateUserAndToken('user1') + await servers[1].videosCommand.upload({ token: token1, attributes: { name: 'video4' } }) - const a2 = await servers[1].usersCommand.generateUserAndToken('user2') - await uploadVideo(servers[1].url, a2, { name: 'video5' }) + const token2 = await servers[1].usersCommand.generateUserAndToken('user2') + await servers[1].videosCommand.upload({ token: token2, attributes: { name: 'video5' } }) } { @@ -75,13 +72,13 @@ describe('Test AP refresher', function () { // Change UUID so the remote server returns a 404 await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') - await getVideo(servers[0].url, videoUUID1) - await getVideo(servers[0].url, videoUUID2) + await servers[0].videosCommand.get({ id: videoUUID1 }) + await servers[0].videosCommand.get({ id: videoUUID2 }) await waitJobs(servers) - await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404) - await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videosCommand.get({ id: videoUUID2 }) }) it('Should not update a remote video if the remote instance is down', async function () { @@ -94,13 +91,13 @@ describe('Test AP refresher', function () { // Video will need a refresh await wait(10000) - await getVideo(servers[0].url, videoUUID3) + await servers[0].videosCommand.get({ id: videoUUID3 }) // The refresh should fail await waitJobs([ servers[0] ]) await reRunServer(servers[1]) - await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: videoUUID3 }) }) }) diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 4cd10a6fd..199cc5599 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -10,12 +10,10 @@ import { cleanupTests, doubleFollow, flushAndRunServer, - getVideoIdFromUUID, makeGetRequest, makePostBodyRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' import { AbuseCreate, AbuseState } from '@shared/models' @@ -41,15 +39,10 @@ describe('Test abuses API validators', function () { await setAccessTokensToServers([ server ]) - const username = 'user1' - const password = 'my super password' - await server.usersCommand.create({ username: username, password: password }) - userToken = await server.loginCommand.getAccessToken({ username, password }) - + userToken = await server.usersCommand.generateUserAndToken('user_1') userToken2 = await server.usersCommand.generateUserAndToken('user_2') - const res = await uploadVideo(server.url, server.accessToken, {}) - server.video = res.body.video + server.video = await server.videosCommand.upload() command = server.abusesCommand }) @@ -421,7 +414,7 @@ describe('Test abuses API validators', function () { await doubleFollow(anotherServer, server) - const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) + const server2VideoId = await anotherServer.videosCommand.getId({ uuid: server.video.uuid }) await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId }) await waitJobs([ server, anotherServer ]) diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 78863fd50..4b54fc31c 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -13,8 +13,7 @@ import { sendRTMPStream, ServerInfo, setAccessTokensToServers, - stopFfmpeg, - uploadVideoAndGetId + stopFfmpeg } from '@shared/extra-utils' import { VideoCreateResult, VideoPrivacy } from '@shared/models' @@ -58,7 +57,7 @@ describe('Test video lives API validator', function () { } { - videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id + videoIdNotLive = (await server.videosCommand.quickUpload({ name: 'not live' })).id } command = server.liveCommand diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index d93022c32..b1692b986 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -10,14 +10,12 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, waitJobs } from '../../../../shared/extra-utils' @@ -45,14 +43,13 @@ describe('Test server redundancy API validators', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await servers[0].loginCommand.getAccessToken(user) - videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id + videoIdLocal = (await servers[0].videosCommand.quickUpload({ name: 'video' })).id - const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid + const remoteUUID = (await servers[1].videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs(servers) - const resVideo = await getVideo(servers[0].url, remoteUUID) - videoRemote = resVideo.body + videoRemote = await servers[0].videosCommand.get({ id: remoteUUID }) }) describe('When listing redundancies', function () { diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index 595fab70d..f86712b4e 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -1,17 +1,16 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { VideoPlaylistPrivacy } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, makeGetRequest, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideo -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' describe('Test services API validators', function () { let server: ServerInfo @@ -26,10 +25,7 @@ describe('Test services API validators', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - { - const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' }) - server.video = res.body.video - } + server.video = await server.videosCommand.upload({ attributes: { name: 'my super name' } }) { const created = await server.playlistsCommand.create({ diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index d94dec624..164c581e3 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -3,7 +3,6 @@ import 'mocha' import { expect } from 'chai' import { HttpStatusCode, randomInt } from '@shared/core-utils' -import { VideoImportState, VideoPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, @@ -11,13 +10,15 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, + VideosCommand, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { VideoImportState, VideoPrivacy } from '@shared/models' describe('Test upload quota', function () { let server: ServerInfo let rootId: number + let command: VideosCommand // --------------------------------------------------------------- @@ -32,6 +33,8 @@ describe('Test upload quota', function () { rootId = user.id await server.usersCommand.update({ userId: rootId, videoQuota: 42 }) + + command = server.videosCommand }) describe('When having a video quota', function () { @@ -41,14 +44,14 @@ describe('Test upload quota', function () { const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } await server.usersCommand.register(user) - const userAccessToken = await server.loginCommand.getAccessToken(user) + const userToken = await server.loginCommand.getAccessToken(user) - const videoAttributes = { fixture: 'video_short2.webm' } + const attributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { - await uploadVideo(server.url, userAccessToken, videoAttributes) + await command.upload({ token: userToken, attributes }) } - await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') + await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) }) it('Should fail with a registered user having too many videos with resumable upload', async function () { @@ -56,14 +59,14 @@ describe('Test upload quota', function () { const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } await server.usersCommand.register(user) - const userAccessToken = await server.loginCommand.getAccessToken(user) + const userToken = await server.loginCommand.getAccessToken(user) - const videoAttributes = { fixture: 'video_short2.webm' } + const attributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { - await uploadVideo(server.url, userAccessToken, videoAttributes) + await command.upload({ token: userToken, attributes }) } - await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) it('Should fail to import with HTTP/Torrent/magnet', async function () { @@ -97,8 +100,8 @@ describe('Test upload quota', function () { it('Should fail with a user having too many videos daily', async function () { await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) }) @@ -110,8 +113,8 @@ describe('Test upload quota', function () { videoQuotaDaily: 1024 * 1024 * 1024 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) it('Should fail if exceeding daily quota', async function () { @@ -121,8 +124,8 @@ describe('Test upload quota', function () { videoQuotaDaily: 42 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) }) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 801131918..33c48a009 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -2,10 +2,12 @@ import 'mocha' import { omit } from 'lodash' -import { UserRole, VideoCreateResult } from '../../../../shared' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, flushAndRunServer, killallServers, @@ -13,19 +15,13 @@ import { makePostBodyRequest, makePutBodyRequest, makeUploadRequest, + MockSmtpServer, reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, UsersCommand -} from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +} from '@shared/extra-utils' +import { UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models' describe('Test users API validators', function () { const path = '/api/v1/users/' @@ -80,8 +76,7 @@ describe('Test users API validators', function () { } { - const res = await uploadVideo(server.url, server.accessToken, {}) - video = res.body.video + video = await server.videosCommand.upload() } { diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 5097f8069..0fda31b29 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -11,20 +11,17 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideoWithToken, makePostBodyRequest, makePutBodyRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' -import { VideoBlacklistType, VideoDetails } from '@shared/models' +import { VideoBlacklistType } from '@shared/models' describe('Test video blacklist API validators', function () { let servers: ServerInfo[] - let notBlacklistedVideoId: number + let notBlacklistedVideoId: string let remoteVideoUUID: string let userAccessToken1 = '' let userAccessToken2 = '' @@ -55,18 +52,17 @@ describe('Test video blacklist API validators', function () { } { - const res = await uploadVideo(servers[0].url, userAccessToken1, {}) - servers[0].video = res.body.video + servers[0].video = await servers[0].videosCommand.upload({ token: userAccessToken1 }) } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, {}) - notBlacklistedVideoId = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload() + notBlacklistedVideoId = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, {}) - remoteVideoUUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload() + remoteVideoUUID = uuid } await waitJobs(servers) @@ -204,17 +200,19 @@ describe('Test video blacklist API validators', function () { describe('When getting blacklisted video', function () { it('Should fail with a non authenticated user', async function () { - await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) + await servers[0].videosCommand.get({ id: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another user', async function () { - await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) + await servers[0].videosCommand.getWithToken({ + token: userAccessToken2, + id: servers[0].video.uuid, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should succeed with the owner authenticated user', async function () { - const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200) - const video: VideoDetails = res.body - + const video = await servers[0].videosCommand.getWithToken({ token: userAccessToken1, id: servers[0].video.uuid }) expect(video.blacklisted).to.be.true }) @@ -222,9 +220,7 @@ describe('Test video blacklist API validators', function () { const video = servers[0].video for (const id of [ video.id, video.uuid, video.shortUUID ]) { - const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id, HttpStatusCode.OK_200) - const video: VideoDetails = res.body - + const video = await servers[0].videosCommand.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 }) expect(video.blacklisted).to.be.true } }) diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 631ef4dac..f3941b3fa 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -10,8 +10,7 @@ import { makeGetRequest, makeUploadRequest, ServerInfo, - setAccessTokensToServers, - uploadVideo + setAccessTokensToServers } from '@shared/extra-utils' import { VideoCreateResult } from '@shared/models' @@ -31,10 +30,7 @@ describe('Test video captions API validator', function () { await setAccessTokensToServers([ server ]) - { - const res = await uploadVideo(server.url, server.accessToken, {}) - video = res.body.video - } + video = await server.videosCommand.upload() { const user = { diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index b7656a176..bdf7f91ee 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -13,8 +13,7 @@ import { makeGetRequest, makePostBodyRequest, ServerInfo, - setAccessTokensToServers, - uploadVideo + setAccessTokensToServers } from '@shared/extra-utils' import { VideoCreateResult } from '@shared/models' @@ -39,8 +38,7 @@ describe('Test video comments API validator', function () { await setAccessTokensToServers([ server ]) { - const res = await uploadVideo(server.url, server.accessToken, {}) - video = res.body.video + const video = await server.videosCommand.upload({ attributes: {} }) pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' } @@ -291,8 +289,8 @@ describe('Test video comments API validator', function () { let anotherVideoUUID: string { - const res = await uploadVideo(server.url, userAccessToken, { name: 'video' }) - anotherVideoUUID = res.body.video.uuid + const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes: { name: 'video' } }) + anotherVideoUUID = uuid } { @@ -318,8 +316,7 @@ describe('Test video comments API validator', function () { describe('When a video has comments disabled', function () { before(async function () { - const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) - video = res.body.video + video = await server.videosCommand.upload({ attributes: { commentsEnabled: false } }) pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' }) diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 46c09bb11..ebd7e2413 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -2,15 +2,6 @@ import 'mocha' import { HttpStatusCode } from '@shared/core-utils' -import { - VideoPlaylistCreate, - VideoPlaylistCreateResult, - VideoPlaylistElementCreate, - VideoPlaylistElementUpdate, - VideoPlaylistPrivacy, - VideoPlaylistReorder, - VideoPlaylistType -} from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -21,9 +12,17 @@ import { PlaylistsCommand, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideoAndGetId -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { + VideoPlaylistCreate, + VideoPlaylistCreateResult, + VideoPlaylistElementCreate, + VideoPlaylistElementUpdate, + VideoPlaylistPrivacy, + VideoPlaylistReorder, + VideoPlaylistType +} from '@shared/models' describe('Test video playlists API validator', function () { let server: ServerInfo @@ -49,7 +48,7 @@ describe('Test video playlists API validator', function () { await setDefaultVideoChannel([ server ]) userAccessToken = await server.usersCommand.generateUserAndToken('user1') - videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id + videoId = (await server.videosCommand.quickUpload({ name: 'video 1' })).id command = server.playlistsCommand @@ -486,8 +485,8 @@ describe('Test video playlists API validator', function () { } before(async function () { - videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id - videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id + videoId3 = (await server.videosCommand.quickUpload({ name: 'video 3' })).id + videoId4 = (await server.videosCommand.quickUpload({ name: 'video 4' })).id for (const id of [ videoId3, videoId4 ]) { await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } }) diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 0e91fe0a8..1da922a17 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { HttpStatusCode } from '@shared/core-utils' import { checkBadCountPagination, checkBadStartPagination, @@ -10,10 +11,8 @@ import { makePostBodyRequest, makePutBodyRequest, ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' + setAccessTokensToServers +} from '@shared/extra-utils' describe('Test videos history API validator', function () { const myHistoryPath = '/api/v1/users/me/history/videos' @@ -30,10 +29,8 @@ describe('Test videos history API validator', function () { await setAccessTokensToServers([ server ]) - const res = await uploadVideo(server.url, server.accessToken, {}) - const videoUUID = res.body.video.uuid - - watchingPath = '/api/v1/videos/' + videoUUID + '/watching' + const { uuid } = await server.videosCommand.upload() + watchingPath = '/api/v1/videos/' + uuid + '/watching' }) describe('When notifying a user is watching a video', function () { diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 855b09f39..8f9f33b8c 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -4,30 +4,23 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { join } from 'path' -import { randomInt } from '@shared/core-utils' -import { PeerTubeProblemDocument, VideoCreateResult } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode, randomInt } from '@shared/core-utils' import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, checkUploadVideoParam, cleanupTests, flushAndRunServer, - getVideo, - getVideosList, makeDeleteRequest, makeGetRequest, makePutBodyRequest, makeUploadRequest, - removeVideo, root, ServerInfo, setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +} from '@shared/extra-utils' +import { PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -210,70 +203,70 @@ describe('Test videos API validator', function () { it('Should fail with nothing', async function () { const fields = {} const attaches = {} - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail without name', async function () { const fields = omit(baseCorrectParams, 'name') const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long name', async function () { const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad category', async function () { const fields = { ...baseCorrectParams, category: 125 } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad licence', async function () { const fields = { ...baseCorrectParams, licence: 125 } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad language', async function () { const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long description', async function () { const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long support text', async function () { const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail without a channel', async function () { const fields = omit(baseCorrectParams, 'channelId') const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad channel', async function () { const fields = { ...baseCorrectParams, channelId: 545454 } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with another user channel', async function () { @@ -290,35 +283,35 @@ describe('Test videos API validator', function () { const fields = { ...baseCorrectParams, channelId: customChannelId } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with too many tags', async function () { const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a tag length too low', async function () { const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a tag length too big', async function () { const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad schedule update (miss updateAt)', async function () { const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad schedule update (wrong updateAt)', async function () { @@ -332,20 +325,20 @@ describe('Test videos API validator', function () { } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad originally published at attribute', async function () { const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail without an input file', async function () { const fields = baseCorrectParams const attaches = {} - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with an incorrect input file', async function () { @@ -353,7 +346,7 @@ describe('Test videos API validator', function () { let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } await checkUploadVideoParam( - server.url, + server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.UNPROCESSABLE_ENTITY_422, @@ -362,7 +355,7 @@ describe('Test videos API validator', function () { attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } await checkUploadVideoParam( - server.url, + server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415, @@ -377,7 +370,7 @@ describe('Test videos API validator', function () { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a big thumbnail file', async function () { @@ -387,7 +380,7 @@ describe('Test videos API validator', function () { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with an incorrect preview file', async function () { @@ -397,7 +390,7 @@ describe('Test videos API validator', function () { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a big preview file', async function () { @@ -407,7 +400,7 @@ describe('Test videos API validator', function () { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should report the appropriate error', async function () { @@ -415,9 +408,9 @@ describe('Test videos API validator', function () { const attaches = baseCorrectAttaches const attributes = { ...fields, ...attaches } - const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode) + const body = await checkUploadVideoParam(server, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode) - const error = res.body as PeerTubeProblemDocument + const error = body as unknown as PeerTubeProblemDocument if (mode === 'legacy') { expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy') @@ -442,7 +435,7 @@ describe('Test videos API validator', function () { { const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } { @@ -452,7 +445,7 @@ describe('Test videos API validator', function () { videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } { @@ -462,7 +455,7 @@ describe('Test videos API validator', function () { videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } }) } @@ -491,8 +484,8 @@ describe('Test videos API validator', function () { } before(async function () { - const res = await getVideosList(server.url) - video = res.body.data[0] + const { data } = await server.videosCommand.list() + video = data[0] }) it('Should fail with nothing', async function () { @@ -717,16 +710,16 @@ describe('Test videos API validator', function () { }) it('Should fail without a correct uuid', async function () { - await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400) + await server.videosCommand.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should return 404 with an incorrect video', async function () { - await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) + await server.videosCommand.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Shoud report the appropriate error', async function () { - const res = await getVideo(server.url, 'hi', HttpStatusCode.BAD_REQUEST_400) - const error = res.body as PeerTubeProblemDocument + const body = await server.videosCommand.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const error = body as unknown as PeerTubeProblemDocument expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo') @@ -741,16 +734,16 @@ describe('Test videos API validator', function () { }) it('Should succeed with the correct parameters', async function () { - await getVideo(server.url, video.shortUUID) + await server.videosCommand.get({ id: video.shortUUID }) }) }) describe('When rating a video', function () { - let videoId + let videoId: number before(async function () { - const res = await getVideosList(server.url) - videoId = res.body.data[0].id + const { data } = await server.videosCommand.list() + videoId = data[0].id }) it('Should fail without a valid uuid', async function () { @@ -804,22 +797,22 @@ describe('Test videos API validator', function () { }) it('Should fail without a correct uuid', async function () { - await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) + await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with a video which does not exist', async function () { - await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) + await server.videosCommand.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a video of another user without the appropriate right', async function () { - await removeVideo(server.url, userAccessToken, video.uuid, HttpStatusCode.FORBIDDEN_403) + await server.videosCommand.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a video of another server') it('Shoud report the appropriate error', async function () { - const res = await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) - const error = res.body as PeerTubeProblemDocument + const body = await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const error = body as unknown as PeerTubeProblemDocument expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo') @@ -834,7 +827,7 @@ describe('Test videos API validator', function () { }) it('Should succeed with the correct parameters', async function () { - await removeVideo(server.url, server.accessToken, video.uuid) + await server.videosCommand.remove({ id: video.uuid }) }) }) diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 290d325d4..7900b1abe 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -2,14 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoPrivacy } from '@shared/models' import { checkLiveCleanup, cleanupTests, ConfigCommand, doubleFollow, flushAndRunMultipleServers, - getVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -39,9 +38,7 @@ describe('Test live constraints', function () { async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { for (const server of servers) { - const res = await getVideo(server.url, videoId) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoId }) expect(video.isLive).to.be.false expect(video.duration).to.be.greaterThan(0) } diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 6f4915a6b..707f2edf8 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -2,13 +2,12 @@ import 'mocha' import * as chai from 'chai' -import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' +import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, ConfigCommand, doubleFollow, flushAndRunMultipleServers, - getVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -38,8 +37,8 @@ describe('Permanent live', function () { async function checkVideoState (videoId: string, state: VideoState) { for (const server of servers) { - const res = await getVideo(server.url, videoId) - expect((res.body as VideoDetails).state.id).to.equal(state) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.state.id).to.equal(state) } } @@ -123,9 +122,7 @@ describe('Permanent live', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - - const videoDetails = res.body as VideoDetails + const videoDetails = await server.videosCommand.get({ id: videoUUID }) expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) } }) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 363fb561c..a87a2cd12 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -3,26 +3,22 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' -import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { checkLiveCleanup, cleanupTests, ConfigCommand, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideosList, - removeVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, testFfmpegStreamError, - updateVideo, wait, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' const expect = chai.expect @@ -34,7 +30,7 @@ describe('Save replay setting', function () { async function createLiveWrapper (saveReplay: boolean) { if (liveVideoUUID) { try { - await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + await servers[0].videosCommand.remove({ id: liveVideoUUID }) await waitJobs(servers) } catch {} } @@ -50,24 +46,24 @@ describe('Save replay setting', function () { return uuid } - async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) { + async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) { for (const server of servers) { const length = existsInList ? 1 : 0 - const resVideos = await getVideosList(server.url) - expect(resVideos.body.data).to.have.lengthOf(length) - expect(resVideos.body.total).to.equal(length) + const { data, total } = await server.videosCommand.list() + expect(data).to.have.lengthOf(length) + expect(total).to.equal(length) - if (getStatus) { - await getVideo(server.url, videoId, getStatus) + if (expectedStatus) { + await server.videosCommand.get({ id: videoId, expectedStatus }) } } } async function checkVideoState (videoId: string, state: VideoState) { for (const server of servers) { - const res = await getVideo(server.url, videoId) - expect((res.body as VideoDetails).state.id).to.equal(state) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.state.id).to.equal(state) } } @@ -179,8 +175,8 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) - await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await wait(5000) await waitJobs(servers) @@ -201,7 +197,7 @@ describe('Save replay setting', function () { await Promise.all([ testFfmpegStreamError(ffmpegCommand, true), - removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + servers[0].videosCommand.remove({ id: liveVideoUUID }) ]) await wait(5000) @@ -253,13 +249,13 @@ describe('Save replay setting', function () { it('Should update the saved live and correctly federate the updated attributes', async function () { this.timeout(30000) - await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' }) + await servers[0].videosCommand.update({ id: liveVideoUUID, attributes: { name: 'video updated' } }) await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, liveVideoUUID) - expect(res.body.name).to.equal('video updated') - expect(res.body.isLive).to.be.false + const video = await server.videosCommand.get({ id: liveVideoUUID }) + expect(video.name).to.equal('video updated') + expect(video.isLive).to.be.false } }) @@ -287,8 +283,8 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) - await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await wait(5000) await waitJobs(servers) @@ -307,7 +303,7 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ - removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), + servers[0].videosCommand.remove({ id: liveVideoUUID }), testFfmpegStreamError(ffmpegCommand, true) ]) diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 4a6677c0a..1f3d455a8 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -7,12 +7,10 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideoIdFromUUID, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - viewVideo, wait, waitJobs, waitUntilLivePublishedOnAllServers @@ -71,7 +69,7 @@ describe('Test live', function () { await waitJobs(servers) { - const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) + const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() localSocket.on('state-change', data => localStateChanges.push(data.state)) @@ -79,7 +77,7 @@ describe('Test live', function () { } { - const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) + const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID }) const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) @@ -119,7 +117,7 @@ describe('Test live', function () { await waitJobs(servers) { - const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) + const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() localSocket.on('views-change', data => { localLastVideoViews = data.views }) @@ -127,7 +125,7 @@ describe('Test live', function () { } { - const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) + const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID }) const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) @@ -142,8 +140,8 @@ describe('Test live', function () { expect(localLastVideoViews).to.equal(0) expect(remoteLastVideoViews).to.equal(0) - await viewVideo(servers[0].url, liveVideoUUID) - await viewVideo(servers[1].url, liveVideoUUID) + await servers[0].videosCommand.view({ id: liveVideoUUID }) + await servers[1].videosCommand.view({ id: liveVideoUUID }) await waitJobs(servers) await wait(5000) @@ -163,7 +161,7 @@ describe('Test live', function () { const liveVideoUUID = await createLiveWrapper() await waitJobs(servers) - const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) + const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) const socket = servers[0].socketIOCommand.getLiveNotificationSocket() socket.on('state-change', data => stateChanges.push(data.state)) diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index 75f95b167..1951b11a5 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -3,17 +3,15 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' -import { VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoPrivacy } from '@shared/models' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - viewVideo, wait, waitJobs, waitUntilLivePublishedOnAllServers @@ -55,9 +53,7 @@ describe('Test live', function () { async function countViews (expected: number) { for (const server of servers) { - const res = await getVideo(server.url, liveVideoId) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: liveVideoId }) expect(video.views).to.equal(expected) } } @@ -86,8 +82,8 @@ describe('Test live', function () { it('Should view a live twice and display 1 view', async function () { this.timeout(30000) - await viewVideo(servers[0].url, liveVideoId) - await viewVideo(servers[0].url, liveVideoId) + await servers[0].videosCommand.view({ id: liveVideoId }) + await servers[0].videosCommand.view({ id: liveVideoId }) await wait(7000) @@ -108,9 +104,9 @@ describe('Test live', function () { it('Should view a live on a remote and on local and display 2 views', async function () { this.timeout(30000) - await viewVideo(servers[0].url, liveVideoId) - await viewVideo(servers[1].url, liveVideoId) - await viewVideo(servers[1].url, liveVideoId) + await servers[0].videosCommand.view({ id: liveVideoId }) + await servers[1].videosCommand.view({ id: liveVideoId }) + await servers[1].videosCommand.view({ id: liveVideoId }) await wait(7000) await waitJobs(servers) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 999a49051..c88143982 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -4,8 +4,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' -import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { checkLiveCleanup, checkLiveSegmentHash, @@ -13,14 +12,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideosWithFilter, - getVideo, - getVideosList, - getVideosWithFilters, killallServers, LiveCommand, makeRawRequest, - removeVideo, reRunServer, sendRTMPStream, ServerInfo, @@ -29,11 +23,11 @@ import { stopFfmpeg, testFfmpegStreamError, testImage, - uploadVideoAndGetId, wait, waitJobs, waitUntilLivePublishedOnAllServers -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' const expect = chai.expect @@ -99,8 +93,7 @@ describe('Test live', function () { await waitJobs(servers) for (const server of servers) { - const resVideo = await getVideo(server.url, liveVideoUUID) - const video: VideoDetails = resVideo.body + const video = await server.videosCommand.get({ id: liveVideoUUID }) expect(video.category.id).to.equal(1) expect(video.licence.id).to.equal(2) @@ -154,9 +147,7 @@ describe('Test live', function () { await waitJobs(servers) for (const server of servers) { - const resVideo = await getVideo(server.url, videoId) - const video: VideoDetails = resVideo.body - + const video = await server.videosCommand.get({ id: videoId }) expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) expect(video.nsfw).to.be.true @@ -167,10 +158,10 @@ describe('Test live', function () { it('Should not have the live listed since nobody streams into', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } }) @@ -204,13 +195,13 @@ describe('Test live', function () { it('Delete the live', async function () { this.timeout(10000) - await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + await servers[0].videosCommand.remove({ id: liveVideoUUID }) await waitJobs(servers) }) it('Should have the live deleted', async function () { for (const server of servers) { - await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await server.videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -224,7 +215,7 @@ describe('Test live', function () { before(async function () { this.timeout(120000) - vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid + vodVideoId = (await servers[0].videosCommand.quickUpload({ name: 'vod video' })).uuid const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } const live = await commands[0].create({ fields: liveOptions }) @@ -236,19 +227,19 @@ describe('Test live', function () { }) it('Should only display lives', async function () { - const res = await getVideosWithFilters(servers[0].url, { isLive: true }) + const { data, total } = await servers[0].videosCommand.list({ isLive: true }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('live') + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('live') }) it('Should not display lives', async function () { - const res = await getVideosWithFilters(servers[0].url, { isLive: false }) + const { data, total } = await servers[0].videosCommand.list({ isLive: false }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('vod video') + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('vod video') }) it('Should display my lives', async function () { @@ -257,24 +248,22 @@ describe('Test live', function () { await stopFfmpeg(ffmpegCommand) await waitJobs(servers) - const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) - const videos = res.body.data as Video[] + const { data } = await servers[0].videosCommand.listMyVideos({ isLive: true }) - const result = videos.every(v => v.isLive) + const result = data.every(v => v.isLive) expect(result).to.be.true }) it('Should not display my lives', async function () { - const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: false }) - const videos = res.body.data as Video[] + const { data } = await servers[0].videosCommand.listMyVideos({ isLive: false }) - const result = videos.every(v => !v.isLive) + const result = data.every(v => !v.isLive) expect(result).to.be.true }) after(async function () { - await removeVideo(servers[0].url, servers[0].accessToken, vodVideoId) - await removeVideo(servers[0].url, servers[0].accessToken, liveVideoId) + await servers[0].videosCommand.remove({ id: vodVideoId }) + await servers[0].videosCommand.remove({ id: liveVideoId }) }) }) @@ -297,9 +286,9 @@ describe('Test live', function () { const { uuid } = await commands[0].create({ fields: liveAttributes }) const live = await commands[0].get({ videoId: uuid }) - const resVideo = await getVideo(servers[0].url, uuid) + const video = await servers[0].videosCommand.get({ id: uuid }) - return Object.assign(resVideo.body as VideoDetails, live) + return Object.assign(video, live) } it('Should not allow a stream without the appropriate path', async function () { @@ -327,13 +316,12 @@ describe('Test live', function () { it('Should list this live now someone stream into it', async function () { for (const server of servers) { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const { total, data } = await server.videosCommand.list() - const video: Video = res.body.data[0] + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + const video = data[0] expect(video.name).to.equal('user live') expect(video.isLive).to.be.true } @@ -355,7 +343,7 @@ describe('Test live', function () { liveVideo = await createLiveWrapper() - await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid) + await servers[0].videosCommand.remove({ id: liveVideo.uuid }) const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) await testFfmpegStreamError(command, true) @@ -379,13 +367,10 @@ describe('Test live', function () { async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { for (const server of servers) { - const resList = await getVideosList(server.url) - const videos: Video[] = resList.body.data - - expect(videos.find(v => v.uuid === liveVideoId)).to.exist + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === liveVideoId)).to.exist - const resVideo = await getVideo(server.url, liveVideoId) - const video: VideoDetails = resVideo.body + const video = await server.videosCommand.get({ id: liveVideoId }) expect(video.streamingPlaylists).to.have.lengthOf(1) @@ -505,8 +490,7 @@ describe('Test live', function () { } for (const server of servers) { - const resVideo = await getVideo(server.url, liveVideoId) - const video: VideoDetails = resVideo.body + const video = await server.videosCommand.get({ id: liveVideoId }) expect(video.state.id).to.equal(VideoState.PUBLISHED) expect(video.duration).to.be.greaterThan(1) 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) 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) diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index 03857f512..efb60dc56 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -6,12 +6,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getLocalIdByUUID, RedundancyCommand, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' @@ -59,13 +56,13 @@ describe('Test manage videos redundancy', function () { commands = servers.map(s => s.redundancyCommand) { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) - video1Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + video1Server2UUID = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' }) - video2Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2' } }) + video2Server2UUID = uuid } await waitJobs(servers) @@ -206,9 +203,9 @@ describe('Test manage videos redundancy', function () { it('Should manually add a redundancy and list it', async function () { this.timeout(120000) - const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid + const uuid = (await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid await waitJobs(servers) - const videoId = await getLocalIdByUUID(servers[0].url, uuid) + const videoId = await servers[0].videosCommand.getId({ uuid }) await commands[0].addVideo({ videoId }) diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index a31278de7..b3f6ed160 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -9,8 +9,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, waitJobs } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -38,11 +36,11 @@ describe('Test redundancy constraints', function () { async function uploadWrapper (videoName: string) { // Wait for transcoding - const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE }) + const { id } = await localServer.videosCommand.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) await waitJobs([ localServer ]) // Update video to schedule a federation - await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC }) + await localServer.videosCommand.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) } async function getTotalRedundanciesLocalServer () { @@ -80,7 +78,7 @@ describe('Test redundancy constraints', function () { // Get the access tokens await setAccessTokensToServers(servers) - await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' }) + await localServer.videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) await waitJobs(servers) diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 00a5e86cc..6ca9c9303 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -12,22 +12,16 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideoWithToken, killallServers, makeGetRequest, - removeVideo, reRunServer, root, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - viewVideo, wait, waitJobs } from '@shared/extra-utils' -import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' +import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' const expect = chai.expect @@ -84,11 +78,11 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add await setAccessTokensToServers(servers) { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) - video1Server2UUID = res.body.video.uuid - video1Server2Id = res.body.video.id + const { uuid, id } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + video1Server2UUID = uuid + video1Server2Id = id - await viewVideo(servers[1].url, video1Server2UUID) + await servers[1].videosCommand.view({ id: video1Server2UUID }) } await waitJobs(servers) @@ -112,9 +106,8 @@ async function check1WebSeed (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) + const video = await server.videosCommand.getWithToken({ id: videoUUID }) - const video: VideoDetails = res.body for (const f of video.files) { checkMagnetWebseeds(f, webseeds, server) } @@ -130,9 +123,7 @@ async function check2Webseeds (videoUUID?: string) { ] for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoUUID }) for (const file of video.files) { checkMagnetWebseeds(file, webseeds, server) @@ -172,8 +163,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.getWithToken({ id: videoUUID }) expect(video.streamingPlaylists).to.be.an('array') expect(video.streamingPlaylists).to.have.lengthOf(1) @@ -185,8 +175,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { if (!videoUUID) videoUUID = video1Server2UUID for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) @@ -199,8 +188,8 @@ async function check1PlaylistRedundancies (videoUUID?: string) { const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' const baseUrlSegment = servers[0].url + '/static/redundancy/hls' - const res = await getVideo(servers[0].url, videoUUID) - const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] + const video = await servers[0].videosCommand.get({ id: videoUUID }) + const hlsPlaylist = video.streamingPlaylists[0] for (const resolution of [ 240, 360, 480, 720 ]) { await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) @@ -427,8 +416,8 @@ describe('Test videos redundancy', function () { it('Should view 2 times the first video to have > min_views config', async function () { this.timeout(80000) - await viewVideo(servers[0].url, video1Server2UUID) - await viewVideo(servers[2].url, video1Server2UUID) + await servers[0].videosCommand.view({ id: video1Server2UUID }) + await servers[2].videosCommand.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) @@ -449,7 +438,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) + await servers[1].videosCommand.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -495,8 +484,8 @@ describe('Test videos redundancy', function () { it('Should have 1 redundancy on the first video', async function () { this.timeout(160000) - await viewVideo(servers[0].url, video1Server2UUID) - await viewVideo(servers[2].url, video1Server2UUID) + await servers[0].videosCommand.view({ id: video1Server2UUID }) + await servers[2].videosCommand.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) @@ -512,7 +501,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) + await servers[1].videosCommand.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -588,8 +577,7 @@ describe('Test videos redundancy', function () { async function checkContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const res = await getVideo(server.url, video1Server2UUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.contain(str) @@ -599,8 +587,7 @@ describe('Test videos redundancy', function () { async function checkNotContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const res = await getVideo(server.url, video1Server2UUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.not.contain(str) @@ -665,13 +652,13 @@ describe('Test videos redundancy', function () { await check1PlaylistRedundancies(video1Server2UUID) await checkStatsWith1Redundancy(strategy) - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE }) - video2Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) + video2Server2UUID = uuid // Wait transcoding before federation await waitJobs(servers) - await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC }) + await servers[1].videosCommand.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) }) it('Should cache video 2 webseeds on the first video', async function () { diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index bcc21381c..75794402d 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -5,12 +5,9 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunMultipleServers, - getVideoChannelVideos, SearchCommand, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, wait, waitJobs } from '@shared/extra-utils' @@ -53,8 +50,9 @@ describe('Test ActivityPub video channels search', function () { const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel }) channelIdServer2 = created.id - const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 }) - videoServer2UUID = res.body.video.uuid + const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 } + const { uuid } = await servers[1].videosCommand.upload({ token: userServer2Token, attributes }) + videoServer2UUID = uuid } await waitJobs(servers) @@ -149,16 +147,21 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) - const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const { total, data } = await servers[0].videosCommand.listByChannel({ + token: null, + videoChannelName: 'channel1_server2@localhost:' + servers[1].port + }) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should list video channel videos of server 2 with token', async function () { - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ + videoChannelName: 'channel1_server2@localhost:' + servers[1].port + }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('video 1 server 2') + expect(total).to.equal(1) + expect(data[0].name).to.equal('video 1 server 2') }) it('Should update video channel of server 2, and refresh it on server 1', async function () { @@ -190,8 +193,8 @@ describe('Test ActivityPub video channels search', function () { it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { this.timeout(60000) - await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' }) - await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 }) + await servers[1].videosCommand.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } }) + await servers[1].videosCommand.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } }) await waitJobs(servers) @@ -204,11 +207,11 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) const videoChannelName = 'channel1_server2@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt') + const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data[0].name).to.equal('video 2 server 2') - expect(res.body.data[1].name).to.equal('video 1 updated') + expect(total).to.equal(2) + expect(data[0].name).to.equal('video 2 server 2') + expect(data[1].name).to.equal('video 1 updated') }) it('Should delete video channel of server 2, and delete it on server 1', async function () { diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index cb7582d29..46105c12c 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -9,7 +9,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -34,8 +33,8 @@ describe('Test ActivityPub playlists search', function () { await setDefaultVideoChannel(servers) { - const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid - const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid + const video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid + const video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid const attributes = { displayName: 'playlist 1 on server 1', @@ -51,8 +50,8 @@ describe('Test ActivityPub playlists search', function () { } { - const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid - video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid + const videoId = (await servers[1].videosCommand.quickUpload({ name: 'video 1' })).uuid + video2Server2 = (await servers[1].videosCommand.quickUpload({ name: 'video 2' })).uuid const attributes = { displayName: 'playlist 1 on server 2', diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 403c84010..19b4d5ed8 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -5,17 +5,13 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunMultipleServers, - getVideosList, - removeVideo, SearchCommand, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoPrivacy } from '../../../../shared/models/videos' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -34,13 +30,13 @@ describe('Test ActivityPub videos search', function () { await setAccessTokensToServers(servers) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 on server 1' }) - videoServer1UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1 on server 1' } }) + videoServer1UUID = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 on server 2' }) - videoServer2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 on server 2' } }) + videoServer2UUID = uuid } await waitJobs(servers) @@ -109,10 +105,10 @@ describe('Test ActivityPub videos search', function () { }) it('Should not list this remote video', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 1') + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video 1 on server 1') }) it('Should update video of server 2, and refresh it on server 1', async function () { @@ -131,7 +127,7 @@ describe('Test ActivityPub videos search', function () { privacy: VideoPrivacy.UNLISTED, channelId: videoChannelId } - await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes) + await servers[1].videosCommand.update({ id: videoServer2UUID, attributes }) await waitJobs(servers) // Expire video @@ -157,7 +153,7 @@ describe('Test ActivityPub videos search', function () { it('Should delete video of server 2, and delete it on server 1', async function () { this.timeout(120000) - await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID) + await servers[1].videosCommand.remove({ id: videoServer2UUID }) await waitJobs(servers) // Expire video diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index 306f84c3a..d5dc40f60 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect @@ -20,7 +20,7 @@ describe('Test videos search', function () { await setAccessTokensToServers([ server ]) - await uploadVideo(server.url, server.accessToken, { name: localVideoName }) + await server.videosCommand.upload({ attributes: { name: localVideoName } }) command = server.searchCommand }) diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index 517884503..2e4773ed6 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -2,16 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { VideoPlaylistPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideoAndGetId -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -27,7 +26,7 @@ describe('Test playlists search', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid + const videoId = (await server.videosCommand.quickUpload({ name: 'video' })).uuid { const attributes = { diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 66f5f3182..148499d5f 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -10,7 +10,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - uploadVideo, wait } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -41,50 +40,49 @@ describe('Test videos search', function () { nsfw: false, language: 'fr' } - await uploadVideo(server.url, server.accessToken, attributes1) + await server.videosCommand.upload({ attributes: attributes1 }) const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } - await uploadVideo(server.url, server.accessToken, attributes2) + await server.videosCommand.upload({ attributes: attributes2 }) { const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } - const res = await uploadVideo(server.url, server.accessToken, attributes3) - const videoId = res.body.video.id - videoUUID = res.body.video.uuid + const { id, uuid } = await server.videosCommand.upload({ attributes: attributes3 }) + videoUUID = uuid await server.captionsCommand.createVideoCaption({ language: 'en', - videoId, + videoId: id, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) await server.captionsCommand.createVideoCaption({ language: 'aa', - videoId, + videoId: id, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) } const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } - await uploadVideo(server.url, server.accessToken, attributes4) + await server.videosCommand.upload({ attributes: attributes4 }) await wait(1000) startDate = new Date().toISOString() const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } - await uploadVideo(server.url, server.accessToken, attributes5) + await server.videosCommand.upload({ attributes: attributes5 }) const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } - await uploadVideo(server.url, server.accessToken, attributes6) + await server.videosCommand.upload({ attributes: attributes6 }) const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } - await uploadVideo(server.url, server.accessToken, attributes7) + await server.videosCommand.upload({ attributes: attributes7 }) const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } - await uploadVideo(server.url, server.accessToken, attributes8) + await server.videosCommand.upload({ attributes: attributes8 }) } { @@ -95,9 +93,9 @@ describe('Test videos search', function () { licence: 2, language: 'en' } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes: attributes }) - await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' }) + await server.videosCommand.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } }) } { @@ -108,7 +106,7 @@ describe('Test videos search', function () { licence: 3, language: 'pl' } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes: attributes }) } { @@ -117,11 +115,11 @@ describe('Test videos search', function () { tags: [ 'aaaa', 'bbbb', 'cccc' ], category: 1 } - await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) + await server.videosCommand.upload({ attributes: attributes1 }) + await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } }) - await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] }) - await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] }) + await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } }) + await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } }) } { @@ -129,8 +127,8 @@ describe('Test videos search', function () { name: 'aaaa 2', category: 1 } - await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) + await server.videosCommand.upload({ attributes: attributes1 }) + await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } }) } command = server.searchCommand diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index 20a9a3dc7..c83bcfb22 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -7,13 +7,10 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideosList, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' -import { Video } from '@shared/models' const expect = chai.expect @@ -64,11 +61,10 @@ describe('Test bulk actions', function () { describe('Bulk remove comments', function () { async function checkInstanceCommentsRemoved () { { - const res = await getVideosList(servers[0].url) - const videos = res.body.data as Video[] + const { data } = await servers[0].videosCommand.list() // Server 1 should not have these comments anymore - for (const video of videos) { + for (const video of data) { const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 3') @@ -77,11 +73,10 @@ describe('Test bulk actions', function () { } { - const res = await getVideosList(servers[1].url) - const videos = res.body.data as Video[] + const { data } = await servers[1].videosCommand.list() // Server 1 should not have these comments on videos of server 1 - for (const video of videos) { + for (const video of data) { const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 3') @@ -97,17 +92,17 @@ describe('Test bulk actions', function () { before(async function () { this.timeout(120000) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' }) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) - await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' }) + await servers[0].videosCommand.upload({ attributes: { name: 'video 1 server 1' } }) + await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) + await servers[0].videosCommand.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } }) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) + await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) await waitJobs(servers) { - const res = await getVideosList(servers[0].url) - for (const video of res.body.data) { + const { data } = await servers[0].videosCommand.list() + for (const video of data) { await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' }) await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' }) await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' }) @@ -115,9 +110,9 @@ describe('Test bulk actions', function () { } { - const res = await getVideosList(servers[1].url) + const { data } = await servers[1].videosCommand.list() - for (const video of res.body.data) { + for (const video of data) { await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' }) const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' }) @@ -142,9 +137,9 @@ describe('Test bulk actions', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - for (const video of res.body.data) { + for (const video of data) { const { data } = await server.commentsCommand.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 2') diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 95dafd378..c613511ed 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -11,8 +11,7 @@ import { parallelTests, reRunServer, ServerInfo, - setAccessTokensToServers, - uploadVideo + setAccessTokensToServers } from '@shared/extra-utils' import { CustomConfig } from '@shared/models' @@ -242,8 +241,8 @@ describe('Test config', function () { expect(data.video.file.extensions).to.contain('.webm') expect(data.video.file.extensions).to.contain('.ogv') - await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) - await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) + await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) + await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) expect(data.contactForm.enabled).to.be.true }) @@ -448,8 +447,8 @@ describe('Test config', function () { expect(data.video.file.extensions).to.contain('.ogg') expect(data.video.file.extensions).to.contain('.flac') - await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200) - await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200) + await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 }) + await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should have the configuration updated after a restart', async function () { diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 422db6ceb..aeda5fddb 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -3,15 +3,7 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - MockSmtpServer, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -58,20 +50,18 @@ describe('Test emails', function () { } { - const attributes = { - name: 'my super user video' - } - const res = await uploadVideo(server.url, userAccessToken, attributes) - videoUserUUID = res.body.video.uuid + const attributes = { name: 'my super user video' } + const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes }) + videoUserUUID = uuid } { const attributes = { name: 'my super name' } - const res = await uploadVideo(server.url, server.accessToken, attributes) - videoUUID = res.body.video.uuid - videoId = res.body.video.id + const { uuid, id } = await server.videosCommand.upload({ attributes }) + videoUUID = uuid + videoId = id } }) diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 29ccb264d..f9014aeee 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -3,19 +3,8 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - getAccountVideos, - getVideo, - getVideoChannelVideos, - getVideoWithToken, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils' const expect = chai.expect @@ -23,7 +12,7 @@ describe('Test follow constraints', function () { let servers: ServerInfo[] = [] let video1UUID: string let video2UUID: string - let userAccessToken: string + let userToken: string before(async function () { this.timeout(90000) @@ -34,12 +23,12 @@ describe('Test follow constraints', function () { await setAccessTokensToServers(servers) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) - video1UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) + video1UUID = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) - video2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) + video2UUID = uuid } const user = { @@ -47,7 +36,7 @@ describe('Test follow constraints', function () { password: 'super_password' } await servers[0].usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await servers[0].loginCommand.getAccessToken(user) + userToken = await servers[0].loginCommand.getAccessToken(user) await doubleFollow(servers[0], servers[1]) }) @@ -57,81 +46,81 @@ describe('Test follow constraints', function () { describe('With an unlogged user', function () { it('Should get the local video', async function () { - await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: video1UUID }) }) it('Should get the remote video', async function () { - await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: video2UUID }) }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[1].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) }) describe('With a logged user', function () { it('Should get the local video', async function () { - await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID }) }) it('Should get the remote video', async function () { - await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID }) }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) }) }) @@ -147,13 +136,12 @@ describe('Test follow constraints', function () { describe('With an unlogged user', function () { it('Should get the local video', async function () { - await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: video1UUID }) }) it('Should not get the remote video', async function () { - const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403) - - const error = res.body as PeerTubeProblemDocument + const body = await servers[0].videosCommand.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + const error = body as unknown as PeerTubeProblemDocument const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints' expect(error.type).to.equal(doc) @@ -168,73 +156,79 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ + token: undefined, + accountName: 'root@localhost:' + servers[0].port + }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should not list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ + token: undefined, + accountName: 'root@localhost:' + servers[1].port + }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should not list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) }) describe('With a logged user', function () { it('Should get the local video', async function () { - await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID }) }) it('Should get the remote video', async function () { - await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID }) }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) }) }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 02d25e67f..5ce8938fa 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -9,12 +9,9 @@ import { expectAccountFollows, flushAndRunMultipleServers, FollowsCommand, - getVideosList, - rateVideo, ServerInfo, setAccessTokensToServers, testCaptionFile, - uploadVideo, waitJobs } from '@shared/extra-utils' import { Video, VideoPrivacy } from '@shared/models' @@ -287,22 +284,28 @@ describe('Test follows', function () { it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { this.timeout(60000) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) + await servers[1].videosCommand.upload({ attributes: { name: 'server2' } }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3' } }) await waitJobs(servers) - let res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('server2') + { + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server2') + } - res = await getVideosList(servers[1].url) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('server2') + { + const { total, data } = await servers[1].videosCommand.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server2') + } - res = await getVideosList(servers[2].url) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('server3') + { + const { total, data } = await servers[2].videosCommand.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server3') + } }) describe('Should propagate data on a new following', function () { @@ -319,21 +322,21 @@ describe('Test follows', function () { tags: [ 'tag1', 'tag2', 'tag3' ] } - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' }) - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' }) - await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes) - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' }) - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3-2' } }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3-3' } }) + await servers[2].videosCommand.upload({ attributes: video4Attributes }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3-5' } }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3-6' } }) { const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain') - const resVideos = await getVideosList(servers[2].url) - video4 = resVideos.body.data.find(v => v.name === 'server3-4') + const { data } = await servers[2].videosCommand.list() + video4 = data.find(v => v.name === 'server3-4') { - await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like') - await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike') + await servers[2].videosCommand.rate({ id: video4.id, rating: 'like' }) + await servers[2].videosCommand.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' }) } { @@ -401,12 +404,12 @@ describe('Test follows', function () { }) it('Should have propagated videos', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(7) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(7) - const video2 = res.body.data.find(v => v.name === 'server3-2') - video4 = res.body.data.find(v => v.name === 'server3-4') - const video6 = res.body.data.find(v => v.name === 'server3-6') + const video2 = data.find(v => v.name === 'server3-2') + video4 = data.find(v => v.name === 'server3-4') + const video6 = data.find(v => v.name === 'server3-6') expect(video2).to.not.be.undefined expect(video4).to.not.be.undefined @@ -447,7 +450,7 @@ describe('Test follows', function () { } ] } - await completeVideoCheck(servers[0].url, video4, checkAttributes) + await completeVideoCheck(servers[0], video4, checkAttributes) }) it('Should have propagated comments', async function () { @@ -542,8 +545,8 @@ describe('Test follows', function () { await waitJobs(servers) - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(1) }) }) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index d45c3ae8a..35b905a8c 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -8,19 +8,14 @@ import { CommentsCommand, completeVideoCheck, flushAndRunMultipleServers, - getVideo, - getVideosList, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' -import { JobState, Video, VideoPrivacy } from '@shared/models' +import { JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -30,9 +25,9 @@ describe('Test handle downs', function () { let threadIdServer2: number let commentIdServer1: number let commentIdServer2: number - let missedVideo1: Video - let missedVideo2: Video - let unlistedVideo: Video + let missedVideo1: VideoCreateResult + let missedVideo2: VideoCreateResult + let unlistedVideo: VideoCreateResult const videoIdsServer1: string[] = [] @@ -110,15 +105,15 @@ describe('Test handle downs', function () { await waitJobs(servers) // Upload a video to server 1 - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes: videoAttributes }) await waitJobs(servers) // And check all servers have this video for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) + const { data } = await server.videosCommand.list() + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) } // Kill server 2 @@ -126,7 +121,7 @@ describe('Test handle downs', function () { // Remove server 2 follower for (let i = 0; i < 10; i++) { - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes: videoAttributes }) } await waitJobs([ servers[0], servers[2] ]) @@ -134,15 +129,12 @@ describe('Test handle downs', function () { // Kill server 3 await killallServers([ servers[2] ]) - const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - missedVideo1 = resLastVideo1.body.video + missedVideo1 = await servers[0].videosCommand.upload({ attributes: videoAttributes }) - const resLastVideo2 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - missedVideo2 = resLastVideo2.body.video + missedVideo2 = await servers[0].videosCommand.upload({ attributes: videoAttributes }) // Unlisted video - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, unlistedVideoAttributes) - unlistedVideo = resVideo.body.video + unlistedVideo = await servers[0].videosCommand.upload({ attributes: unlistedVideoAttributes }) // Add comments to video 2 { @@ -202,25 +194,27 @@ describe('Test handle downs', function () { it('Should send an update to server 3, and automatically fetch the video', async function () { this.timeout(15000) - const res1 = await getVideosList(servers[2].url) - expect(res1.body.data).to.be.an('array') - expect(res1.body.data).to.have.lengthOf(11) + { + const { data } = await servers[2].videosCommand.list() + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(11) + } - await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, {}) - await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, {}) + await servers[0].videosCommand.update({ id: missedVideo1.uuid }) + await servers[0].videosCommand.update({ id: unlistedVideo.uuid }) await waitJobs(servers) - const res = await getVideosList(servers[2].url) - expect(res.body.data).to.be.an('array') - // 1 video is unlisted - expect(res.body.data).to.have.lengthOf(12) + { + const { data } = await servers[2].videosCommand.list() + expect(data).to.be.an('array') + // 1 video is unlisted + expect(data).to.have.lengthOf(12) + } // Check unlisted video - const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid) - expect(resVideo.body).not.to.be.undefined - - await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes) + const video = await servers[2].videosCommand.get({ id: unlistedVideo.uuid }) + await completeVideoCheck(servers[2], video, unlistedCheckAttributes) }) it('Should send comments on a video to server 3, and automatically fetch the video', async function () { @@ -230,8 +224,7 @@ describe('Test handle downs', function () { await waitJobs(servers) - const resVideo = await getVideo(servers[2].url, missedVideo2.uuid) - expect(resVideo.body).not.to.be.undefined + await servers[2].videosCommand.get({ id: missedVideo2.uuid }) { const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid }) @@ -293,14 +286,14 @@ describe('Test handle downs', function () { this.timeout(120000) for (let i = 0; i < 10; i++) { - const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video ' + i })).uuid + const uuid = (await servers[0].videosCommand.quickUpload({ name: 'video ' + i })).uuid videoIdsServer1.push(uuid) } await waitJobs(servers) for (const id of videoIdsServer1) { - await getVideo(servers[1].url, id) + await servers[1].videosCommand.get({ id }) } await waitJobs(servers) @@ -310,7 +303,7 @@ describe('Test handle downs', function () { await wait(11000) // Refresh video -> score + 10 = 30 - await getVideo(servers[1].url, videoIdsServer1[0]) + await servers[1].videosCommand.get({ id: videoIdsServer1[0] }) await waitJobs(servers) }) @@ -325,14 +318,14 @@ describe('Test handle downs', function () { for (let i = 0; i < 5; i++) { try { - await getVideo(servers[1].url, videoIdsServer1[i]) + await servers[1].videosCommand.get({ id: videoIdsServer1[i] }) await waitJobs([ servers[1] ]) await wait(1500) } catch {} } for (const id of videoIdsServer1) { - await getVideo(servers[1].url, id, HttpStatusCode.FORBIDDEN_403) + await servers[1].videosCommand.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) } }) diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 6854568d3..aa4c7587b 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -9,7 +9,6 @@ import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' @@ -32,8 +31,8 @@ describe('Test jobs', function () { it('Should create some jobs', async function () { this.timeout(120000) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) + await servers[1].videosCommand.upload({ attributes: { name: 'video1' } }) + await servers[1].videosCommand.upload({ attributes: { name: 'video2' } }) await waitJobs(servers) }) diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index 096d63e21..e7bef5a4a 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -10,7 +10,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' @@ -34,12 +33,12 @@ describe('Test logs', function () { it('Should get logs with a start date', async function () { this.timeout(20000) - await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) + await server.videosCommand.upload({ attributes: { name: 'video 1' } }) await waitJobs([ server ]) const now = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) + await server.videosCommand.upload({ attributes: { name: 'video 2' } }) await waitJobs([ server ]) const body = await logsCommand.getLogs({ startDate: now }) @@ -52,17 +51,17 @@ describe('Test logs', function () { it('Should get logs with an end date', async function () { this.timeout(30000) - await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) + await server.videosCommand.upload({ attributes: { name: 'video 3' } }) await waitJobs([ server ]) const now1 = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 4' }) + await server.videosCommand.upload({ attributes: { name: 'video 4' } }) await waitJobs([ server ]) const now2 = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 5' }) + await server.videosCommand.upload({ attributes: { name: 'video 5' } }) await waitJobs([ server ]) const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 }) @@ -78,7 +77,7 @@ describe('Test logs', function () { const now = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 6' }) + await server.videosCommand.upload({ attributes: { name: 'video 6' } }) await waitJobs([ server ]) { @@ -131,12 +130,12 @@ describe('Test logs', function () { it('Should get logs with a start date', async function () { this.timeout(20000) - await uploadVideo(server.url, server.accessToken, { name: 'video 7' }) + await server.videosCommand.upload({ attributes: { name: 'video 7' } }) await waitJobs([ server ]) const now = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 8' }) + await server.videosCommand.upload({ attributes: { name: 'video 8' } }) await waitJobs([ server ]) const body = await logsCommand.getAuditLogs({ startDate: now }) @@ -157,17 +156,17 @@ describe('Test logs', function () { it('Should get logs with an end date', async function () { this.timeout(30000) - await uploadVideo(server.url, server.accessToken, { name: 'video 9' }) + await server.videosCommand.upload({ attributes: { name: 'video 9' } }) await waitJobs([ server ]) const now1 = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 10' }) + await server.videosCommand.upload({ attributes: { name: 'video 10' } }) await waitJobs([ server ]) const now2 = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 11' }) + await server.videosCommand.upload({ attributes: { name: 'video 11' } }) await waitJobs([ server ]) const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 }) diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index b8bae161a..5a6491430 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -2,20 +2,11 @@ import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - getVideo, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - viewVideo, - wait -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' describe('Test application behind a reverse proxy', function () { let server: ServerInfo - let videoId: number + let videoId: string before(async function () { this.timeout(30000) @@ -42,60 +33,60 @@ describe('Test application behind a reverse proxy', function () { server = await flushAndRunServer(1, config) await setAccessTokensToServers([ server ]) - const { body } = await uploadVideo(server.url, server.accessToken, {}) - videoId = body.video.uuid + const { uuid } = await server.videosCommand.upload() + videoId = uuid }) it('Should view a video only once with the same IP by default', async function () { this.timeout(20000) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) // Wait the repeatable job await wait(8000) - const { body } = await getVideo(server.url, videoId) - expect(body.views).to.equal(1) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.views).to.equal(1) }) it('Should view a video 2 times with the X-Forwarded-For header set', async function () { this.timeout(20000) - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.1,127.0.0.1') - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.2,127.0.0.1') + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.1,127.0.0.1' }) + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.2,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const { body } = await getVideo(server.url, videoId) - expect(body.views).to.equal(3) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.views).to.equal(3) }) it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () { this.timeout(20000) - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1') - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.5,0.0.0.3,127.0.0.1') + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.4,0.0.0.3,::ffff:127.0.0.1' }) + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.5,0.0.0.3,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const { body } = await getVideo(server.url, videoId) - expect(body.views).to.equal(4) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.views).to.equal(4) }) it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () { this.timeout(20000) - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.6,127.0.0.1') - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.7,127.0.0.1') + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.6,127.0.0.1' }) + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.7,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const { body } = await getVideo(server.url, videoId) - expect(body.views).to.equal(6) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.views).to.equal(6) }) it('Should rate limit logins', async function () { @@ -140,13 +131,13 @@ describe('Test application behind a reverse proxy', function () { for (let i = 0; i < 100; i++) { try { - await getVideo(server.url, videoId) + await server.videosCommand.get({ id: videoId }) } catch { // don't care if it fails } } - await getVideo(server.url, videoId, HttpStatusCode.TOO_MANY_REQUESTS_429) + await server.videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) }) after(async function () { diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts index 77b95de10..a62fb3939 100644 --- a/server/tests/api/server/services.ts +++ b/server/tests/api/server/services.ts @@ -2,15 +2,8 @@ import 'mocha' import * as chai from 'chai' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' import { Video, VideoPlaylistPrivacy } from '@shared/models' -import { - getVideosList, - ServerInfo, - setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideo -} from '../../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' const expect = chai.expect @@ -29,13 +22,11 @@ describe('Test services', function () { await setDefaultVideoChannel([ server ]) { - const videoAttributes = { - name: 'my super name' - } - await uploadVideo(server.url, server.accessToken, videoAttributes) + const attributes = { name: 'my super name' } + await server.videosCommand.upload({ attributes }) - const res = await getVideosList(server.url) - video = res.body.data[0] + const { data } = await server.videosCommand.list() + video = data[0] } { diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index a35709c26..3eb1efb94 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -8,8 +8,6 @@ import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, - uploadVideo, - viewVideo, wait, waitJobs } from '@shared/extra-utils' @@ -36,12 +34,11 @@ describe('Test stats (excluding redundancy)', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) - const videoUUID = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { fixture: 'video_short.webm' } }) - await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'comment' }) + await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) - await viewVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.view({ id: uuid }) // Wait the video views repeatable job await wait(8000) @@ -154,7 +151,7 @@ describe('Test stats (excluding redundancy)', function () { } { - await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId }) + await server.videosCommand.upload({ attributes: { fixture: 'video_short.webm', channelId } }) const data = await server.statsCommand.get() @@ -213,7 +210,7 @@ describe('Test stats (excluding redundancy)', function () { } }) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' }) + await servers[0].videosCommand.upload({ attributes: { name: 'video', fixture: 'video_short.webm' } }) await waitJobs(servers) @@ -243,7 +240,7 @@ describe('Test stats (excluding redundancy)', function () { const first = await servers[1].statsCommand.get() for (let i = 0; i < 10; i++) { - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) + await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) } await waitJobs(servers) diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index 868dc8977..032012edf 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts @@ -1,19 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */ -import * as magnetUtil from 'magnet-uri' import 'mocha' -import { - cleanupTests, - flushAndRunServer, - getVideo, - killallServers, - reRunServer, - ServerInfo, - uploadVideo -} from '../../../../shared/extra-utils' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { VideoDetails } from '../../../../shared/models/videos' +import * as magnetUtil from 'magnet-uri' import * as WebTorrent from 'webtorrent' +import { cleanupTests, flushAndRunServer, killallServers, reRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' describe('Test tracker', function () { let server: ServerInfo @@ -26,11 +16,8 @@ describe('Test tracker', function () { await setAccessTokensToServers([ server ]) { - const res = await uploadVideo(server.url, server.accessToken, {}) - const videoUUID = res.body.video.uuid - - const resGet = await getVideo(server.url, videoUUID) - const video: VideoDetails = resGet.body + const { uuid } = await server.videosCommand.upload() + const video = await server.videosCommand.get({ id: uuid }) goodMagnet = video.files[0].magnetUri const parsed = magnetUtil.decode(goodMagnet) diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index c09a85a32..622cddb7d 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -6,12 +6,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideosList, ServerInfo, setAccessTokensToServers, SubscriptionsCommand, - updateVideo, - uploadVideo, waitJobs } from '@shared/extra-utils' @@ -44,10 +41,10 @@ describe('Test users subscriptions', function () { users.push({ accessToken }) const videoName1 = 'video 1-' + server.serverNumber - await uploadVideo(server.url, accessToken, { name: videoName1 }) + await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } }) const videoName2 = 'video 2-' + server.serverNumber - await uploadVideo(server.url, accessToken, { name: videoName2 }) + await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } }) } } @@ -57,9 +54,9 @@ describe('Test users subscriptions', function () { }) it('Should display videos of server 2 on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total } = await servers[0].videosCommand.list() - expect(res.body.total).to.equal(4) + expect(total).to.equal(4) }) it('User of server 1 should follow user of server 3 and root of server 1', async function () { @@ -70,17 +67,17 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) - video3UUID = res.body.video.uuid + const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } }) + video3UUID = uuid await waitJobs(servers) }) it('Should not display videos of server 3 on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(4) - expect(res.body.total).to.equal(4) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -186,7 +183,7 @@ describe('Test users subscriptions', function () { this.timeout(60000) const videoName = 'video server 1 added after follow' - await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) + await servers[0].videosCommand.upload({ attributes: { name: videoName } }) await waitJobs(servers) @@ -212,10 +209,10 @@ describe('Test users subscriptions', function () { } { - const res = await getVideosList(servers[0].url) + const { data, total } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -230,13 +227,12 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await getVideosList(servers[0].url) - - expect(res.body.total).to.equal(8) + const { data, total } = await servers[0].videosCommand.list() + expect(total).to.equal(8) const names = [ '1-3', '2-3', 'video server 3 added after follow' ] for (const name of names) { - const video = res.body.data.find(v => v.name.indexOf(name) === -1) + const video = data.find(v => v.name.includes(name)) expect(video).to.not.be.undefined } }) @@ -248,10 +244,10 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -284,7 +280,7 @@ describe('Test users subscriptions', function () { it('Should update a video of server 3 and see the updated video on server 1', async function () { this.timeout(30000) - await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) + await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) await waitJobs(servers) @@ -329,10 +325,10 @@ describe('Test users subscriptions', function () { }) it('Should correctly display public videos on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow updated') @@ -360,10 +356,10 @@ describe('Test users subscriptions', function () { } { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow updated') diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 43e67ee60..3ae105008 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -9,11 +9,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getAccountVideos, ServerInfo, setAccessTokensToServers, testImage, - uploadVideo, waitJobs } from '@shared/extra-utils' import { User } from '@shared/models' @@ -44,7 +42,7 @@ describe('Test users with multiple servers', function () { await doubleFollow(servers[1], servers[2]) // The root user of server 1 is propagated to servers 2 and 3 - await uploadVideo(servers[0].url, servers[0].accessToken, {}) + await servers[0].videosCommand.upload() { const user = { @@ -57,8 +55,8 @@ describe('Test users with multiple servers', function () { } { - const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) - videoUUID = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken }) + videoUUID = uuid } await waitJobs(servers) @@ -133,31 +131,29 @@ describe('Test users with multiple servers', function () { it('Should list account videos', async function () { for (const server of servers) { - const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5) + const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].uuid).to.equal(videoUUID) + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].uuid).to.equal(videoUUID) } }) it('Should search through account videos', async function () { this.timeout(10_000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) + const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) await waitJobs(servers) for (const server of servers) { - const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { - search: 'Kami' - }) - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid) + const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) + + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].uuid).to.equal(created.uuid) } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 30d7e850d..6f3873939 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -6,17 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, - getMyVideos, - getVideosList, killallServers, makePutBodyRequest, - rateVideo, - removeVideo, reRunServer, ServerInfo, setAccessTokensToServers, testImage, - uploadVideo, waitJobs } from '@shared/extra-utils' import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' @@ -25,8 +20,8 @@ const expect = chai.expect describe('Test users', function () { let server: ServerInfo - let accessToken: string - let accessTokenUser: string + let token: string + let userToken: string let videoId: number let userId: number const user = { @@ -101,18 +96,17 @@ describe('Test users', function () { }) it('Should not be able to upload a video', async function () { - accessToken = 'my_super_token' + token = 'my_super_token' - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to follow', async function () { - accessToken = 'my_super_token' + token = 'my_super_token' await server.followsCommand.follow({ targets: [ 'http://example.com' ], - token: accessToken, + token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -122,7 +116,7 @@ describe('Test users', function () { it('Should be able to login', async function () { const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) - accessToken = body.access_token + token = body.access_token }) it('Should be able to login with an insensitive username', async function () { @@ -140,33 +134,31 @@ describe('Test users', function () { describe('Upload', function () { it('Should upload the video with the correct token', async function () { - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes) - const res = await getVideosList(server.url) - const video = res.body.data[0] + await server.videosCommand.upload({ token }) + const { data } = await server.videosCommand.list() + const video = data[0] expect(video.account.name).to.equal('root') videoId = video.id }) it('Should upload the video again with the correct token', async function () { - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes) + await server.videosCommand.upload({ token }) }) }) describe('Ratings', function () { it('Should retrieve a video rating', async function () { - await rateVideo(server.url, accessToken, videoId, 'like') - const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) + await server.videosCommand.rate({ id: videoId, rating: 'like' }) + const rating = await server.usersCommand.getMyRating({ token, videoId }) expect(rating.videoId).to.equal(videoId) expect(rating.rating).to.equal('like') }) it('Should retrieve ratings list', async function () { - await rateVideo(server.url, accessToken, videoId, 'like') + await server.videosCommand.rate({ id: videoId, rating: 'like' }) const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) @@ -190,13 +182,13 @@ describe('Test users', function () { describe('Remove video', function () { it('Should not be able to remove the video with an incorrect token', async function () { - await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to remove the video with the token of another account') it('Should be able to remove the video with the correct token', async function () { - await removeVideo(server.url, accessToken, videoId) + await server.videosCommand.remove({ token, id: videoId }) }) }) @@ -210,7 +202,7 @@ describe('Test users', function () { }) it('Should not be able to upload a video', async function () { - await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to rate a video', async function () { @@ -281,11 +273,11 @@ describe('Test users', function () { }) it('Should be able to login with this user', async function () { - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) it('Should be able to get user information', async function () { - const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const userMe = await server.usersCommand.getMyInfo({ token: userToken }) const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) @@ -323,15 +315,15 @@ describe('Test users', function () { it('Should be able to upload a video with this user', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'super user video', fixture: 'video_short.webm' } - await uploadVideo(server.url, accessTokenUser, videoAttributes) + await server.videosCommand.upload({ token: userToken, attributes }) }) it('Should have video quota updated', async function () { - const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) + const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken }) expect(quota.videoQuotaUsed).to.equal(218910) const { data } = await server.usersCommand.list() @@ -340,13 +332,11 @@ describe('Test users', function () { }) it('Should be able to list my videos', async function () { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5) - expect(res.body.total).to.equal(1) - - const videos = res.body.data - expect(videos).to.have.lengthOf(1) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken }) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) - const video: Video = videos[0] + const video: Video = data[0] expect(video.name).to.equal('super user video') expect(video.thumbnailPath).to.not.be.null expect(video.previewPath).to.not.be.null @@ -354,19 +344,15 @@ describe('Test users', function () { it('Should be able to search in my videos', async function () { { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') - expect(res.body.total).to.equal(1) - - const videos = res.body.data - expect(videos).to.have.lengthOf(1) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) } { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') - expect(res.body.total).to.equal(0) - - const videos = res.body.data - expect(videos).to.have.lengthOf(0) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } }) @@ -382,17 +368,17 @@ describe('Test users', function () { } { - const videoAttributes = { + const attributes = { name: 'super user video 2', fixture: 'video_short.webm' } - await uploadVideo(server.url, accessTokenUser, videoAttributes) + await server.videosCommand.upload({ token: userToken, attributes }) await waitJobs([ server ]) } { - const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) + const data = await server.usersCommand.getMyQuotaUsed({ token: userToken }) expect(data.videoQuotaUsed).to.be.greaterThan(220000) } }) @@ -505,7 +491,7 @@ describe('Test users', function () { it('Should update my password', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, currentPassword: 'super password', password: 'new password' }) @@ -516,11 +502,11 @@ describe('Test users', function () { it('Should be able to change the NSFW display attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, nsfwPolicy: 'do_not_list' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -532,32 +518,32 @@ describe('Test users', function () { it('Should be able to change the autoPlayVideo attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, autoPlayVideo: false }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.autoPlayVideo).to.be.false }) it('Should be able to change the autoPlayNextVideo attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, autoPlayNextVideo: true }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.autoPlayNextVideo).to.be.true }) it('Should be able to change the email attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, currentPassword: 'new password', email: 'updated@example.com' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -570,9 +556,9 @@ describe('Test users', function () { it('Should be able to update my avatar with a gif', async function () { const fixture = 'avatar.gif' - await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') }) @@ -580,17 +566,17 @@ describe('Test users', function () { for (const extension of [ '.png', '.gif' ]) { const fixture = 'avatar' + extension - await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) } }) it('Should be able to update my display name', async function () { - await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) + await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -601,9 +587,9 @@ describe('Test users', function () { }) it('Should be able to update my description', async function () { - await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) + await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -617,21 +603,21 @@ describe('Test users', function () { it('Should be able to update my theme', async function () { for (const theme of [ 'background-red', 'default', 'instance-default' ]) { - await server.usersCommand.updateMe({ token: accessTokenUser, theme }) + await server.usersCommand.updateMe({ token: userToken, theme }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.theme).to.equal(theme) } }) it('Should be able to update my modal preferences', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, noInstanceConfigWarningModal: true, noWelcomeModal: true }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.noWelcomeModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true }) @@ -641,7 +627,7 @@ describe('Test users', function () { it('Should be able to update another user', async function () { await server.usersCommand.update({ userId, - token: accessToken, + token, email: 'updated2@example.com', emailVerified: true, videoQuota: 42, @@ -650,7 +636,7 @@ describe('Test users', function () { pluginAuth: 'toto' }) - const user = await server.usersCommand.get({ token: accessToken, userId }) + const user = await server.usersCommand.get({ token, userId }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated2@example.com') @@ -664,39 +650,39 @@ describe('Test users', function () { }) it('Should reset the auth plugin', async function () { - await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) + await server.usersCommand.update({ userId, token, pluginAuth: null }) - const user = await server.usersCommand.get({ token: accessToken, userId }) + const user = await server.usersCommand.get({ token, userId }) expect(user.pluginAuth).to.be.null }) it('Should have removed the user token', async function () { - await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) it('Should be able to update another user password', async function () { - await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) + await server.usersCommand.update({ userId, token, password: 'password updated' }) - await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) user.password = 'password updated' - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) }) describe('Video blacklists', function () { it('Should be able to list video blacklist by a moderator', async function () { - await server.blacklistCommand.list({ token: accessTokenUser }) + await server.blacklistCommand.list({ token: userToken }) }) }) describe('Remove a user', function () { it('Should be able to remove this user', async function () { - await server.usersCommand.remove({ userId, token: accessToken }) + await server.usersCommand.remove({ userId, token }) }) it('Should not be able to login with this user', async function () { @@ -704,11 +690,10 @@ describe('Test users', function () { }) it('Should not have videos of this user', async function () { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(1) + const { data, total } = await server.videosCommand.list() + expect(total).to.equal(1) - const video = res.body.data[0] + const video = data[0] expect(video.account.name).to.equal('root') }) }) @@ -832,12 +817,11 @@ describe('Test users', function () { }) it('Should report correct videos count', async function () { - const videoAttributes = { - name: 'video to test user stats' - } - await uploadVideo(server.url, user17AccessToken, videoAttributes) - const res1 = await getVideosList(server.url) - videoId = res1.body.data.find(video => video.name === videoAttributes.name).id + const attributes = { name: 'video to test user stats' } + await server.videosCommand.upload({ token: user17AccessToken, attributes }) + + const { data } = await server.videosCommand.list() + videoId = data.find(video => video.name === attributes.name).id const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(1) diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index 9b516af81..e31905b36 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -4,17 +4,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - getVideo, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '../../../../shared/extra-utils' -import { VideoDetails } from '../../../../shared/models/videos' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -58,15 +48,13 @@ describe('Test audio only video transcoding', function () { it('Should upload a video and transcode it', async function () { this.timeout(120000) - const resUpload = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'audio only' }) - videoUUID = resUpload.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'audio only' } }) + videoUUID = uuid await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) for (const files of [ video.files, video.streamingPlaylists[0].files ]) { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 169bb2e23..5c13ac629 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -13,17 +13,9 @@ import { dateIsValid, doubleFollow, flushAndRunMultipleServers, - getLocalVideos, - getVideo, - getVideosList, - rateVideo, - removeVideo, ServerInfo, setAccessTokensToServers, testImage, - updateVideo, - uploadVideo, - viewVideo, wait, waitJobs, webtorrentAdd @@ -67,10 +59,9 @@ describe('Test multiple servers', function () { it('Should not have videos for all servers', async function () { for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(0) + const { data } = await server.videosCommand.list() + expect(data).to.be.an('array') + expect(data.length).to.equal(0) } }) @@ -78,7 +69,7 @@ describe('Test multiple servers', function () { it('Should upload the video on server 1 and propagate on each server', async function () { this.timeout(25000) - const videoAttributes = { + const attributes = { name: 'my super name for server 1', category: 5, licence: 4, @@ -91,7 +82,7 @@ describe('Test multiple servers', function () { channelId: videoChannelId, fixture: 'video_short1.webm' } - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) @@ -134,14 +125,13 @@ describe('Test multiple servers', function () { ] } - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) - const video = videos[0] + const { data } = await server.videosCommand.list() + expect(data).to.be.an('array') + expect(data.length).to.equal(1) + const video = data[0] - await completeVideoCheck(server.url, video, checkAttributes) - publishedAt = video.publishedAt + await completeVideoCheck(server, video, checkAttributes) + publishedAt = video.publishedAt as string } }) @@ -155,7 +145,7 @@ describe('Test multiple servers', function () { await servers[1].usersCommand.create({ username: user.username, password: user.password }) const userAccessToken = await servers[1].loginCommand.getAccessToken(user) - const videoAttributes = { + const attributes = { name: 'my super name for server 2', category: 4, licence: 3, @@ -168,7 +158,7 @@ describe('Test multiple servers', function () { thumbnailfile: 'thumbnail.jpg', previewfile: 'preview.jpg' } - await uploadVideo(servers[1].url, userAccessToken, videoAttributes, HttpStatusCode.OK_200, 'resumable') + await servers[1].videosCommand.upload({ token: userAccessToken, attributes, mode: 'resumable' }) // Transcoding await waitJobs(servers) @@ -223,65 +213,67 @@ describe('Test multiple servers', function () { previewfile: 'preview' } - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - const video = videos[1] + const { data } = await server.videosCommand.list() + expect(data).to.be.an('array') + expect(data.length).to.equal(2) + const video = data[1] - await completeVideoCheck(server.url, video, checkAttributes) + await completeVideoCheck(server, video, checkAttributes) } }) it('Should upload two videos on server 3 and propagate on each server', async function () { this.timeout(45000) - const videoAttributes1 = { - name: 'my super name for server 3', - category: 6, - licence: 5, - language: 'de', - nsfw: true, - description: 'my super description for server 3', - support: 'my super support text for server 3', - tags: [ 'tag1p3' ], - fixture: 'video_short3.webm' + { + const attributes = { + name: 'my super name for server 3', + category: 6, + licence: 5, + language: 'de', + nsfw: true, + description: 'my super description for server 3', + support: 'my super support text for server 3', + tags: [ 'tag1p3' ], + fixture: 'video_short3.webm' + } + await servers[2].videosCommand.upload({ attributes }) } - await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) - - const videoAttributes2 = { - name: 'my super name for server 3-2', - category: 7, - licence: 6, - language: 'ko', - nsfw: false, - description: 'my super description for server 3-2', - support: 'my super support text for server 3-2', - tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], - fixture: 'video_short.webm' + + { + const attributes = { + name: 'my super name for server 3-2', + category: 7, + licence: 6, + language: 'ko', + nsfw: false, + description: 'my super description for server 3-2', + support: 'my super support text for server 3-2', + tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], + fixture: 'video_short.webm' + } + await servers[2].videosCommand.upload({ attributes }) } - await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) await waitJobs(servers) // All servers should have this video for (const server of servers) { const isLocal = server.url === 'http://localhost:' + servers[2].port - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(4) + expect(data).to.be.an('array') + expect(data.length).to.equal(4) // We not sure about the order of the two last uploads let video1 = null let video2 = null - if (videos[2].name === 'my super name for server 3') { - video1 = videos[2] - video2 = videos[3] + if (data[2].name === 'my super name for server 3') { + video1 = data[2] + video2 = data[3] } else { - video1 = videos[3] - video2 = videos[2] + video1 = data[3] + video2 = data[2] } const checkAttributesVideo1 = { @@ -316,7 +308,7 @@ describe('Test multiple servers', function () { } ] } - await completeVideoCheck(server.url, video1, checkAttributesVideo1) + await completeVideoCheck(server, video1, checkAttributesVideo1) const checkAttributesVideo2 = { name: 'my super name for server 3-2', @@ -350,38 +342,38 @@ describe('Test multiple servers', function () { } ] } - await completeVideoCheck(server.url, video2, checkAttributesVideo2) + await completeVideoCheck(server, video2, checkAttributesVideo2) } }) }) describe('It should list local videos', function () { it('Should list only local videos on server 1', async function () { - const { body } = await getLocalVideos(servers[0].url) + const { data, total } = await servers[0].videosCommand.list({ filter: 'local' }) - expect(body.total).to.equal(1) - expect(body.data).to.be.an('array') - expect(body.data.length).to.equal(1) - expect(body.data[0].name).to.equal('my super name for server 1') + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) + expect(data[0].name).to.equal('my super name for server 1') }) it('Should list only local videos on server 2', async function () { - const { body } = await getLocalVideos(servers[1].url) + const { data, total } = await servers[1].videosCommand.list({ filter: 'local' }) - expect(body.total).to.equal(1) - expect(body.data).to.be.an('array') - expect(body.data.length).to.equal(1) - expect(body.data[0].name).to.equal('my super name for server 2') + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) + expect(data[0].name).to.equal('my super name for server 2') }) it('Should list only local videos on server 3', async function () { - const { body } = await getLocalVideos(servers[2].url) + const { data, total } = await servers[2].videosCommand.list({ filter: 'local' }) - expect(body.total).to.equal(2) - expect(body.data).to.be.an('array') - expect(body.data.length).to.equal(2) - expect(body.data[0].name).to.equal('my super name for server 3') - expect(body.data[1].name).to.equal('my super name for server 3-2') + expect(total).to.equal(2) + expect(data).to.be.an('array') + expect(data.length).to.equal(2) + expect(data[0].name).to.equal('my super name for server 3') + expect(data[1].name).to.equal('my super name for server 3-2') }) }) @@ -389,15 +381,13 @@ describe('Test multiple servers', function () { it('Should add the file 1 by asking server 3', async function () { this.timeout(10000) - const res = await getVideosList(servers[2].url) - - const video = res.body.data[0] - toRemove.push(res.body.data[2]) - toRemove.push(res.body.data[3]) + const { data } = await servers[2].videosCommand.list() - const res2 = await getVideo(servers[2].url, video.id) - const videoDetails = res2.body + const video = data[0] + toRemove.push(data[2]) + toRemove.push(data[3]) + const videoDetails = await servers[2].videosCommand.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') expect(torrent.files.length).to.equal(1) @@ -407,11 +397,10 @@ describe('Test multiple servers', function () { it('Should add the file 2 by asking server 1', async function () { this.timeout(10000) - const res = await getVideosList(servers[0].url) + const { data } = await servers[0].videosCommand.list() - const video = res.body.data[1] - const res2 = await getVideo(servers[0].url, video.id) - const videoDetails = res2.body + const video = data[1] + const videoDetails = await servers[0].videosCommand.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') @@ -422,11 +411,10 @@ describe('Test multiple servers', function () { it('Should add the file 3 by asking server 2', async function () { this.timeout(10000) - const res = await getVideosList(servers[1].url) + const { data } = await servers[1].videosCommand.list() - const video = res.body.data[2] - const res2 = await getVideo(servers[1].url, video.id) - const videoDetails = res2.body + const video = data[2] + const videoDetails = await servers[1].videosCommand.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') @@ -437,11 +425,10 @@ describe('Test multiple servers', function () { it('Should add the file 3-2 by asking server 1', async function () { this.timeout(10000) - const res = await getVideosList(servers[0].url) + const { data } = await servers[0].videosCommand.list() - const video = res.body.data[3] - const res2 = await getVideo(servers[0].url, video.id) - const videoDetails = res2.body + const video = data[3] + const videoDetails = await servers[0].videosCommand.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) expect(torrent.files).to.be.an('array') @@ -452,11 +439,10 @@ describe('Test multiple servers', function () { it('Should add the file 2 in 360p by asking server 1', async function () { this.timeout(10000) - const res = await getVideosList(servers[0].url) + const { data } = await servers[0].videosCommand.list() - const video = res.body.data.find(v => v.name === 'my super name for server 2') - const res2 = await getVideo(servers[0].url, video.id) - const videoDetails = res2.body + const video = data.find(v => v.name === 'my super name for server 2') + const videoDetails = await servers[0].videosCommand.get({ id: video.id }) const file = videoDetails.files.find(f => f.resolution.id === 360) expect(file).not.to.be.undefined @@ -475,30 +461,36 @@ describe('Test multiple servers', function () { let remoteVideosServer3 = [] before(async function () { - const res1 = await getVideosList(servers[0].url) - remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) + { + const { data } = await servers[0].videosCommand.list() + remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid) + } - const res2 = await getVideosList(servers[1].url) - remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) + { + const { data } = await servers[1].videosCommand.list() + remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid) + } - const res3 = await getVideosList(servers[2].url) - localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) - remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) + { + const { data } = await servers[2].videosCommand.list() + localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid) + remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid) + } }) it('Should view multiple videos on owned servers', async function () { this.timeout(30000) - await viewVideo(servers[2].url, localVideosServer3[0]) + await servers[2].videosCommand.view({ id: localVideosServer3[0] }) await wait(1000) - await viewVideo(servers[2].url, localVideosServer3[0]) - await viewVideo(servers[2].url, localVideosServer3[1]) + await servers[2].videosCommand.view({ id: localVideosServer3[0] }) + await servers[2].videosCommand.view({ id: localVideosServer3[1] }) await wait(1000) - await viewVideo(servers[2].url, localVideosServer3[0]) - await viewVideo(servers[2].url, localVideosServer3[0]) + await servers[2].videosCommand.view({ id: localVideosServer3[0] }) + await servers[2].videosCommand.view({ id: localVideosServer3[0] }) await waitJobs(servers) @@ -508,11 +500,10 @@ describe('Test multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - const video0 = videos.find(v => v.uuid === localVideosServer3[0]) - const video1 = videos.find(v => v.uuid === localVideosServer3[1]) + const video0 = data.find(v => v.uuid === localVideosServer3[0]) + const video1 = data.find(v => v.uuid === localVideosServer3[1]) expect(video0.views).to.equal(3) expect(video1.views).to.equal(1) @@ -523,16 +514,16 @@ describe('Test multiple servers', function () { this.timeout(45000) const tasks: Promise[] = [] - tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) - tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) - tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) - tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) - tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) + tasks.push(servers[0].videosCommand.view({ id: remoteVideosServer1[0] })) + tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] })) + tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] })) + tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[0] })) + tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) await Promise.all(tasks) @@ -546,18 +537,16 @@ describe('Test multiple servers', function () { let baseVideos = null for (const server of servers) { - const res = await getVideosList(server.url) - - const videos = res.body.data + const { data } = await server.videosCommand.list() // Initialize base videos for future comparisons if (baseVideos === null) { - baseVideos = videos + baseVideos = data continue } for (const baseVideo of baseVideos) { - const sameVideo = videos.find(video => video.name === baseVideo.name) + const sameVideo = data.find(video => video.name === baseVideo.name) expect(baseVideo.views).to.equal(sameVideo.views) } } @@ -566,17 +555,17 @@ describe('Test multiple servers', function () { it('Should like and dislikes videos on different services', async function () { this.timeout(50000) - await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') + await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' }) await wait(500) - await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike') + await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'dislike' }) await wait(500) - await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') - await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like') + await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' }) + await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'like' }) await wait(500) - await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike') - await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike') + await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'dislike' }) + await servers[2].videosCommand.rate({ id: remoteVideosServer3[1], rating: 'dislike' }) await wait(500) - await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') + await servers[2].videosCommand.rate({ id: remoteVideosServer3[0], rating: 'like' }) await waitJobs(servers) await wait(5000) @@ -584,18 +573,16 @@ describe('Test multiple servers', function () { let baseVideos = null for (const server of servers) { - const res = await getVideosList(server.url) - - const videos = res.body.data + const { data } = await server.videosCommand.list() // Initialize base videos for future comparisons if (baseVideos === null) { - baseVideos = videos + baseVideos = data continue } for (const baseVideo of baseVideos) { - const sameVideo = videos.find(video => video.name === baseVideo.name) + const sameVideo = data.find(video => video.name === baseVideo.name) expect(baseVideo.likes).to.equal(sameVideo.likes) expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) } @@ -621,7 +608,7 @@ describe('Test multiple servers', function () { previewfile: 'preview.jpg' } - await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) + await servers[2].videosCommand.update({ id: toRemove[0].id, attributes }) await waitJobs(servers) }) @@ -630,10 +617,9 @@ describe('Test multiple servers', function () { this.timeout(10000) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - const videoUpdated = videos.find(video => video.name === 'my super video updated') + const videoUpdated = data.find(video => video.name === 'my super video updated') expect(!!videoUpdated).to.be.true const isLocal = server.url === 'http://localhost:' + servers[2].port @@ -672,15 +658,15 @@ describe('Test multiple servers', function () { thumbnailfile: 'thumbnail', previewfile: 'preview' } - await completeVideoCheck(server.url, videoUpdated, checkAttributes) + await completeVideoCheck(server, videoUpdated, checkAttributes) } }) it('Should remove the videos 3 and 3-2 by asking server 3', async function () { this.timeout(10000) - await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) - await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) + await servers[2].videosCommand.remove({ id: toRemove[0].id }) + await servers[2].videosCommand.remove({ id: toRemove[1].id }) await waitJobs(servers) }) @@ -694,27 +680,24 @@ describe('Test multiple servers', function () { it('Should have videos 1 and 3 on each server', async function () { for (const server of servers) { - const res = await getVideosList(server.url) - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - expect(videos[0].name).not.to.equal(videos[1].name) - expect(videos[0].name).not.to.equal(toRemove[0].name) - expect(videos[1].name).not.to.equal(toRemove[0].name) - expect(videos[0].name).not.to.equal(toRemove[1].name) - expect(videos[1].name).not.to.equal(toRemove[1].name) - - videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid + const { data } = await server.videosCommand.list() + + expect(data).to.be.an('array') + expect(data.length).to.equal(2) + expect(data[0].name).not.to.equal(data[1].name) + expect(data[0].name).not.to.equal(toRemove[0].name) + expect(data[1].name).not.to.equal(toRemove[0].name) + expect(data[0].name).not.to.equal(toRemove[1].name) + expect(data[1].name).not.to.equal(toRemove[1].name) + + videoUUID = data.find(video => video.name === 'my super name for server 1').uuid } }) it('Should get the same video by UUID on each server', async function () { let baseVideo = null for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) if (baseVideo === null) { baseVideo = video @@ -737,8 +720,7 @@ describe('Test multiple servers', function () { it('Should get the preview from each server', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) await testImage(server.url, 'video_short1-preview.webm', video.previewPath) } @@ -975,14 +957,14 @@ describe('Test multiple servers', function () { downloadEnabled: false } - await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) + await servers[0].videosCommand.update({ id: videoUUID, attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - expect(res.body.commentsEnabled).to.be.false - expect(res.body.downloadEnabled).to.be.false + const video = await server.videosCommand.get({ id: videoUUID }) + expect(video.commentsEnabled).to.be.false + expect(video.downloadEnabled).to.be.false const text = 'my super forbidden comment' await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) @@ -1010,8 +992,8 @@ describe('Test multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const video = res.body.data.find(v => v.name === 'minimum parameters') + const { data } = await server.videosCommand.list() + const video = data.find(v => v.name === 'minimum parameters') const isLocal = server.url === 'http://localhost:' + servers[1].port const checkAttributes = { @@ -1058,7 +1040,7 @@ describe('Test multiple servers', function () { } ] } - await completeVideoCheck(server.url, video, checkAttributes) + await completeVideoCheck(server, video, checkAttributes) } }) }) diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 642c115d0..b7756a4a8 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -9,8 +9,6 @@ import { buildAbsoluteFixturePath, cleanupTests, flushAndRunServer, - prepareResumableUpload, - sendResumableChunks, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel @@ -45,7 +43,7 @@ describe('Test resumable upload', function () { const mimetype = 'video/mp4' - const res = await prepareResumableUpload({ url: server.url, token: server.accessToken, attributes, size, mimetype }) + const res = await server.videosCommand.prepareResumableUpload({ attributes, size, mimetype }) return res.header['location'].split('?')[1] } @@ -63,15 +61,13 @@ describe('Test resumable upload', function () { const size = await buildSize(defaultFixture, options.size) const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture) - return sendResumableChunks({ - url: server.url, - token: server.accessToken, + return server.videosCommand.sendResumableChunks({ pathUploadId, videoFilePath: absoluteFilePath, size, contentLength, contentRangeBuilder, - specialStatus: expectedStatus + expectedStatus }) } diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index af1703e02..da0b2011e 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -2,34 +2,17 @@ import 'mocha' import * as chai from 'chai' -import { keyBy } from 'lodash' - import { checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, flushAndRunServer, - getVideo, - getVideoCategories, - getVideoLanguages, - getVideoLicences, - getVideoPrivacies, - getVideosList, - getVideosListPagination, - getVideosListSort, - getVideosWithFilters, - rateVideo, - removeVideo, ServerInfo, setAccessTokensToServers, testImage, - updateVideo, - uploadVideo, - viewVideo, wait -} from '../../../../shared/extra-utils' -import { VideoPrivacy } from '../../../../shared/models/videos' -import { HttpStatusCode } from '@shared/core-utils' +} from '@shared/extra-utils' +import { Video, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -37,8 +20,8 @@ describe('Test a single server', function () { function runSuite (mode: 'legacy' | 'resumable') { let server: ServerInfo = null - let videoId = -1 - let videoId2 = -1 + let videoId: number | string + let videoId2: string let videoUUID = '' let videosListBase: any[] = null @@ -117,128 +100,116 @@ describe('Test a single server', function () { }) it('Should list video categories', async function () { - const res = await getVideoCategories(server.url) - - const categories = res.body + const categories = await server.videosCommand.getCategories() expect(Object.keys(categories)).to.have.length.above(10) expect(categories[11]).to.equal('News & Politics') }) it('Should list video licences', async function () { - const res = await getVideoLicences(server.url) - - const licences = res.body + const licences = await server.videosCommand.getLicences() expect(Object.keys(licences)).to.have.length.above(5) expect(licences[3]).to.equal('Attribution - No Derivatives') }) it('Should list video languages', async function () { - const res = await getVideoLanguages(server.url) - - const languages = res.body + const languages = await server.videosCommand.getLanguages() expect(Object.keys(languages)).to.have.length.above(5) expect(languages['ru']).to.equal('Russian') }) it('Should list video privacies', async function () { - const res = await getVideoPrivacies(server.url) - - const privacies = res.body + const privacies = await server.videosCommand.getPrivacies() expect(Object.keys(privacies)).to.have.length.at.least(3) expect(privacies[3]).to.equal('Private') }) it('Should not have videos', async function () { - const res = await getVideosList(server.url) + const { data, total } = await server.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) }) it('Should upload the video', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'my super name', category: 2, nsfw: true, licence: 6, tags: [ 'tag1', 'tag2', 'tag3' ] } - const res = await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) - expect(res.body.video).to.not.be.undefined - expect(res.body.video.id).to.equal(1) - expect(res.body.video.uuid).to.have.length.above(5) + const video = await server.videosCommand.upload({ attributes, mode }) + expect(video).to.not.be.undefined + expect(video.id).to.equal(1) + expect(video.uuid).to.have.length.above(5) - videoId = res.body.video.id - videoUUID = res.body.video.uuid + videoId = video.id + videoUUID = video.uuid }) it('Should get and seed the uploaded video', async function () { this.timeout(5000) - const res = await getVideosList(server.url) + const { data, total } = await server.videosCommand.list() - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) - const video = res.body.data[0] - await completeVideoCheck(server.url, video, getCheckAttributes()) + const video = data[0] + await completeVideoCheck(server, video, getCheckAttributes()) }) it('Should get the video by UUID', async function () { this.timeout(5000) - const res = await getVideo(server.url, videoUUID) - - const video = res.body - await completeVideoCheck(server.url, video, getCheckAttributes()) + const video = await server.videosCommand.get({ id: videoUUID }) + await completeVideoCheck(server, video, getCheckAttributes()) }) it('Should have the views updated', async function () { this.timeout(20000) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) await wait(1500) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) await wait(1500) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) // Wait the repeatable job await wait(8000) - const res = await getVideo(server.url, videoId) - - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) expect(video.views).to.equal(3) }) it('Should remove the video', async function () { - await removeVideo(server.url, server.accessToken, videoId) + await server.videosCommand.remove({ id: videoId }) await checkVideoFilesWereRemoved(videoUUID, server) }) it('Should not have videos', async function () { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(0) }) it('Should upload 6 videos', async function () { @@ -250,7 +221,7 @@ describe('Test a single server', function () { ]) for (const video of videos) { - const videoAttributes = { + const attributes = { name: video + ' name', description: video + ' description', category: 2, @@ -261,19 +232,20 @@ describe('Test a single server', function () { fixture: video } - await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) + await server.videosCommand.upload({ attributes, mode }) } }) it('Should have the correct durations', async function () { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() + + expect(total).to.equal(6) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(6) - expect(res.body.total).to.equal(6) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos).to.have.lengthOf(6) + const videosByName: { [ name: string ]: Video } = {} + data.forEach(v => { videosByName[v.name] = v }) - const videosByName = keyBy<{ duration: number }>(videos, 'name') expect(videosByName['video_short.mp4 name'].duration).to.equal(5) expect(videosByName['video_short.ogv name'].duration).to.equal(5) expect(videosByName['video_short.webm name'].duration).to.equal(5) @@ -283,96 +255,87 @@ describe('Test a single server', function () { }) it('Should have the correct thumbnails', async function () { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data // For the next test - videosListBase = videos + videosListBase = data - for (const video of videos) { + for (const video of data) { const videoName = video.name.replace(' name', '') await testImage(server.url, videoName, video.thumbnailPath) } }) it('Should list only the two first videos', async function () { - const res = await getVideosListPagination(server.url, 0, 2, 'name') + const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: 'name' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) - expect(videos[0].name).to.equal(videosListBase[0].name) - expect(videos[1].name).to.equal(videosListBase[1].name) + expect(total).to.equal(6) + expect(data.length).to.equal(2) + expect(data[0].name).to.equal(videosListBase[0].name) + expect(data[1].name).to.equal(videosListBase[1].name) }) it('Should list only the next three videos', async function () { - const res = await getVideosListPagination(server.url, 2, 3, 'name') + const { total, data } = await server.videosCommand.list({ start: 2, count: 3, sort: 'name' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(3) - expect(videos[0].name).to.equal(videosListBase[2].name) - expect(videos[1].name).to.equal(videosListBase[3].name) - expect(videos[2].name).to.equal(videosListBase[4].name) + expect(total).to.equal(6) + expect(data.length).to.equal(3) + expect(data[0].name).to.equal(videosListBase[2].name) + expect(data[1].name).to.equal(videosListBase[3].name) + expect(data[2].name).to.equal(videosListBase[4].name) }) it('Should list the last video', async function () { - const res = await getVideosListPagination(server.url, 5, 6, 'name') + const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(1) - expect(videos[0].name).to.equal(videosListBase[5].name) + expect(total).to.equal(6) + expect(data.length).to.equal(1) + expect(data[0].name).to.equal(videosListBase[5].name) }) it('Should not have the total field', async function () { - const res = await getVideosListPagination(server.url, 5, 6, 'name', true) + const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name', skipCount: true }) - const videos = res.body.data - expect(res.body.total).to.not.exist - expect(videos.length).to.equal(1) - expect(videos[0].name).to.equal(videosListBase[5].name) + expect(total).to.not.exist + expect(data.length).to.equal(1) + expect(data[0].name).to.equal(videosListBase[5].name) }) it('Should list and sort by name in descending order', async function () { - const res = await getVideosListSort(server.url, '-name') + const { total, data } = await server.videosCommand.list({ sort: '-name' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(6) - expect(videos[0].name).to.equal('video_short.webm name') - expect(videos[1].name).to.equal('video_short.ogv name') - expect(videos[2].name).to.equal('video_short.mp4 name') - expect(videos[3].name).to.equal('video_short3.webm name') - expect(videos[4].name).to.equal('video_short2.webm name') - expect(videos[5].name).to.equal('video_short1.webm name') + expect(total).to.equal(6) + expect(data.length).to.equal(6) + expect(data[0].name).to.equal('video_short.webm name') + expect(data[1].name).to.equal('video_short.ogv name') + expect(data[2].name).to.equal('video_short.mp4 name') + expect(data[3].name).to.equal('video_short3.webm name') + expect(data[4].name).to.equal('video_short2.webm name') + expect(data[5].name).to.equal('video_short1.webm name') - videoId = videos[3].uuid - videoId2 = videos[5].uuid + videoId = data[3].uuid + videoId2 = data[5].uuid }) it('Should list and sort by trending in descending order', async function () { - const res = await getVideosListPagination(server.url, 0, 2, '-trending') + const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-trending' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) + expect(total).to.equal(6) + expect(data.length).to.equal(2) }) it('Should list and sort by hotness in descending order', async function () { - const res = await getVideosListPagination(server.url, 0, 2, '-hot') + const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-hot' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) + expect(total).to.equal(6) + expect(data.length).to.equal(2) }) it('Should list and sort by best in descending order', async function () { - const res = await getVideosListPagination(server.url, 0, 2, '-best') + const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-best' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) + expect(total).to.equal(6) + expect(data.length).to.equal(2) }) it('Should update a video', async function () { @@ -387,67 +350,66 @@ describe('Test a single server', function () { downloadEnabled: false, tags: [ 'tagup1', 'tagup2' ] } - await updateVideo(server.url, server.accessToken, videoId, attributes) + await server.videosCommand.update({ id: videoId, attributes }) }) it('Should filter by tags and category', async function () { - const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) - expect(res1.body.total).to.equal(1) - expect(res1.body.data[0].name).to.equal('my super video updated') + { + const { data, total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) + expect(total).to.equal(1) + expect(data[0].name).to.equal('my super video updated') + } - const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) - expect(res2.body.total).to.equal(0) + { + const { total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) + expect(total).to.equal(0) + } }) it('Should have the video updated', async function () { this.timeout(60000) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) - await completeVideoCheck(server.url, video, updateCheckAttributes()) + await completeVideoCheck(server, video, updateCheckAttributes()) }) it('Should update only the tags of a video', async function () { const attributes = { tags: [ 'supertag', 'tag1', 'tag2' ] } - await updateVideo(server.url, server.accessToken, videoId, attributes) + await server.videosCommand.update({ id: videoId, attributes }) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) - await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes)) + await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes)) }) it('Should update only the description of a video', async function () { const attributes = { description: 'hello everybody' } - await updateVideo(server.url, server.accessToken, videoId, attributes) + await server.videosCommand.update({ id: videoId, attributes }) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) - await completeVideoCheck(server.url, video, expectedAttributes) + await completeVideoCheck(server, video, expectedAttributes) }) it('Should like a video', async function () { - await rateVideo(server.url, server.accessToken, videoId, 'like') + await server.videosCommand.rate({ id: videoId, rating: 'like' }) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) expect(video.likes).to.equal(1) expect(video.dislikes).to.equal(0) }) it('Should dislike the same video', async function () { - await rateVideo(server.url, server.accessToken, videoId, 'dislike') + await server.videosCommand.rate({ id: videoId, rating: 'dislike' }) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(1) @@ -457,10 +419,10 @@ describe('Test a single server', function () { { const now = new Date() const attributes = { originallyPublishedAt: now.toISOString() } - await updateVideo(server.url, server.accessToken, videoId, attributes) + await server.videosCommand.update({ id: videoId, attributes }) - const res = await getVideosListSort(server.url, '-originallyPublishedAt') - const names = res.body.data.map(v => v.name) + const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' }) + const names = data.map(v => v.name) expect(names[0]).to.equal('my super video updated') expect(names[1]).to.equal('video_short2.webm name') @@ -473,10 +435,10 @@ describe('Test a single server', function () { { const now = new Date() const attributes = { originallyPublishedAt: now.toISOString() } - await updateVideo(server.url, server.accessToken, videoId2, attributes) + await server.videosCommand.update({ id: videoId2, attributes }) - const res = await getVideosListSort(server.url, '-originallyPublishedAt') - const names = res.body.data.map(v => v.name) + const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' }) + const names = data.map(v => v.name) expect(names[0]).to.equal('video_short1.webm name') expect(names[1]).to.equal('my super video updated') diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index d4a5385ab..4c67e96f7 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -7,11 +7,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - removeVideo, ServerInfo, setAccessTokensToServers, testCaptionFile, - uploadVideo, wait, waitJobs } from '@shared/extra-utils' @@ -34,8 +32,8 @@ describe('Test video captions', function () { await waitJobs(servers) - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'my video name' } }) + videoUUID = uuid await waitJobs(servers) }) @@ -180,7 +178,7 @@ describe('Test video captions', function () { }) it('Should remove the video, and thus all video captions', async function () { - await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) + await servers[0].videosCommand.remove({ id: videoUUID }) await checkVideoFilesWereRemoved(videoUUID, servers[0]) }) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index b0bbd5a0d..b85edd920 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,22 +2,19 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { ChangeOwnershipCommand, cleanupTests, doubleFollow, flushAndRunMultipleServers, flushAndRunServer, - getVideo, - getVideosList, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -71,14 +68,13 @@ describe('Test video change ownership - nominal', function () { } { - const videoAttributes = { + const attributes = { name: 'my super name', description: 'my super description' } - const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes) + const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes }) - const resVideo = await getVideo(servers[0].url, res.body.video.id) - servers[0].video = resVideo.body + servers[0].video = await servers[0].videosCommand.get({ id }) } { @@ -212,9 +208,7 @@ describe('Test video change ownership - nominal', function () { it('Should have the channel of the video updated', async function () { for (const server of servers) { - const res = await getVideo(server.url, servers[0].video.uuid) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: servers[0].video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -243,9 +237,7 @@ describe('Test video change ownership - nominal', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, servers[0].video.uuid) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: servers[0].video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -280,20 +272,18 @@ describe('Test video change ownership - quota too small', function () { secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server - const video1Attributes = { + const attributes = { name: 'my super name', description: 'my super description' } - await uploadVideo(server.url, firstUserToken, video1Attributes) + await server.videosCommand.upload({ token: firstUserToken, attributes }) await waitJobs(server) - const res = await getVideosList(server.url) - const videos = res.body.data - - expect(videos.length).to.equal(1) + const { data } = await server.videosCommand.list() + expect(data.length).to.equal(1) - server.video = videos.find(video => video.name === 'my super name') + server.video = data.find(video => video.name === 'my super name') }) it('Should send a request to change ownership of a video', async function () { diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 2e57cbbff..170cc942e 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -8,20 +8,15 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideoChannelVideos, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, testFileExistsOrNot, testImage, - updateVideo, - uploadVideo, - viewVideo, wait, waitJobs } from '@shared/extra-utils' -import { User, Video, VideoChannel, VideoDetails } from '@shared/models' +import { User, VideoChannel } from '@shared/models' const expect = chai.expect @@ -77,9 +72,9 @@ describe('Test video channels', function () { // The channel is 1 is propagated to servers 2 { - const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } - const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg) - videoUUID = res.body.video.uuid + const attributes = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } + const { uuid } = await servers[0].videosCommand.upload({ attributes }) + videoUUID = uuid } await waitJobs(servers) @@ -219,9 +214,7 @@ describe('Test video channels', function () { it('Should not have updated the video support field', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.support).to.equal('video support field') } }) @@ -239,9 +232,7 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.support).to.equal(videoChannelAttributes.support) } }) @@ -333,18 +324,19 @@ describe('Test video channels', function () { for (const server of servers) { const channelURI = 'second_video_channel@localhost:' + servers[0].port - const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) - expect(res1.body.total).to.equal(1) - expect(res1.body.data).to.be.an('array') - expect(res1.body.data).to.have.lengthOf(1) - expect(res1.body.data[0].name).to.equal('my video name') + const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI }) + + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('my video name') } }) it('Should change the video channel of a video', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: servers[0].videoChannel.id }) + await servers[0].videosCommand.update({ id: videoUUID, attributes: { channelId: servers[0].videoChannel.id } }) await waitJobs(servers) }) @@ -353,18 +345,21 @@ describe('Test video channels', function () { this.timeout(10000) for (const server of servers) { - const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port - const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) - expect(res1.body.total).to.equal(0) - - const channelURI = 'root_channel@localhost:' + servers[0].port - const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) - expect(res2.body.total).to.equal(1) - - const videos: Video[] = res2.body.data - expect(videos).to.be.an('array') - expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('my video name') + { + const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port + const { total } = await server.videosCommand.listByChannel({ videoChannelName: secondChannelURI }) + expect(total).to.equal(0) + } + + { + const channelURI = 'root_channel@localhost:' + servers[0].port + const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI }) + expect(total).to.equal(1) + + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('my video name') + } } }) @@ -417,8 +412,8 @@ describe('Test video channels', function () { { // video has been posted on channel servers[0].videoChannel.id since last update - await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') - await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') + await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' }) + await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' }) // Wait the repeatable job await wait(8000) @@ -460,7 +455,7 @@ describe('Test video channels', function () { it('Should list channels by updatedAt desc if a video has been uploaded', async function () { this.timeout(30000) - await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: totoChannel }) + await servers[0].videosCommand.upload({ attributes: { channelId: totoChannel } }) await waitJobs(servers) for (const server of servers) { @@ -470,7 +465,7 @@ describe('Test video channels', function () { expect(data[1].name).to.equal('root_channel') } - await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: servers[0].videoChannel.id }) + await servers[0].videosCommand.upload({ attributes: { channelId: servers[0].videoChannel.id } }) await waitJobs(servers) for (const server of servers) { diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 266824d58..41be54c81 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -9,8 +9,7 @@ import { flushAndRunServer, ServerInfo, setAccessTokensToServers, - testImage, - uploadVideo + testImage } from '@shared/extra-utils' const expect = chai.expect @@ -33,9 +32,9 @@ describe('Test video comments', function () { await setAccessTokensToServers([ server ]) - const res = await uploadVideo(server.url, server.accessToken, {}) - videoUUID = res.body.video.uuid - videoId = res.body.video.id + const { id, uuid } = await server.videosCommand.upload() + videoUUID = uuid + videoId = id await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index e1c9afe79..6ac9206f5 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -2,19 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - flushAndRunMultipleServers, - getVideo, - getVideoDescription, - getVideosList, - ServerInfo, - setAccessTokensToServers, - updateVideo, - uploadVideo -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -43,20 +31,19 @@ describe('Test video description', function () { const attributes = { description: longDescription } - await uploadVideo(servers[0].url, servers[0].accessToken, attributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) - const res = await getVideosList(servers[0].url) + const { data } = await servers[0].videosCommand.list() - videoId = res.body.data[0].id - videoUUID = res.body.data[0].uuid + videoId = data[0].id + videoUUID = data[0].uuid }) it('Should have a truncated description on each server', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) // 30 characters * 6 -> 240 characters const truncatedDescription = 'my super description for server 1'.repeat(7) + @@ -68,11 +55,10 @@ describe('Test video description', function () { it('Should fetch long description on each server', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) - const res2 = await getVideoDescription(server.url, video.descriptionPath) - expect(res2.body.description).to.equal(longDescription) + const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath }) + expect(description).to.equal(longDescription) } }) @@ -82,20 +68,19 @@ describe('Test video description', function () { const attributes = { description: 'short description' } - await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes) + await servers[0].videosCommand.update({ id: videoId, attributes }) await waitJobs(servers) }) it('Should have a small description on each server', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.description).to.equal('short description') - const res2 = await getVideoDescription(server.url, video.descriptionPath) - expect(res2.body.description).to.equal('short description') + const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath }) + expect(description).to.equal('short description') } }) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 428e1316d..d63b81694 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, @@ -12,26 +12,20 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, makeRawRequest, - removeVideo, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, waitJobs, webtorrentAdd -} from '../../../../shared/extra-utils' -import { VideoDetails } from '../../../../shared/models/videos' -import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' +} from '@shared/extra-utils' +import { VideoStreamingPlaylistType } from '@shared/models' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' const expect = chai.expect async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { for (const server of servers) { - const resVideoDetails = await getVideo(server.url, videoUUID) - const videoDetails: VideoDetails = resVideoDetails.body + const videoDetails = await server.videosCommand.get({ id: videoUUID }) const baseUrl = `http://${videoDetails.account.host}` expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) @@ -113,8 +107,8 @@ describe('Test HLS videos', function () { it('Should upload a video and transcode it to HLS', async function () { this.timeout(120000) - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } }) + videoUUID = uuid await waitJobs(servers) @@ -124,8 +118,8 @@ describe('Test HLS videos', function () { it('Should upload an audio file and transcode it to HLS', async function () { this.timeout(120000) - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) - videoAudioUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } }) + videoAudioUUID = uuid await waitJobs(servers) @@ -135,7 +129,7 @@ describe('Test HLS videos', function () { it('Should update the video', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' }) + await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video 1 updated' } }) await waitJobs(servers) @@ -145,14 +139,14 @@ describe('Test HLS videos', function () { it('Should delete videos', async function () { this.timeout(10000) - await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) - await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) + await servers[0].videosCommand.remove({ id: videoUUID }) + await servers[0].videosCommand.remove({ id: videoAudioUUID }) await waitJobs(servers) for (const server of servers) { - await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) - await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) + await server.videosCommand.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videosCommand.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 052c052b4..31fdfe12e 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -7,9 +7,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideos, - getVideo, - getVideosList, ImportsCommand, ServerInfo, setAccessTokensToServers, @@ -17,7 +14,7 @@ import { testImage, waitJobs } from '@shared/extra-utils' -import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models' +import { VideoPrivacy, VideoResolution } from '@shared/models' const expect = chai.expect @@ -29,8 +26,7 @@ describe('Test video imports', function () { if (areHttpImportTestsDisabled()) return async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { - const resHttp = await getVideo(server.url, idHttp) - const videoHttp: VideoDetails = resHttp.body + const videoHttp = await server.videosCommand.get({ id: idHttp }) expect(videoHttp.name).to.equal('small video - youtube') // FIXME: youtube-dl seems broken @@ -47,10 +43,8 @@ describe('Test video imports', function () { expect(originallyPublishedAt.getMonth()).to.equal(0) expect(originallyPublishedAt.getFullYear()).to.equal(2019) - const resMagnet = await getVideo(server.url, idMagnet) - const videoMagnet: VideoDetails = resMagnet.body - const resTorrent = await getVideo(server.url, idTorrent) - const videoTorrent: VideoDetails = resTorrent.body + const videoMagnet = await server.videosCommand.get({ id: idMagnet }) + const videoTorrent = await server.videosCommand.get({ id: idTorrent }) for (const video of [ videoMagnet, videoTorrent ]) { expect(video.category.label).to.equal('Misc') @@ -70,8 +64,7 @@ describe('Test video imports', function () { } async function checkVideoServer2 (server: ServerInfo, id: number | string) { - const res = await getVideo(server.url, id) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id }) expect(video.name).to.equal('my super name') expect(video.category.label).to.equal('Entertainment') @@ -190,15 +183,14 @@ Ajouter un sous-titre est vraiment facile`) }) it('Should list the videos to import in my videos on server 1', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt') + const { total, data } = await servers[0].videosCommand.listMyVideos({ sort: 'createdAt' }) - expect(res.body.total).to.equal(3) + expect(total).to.equal(3) - const videos = res.body.data - expect(videos).to.have.lengthOf(3) - expect(videos[0].name).to.equal('small video - youtube') - expect(videos[1].name).to.equal('super peertube2 video') - expect(videos[2].name).to.equal('你好 世界 720p.mp4') + expect(data).to.have.lengthOf(3) + expect(data[0].name).to.equal('small video - youtube') + expect(data[1].name).to.equal('super peertube2 video') + expect(data[2].name).to.equal('你好 世界 720p.mp4') }) it('Should list the videos to import in my imports on server 1', async function () { @@ -229,11 +221,11 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(3) - expect(res.body.data).to.have.lengthOf(3) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(3) + expect(data).to.have.lengthOf(3) - const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data + const [ videoHttp, videoMagnet, videoTorrent ] = data await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) } }) @@ -262,13 +254,13 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(4) - expect(res.body.data).to.have.lengthOf(4) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(4) + expect(data).to.have.lengthOf(4) - await checkVideoServer2(server, res.body.data[0].uuid) + await checkVideoServer2(server, data[0].uuid) - const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data + const [ , videoHttp, videoMagnet, videoTorrent ] = data await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) } }) @@ -288,8 +280,7 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.name).to.equal('transcoded video') expect(video.files).to.have.lengthOf(4) @@ -339,8 +330,7 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) // test resolution - const res2 = await getVideo(servers[0].url, videoUUID) - const video: VideoDetails = res2.body + const video = await servers[0].videosCommand.get({ id: videoUUID }) expect(video.name).to.equal('hdr video') const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 9dc26fca6..b8fff096d 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -2,18 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - flushAndRunServer, - getAccountVideos, - getMyVideos, - getVideoChannelVideos, - getVideosList, - getVideosListWithToken, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' const expect = chai.expect @@ -37,10 +26,10 @@ describe('Test video NSFW policy', function () { if (token) { promises = [ - getVideosListWithToken(server.url, token, query).then(res => res.body), server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), - getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body), - getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body) + server.videosCommand.listWithToken({ token, ...query }), + server.videosCommand.listByAccount({ token, accountName, ...query }), + server.videosCommand.listByChannel({ token, videoChannelName, ...query }) ] // Overviews do not support video filters @@ -54,10 +43,10 @@ describe('Test video NSFW policy', function () { } promises = [ - getVideosList(server.url).then(res => res.body), server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }), - getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body), - getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body) + server.videosCommand.list(), + server.videosCommand.listByAccount({ accountName }), + server.videosCommand.listByChannel({ videoChannelName }) ] // Overviews do not support video filters @@ -79,12 +68,12 @@ describe('Test video NSFW policy', function () { { const attributes = { name: 'nsfw', nsfw: true, category: 1 } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes }) } { const attributes = { name: 'normal', nsfw: false, category: 1 } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes }) } customConfig = await server.configCommand.getCustomConfig() @@ -192,13 +181,12 @@ describe('Test video NSFW policy', function () { }) it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () { - const res = await getMyVideos(server.url, server.accessToken, 0, 5) - expect(res.body.total).to.equal(2) + const { total, data } = await server.videosCommand.listMyVideos() + expect(total).to.equal(2) - const videos = res.body.data - expect(videos).to.have.lengthOf(2) - expect(videos[0].name).to.equal('normal') - expect(videos[1].name).to.equal('nsfw') + expect(data).to.have.lengthOf(2) + expect(data[0].name).to.equal('normal') + expect(data[1].name).to.equal('nsfw') }) it('Should display NSFW videos when the nsfw param === true', async function () { diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index af5df8d90..14739af20 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -10,7 +10,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, testImage, - uploadVideoAndGetId, waitJobs } from '../../../../shared/extra-utils' import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' @@ -55,8 +54,8 @@ describe('Playlist thumbnail', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id - video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id + video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).id + video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).id await waitJobs(servers) }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index e57d86c14..40f61ca19 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -13,9 +13,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, testImage, - updateVideo, - uploadVideo, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -99,14 +96,14 @@ describe('Test video playlists', function () { for (const server of servers) { for (let i = 0; i < 7; i++) { const name = `video ${i} server ${server.serverNumber}` - const resVideo = await uploadVideo(server.url, server.accessToken, { name, nsfw: false }) + const video = await server.videosCommand.upload({ attributes: { name, nsfw: false } }) - server.videos.push(resVideo.body.video) + server.videos.push(video) } } } - nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id + nsfwVideoServer1 = (await servers[0].videosCommand.quickUpload({ name: 'NSFW video', nsfw: true })).id userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1') @@ -620,9 +617,9 @@ describe('Test video playlists', function () { return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes }) } - video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userTokenServer1 })).uuid - video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid - video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid + video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid + video2 = (await servers[1].videosCommand.quickUpload({ name: 'video 90' })).uuid + video3 = (await servers[0].videosCommand.quickUpload({ name: 'video 91', nsfw: true })).uuid await waitJobs(servers) @@ -640,7 +637,7 @@ describe('Test video playlists', function () { const position = 1 { - await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE }) + await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -650,7 +647,7 @@ describe('Test video playlists', function () { } { - await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC }) + await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 4e349e350..bcf431edb 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -3,22 +3,8 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - doubleFollow, - flushAndRunServer, - getMyVideos, - getVideo, - getVideosList, - getVideosListWithToken, - getVideoWithToken, - ServerInfo, - setAccessTokensToServers, - updateVideo, - uploadVideo, - waitJobs -} from '@shared/extra-utils' -import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models' +import { cleanupTests, doubleFollow, flushAndRunServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -66,55 +52,53 @@ describe('Test video privacy', function () { for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { const attributes = { privacy } - await uploadVideo(servers[0].url, servers[0].accessToken, attributes) + await servers[0].videosCommand.upload({ attributes }) } await waitJobs(servers) }) it('Should not have these private and internal videos 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(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should not list the private and internal videos for an unauthenticated user 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.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { total, data } = await servers[0].videosCommand.listWithToken() - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) - expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) + expect(data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) }) it('Should list my (private and internal) videos', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10) + const { total, data } = await servers[0].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) - const videos: Video[] = res.body.data - - const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE) + const privateVideo = data.find(v => v.privacy.id === VideoPrivacy.PRIVATE) privateVideoId = privateVideo.id privateVideoUUID = privateVideo.uuid - const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL) + const internalVideo = data.find(v => v.privacy.id === VideoPrivacy.INTERNAL) internalVideoId = internalVideo.id internalVideoUUID = internalVideo.uuid }) it('Should not be able to watch the private/internal video with non authenticated user', async function () { - await getVideo(servers[0].url, privateVideoUUID, HttpStatusCode.UNAUTHORIZED_401) - await getVideo(servers[0].url, internalVideoUUID, HttpStatusCode.UNAUTHORIZED_401) + await servers[0].videosCommand.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].videosCommand.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to watch the private video with another user', async function () { @@ -127,15 +111,20 @@ describe('Test video privacy', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) anotherUserToken = await servers[0].loginCommand.getAccessToken(user) - await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) + + await servers[0].videosCommand.getWithToken({ + token: anotherUserToken, + id: privateVideoUUID, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should be able to watch the internal video with another user', async function () { - await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: anotherUserToken, id: internalVideoUUID }) }) it('Should be able to watch the private video with the correct user', async function () { - await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ id: privateVideoUUID }) }) }) @@ -148,7 +137,7 @@ describe('Test video privacy', function () { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - await uploadVideo(servers[1].url, servers[1].accessToken, attributes) + await servers[1].videosCommand.upload({ attributes }) // Server 2 has transcoding enabled await waitJobs(servers) @@ -156,32 +145,32 @@ describe('Test video privacy', function () { it('Should not have this unlisted video listed on server 1 and 2', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } }) it('Should list my (unlisted) videos', async function () { - const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) + const { total, data } = await servers[1].videosCommand.listMyVideos() - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) - unlistedVideo = res.body.data[0] + unlistedVideo = data[0] }) it('Should not be able to get this unlisted video using its id', async function () { - await getVideo(servers[1].url, unlistedVideo.id, 404) + await servers[1].videosCommand.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should be able to get this unlisted video using its uuid/shortUUID', async function () { for (const server of servers) { for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) { - const res = await getVideo(server.url, id) + const video = await server.videosCommand.get({ id }) - expect(res.body.name).to.equal('unlisted video') + expect(video.name).to.equal('unlisted video') } } }) @@ -193,28 +182,28 @@ describe('Test video privacy', function () { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - await uploadVideo(servers[0].url, servers[0].accessToken, attributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) }) it('Should list my new unlisted video', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 3) + const { total, data } = await servers[0].videosCommand.listMyVideos() - expect(res.body.total).to.equal(3) - expect(res.body.data).to.have.lengthOf(3) + expect(total).to.equal(3) + expect(data).to.have.lengthOf(3) - nonFederatedUnlistedVideoUUID = res.body.data[0].uuid + nonFederatedUnlistedVideoUUID = data[0].uuid }) it('Should be able to get non-federated unlisted video from origin', async function () { - const res = await getVideo(servers[0].url, nonFederatedUnlistedVideoUUID) + const video = await servers[0].videosCommand.get({ id: nonFederatedUnlistedVideoUUID }) - expect(res.body.name).to.equal('unlisted video') + expect(video.name).to.equal('unlisted video') }) it('Should not be able to get non-federated unlisted video from federated server', async function () { - await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, HttpStatusCode.NOT_FOUND_404) + await servers[1].videosCommand.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -226,20 +215,20 @@ describe('Test video privacy', function () { now = Date.now() { - const attribute = { + const attributes = { name: 'private video becomes public', privacy: VideoPrivacy.PUBLIC } - await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) + await servers[0].videosCommand.update({ id: privateVideoId, attributes }) } { - const attribute = { + const attributes = { name: 'internal video becomes public', privacy: VideoPrivacy.PUBLIC } - await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, attribute) + await servers[0].videosCommand.update({ id: internalVideoId, attributes }) } await waitJobs(servers) @@ -247,13 +236,12 @@ describe('Test video privacy', function () { it('Should have this new public video listed on server 1 and 2', async function () { for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(2) + expect(data).to.have.lengthOf(2) - const videos: Video[] = res.body.data - const privateVideo = videos.find(v => v.name === 'private video becomes public') - const internalVideo = videos.find(v => v.name === 'internal video becomes public') + const privateVideo = data.find(v => v.name === 'private video becomes public') + const internalVideo = data.find(v => v.name === 'internal video becomes public') expect(privateVideo).to.not.be.undefined expect(internalVideo).to.not.be.undefined @@ -270,27 +258,25 @@ describe('Test video privacy', function () { it('Should set these videos as private and internal', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE }) - await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL }) + await servers[0].videosCommand.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } }) + await servers[0].videosCommand.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) - const videos = res.body.data - - expect(res.body.total).to.equal(3) - expect(videos).to.have.lengthOf(3) + const { total, data } = await servers[0].videosCommand.listMyVideos() + expect(total).to.equal(3) + expect(data).to.have.lengthOf(3) - const privateVideo = videos.find(v => v.name === 'private video becomes public') - const internalVideo = videos.find(v => v.name === 'internal video becomes public') + const privateVideo = data.find(v => v.name === 'private video becomes public') + const internalVideo = data.find(v => v.name === 'internal video becomes public') expect(privateVideo).to.not.be.undefined expect(internalVideo).to.not.be.undefined diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 204f43611..635ae6ff1 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -1,22 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { VideoPrivacy } from '../../../../shared/models/videos' +import * as chai from 'chai' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideos, - getVideosList, - getVideoWithToken, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -45,35 +40,34 @@ describe('Test video update scheduler', function () { it('Should upload a video and schedule an update in 10 seconds', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 1', privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: in10Seconds().toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) }) it('Should not list the video (in privacy mode)', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) + expect(total).to.equal(0) } }) it('Should have my scheduled video in my account videos', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) - expect(res.body.total).to.equal(1) + const { total, data } = await servers[0].videosCommand.listMyVideos() + expect(total).to.equal(1) - const videoFromList = res.body.data[0] - const res2 = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoFromList.uuid) - const videoFromGet = res2.body + const videoFromList = data[0] + const videoFromGet = await servers[0].videosCommand.getWithToken({ id: videoFromList.uuid }) for (const video of [ videoFromList, videoFromGet ]) { expect(video.name).to.equal('video 1') @@ -90,23 +84,23 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('video 1') + expect(total).to.equal(1) + expect(data[0].name).to.equal('video 1') } }) it('Should upload a video without scheduling an update', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 2', privacy: VideoPrivacy.PRIVATE } - const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - video2UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes }) + video2UUID = uuid await waitJobs(servers) }) @@ -114,31 +108,31 @@ describe('Test video update scheduler', function () { it('Should update a video by scheduling an update', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 2 updated', scheduleUpdate: { updateAt: in10Seconds().toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes) + await servers[0].videosCommand.update({ id: video2UUID, attributes }) await waitJobs(servers) }) it('Should not display the updated video', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total } = await server.videosCommand.list() - expect(res.body.total).to.equal(1) + expect(total).to.equal(1) } }) it('Should have my scheduled updated video in my account videos', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) - expect(res.body.total).to.equal(2) + const { total, data } = await servers[0].videosCommand.listMyVideos() + expect(total).to.equal(2) - const video = res.body.data.find(v => v.uuid === video2UUID) + const video = data.find(v => v.uuid === video2UUID) expect(video).not.to.be.undefined expect(video.name).to.equal('video 2 updated') @@ -155,11 +149,10 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(2) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(2) - const video = res.body.data.find(v => v.uuid === video2UUID) + const video = data.find(v => v.uuid === video2UUID) expect(video).not.to.be.undefined expect(video.name).to.equal('video 2 updated') } diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index f16b22bae..b41c68283 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -2,11 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { FfprobeData } from 'fluent-ffmpeg' import { omit } from 'lodash' import { join } from 'path' -import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, @@ -14,19 +12,14 @@ import { flushAndRunMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, - getMyVideos, - getVideo, - getVideoFileMetadataUrl, - getVideosList, makeGetRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, waitJobs, webtorrentAdd -} from '../../../../shared/extra-utils' -import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' +} from '@shared/extra-utils' +import { getMaxBitrate, VideoResolution, VideoState } from '@shared/models' +import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { canDoQuickTranscode, getAudioStream, @@ -84,21 +77,20 @@ describe('Test video transcoding', function () { it('Should not transcode video on server 1', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'my super name for server 1', description: 'my super description for server 1', fixture: 'video_short.webm' } - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const video = res.body.data[0] + const { data } = await server.videosCommand.list() + const video = data[0] - const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) const magnetUri = videoDetails.files[0].magnetUri @@ -114,21 +106,20 @@ describe('Test video transcoding', function () { it('Should transcode video on server 2', async function () { this.timeout(120_000) - const videoAttributes = { + const attributes = { name: 'my super name for server 2', description: 'my super description for server 2', fixture: 'video_short.webm' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) @@ -147,47 +138,50 @@ describe('Test video transcoding', function () { { // Upload the video, but wait transcoding - const videoAttributes = { + const attributes = { name: 'waiting video', fixture: 'video_short1.webm', waitTranscoding: true } - const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) - const videoId = resVideo.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes }) + const videoId = uuid // Should be in transcode state - const { body } = await getVideo(servers[1].url, videoId) + const body = await servers[1].videosCommand.get({ id: videoId }) expect(body.name).to.equal('waiting video') expect(body.state.id).to.equal(VideoState.TO_TRANSCODE) expect(body.state.label).to.equal('To transcode') expect(body.waitTranscoding).to.be.true - // Should have my video - const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10) - const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name) - expect(videoToFindInMine).not.to.be.undefined - expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) - expect(videoToFindInMine.state.label).to.equal('To transcode') - expect(videoToFindInMine.waitTranscoding).to.be.true + { + // Should have my video + const { data } = await servers[1].videosCommand.listMyVideos() + const videoToFindInMine = data.find(v => v.name === attributes.name) + expect(videoToFindInMine).not.to.be.undefined + expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) + expect(videoToFindInMine.state.label).to.equal('To transcode') + expect(videoToFindInMine.waitTranscoding).to.be.true + } - // Should not list this video - const resVideos = await getVideosList(servers[1].url) - const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name) - expect(videoToFindInList).to.be.undefined + { + // Should not list this video + const { data } = await servers[1].videosCommand.list() + const videoToFindInList = data.find(v => v.name === attributes.name) + expect(videoToFindInList).to.be.undefined + } // Server 1 should not have the video yet - await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404) + await servers[0].videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videoToFind = res.body.data.find(v => v.name === 'waiting video') + const { data } = await server.videosCommand.list() + const videoToFind = data.find(v => v.name === 'waiting video') expect(videoToFind).not.to.be.undefined - const res2 = await getVideo(server.url, videoToFind.id) - const videoDetails: VideoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id: videoToFind.id }) expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) expect(videoDetails.state.label).to.equal('Published') @@ -208,22 +202,20 @@ describe('Test video transcoding', function () { } for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { - const videoAttributes = { + const attributes = { name: fixture, fixture } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const { data } = await server.videosCommand.list() + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) const magnetUri = videoDetails.files[0].magnetUri @@ -235,22 +227,20 @@ describe('Test video transcoding', function () { it('Should transcode a 4k video', async function () { this.timeout(200_000) - const videoAttributes = { + const attributes = { name: '4k video', fixture: 'video_short_4k.mp4' } - const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) - video4k = resUpload.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes }) + video4k = uuid await waitJobs(servers) const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] for (const server of servers) { - const res = await getVideo(server.url, video4k) - const videoDetails: VideoDetails = res.body - + const videoDetails = await server.videosCommand.get({ id: video4k }) expect(videoDetails.files).to.have.lengthOf(resolutions.length) for (const r of resolutions) { @@ -266,20 +256,19 @@ describe('Test video transcoding', function () { it('Should transcode high bit rate mp3 to proper bit rate', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'mp3_256k', fixture: 'video_short_mp3_256k.mp4' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) @@ -298,20 +287,19 @@ describe('Test video transcoding', function () { it('Should transcode video with no audio and have no audio itself', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'no_audio', fixture: 'video_short_no_audio.mp4' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) @@ -323,24 +311,23 @@ describe('Test video transcoding', function () { it('Should leave the audio untouched, but properly transcode the video', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'untouched_audio', fixture: 'video_short.mp4' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) - const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) + const fixturePath = buildAbsoluteFixturePath(attributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) @@ -384,17 +371,16 @@ describe('Test video transcoding', function () { it('Should merge an audio file with the preview file', async function () { this.timeout(60_000) - const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) + const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } + await servers[1].videosCommand.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === 'audio_with_preview') - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === 'audio_with_preview') + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) @@ -409,17 +395,16 @@ describe('Test video transcoding', function () { it('Should upload an audio file and choose a default background image', async function () { this.timeout(60_000) - const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) + const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' } + await servers[1].videosCommand.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === 'audio_without_preview') - const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const video = data.find(v => v.name === 'audio_without_preview') + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) @@ -448,14 +433,13 @@ describe('Test video transcoding', function () { } }) - const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } - const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) + const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } + const { id } = await servers[1].videosCommand.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const res2 = await getVideo(server.url, resVideo.body.video.id) - const videoDetails: VideoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id }) for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { expect(files).to.have.lengthOf(2) @@ -481,21 +465,20 @@ describe('Test video transcoding', function () { it('Should transcode a 60 FPS video', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'my super 30fps name for server 2', description: 'my super 30fps description for server 2', fixture: '60fps_720p_small.mp4' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) @@ -529,20 +512,20 @@ describe('Test video transcoding', function () { expect(fps).to.be.equal(59) } - const videoAttributes = { + const attributes = { name: '59fps video', description: '59fps video', fixture: tempFixturePath } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) + const video = data.find(v => v.name === attributes.name) { const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) @@ -572,20 +555,20 @@ describe('Test video transcoding', function () { expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) } - const videoAttributes = { + const attributes = { name: 'high bitrate video', description: 'high bitrate video', fixture: tempFixturePath } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) + const video = data.find(v => v.name === attributes.name) for (const resolution of [ '240', '360', '480', '720', '1080' ]) { const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) @@ -621,19 +604,18 @@ describe('Test video transcoding', function () { } await servers[1].configCommand.updateCustomSubConfig({ newConfig }) - const videoAttributes = { + const attributes = { name: 'low bitrate', fixture: 'low-bitrate.mp4' } - const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) - const videoUUID = resUpload.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) const resolutions = [ 240, 360, 480, 720, 1080 ] for (const r of resolutions) { - const path = `videos/${videoUUID}-${r}.mp4` + const path = `videos/${uuid}-${r}.mp4` const size = await servers[1].serversCommand.getServerFileSize(path) expect(size, `${path} not below ${60_000}`).to.be.below(60_000) } @@ -645,7 +627,7 @@ describe('Test video transcoding', function () { it('Should provide valid ffprobe data', async function () { this.timeout(160_000) - const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid + const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'ffprobe data' })).uuid await waitJobs(servers) { @@ -679,8 +661,7 @@ describe('Test video transcoding', function () { } for (const server of servers) { - const res2 = await getVideo(server.url, videoUUID) - const videoDetails: VideoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id: videoUUID }) const videoFiles = videoDetails.files .concat(videoDetails.streamingPlaylists[0].files) @@ -692,8 +673,7 @@ describe('Test video transcoding', function () { expect(file.metadataUrl).to.contain(servers[1].url) expect(file.metadataUrl).to.contain(videoUUID) - const res3 = await getVideoFileMetadataUrl(file.metadataUrl) - const metadata: FfprobeData = res3.body + const metadata = await server.videosCommand.getFileMetadata({ url: file.metadataUrl }) expect(metadata).to.have.nested.property('format.size') } } diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 4aa00cfc4..4a5a83ee6 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -1,21 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { expect } from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, makeGetRequest, ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils' -import { UserRole } from '../../../../shared/models/users' -import { Video, VideoPrivacy } from '../../../../shared/models/videos' - -const expect = chai.expect + setAccessTokensToServers +} from '@shared/extra-utils' +import { UserRole, Video, VideoPrivacy } from '@shared/models' async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { const paths = [ @@ -62,16 +58,16 @@ describe('Test videos filter', function () { await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) - await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) + await server.videosCommand.upload({ attributes: { name: 'public ' + server.serverNumber } }) { const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes }) } { const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes }) } } diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index aa0623f7d..8614078f1 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -6,17 +6,14 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, - getVideosListWithToken, - getVideoWithToken, HistoryCommand, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, wait } from '@shared/extra-utils' -import { Video, VideoDetails } from '@shared/models' +import { Video } from '@shared/models' const expect = chai.expect @@ -39,18 +36,18 @@ describe('Test videos history', function () { command = server.historyCommand { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) - video1UUID = res.body.video.uuid + const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 1' } }) + video1UUID = uuid } { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) - video2UUID = res.body.video.uuid + const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 2' } }) + video2UUID = uuid } { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) - video3UUID = res.body.video.uuid + const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 3' } }) + video3UUID = uuid } const user = { @@ -62,12 +59,10 @@ describe('Test videos history', function () { }) it('Should get videos, without watching history', async function () { - const res = await getVideosListWithToken(server.url, server.accessToken) - const videos: Video[] = res.body.data + const { data } = await server.videosCommand.listWithToken() - for (const video of videos) { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id) - const videoDetails: VideoDetails = resDetail.body + for (const video of data) { + const videoDetails = await server.videosCommand.getWithToken({ id: video.id }) expect(video.userHistory).to.be.undefined expect(videoDetails.userHistory).to.be.undefined @@ -83,8 +78,8 @@ describe('Test videos history', function () { const videosOfVideos: Video[][] = [] { - const res = await getVideosListWithToken(server.url, server.accessToken) - videosOfVideos.push(res.body.data) + const { data } = await server.videosCommand.listWithToken() + videosOfVideos.push(data) } { @@ -107,24 +102,21 @@ describe('Test videos history', function () { } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videosCommand.getWithToken({ id: video1UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(3) } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videosCommand.getWithToken({ id: video2UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(8) } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videosCommand.getWithToken({ id: video3UUID }) expect(videoDetails.userHistory).to.be.undefined } diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index a2da2eaef..969393842 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' import { VideosOverview } from '@shared/models' const expect = chai.expect @@ -35,10 +35,12 @@ describe('Test a videos overview', function () { await wait(3000) - await uploadVideo(server.url, server.accessToken, { - name: 'video 0', - category: 3, - tags: [ 'coucou1', 'coucou2' ] + await server.videosCommand.upload({ + attributes: { + name: 'video 0', + category: 3, + tags: [ 'coucou1', 'coucou2' ] + } }) const body = await server.overviewsCommand.getVideos({ page: 1 }) @@ -51,10 +53,12 @@ describe('Test a videos overview', function () { { for (let i = 1; i < 6; i++) { - await uploadVideo(server.url, server.accessToken, { - name: 'video ' + i, - category: 3, - tags: [ 'coucou1', 'coucou2' ] + await server.videosCommand.upload({ + attributes: { + name: 'video ' + i, + category: 3, + tags: [ 'coucou1', 'coucou2' ] + } }) } diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index b6cde6b50..7ded1bf38 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -10,8 +10,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, - viewVideo, wait, waitJobs } from '../../../../shared/extra-utils' @@ -32,15 +30,15 @@ describe('Test video views cleaner', function () { await doubleFollow(servers[0], servers[1]) - videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid - videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid + videoIdServer1 = (await servers[0].videosCommand.quickUpload({ name: 'video server 1' })).uuid + videoIdServer2 = (await servers[1].videosCommand.quickUpload({ name: 'video server 2' })).uuid await waitJobs(servers) - await viewVideo(servers[0].url, videoIdServer1) - await viewVideo(servers[1].url, videoIdServer1) - await viewVideo(servers[0].url, videoIdServer2) - await viewVideo(servers[1].url, videoIdServer2) + await servers[0].videosCommand.view({ id: videoIdServer1 }) + await servers[1].videosCommand.view({ id: videoIdServer1 }) + await servers[0].videosCommand.view({ id: videoIdServer2 }) + await servers[1].videosCommand.view({ id: videoIdServer2 }) await waitJobs(servers) }) diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts index 8a23a94de..b1d9da242 100644 --- a/server/tests/cli/create-import-video-file-job.ts +++ b/server/tests/cli/create-import-video-file-job.ts @@ -2,19 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { VideoFile } from '@shared/models/videos/video-file.model' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - getVideo, - getVideosList, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../shared/extra-utils' -import { waitJobs } from '../../../shared/extra-utils/server/jobs' -import { VideoDetails } from '../../../shared/models/videos' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { VideoFile } from '@shared/models' const expect = chai.expect @@ -45,10 +34,15 @@ describe('Test create import video jobs', function () { await doubleFollow(servers[0], servers[1]) // Upload two videos for our needs - const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' }) - video1UUID = res1.body.video.uuid - const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) - video2UUID = res2.body.video.uuid + { + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video1' } }) + video1UUID = uuid + } + + { + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video2' } }) + video2UUID = uuid + } // Transcoding await waitJobs(servers) @@ -61,14 +55,14 @@ describe('Test create import video jobs', function () { await waitJobs(servers) for (const server of servers) { - const { data: videos } = (await getVideosList(server.url)).body + const { data: videos } = await server.videosCommand.list() expect(videos).to.have.lengthOf(2) const video = videos.find(({ uuid }) => uuid === video1UUID) - const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body + const videoDetails = await server.videosCommand.get({ id: video.uuid }) - expect(videoDetail.files).to.have.lengthOf(2) - const [ originalVideo, transcodedVideo ] = videoDetail.files + expect(videoDetails.files).to.have.lengthOf(2) + const [ originalVideo, transcodedVideo ] = videoDetails.files assertVideoProperties(originalVideo, 720, 'webm', 218910) assertVideoProperties(transcodedVideo, 480, 'webm', 69217) } @@ -81,14 +75,14 @@ describe('Test create import video jobs', function () { await waitJobs(servers) for (const server of servers) { - const { data: videos } = (await getVideosList(server.url)).body + const { data: videos } = await server.videosCommand.list() expect(videos).to.have.lengthOf(2) const video = videos.find(({ uuid }) => uuid === video2UUID) - const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body + const videoDetails = await server.videosCommand.get({ id: video.uuid }) - expect(videoDetail.files).to.have.lengthOf(4) - const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files + expect(videoDetails.files).to.have.lengthOf(4) + const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files assertVideoProperties(originalVideo, 720, 'ogv', 140849) assertVideoProperties(transcodedVideo420, 480, 'mp4') assertVideoProperties(transcodedVideo320, 360, 'mp4') @@ -103,14 +97,14 @@ describe('Test create import video jobs', function () { await waitJobs(servers) for (const server of servers) { - const { data: videos } = (await getVideosList(server.url)).body + const { data: videos } = await server.videosCommand.list() expect(videos).to.have.lengthOf(2) const video = videos.find(({ uuid }) => uuid === video1UUID) - const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body + const videoDetails = await server.videosCommand.get({ id: video.uuid }) - expect(videoDetail.files).to.have.lengthOf(2) - const [ video720, video480 ] = videoDetail.files + expect(videoDetails.files).to.have.lengthOf(2) + const [ video720, video480 ] = videoDetails.files assertVideoProperties(video720, 720, 'webm', 942961) assertVideoProperties(video480, 480, 'webm', 69217) } diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts index e3211882d..f629306e6 100644 --- a/server/tests/cli/create-transcoding-job.ts +++ b/server/tests/cli/create-transcoding-job.ts @@ -6,14 +6,10 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideosList, ServerInfo, setAccessTokensToServers, - uploadVideo + waitJobs } from '../../../shared/extra-utils' -import { waitJobs } from '../../../shared/extra-utils/server/jobs' -import { VideoDetails } from '../../../shared/models/videos' const expect = chai.expect @@ -51,8 +47,8 @@ describe('Test create transcoding jobs', function () { await doubleFollow(servers[0], servers[1]) for (let i = 1; i <= 5; i++) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' + i }) - videosUUID.push(res.body.video.uuid) + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' + i } }) + videosUUID.push(uuid) } await waitJobs(servers) @@ -62,13 +58,11 @@ describe('Test create transcoding jobs', function () { this.timeout(30000) for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.have.lengthOf(videosUUID.length) + const { data } = await server.videosCommand.list() + expect(data).to.have.lengthOf(videosUUID.length) - for (const video of videos) { - const res2 = await getVideo(server.url, video.uuid) - const videoDetail: VideoDetails = res2.body + for (const video of data) { + const videoDetail = await server.videosCommand.get({ id: video.uuid }) expect(videoDetail.files).to.have.lengthOf(1) expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) } @@ -82,14 +76,12 @@ describe('Test create transcoding jobs', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data + const { data } = await server.videosCommand.list() let infoHashes: { [id: number]: string } - for (const video of videos) { - const res2 = await getVideo(server.url, video.uuid) - const videoDetail: VideoDetails = res2.body + for (const video of data) { + const videoDetail = await server.videosCommand.get({ id: video.uuid }) if (video.uuid === videosUUID[1]) { expect(videoDetail.files).to.have.lengthOf(4) @@ -123,18 +115,16 @@ describe('Test create transcoding jobs', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.have.lengthOf(videosUUID.length) + const { data } = await server.videosCommand.list() + expect(data).to.have.lengthOf(videosUUID.length) - const res2 = await getVideo(server.url, videosUUID[0]) - const videoDetail: VideoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id: videosUUID[0] }) - expect(videoDetail.files).to.have.lengthOf(2) - expect(videoDetail.files[0].resolution.id).to.equal(720) - expect(videoDetail.files[1].resolution.id).to.equal(480) + expect(videoDetails.files).to.have.lengthOf(2) + expect(videoDetails.files[0].resolution.id).to.equal(720) + expect(videoDetails.files[1].resolution.id).to.equal(480) - expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) + expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) } }) @@ -146,13 +136,12 @@ describe('Test create transcoding jobs', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videosUUID[2]) - const videoDetail: VideoDetails = res.body + const videoDetails = await server.videosCommand.get({ id: videosUUID[2] }) - expect(videoDetail.files).to.have.lengthOf(1) - expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) + expect(videoDetails.files).to.have.lengthOf(1) + expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) - const files = videoDetail.streamingPlaylists[0].files + const files = videoDetails.streamingPlaylists[0].files expect(files).to.have.lengthOf(1) expect(files[0].resolution.id).to.equal(480) } @@ -166,10 +155,9 @@ describe('Test create transcoding jobs', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videosUUID[2]) - const videoDetail: VideoDetails = res.body + const videoDetails = await server.videosCommand.get({ id: videosUUID[2] }) - const files = videoDetail.streamingPlaylists[0].files + const files = videoDetails.streamingPlaylists[0].files expect(files).to.have.lengthOf(1) expect(files[0].resolution.id).to.equal(480) } @@ -183,13 +171,12 @@ describe('Test create transcoding jobs', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videosUUID[3]) - const videoDetail: VideoDetails = res.body + const videoDetails = await server.videosCommand.get({ id: videosUUID[3] }) - expect(videoDetail.files).to.have.lengthOf(1) - expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) + expect(videoDetails.files).to.have.lengthOf(1) + expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) - const files = videoDetail.streamingPlaylists[0].files + const files = videoDetails.streamingPlaylists[0].files expect(files).to.have.lengthOf(4) } }) @@ -205,12 +192,11 @@ describe('Test create transcoding jobs', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videosUUID[4]) - const videoDetail: VideoDetails = res.body + const videoDetails = await server.videosCommand.get({ id: videosUUID[4] }) - expect(videoDetail.files).to.have.lengthOf(4) - expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) - expect(videoDetail.streamingPlaylists[0].files).to.have.lengthOf(4) + expect(videoDetails.files).to.have.lengthOf(4) + expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) + expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(4) } }) diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts index e369a3305..ef8603a33 100644 --- a/server/tests/cli/optimize-old-videos.ts +++ b/server/tests/cli/optimize-old-videos.ts @@ -8,16 +8,12 @@ import { doubleFollow, flushAndRunMultipleServers, generateHighBitrateVideo, - getVideo, - getVideosList, ServerInfo, setAccessTokensToServers, - uploadVideo, - viewVideo, - wait -} from '../../../shared/extra-utils' -import { waitJobs } from '../../../shared/extra-utils/server/jobs' -import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos' + wait, + waitJobs +} from '@shared/extra-utils' +import { getMaxBitrate, VideoResolution } from '@shared/models' import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils' import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' @@ -45,8 +41,8 @@ describe('Test optimize old videos', function () { } // Upload two videos for our needs - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1', fixture: tempFixturePath }) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2', fixture: tempFixturePath }) + await servers[0].videosCommand.upload({ attributes: { name: 'video1', fixture: tempFixturePath } }) + await servers[0].videosCommand.upload({ attributes: { name: 'video2', fixture: tempFixturePath } }) await waitJobs(servers) }) @@ -55,14 +51,12 @@ describe('Test optimize old videos', function () { this.timeout(30000) for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.have.lengthOf(2) - - for (const video of videos) { - const res2 = await getVideo(server.url, video.uuid) - const videoDetail: VideoDetails = res2.body - expect(videoDetail.files).to.have.lengthOf(1) + const { data } = await server.videosCommand.list() + expect(data).to.have.lengthOf(2) + + for (const video of data) { + const videoDetails = await server.videosCommand.get({ id: video.uuid }) + expect(videoDetails.files).to.have.lengthOf(1) } } }) @@ -74,24 +68,21 @@ describe('Test optimize old videos', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videos: Video[] = res.body.data - - expect(videos).to.have.lengthOf(2) + const { data } = await server.videosCommand.list() + expect(data).to.have.lengthOf(2) - for (const video of videos) { - await viewVideo(server.url, video.uuid) + for (const video of data) { + await server.videosCommand.view({ id: video.uuid }) // Refresh video await waitJobs(servers) await wait(5000) await waitJobs(servers) - const res2 = await getVideo(server.url, video.uuid) - const videosDetails: VideoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id: video.uuid }) - expect(videosDetails.files).to.have.lengthOf(1) - const file = videosDetails.files[0] + expect(videoDetails.files).to.have.lengthOf(1) + const file = videoDetails.files[0] expect(file.size).to.be.below(8000000) diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index a0c149ac0..fe5f63191 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts @@ -2,7 +2,6 @@ import 'mocha' import { expect } from 'chai' -import { Video, VideoDetails } from '../../../shared' import { areHttpImportTestsDisabled, buildAbsoluteFixturePath, @@ -10,15 +9,10 @@ import { CLICommand, doubleFollow, flushAndRunServer, - getLocalIdByUUID, - getVideo, - getVideosList, ImportsCommand, - removeVideo, ServerInfo, setAccessTokensToServers, testHelloWorldRegisteredSettings, - uploadVideoAndGetId, waitJobs } from '../../../shared/extra-utils' @@ -109,14 +103,10 @@ describe('Test CLI wrapper', function () { }) it('Should have the video uploaded', async function () { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(1) - - const videos: Video[] = res.body.data - - const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(1) + const video = await server.videosCommand.get({ id: data[0].uuid }) expect(video.name).to.equal('test upload') expect(video.support).to.equal('support_text') expect(video.channel.name).to.equal('user_channel') @@ -138,21 +128,19 @@ describe('Test CLI wrapper', function () { await waitJobs([ server ]) - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(2) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(2) - const videos: Video[] = res.body.data - const video = videos.find(v => v.name === 'small video - youtube') + const video = data.find(v => v.name === 'small video - youtube') expect(video).to.not.be.undefined - const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.channel.name).to.equal('user_channel') expect(videoDetails.support).to.equal('super support text') expect(videoDetails.nsfw).to.be.false // So we can reimport it - await removeVideo(server.url, userAccessToken, video.id) + await server.videosCommand.remove({ token: userAccessToken, id: video.id }) }) it('Should import and override some imported attributes', async function () { @@ -167,14 +155,13 @@ describe('Test CLI wrapper', function () { await waitJobs([ server ]) { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(2) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(2) - const videos: Video[] = res.body.data - const video = videos.find(v => v.name === 'toto') + const video = data.find(v => v.name === 'toto') expect(video).to.not.be.undefined - const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.channel.name).to.equal('user_channel') expect(videoDetails.support).to.equal('support') expect(videoDetails.nsfw).to.be.true @@ -238,10 +225,10 @@ describe('Test CLI wrapper', function () { servers = [ server, anotherServer ] await waitJobs(servers) - const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid + const { uuid } = await anotherServer.videosCommand.quickUpload({ name: 'super video' }) await waitJobs(servers) - video1Server2 = await getLocalIdByUUID(server.url, uuid) + video1Server2 = await server.videosCommand.getId({ uuid }) }) it('Should add a redundancy', async function () { diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index b45049964..a4556312b 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts @@ -16,7 +16,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, wait, waitJobs } from '@shared/extra-utils' @@ -69,8 +68,8 @@ describe('Test prune storage scripts', function () { await setDefaultVideoChannel(servers) for (const server of servers) { - await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) - await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) + await server.videosCommand.upload({ attributes: { name: 'video 1' } }) + await server.videosCommand.upload({ attributes: { name: 'video 2' } }) await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts index 68a4711b6..d59520783 100644 --- a/server/tests/cli/regenerate-thumbnails.ts +++ b/server/tests/cli/regenerate-thumbnails.ts @@ -2,29 +2,30 @@ import 'mocha' import { expect } from 'chai' import { writeFile } from 'fs-extra' import { basename, join } from 'path' -import { Video, VideoDetails } from '@shared/models' +import { HttpStatusCode } from '@shared/core-utils' +import { Video } from '@shared/models' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, makeRawRequest, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, waitJobs } from '../../../shared/extra-utils' -import { HttpStatusCode } from '@shared/core-utils' async function testThumbnail (server: ServerInfo, videoId: number | string) { - const res = await getVideo(server.url, videoId) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoId }) - const res1 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) - expect(res1.body).to.not.have.lengthOf(0) + const requests = [ + makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200), + makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) + ] - const res2 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) - expect(res2.body).to.not.have.lengthOf(0) + for (const req of requests) { + const res = await req + expect(res.body).to.not.have.lengthOf(0) + } } describe('Test regenerate thumbnails script', function () { @@ -46,20 +47,20 @@ describe('Test regenerate thumbnails script', function () { await doubleFollow(servers[0], servers[1]) { - const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid - video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body)) + const videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid + video1 = await servers[0].videosCommand.get({ id: videoUUID1 }) thumbnail1Path = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(video1.thumbnailPath)) - const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid - video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body)) + const videoUUID2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid + video2 = await servers[0].videosCommand.get({ id: videoUUID2 }) } { - const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid + const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'video 3' })).uuid await waitJobs(servers) - remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body)) + remoteVideo = await servers[0].videosCommand.get({ id: videoUUID }) thumbnailRemotePath = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath)) } diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index b857fcf28..d90b4a64d 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.ts @@ -5,18 +5,14 @@ import { expect } from 'chai' import { cleanupTests, flushAndRunServer, - getVideo, - getVideosList, killallServers, makeActivityPubGetRequest, parseTorrentVideo, reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' -import { VideoDetails } from '@shared/models' describe('Test update host scripts', function () { let server: ServerInfo @@ -34,10 +30,8 @@ describe('Test update host scripts', function () { await setAccessTokensToServers([ server ]) // Upload two videos for our needs - const videoAttributes = {} - const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes) - const video1UUID = resVideo1.body.video.uuid - await uploadVideo(server.url, server.accessToken, videoAttributes) + const { uuid: video1UUID } = await server.videosCommand.upload() + await server.videosCommand.upload() // Create a user await server.usersCommand.create({ username: 'toto', password: 'coucou' }) @@ -68,16 +62,15 @@ describe('Test update host scripts', function () { }) it('Should have updated videos url', async function () { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(2) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(2) - for (const video of res.body.data) { + for (const video of data) { const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid) - const res = await getVideo(server.url, video.uuid) - const videoDetails: VideoDetails = res.body + const videoDetails = await server.videosCommand.get({ id: video.uuid }) expect(videoDetails.trackerUrls[0]).to.include(server.host) expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host) @@ -111,13 +104,11 @@ describe('Test update host scripts', function () { it('Should have updated torrent hosts', async function () { this.timeout(30000) - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.have.lengthOf(2) + const { data } = await server.videosCommand.list() + expect(data).to.have.lengthOf(2) - for (const video of videos) { - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + for (const video of data) { + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) diff --git a/server/tests/client.ts b/server/tests/client.ts index 96403da37..e91d4c671 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -9,13 +9,11 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideosList, makeGetRequest, makeHTMLRequest, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, waitJobs } from '../../shared/extra-utils' @@ -68,36 +66,41 @@ describe('Test a client controllers', function () { // Video - const videoAttributes = { name: videoName, description: videoDescription } - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + { + const attributes = { name: videoName, description: videoDescription } + await servers[0].videosCommand.upload({ attributes }) - const resVideosRequest = await getVideosList(servers[0].url) - const videos = resVideosRequest.body.data - expect(videos.length).to.equal(1) + const { data } = await servers[0].videosCommand.list() + expect(data.length).to.equal(1) - const video = videos[0] - servers[0].video = video - videoIds = [ video.id, video.uuid, video.shortUUID ] + const video = data[0] + servers[0].video = video + videoIds = [ video.id, video.uuid, video.shortUUID ] + } // Playlist - const attributes = { - displayName: playlistName, - description: playlistDescription, - privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[0].videoChannel.id - } + { + const attributes = { + displayName: playlistName, + description: playlistDescription, + privacy: VideoPlaylistPrivacy.PUBLIC, + videoChannelId: servers[0].videoChannel.id + } - playlist = await servers[0].playlistsCommand.create({ attributes }) - playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ] + playlist = await servers[0].playlistsCommand.create({ attributes }) + playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ] - await servers[0].playlistsCommand.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: video.id } }) + await servers[0].playlistsCommand.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: servers[0].video.id } }) + } // Account - await servers[0].usersCommand.updateMe({ description: 'my account description' }) + { + await servers[0].usersCommand.updateMe({ description: 'my account description' }) - account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` }) + account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` }) + } await waitJobs(servers) }) diff --git a/server/tests/external-plugins/auth-ldap.ts b/server/tests/external-plugins/auth-ldap.ts index d99b3badc..b626ab2bb 100644 --- a/server/tests/external-plugins/auth-ldap.ts +++ b/server/tests/external-plugins/auth-ldap.ts @@ -3,7 +3,7 @@ import 'mocha' import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' describe('Official plugin auth-ldap', function () { let server: ServerInfo @@ -77,7 +77,7 @@ describe('Official plugin auth-ldap', function () { }) it('Should upload a video', async function () { - await uploadVideo(server.url, accessToken, { name: 'my super video' }) + await server.videosCommand.upload({ token: accessToken, attributes: { name: 'my super video' } }) }) it('Should not be able to login if the user is banned', async function () { diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts index f4b55522a..1cce15a2f 100644 --- a/server/tests/external-plugins/auto-block-videos.ts +++ b/server/tests/external-plugins/auto-block-videos.ts @@ -2,27 +2,23 @@ import 'mocha' import { expect } from 'chai' -import { Video } from '@shared/models' -import { - doubleFollow, - getVideosList, - MockBlocklist, - setAccessTokensToServers, - uploadVideoAndGetId, - wait -} from '../../../shared/extra-utils' import { cleanupTests, + doubleFollow, flushAndRunMultipleServers, killallServers, + MockBlocklist, reRunServer, - ServerInfo -} from '../../../shared/extra-utils/server/servers' + ServerInfo, + setAccessTokensToServers, + wait +} from '@shared/extra-utils' +import { Video } from '@shared/models' async function check (server: ServerInfo, videoUUID: string, exists = true) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.uuid === videoUUID) + const video = data.find(v => v.uuid === videoUUID) if (exists) expect(video).to.not.be.undefined else expect(video).to.be.undefined @@ -48,19 +44,19 @@ describe('Official plugin auto-block videos', function () { blocklistServer = new MockBlocklist() port = await blocklistServer.initialize() - await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) - await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) - await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2 server 2' }) - await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2' }) + await await servers[0].videosCommand.quickUpload({ name: 'video server 1' }) + await await servers[1].videosCommand.quickUpload({ name: 'video server 2' }) + await await servers[1].videosCommand.quickUpload({ name: 'video 2 server 2' }) + await await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2' }) { - const res = await getVideosList(servers[0].url) - server1Videos = res.body.data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid })) + const { data } = await servers[0].videosCommand.list() + server1Videos = data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid })) } { - const res = await getVideosList(servers[1].url) - server2Videos = res.body.data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid })) + const { data } = await servers[1].videosCommand.list() + server2Videos = data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid })) } await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts index 844023b83..81a96744e 100644 --- a/server/tests/external-plugins/auto-mute.ts +++ b/server/tests/external-plugins/auto-mute.ts @@ -7,14 +7,12 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideosList, killallServers, makeGetRequest, MockBlocklist, reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, wait } from '@shared/extra-utils' @@ -37,8 +35,8 @@ describe('Official plugin auto-mute', function () { blocklistServer = new MockBlocklist() port = await blocklistServer.initialize() - await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) - await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) + await await servers[0].videosCommand.quickUpload({ name: 'video server 1' }) + await await servers[1].videosCommand.quickUpload({ name: 'video server 2' }) await doubleFollow(servers[0], servers[1]) }) @@ -66,8 +64,8 @@ describe('Official plugin auto-mute', function () { await wait(2000) - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(1) }) it('Should remove a server blocklist', async function () { @@ -84,8 +82,8 @@ describe('Official plugin auto-mute', function () { await wait(2000) - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(2) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(2) }) it('Should add an account blocklist', async function () { @@ -101,8 +99,8 @@ describe('Official plugin auto-mute', function () { await wait(2000) - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(1) }) it('Should remove an account blocklist', async function () { @@ -119,8 +117,8 @@ describe('Official plugin auto-mute', function () { await wait(2000) - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(2) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(2) }) it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () { @@ -140,15 +138,15 @@ describe('Official plugin auto-mute', function () { await wait(2000) { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(1) } await servers[0].blocklistCommand.removeFromServerBlocklist({ account }) { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(2) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(2) } await killallServers([ servers[0] ]) @@ -156,8 +154,8 @@ describe('Official plugin auto-mute', function () { await wait(2000) { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(2) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(2) } }) @@ -215,8 +213,8 @@ describe('Official plugin auto-mute', function () { await wait(2000) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(1) + const { total } = await server.videosCommand.list() + expect(total).to.equal(1) } }) diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts index 18ce8f7c5..c66cdde1b 100644 --- a/server/tests/feeds/feeds.ts +++ b/server/tests/feeds/feeds.ts @@ -11,8 +11,6 @@ import { flushAndRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -68,28 +66,26 @@ describe('Test syndication feeds', () => { } { - await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' }) + await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'user video' } }) } { - const videoAttributes = { + const attributes = { name: 'my super name for server 1', description: 'my super description for server 1', fixture: 'video_short.webm' } - const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - const videoId = res.body.video.id + const { id } = await servers[0].videosCommand.upload({ attributes }) - await servers[0].commentsCommand.createThread({ videoId, text: 'super comment 1' }) - await servers[0].commentsCommand.createThread({ videoId, text: 'super comment 2' }) + await servers[0].commentsCommand.createThread({ videoId: id, text: 'super comment 1' }) + await servers[0].commentsCommand.createThread({ videoId: id, text: 'super comment 2' }) } { - const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - const videoId = res.body.video.id + const attributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } + const { id } = await servers[0].videosCommand.upload({ attributes }) - await servers[0].commentsCommand.createThread({ videoId, text: 'comment on unlisted video' }) + await servers[0].commentsCommand.createThread({ videoId: id, text: 'comment on unlisted video' }) } await waitJobs(servers) @@ -218,7 +214,7 @@ describe('Test syndication feeds', () => { it('Should correctly have videos feed with HLS only', async function () { this.timeout(120000) - await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' }) + await serverHLSOnly.videosCommand.upload({ attributes: { name: 'hls only video' } }) await waitJobs([ serverHLSOnly ]) @@ -265,7 +261,7 @@ describe('Test syndication feeds', () => { await servers[1].blocklistCommand.removeFromServerBlocklist({ account: remoteHandle }) { - const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid + const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid await waitJobs(servers) await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'super comment' }) await waitJobs(servers) diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts index 84bdcaabf..b5b10bd5e 100644 --- a/server/tests/misc-endpoints.ts +++ b/server/tests/misc-endpoints.ts @@ -3,15 +3,8 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - makeGetRequest, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../shared/extra-utils' -import { VideoPrivacy } from '../../shared/models/videos' +import { cleanupTests, flushAndRunServer, makeGetRequest, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -165,9 +158,9 @@ describe('Test misc endpoints', function () { it('Should add videos, channel and accounts and get sitemap', async function () { this.timeout(35000) - await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false }) - await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false }) - await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE }) + await server.videosCommand.upload({ attributes: { name: 'video 1', nsfw: false } }) + await server.videosCommand.upload({ attributes: { name: 'video 2', nsfw: false } }) + await server.videosCommand.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } }) await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } }) await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } }) diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index b156f6b60..9e12c8aa7 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -9,10 +9,7 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - updateVideo, - uploadVideo, - viewVideo + setDefaultVideoChannel } from '@shared/extra-utils' import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' @@ -52,20 +49,20 @@ describe('Test plugin action hooks', function () { describe('Videos hooks', function () { it('Should run action:api.video.uploaded', async function () { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) + videoUUID = uuid await checkHook('action:api.video.uploaded') }) it('Should run action:api.video.updated', async function () { - await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) + await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video updated' } }) await checkHook('action:api.video.updated') }) it('Should run action:api.video.viewed', async function () { - await viewVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.view({ id: videoUUID }) await checkHook('action:api.video.viewed') }) @@ -170,8 +167,8 @@ describe('Test plugin action hooks', function () { } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' }) - videoId = res.body.video.id + const { id } = await servers[0].videosCommand.upload({ attributes: { name: 'my super name' } }) + videoId = id } }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index c82025f6a..e82aa3bfb 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -7,22 +7,12 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getAccountVideos, - getMyVideos, - getVideo, - getVideoChannelVideos, - getVideosList, - getVideosListPagination, - getVideoWithToken, ImportsCommand, makeRawRequest, PluginsCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateVideo, - uploadVideo, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' @@ -46,11 +36,11 @@ describe('Test plugin filter hooks', function () { await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) for (let i = 0; i < 10; i++) { - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) + await servers[0].videosCommand.upload({ attributes: { name: 'default video ' + i } }) } - const res = await getVideosList(servers[0].url) - videoUUID = res.body.data[0].uuid + const { data } = await servers[0].videosCommand.list() + videoUUID = data[0].uuid await servers[0].configCommand.updateCustomSubConfig({ newConfig: { @@ -67,69 +57,68 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.videos.list.params', async function () { - const res = await getVideosListPagination(servers[0].url, 0, 2) + const { data } = await servers[0].videosCommand.list({ start: 0, count: 2 }) // 2 plugins do +1 to the count parameter - expect(res.body.data).to.have.lengthOf(4) + expect(data).to.have.lengthOf(4) }) it('Should run filter:api.videos.list.result', async function () { - const res = await getVideosListPagination(servers[0].url, 0, 0) + const { total } = await servers[0].videosCommand.list({ start: 0, count: 0 }) // Plugin do +1 to the total result - expect(res.body.total).to.equal(11) + expect(total).to.equal(11) }) it('Should run filter:api.accounts.videos.list.params', async function () { - const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) + const { data } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 }) // 1 plugin do +1 to the count parameter - expect(res.body.data).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) }) it('Should run filter:api.accounts.videos.list.result', async function () { - const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) + const { total } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 }) // Plugin do +2 to the total result - expect(res.body.total).to.equal(12) + expect(total).to.equal(12) }) it('Should run filter:api.video-channels.videos.list.params', async function () { - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) + const { data } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) // 1 plugin do +3 to the count parameter - expect(res.body.data).to.have.lengthOf(5) + expect(data).to.have.lengthOf(5) }) it('Should run filter:api.video-channels.videos.list.result', async function () { - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) + const { total } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) // Plugin do +3 to the total result - expect(res.body.total).to.equal(13) + expect(total).to.equal(13) }) it('Should run filter:api.user.me.videos.list.params', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) + const { data } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 }) // 1 plugin do +4 to the count parameter - expect(res.body.data).to.have.lengthOf(6) + expect(data).to.have.lengthOf(6) }) it('Should run filter:api.user.me.videos.list.result', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) + const { total } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 }) // Plugin do +4 to the total result - expect(res.body.total).to.equal(14) + expect(total).to.equal(14) }) it('Should run filter:api.video.get.result', async function () { - const res = await getVideo(servers[0].url, videoUUID) - - expect(res.body.name).to.contain('<3') + const video = await servers[0].videosCommand.get({ id: videoUUID }) + expect(video.name).to.contain('<3') }) it('Should run filter:api.video.upload.accept.result', async function () { - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) + await servers[0].videosCommand.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.live-video.create.accept.result', async function () { @@ -270,14 +259,13 @@ describe('Test plugin filter hooks', function () { describe('Should run filter:video.auto-blacklist.result', function () { async function checkIsBlacklisted (id: number | string, value: boolean) { - const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id) - const video: VideoDetails = res.body + const video = await servers[0].videosCommand.getWithToken({ id }) expect(video.blacklisted).to.equal(value) } it('Should blacklist on upload', async function () { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) - await checkIsBlacklisted(res.body.video.uuid, true) + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video please blacklist me' } }) + await checkIsBlacklisted(uuid, true) }) it('Should blacklist on import', async function () { @@ -293,36 +281,34 @@ describe('Test plugin filter hooks', function () { }) it('Should blacklist on update', async function () { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) - const videoId = res.body.video.uuid - await checkIsBlacklisted(videoId, false) + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) + await checkIsBlacklisted(uuid, false) - await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) - await checkIsBlacklisted(videoId, true) + await servers[0].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } }) + await checkIsBlacklisted(uuid, true) }) it('Should blacklist on remote upload', async function () { this.timeout(120000) - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'remote please blacklist me' } }) await waitJobs(servers) - await checkIsBlacklisted(res.body.video.uuid, true) + await checkIsBlacklisted(uuid, true) }) it('Should blacklist on remote update', async function () { this.timeout(120000) - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video' } }) await waitJobs(servers) - const videoId = res.body.video.uuid - await checkIsBlacklisted(videoId, false) + await checkIsBlacklisted(uuid, false) - await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) + await servers[1].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } }) await waitJobs(servers) - await checkIsBlacklisted(videoId, true) + await checkIsBlacklisted(uuid, true) }) }) @@ -370,15 +356,14 @@ describe('Test plugin filter hooks', function () { const uuids: string[] = [] for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { - const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid + const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid uuids.push(uuid) } await waitJobs(servers) for (const uuid of uuids) { - const res = await getVideo(servers[0].url, uuid) - downloadVideos.push(res.body) + downloadVideos.push(await servers[0].videosCommand.get({ id: uuid })) } }) @@ -428,9 +413,8 @@ describe('Test plugin filter hooks', function () { for (const name of [ 'bad embed', 'good embed' ]) { { - const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid - const res = await getVideo(servers[0].url, uuid) - embedVideos.push(res.body) + const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid + embedVideos.push(await servers[0].videosCommand.get({ id: uuid })) } { diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index cbb6887eb..509aba13d 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -8,15 +8,11 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideosList, makeGetRequest, makePostBodyRequest, PluginsCommand, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, - viewVideo, waitJobs } from '@shared/extra-utils' @@ -144,59 +140,54 @@ describe('Test plugin helpers', function () { this.timeout(60000) { - const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) + const res = await await servers[0].videosCommand.quickUpload({ name: 'video server 1' }) videoUUIDServer1 = res.uuid } { - await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) + await await servers[1].videosCommand.quickUpload({ name: 'video server 2' }) } await waitJobs(servers) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(2) + expect(data).to.have.lengthOf(2) }) it('Should mute server 2', async function () { this.timeout(10000) await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('video server 1') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video server 1') }) it('Should unmute server 2', async function () { await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(2) + expect(data).to.have.lengthOf(2) }) it('Should mute account of server 2', async function () { await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('video server 1') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video server 1') }) it('Should unmute account of server 2', async function () { await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(2) + expect(data).to.have.lengthOf(2) }) it('Should blacklist video', async function () { @@ -207,11 +198,10 @@ describe('Test plugin helpers', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data + const { data } = await server.videosCommand.list() - expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('video server 2') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video server 2') } }) @@ -223,10 +213,9 @@ describe('Test plugin helpers', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data + const { data } = await server.videosCommand.list() - expect(videos).to.have.lengthOf(2) + expect(data).to.have.lengthOf(2) } }) }) @@ -235,7 +224,7 @@ describe('Test plugin helpers', function () { let videoUUID: string before(async () => { - const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' }) + const res = await await servers[0].videosCommand.quickUpload({ name: 'video1' }) videoUUID = res.uuid }) @@ -243,15 +232,15 @@ describe('Test plugin helpers', function () { this.timeout(40000) // Should not throw -> video exists - await getVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.get({ id: videoUUID }) // Should delete the video - await viewVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.view({ id: videoUUID }) await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.') try { // Should throw because the video should have been deleted - await getVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.get({ id: videoUUID }) throw new Error('Video exists') } catch (err) { if (err.message.includes('exists')) throw err diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index 4839e8792..a3613293a 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -7,16 +7,14 @@ import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server import { cleanupTests, flushAndRunServer, - getVideo, PluginsCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, testFfmpegStreamError, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' -import { VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoPrivacy } from '@shared/models' async function createLiveWrapper (server: ServerInfo) { const liveAttributes = { @@ -81,8 +79,7 @@ describe('Test transcoding plugins', function () { describe('When using a plugin adding profiles to existing encoders', function () { async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) { - const res = await getVideo(server.url, uuid) - const video = res.body as VideoDetails + const video = await server.videosCommand.get({ id: uuid }) const files = video.files.concat(...video.streamingPlaylists.map(p => p.files)) for (const file of files) { @@ -119,7 +116,7 @@ describe('Test transcoding plugins', function () { it('Should not use the plugin profile if not chosen by the admin', async function () { this.timeout(240000) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'above', 20) @@ -130,7 +127,7 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'low-vod', 'default') - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'below', 12) @@ -141,7 +138,7 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'input-options-vod', 'default') - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'below', 6) @@ -152,13 +149,11 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'bad-scale-vod', 'default') - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) // Transcoding failed - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.files).to.have.lengthOf(1) expect(video.streamingPlaylists).to.have.lengthOf(0) }) @@ -224,7 +219,7 @@ describe('Test transcoding plugins', function () { expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'above', 20) @@ -243,7 +238,7 @@ describe('Test transcoding plugins', function () { it('Should use the new vod encoders', async function () { this.timeout(240000) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid await waitJobs([ server ]) const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index 4a05af042..641e37fbb 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -3,20 +3,8 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - getVideo, - getVideoCategories, - getVideoLanguages, - getVideoLicences, - getVideoPrivacies, - PluginsCommand, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '@shared/extra-utils' -import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models' +import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -33,8 +21,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated languages', async function () { - const res = await getVideoLanguages(server.url) - const languages = res.body + const languages = await server.videosCommand.getLanguages() expect(languages['en']).to.not.exist expect(languages['fr']).to.not.exist @@ -45,8 +32,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated categories', async function () { - const res = await getVideoCategories(server.url) - const categories = res.body + const categories = await server.videosCommand.getCategories() expect(categories[1]).to.not.exist expect(categories[2]).to.not.exist @@ -56,8 +42,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated licences', async function () { - const res = await getVideoLicences(server.url) - const licences = res.body + const licences = await server.videosCommand.getLicences() expect(licences[1]).to.not.exist expect(licences[7]).to.not.exist @@ -67,8 +52,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated video privacies', async function () { - const res = await getVideoPrivacies(server.url) - const privacies = res.body + const privacies = await server.videosCommand.getPrivacies() expect(privacies[1]).to.exist expect(privacies[2]).to.not.exist @@ -85,8 +69,8 @@ describe('Test plugin altering video constants', function () { }) it('Should not be able to create a video with this privacy', async function () { - const attrs = { name: 'video', privacy: 2 } - await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) + const attributes = { name: 'video', privacy: 2 } + await server.videosCommand.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not be able to create a video with this privacy', async function () { @@ -95,12 +79,10 @@ describe('Test plugin altering video constants', function () { }) it('Should be able to upload a video with these values', async function () { - const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } - const resUpload = await uploadVideo(server.url, server.accessToken, attrs) + const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } + const { uuid } = await server.videosCommand.upload({ attributes }) - const res = await getVideo(server.url, resUpload.body.video.uuid) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: uuid }) expect(video.language.label).to.equal('Al Bhed 2') expect(video.licence.label).to.equal('Best licence') expect(video.category.label).to.equal('Best category') @@ -110,8 +92,7 @@ describe('Test plugin altering video constants', function () { await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) { - const res = await getVideoLanguages(server.url) - const languages = res.body + const languages = await server.videosCommand.getLanguages() expect(languages['en']).to.equal('English') expect(languages['fr']).to.equal('French') @@ -122,8 +103,7 @@ describe('Test plugin altering video constants', function () { } { - const res = await getVideoCategories(server.url) - const categories = res.body + const categories = await server.videosCommand.getCategories() expect(categories[1]).to.equal('Music') expect(categories[2]).to.equal('Films') @@ -133,8 +113,7 @@ describe('Test plugin altering video constants', function () { } { - const res = await getVideoLicences(server.url) - const licences = res.body + const licences = await server.videosCommand.getLicences() expect(licences[1]).to.equal('Attribution') expect(licences[7]).to.equal('Public Domain Dedication') @@ -144,8 +123,7 @@ describe('Test plugin altering video constants', function () { } { - const res = await getVideoPrivacies(server.url) - const privacies = res.body + const privacies = await server.videosCommand.getPrivacies() expect(privacies[1]).to.exist expect(privacies[2]).to.exist diff --git a/server/tools/cli.ts b/server/tools/cli.ts index 17c2e8c74..163ed62d1 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts @@ -16,7 +16,7 @@ const version = require('../../../package.json').version async function getAdminTokenOrDie (server: ServerInfo, username: string, password: string) { const token = await server.loginCommand.getAccessToken(username, password) - const me = await server.usersCommand.getMyUserInformation({ token }) + const me = await server.usersCommand.getMyInfo({ token }) if (me.role !== UserRole.ADMINISTRATOR) { console.error('You must be an administrator.') diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 0a4d6fa6e..fc76735b9 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -9,7 +9,6 @@ import { join } from 'path' import * as prompt from 'prompt' import { promisify } from 'util' import { YoutubeDL } from '@server/helpers/youtube-dl' -import { getVideoCategories, uploadVideo } from '../../shared/extra-utils/index' import { sha256 } from '../helpers/core-utils' import { doRequestAndSaveToFile } from '../helpers/requests' import { CONSTRAINTS_FIELDS } from '../initializers/constants' @@ -21,6 +20,7 @@ import { getLogger, getServerCredentials } from './cli' +import { ServerInfo } from '@shared/extra-utils' const processOptions = { maxBuffer: Infinity @@ -200,7 +200,10 @@ async function uploadVideoOnPeerTube (parameters: { }) { const { youtubeDL, videoInfo, videoPath, cwd, url, username, password } = parameters - const category = await getCategory(videoInfo.categories, url) + const server = buildServer(url) + await assignToken(server, username, password) + + const category = await getCategory(server, videoInfo.categories) const licence = getLicence(videoInfo.license) let tags = [] if (Array.isArray(videoInfo.tags)) { @@ -232,29 +235,28 @@ async function uploadVideoOnPeerTube (parameters: { tags } - const server = buildServer(url) - await assignToken(server, username, password) + const baseAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes) - const videoAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes) + const attributes = { + ...baseAttributes, - Object.assign(videoAttributes, { originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null, thumbnailfile, previewfile: thumbnailfile, fixture: videoPath - }) + } - log.info('\nUploading on PeerTube video "%s".', videoAttributes.name) + log.info('\nUploading on PeerTube video "%s".', attributes.name) try { - await uploadVideo(url, server.accessToken, videoAttributes) + await server.videosCommand.upload({ attributes }) } catch (err) { if (err.message.indexOf('401') !== -1) { log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.') server.accessToken = await server.loginCommand.getAccessToken(username, password) - await uploadVideo(url, server.accessToken, videoAttributes) + await server.videosCommand.upload({ attributes }) } else { exitError(err.message) } @@ -263,20 +265,19 @@ async function uploadVideoOnPeerTube (parameters: { await remove(videoPath) if (thumbnailfile) await remove(thumbnailfile) - log.warn('Uploaded video "%s"!\n', videoAttributes.name) + log.warn('Uploaded video "%s"!\n', attributes.name) } /* ---------------------------------------------------------- */ -async function getCategory (categories: string[], url: string) { +async function getCategory (server: ServerInfo, categories: string[]) { if (!categories) return undefined const categoryString = categories[0] if (categoryString === 'News & Politics') return 11 - const res = await getVideoCategories(url) - const categoriesServer = res.body + const categoriesServer = await server.videosCommand.getCategories() for (const key of Object.keys(categoriesServer)) { const categoryServer = categoriesServer[key] diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts index c94b05857..597137e4c 100644 --- a/server/tools/peertube-upload.ts +++ b/server/tools/peertube-upload.ts @@ -4,7 +4,6 @@ registerTSPaths() import { program } from 'commander' import { access, constants } from 'fs-extra' import { isAbsolute } from 'path' -import { uploadVideo } from '../../shared/extra-utils/' import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli' let command = program @@ -52,16 +51,18 @@ async function run (url: string, username: string, password: string) { console.log('Uploading %s video...', options.videoName) - const videoAttributes = await buildVideoAttributesFromCommander(server, program) + const baseAttributes = await buildVideoAttributesFromCommander(server, program) + + const attributes = { + ...baseAttributes, - Object.assign(videoAttributes, { fixture: options.file, thumbnailfile: options.thumbnail, previewfile: options.preview - }) + } try { - await uploadVideo(url, server.accessToken, videoAttributes) + await server.videosCommand.upload({ attributes }) console.log(`Video ${options.videoName} uploaded.`) process.exit(0) } catch (err) { diff --git a/shared/extra-utils/miscs/webtorrent.ts b/shared/extra-utils/miscs/webtorrent.ts index 82548946d..63e648309 100644 --- a/shared/extra-utils/miscs/webtorrent.ts +++ b/shared/extra-utils/miscs/webtorrent.ts @@ -1,4 +1,8 @@ +import { readFile } from 'fs-extra' +import * as parseTorrent from 'parse-torrent' +import { join } from 'path' import * as WebTorrent from 'webtorrent' +import { ServerInfo } from '../server' let webtorrent: WebTorrent.Instance @@ -11,6 +15,16 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { return new Promise(res => webtorrent.add(torrent, res)) } +async function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { + const torrentName = videoUUID + '-' + resolution + '.torrent' + const torrentPath = server.serversCommand.buildDirectory(join('torrents', torrentName)) + + const data = await readFile(torrentPath) + + return parseTorrent(data) +} + export { - webtorrentAdd + webtorrentAdd, + parseTorrentVideo } diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts index c5ee63e05..3f1ac6650 100644 --- a/shared/extra-utils/requests/requests.ts +++ b/shared/extra-utils/requests/requests.ts @@ -67,11 +67,17 @@ function makeUploadRequest (options: { method?: 'POST' | 'PUT' path: string token?: string + fields: { [ fieldName: string ]: any } attaches?: { [ attachName: string ]: any | any[] } + + headers?: { [ name: string ]: string } + statusCodeExpected?: HttpStatusCode }) { - if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 + if (options.statusCodeExpected === undefined) { + options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 + } let req: request.Test if (options.method === 'PUT') { @@ -84,6 +90,10 @@ function makeUploadRequest (options: { if (options.token) req.set('Authorization', 'Bearer ' + options.token) + Object.keys(options.headers || {}).forEach(name => { + req.set(name, options.headers[name]) + }) + Object.keys(options.fields).forEach(field => { const value = options.fields[field] @@ -107,7 +117,11 @@ function makeUploadRequest (options: { } }) - return req.expect(options.statusCodeExpected) + if (options.statusCodeExpected) { + req.expect(options.statusCodeExpected) + } + + return req } function makePostBodyRequest (options: { @@ -115,7 +129,9 @@ function makePostBodyRequest (options: { path: string token?: string fields?: { [ fieldName: string ]: any } + headers?: { [ name: string ]: string } type?: string + xForwardedFor?: string statusCodeExpected?: HttpStatusCode }) { if (!options.fields) options.fields = {} @@ -126,8 +142,13 @@ function makePostBodyRequest (options: { .set('Accept', 'application/json') if (options.token) req.set('Authorization', 'Bearer ' + options.token) + if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor) if (options.type) req.type(options.type) + Object.keys(options.headers || {}).forEach(name => { + req.set(name, options.headers[name]) + }) + return req.send(options.fields) .expect(options.statusCodeExpected) } diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index b6d597c5d..fda5c3d6d 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -27,7 +27,8 @@ import { LiveCommand, PlaylistsCommand, ServicesCommand, - StreamingPlaylistsCommand + StreamingPlaylistsCommand, + VideosCommand } from '../videos' import { CommentsCommand } from '../videos/comments-command' import { ConfigCommand } from './config-command' @@ -128,6 +129,7 @@ interface ServerInfo { serversCommand?: ServersCommand loginCommand?: LoginCommand usersCommand?: UsersCommand + videosCommand?: VideosCommand } function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { @@ -361,6 +363,7 @@ function assignCommands (server: ServerInfo) { server.serversCommand = new ServersCommand(server) server.loginCommand = new LoginCommand(server) server.usersCommand = new UsersCommand(server) + server.videosCommand = new VideosCommand(server) } async function reRunServer (server: ServerInfo, configOverride?: any) { diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts index af9ecd926..5fddcf639 100644 --- a/shared/extra-utils/shared/abstract-command.ts +++ b/shared/extra-utils/shared/abstract-command.ts @@ -1,5 +1,4 @@ import { isAbsolute, join } from 'path' -import { HttpStatusCode } from '@shared/core-utils' import { root } from '../miscs/tests' import { makeDeleteRequest, @@ -38,22 +37,12 @@ interface InternalGetCommandOptions extends InternalCommonCommandOptions { abstract class AbstractCommand { - private expectedStatus: HttpStatusCode - constructor ( protected server: ServerInfo ) { } - setServer (server: ServerInfo) { - this.server = server - } - - setExpectedStatus (status: HttpStatusCode) { - this.expectedStatus = status - } - protected getRequestBody (options: InternalGetCommandOptions) { return unwrapBody(this.getRequest(options)) } @@ -111,43 +100,51 @@ abstract class AbstractCommand { protected postBodyRequest (options: InternalCommonCommandOptions & { fields?: { [ fieldName: string ]: any } + headers?: { [ name: string ]: string } type?: string + xForwardedFor?: string }) { - const { type, fields } = options + const { type, fields, xForwardedFor, headers } = options return makePostBodyRequest({ ...this.buildCommonRequestOptions(options), fields, - type + xForwardedFor, + type, + headers }) } protected postUploadRequest (options: InternalCommonCommandOptions & { fields?: { [ fieldName: string ]: any } - attaches?: any + attaches?: { [ fieldName: string ]: any } + headers?: { [ name: string ]: string } }) { - const { fields, attaches } = options + const { fields, attaches, headers } = options return makeUploadRequest({ ...this.buildCommonRequestOptions(options), method: 'POST', fields, - attaches + attaches, + headers }) } protected putUploadRequest (options: InternalCommonCommandOptions & { fields?: { [ fieldName: string ]: any } - attaches?: any + attaches?: { [ fieldName: string ]: any } + headers?: { [ name: string ]: string } }) { - const { fields, attaches } = options + const { fields, attaches, headers } = options return makeUploadRequest({ ...this.buildCommonRequestOptions(options), method: 'PUT', + headers, fields, attaches }) @@ -172,7 +169,7 @@ abstract class AbstractCommand { }) } - private buildCommonRequestOptions (options: InternalCommonCommandOptions) { + protected buildCommonRequestOptions (options: InternalCommonCommandOptions) { const { url, path } = options return { @@ -184,7 +181,7 @@ abstract class AbstractCommand { } } - private buildCommonRequestToken (options: Pick) { + protected buildCommonRequestToken (options: Pick) { const { token } = options const fallbackToken = options.implicitToken @@ -194,10 +191,10 @@ abstract class AbstractCommand { return token !== undefined ? token : fallbackToken } - private buildStatusCodeExpected (options: Pick) { + protected buildStatusCodeExpected (options: Pick) { const { expectedStatus, defaultExpectedStatus } = options - return expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus + return expectedStatus !== undefined ? expectedStatus : defaultExpectedStatus } } diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts index 652d82842..26e663f46 100644 --- a/shared/extra-utils/videos/index.ts +++ b/shared/extra-utils/videos/index.ts @@ -15,4 +15,5 @@ export * from './services-command' export * from './streaming-playlists-command' export * from './streaming-playlists' export * from './comments-command' +export * from './videos-command' export * from './videos' diff --git a/shared/extra-utils/videos/live-command.ts b/shared/extra-utils/videos/live-command.ts index a494e60fa..5adf601cc 100644 --- a/shared/extra-utils/videos/live-command.ts +++ b/shared/extra-utils/videos/live-command.ts @@ -9,7 +9,6 @@ import { wait } from '../miscs' import { unwrapBody } from '../requests' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { sendRTMPStream, testFfmpegStreamError } from './live' -import { getVideoWithToken } from './videos' export class LiveCommand extends AbstractCommand { @@ -124,8 +123,7 @@ export class LiveCommand extends AbstractCommand { let video: VideoDetails do { - const res = await getVideoWithToken(this.server.url, options.token ?? this.server.accessToken, options.videoId) - video = res.body + video = await this.server.videosCommand.getWithToken({ token: options.token, id: options.videoId }) await wait(500) } while (video.isLive === true && video.state.id !== VideoState.PUBLISHED) @@ -149,8 +147,7 @@ export class LiveCommand extends AbstractCommand { let video: VideoDetails do { - const res = await getVideoWithToken(this.server.url, options.token ?? this.server.accessToken, options.videoId) - video = res.body + video = await this.server.videosCommand.getWithToken({ token: options.token, id: options.videoId }) await wait(500) } while (video.state.id !== options.state) diff --git a/shared/extra-utils/videos/playlists-command.ts b/shared/extra-utils/videos/playlists-command.ts index f77decc1a..75c8f2433 100644 --- a/shared/extra-utils/videos/playlists-command.ts +++ b/shared/extra-utils/videos/playlists-command.ts @@ -1,23 +1,22 @@ import { omit, pick } from 'lodash' +import { HttpStatusCode } from '@shared/core-utils' import { BooleanBothQuery, ResultList, VideoExistInPlaylist, VideoPlaylist, + VideoPlaylistCreate, VideoPlaylistCreateResult, VideoPlaylistElement, + VideoPlaylistElementCreate, VideoPlaylistElementCreateResult, - VideoPlaylistReorder + VideoPlaylistElementUpdate, + VideoPlaylistReorder, + VideoPlaylistType, + VideoPlaylistUpdate } from '@shared/models' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' -import { VideoPlaylistCreate } from '../../models/videos/playlist/video-playlist-create.model' -import { VideoPlaylistElementCreate } from '../../models/videos/playlist/video-playlist-element-create.model' -import { VideoPlaylistElementUpdate } from '../../models/videos/playlist/video-playlist-element-update.model' -import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model' -import { VideoPlaylistUpdate } from '../../models/videos/playlist/video-playlist-update.model' import { unwrapBody } from '../requests' import { AbstractCommand, OverrideCommandOptions } from '../shared' -import { videoUUIDToId } from './videos' export class PlaylistsCommand extends AbstractCommand { @@ -185,7 +184,7 @@ export class PlaylistsCommand extends AbstractCommand { const attributes = { ...options.attributes, - videoId: await videoUUIDToId(this.server.url, options.attributes.videoId) + videoId: await this.server.videosCommand.getId({ ...options, uuid: options.attributes.videoId }) } const path = '/api/v1/video-playlists/' + options.playlistId + '/videos' diff --git a/shared/extra-utils/videos/videos-command.ts b/shared/extra-utils/videos/videos-command.ts new file mode 100644 index 000000000..574705474 --- /dev/null +++ b/shared/extra-utils/videos/videos-command.ts @@ -0,0 +1,583 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ + +import { expect } from 'chai' +import { createReadStream, stat } from 'fs-extra' +import got, { Response as GotResponse } from 'got' +import { omit, pick } from 'lodash' +import validator from 'validator' +import { buildUUID } from '@server/helpers/uuid' +import { loadLanguages } from '@server/initializers/constants' +import { HttpStatusCode } from '@shared/core-utils' +import { + ResultList, + UserVideoRateType, + Video, + VideoCreate, + VideoCreateResult, + VideoDetails, + VideoFileMetadata, + VideoPrivacy, + VideosCommonQuery, + VideosWithSearchCommonQuery +} from '@shared/models' +import { buildAbsoluteFixturePath, wait } from '../miscs' +import { unwrapBody } from '../requests' +import { ServerInfo, waitJobs } from '../server' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export type VideoEdit = Partial> & { + fixture?: string + thumbnailfile?: string + previewfile?: string +} + +export class VideosCommand extends AbstractCommand { + + constructor (server: ServerInfo) { + super(server) + + loadLanguages() + } + + getCategories (options: OverrideCommandOptions = {}) { + const path = '/api/v1/videos/categories' + + return this.getRequestBody<{ [id: number]: string }>({ + ...options, + path, + + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getLicences (options: OverrideCommandOptions = {}) { + const path = '/api/v1/videos/licences' + + return this.getRequestBody<{ [id: number]: string }>({ + ...options, + path, + + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getLanguages (options: OverrideCommandOptions = {}) { + const path = '/api/v1/videos/languages' + + return this.getRequestBody<{ [id: string]: string }>({ + ...options, + path, + + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getPrivacies (options: OverrideCommandOptions = {}) { + const path = '/api/v1/videos/privacies' + + return this.getRequestBody<{ [id in VideoPrivacy]: string }>({ + ...options, + path, + + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + // --------------------------------------------------------------------------- + + getDescription (options: OverrideCommandOptions & { + descriptionPath: string + }) { + return this.getRequestBody<{ description: string }>({ + ...options, + path: options.descriptionPath, + + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getFileMetadata (options: OverrideCommandOptions & { + url: string + }) { + return unwrapBody(this.getRawRequest({ + ...options, + + url: options.url, + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + })) + } + + // --------------------------------------------------------------------------- + + view (options: OverrideCommandOptions & { + id: number | string + xForwardedFor?: string + }) { + const { id, xForwardedFor } = options + const path = '/api/v1/videos/' + id + '/views' + + return this.postBodyRequest({ + ...options, + + path, + xForwardedFor, + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + rate (options: OverrideCommandOptions & { + id: number | string + rating: UserVideoRateType + }) { + const { id, rating } = options + const path = '/api/v1/videos/' + id + '/rate' + + return this.putBodyRequest({ + ...options, + + path, + fields: { rating }, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + // --------------------------------------------------------------------------- + + get (options: OverrideCommandOptions & { + id: number | string + }) { + const path = '/api/v1/videos/' + options.id + + return this.getRequestBody({ + ...options, + + path, + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getWithToken (options: OverrideCommandOptions & { + id: number | string + }) { + return this.get({ + ...options, + + token: this.buildCommonRequestToken({ ...options, implicitToken: true }) + }) + } + + async getId (options: OverrideCommandOptions & { + uuid: number | string + }) { + const { uuid } = options + + if (validator.isUUID('' + uuid) === false) return uuid as number + + const { id } = await this.get({ ...options, id: uuid }) + + return id + } + + // --------------------------------------------------------------------------- + + listMyVideos (options: OverrideCommandOptions & { + start?: number + count?: number + sort?: string + search?: string + isLive?: boolean + } = {}) { + const path = '/api/v1/users/me/videos' + + return this.getRequestBody>({ + ...options, + + path, + query: pick(options, [ 'start', 'count', 'sort', 'search', 'isLive' ]), + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + // --------------------------------------------------------------------------- + + list (options: OverrideCommandOptions & VideosCommonQuery = {}) { + const path = '/api/v1/videos' + + const query = this.buildListQuery(options) + + return this.getRequestBody>({ + ...options, + + path, + query: { sort: 'name', ...query }, + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + listWithToken (options: OverrideCommandOptions & VideosCommonQuery = {}) { + return this.list({ + ...options, + + token: this.buildCommonRequestToken({ ...options, implicitToken: true }) + }) + } + + listByAccount (options: OverrideCommandOptions & VideosWithSearchCommonQuery & { + accountName: string + }) { + const { accountName, search } = options + const path = '/api/v1/accounts/' + accountName + '/videos' + + return this.getRequestBody>({ + ...options, + + path, + query: { search, ...this.buildListQuery(options) }, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + listByChannel (options: OverrideCommandOptions & VideosWithSearchCommonQuery & { + videoChannelName: string + }) { + const { videoChannelName } = options + const path = '/api/v1/video-channels/' + videoChannelName + '/videos' + + return this.getRequestBody>({ + ...options, + + path, + query: this.buildListQuery(options), + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + // --------------------------------------------------------------------------- + + update (options: OverrideCommandOptions & { + id: number | string + attributes?: VideoEdit + }) { + const { id, attributes = {} } = options + const path = '/api/v1/videos/' + id + + // Upload request + if (attributes.thumbnailfile || attributes.previewfile) { + const attaches: any = {} + if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile + if (attributes.previewfile) attaches.previewfile = attributes.previewfile + + return this.putUploadRequest({ + ...options, + + path, + fields: options.attributes, + attaches: { + thumbnailfile: attributes.thumbnailfile, + previewfile: attributes.previewfile + }, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + return this.putBodyRequest({ + ...options, + + path, + fields: options.attributes, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + remove (options: OverrideCommandOptions & { + id: number | string + }) { + const path = '/api/v1/videos/' + options.id + + return this.deleteRequest({ + ...options, + + path, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + async removeAll () { + const { data } = await this.list() + + for (const v of data) { + await this.remove({ id: v.id }) + } + } + + // --------------------------------------------------------------------------- + + async upload (options: OverrideCommandOptions & { + attributes?: VideoEdit + mode?: 'legacy' | 'resumable' // default legacy + } = {}) { + const { mode = 'legacy', expectedStatus } = options + let defaultChannelId = 1 + + try { + const { videoChannels } = await this.server.usersCommand.getMyInfo({ token: options.token }) + defaultChannelId = videoChannels[0].id + } catch (e) { /* empty */ } + + // Override default attributes + const attributes = { + name: 'my super video', + category: 5, + licence: 4, + language: 'zh', + channelId: defaultChannelId, + nsfw: true, + waitTranscoding: false, + description: 'my super description', + support: 'my super support text', + tags: [ 'tag' ], + privacy: VideoPrivacy.PUBLIC, + commentsEnabled: true, + downloadEnabled: true, + fixture: 'video_short.webm', + + ...options.attributes + } + + const res = mode === 'legacy' + ? await this.buildLegacyUpload({ ...options, attributes }) + : await this.buildResumeUpload({ ...options, attributes }) + + // Wait torrent generation + if (expectedStatus === HttpStatusCode.OK_200) { + let video: VideoDetails + + do { + video = await this.getWithToken({ ...options, id: video.uuid }) + + await wait(50) + } while (!video.files[0].torrentUrl) + } + + return res + } + + async buildLegacyUpload (options: OverrideCommandOptions & { + attributes: VideoEdit + }): Promise { + const path = '/api/v1/videos/upload' + + return unwrapBody<{ video: VideoCreateResult }>(this.postUploadRequest({ + ...options, + + path, + fields: this.buildUploadFields(options.attributes), + attaches: this.buildUploadAttaches(options.attributes), + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.OK_200 + })).then(body => body.video || body as any) + } + + async buildResumeUpload (options: OverrideCommandOptions & { + attributes: VideoEdit + }) { + const { attributes, expectedStatus } = options + + let size = 0 + let videoFilePath: string + let mimetype = 'video/mp4' + + if (attributes.fixture) { + videoFilePath = buildAbsoluteFixturePath(attributes.fixture) + size = (await stat(videoFilePath)).size + + if (videoFilePath.endsWith('.mkv')) { + mimetype = 'video/x-matroska' + } else if (videoFilePath.endsWith('.webm')) { + mimetype = 'video/webm' + } + } + + const initializeSessionRes = await this.prepareResumableUpload({ ...options, attributes, size, mimetype }) + const initStatus = initializeSessionRes.status + + if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) { + const locationHeader = initializeSessionRes.header['location'] + expect(locationHeader).to.not.be.undefined + + const pathUploadId = locationHeader.split('?')[1] + + const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size }) + + return result.body.video + } + + const expectedInitStatus = expectedStatus === HttpStatusCode.OK_200 + ? HttpStatusCode.CREATED_201 + : expectedStatus + + expect(initStatus).to.equal(expectedInitStatus) + + return initializeSessionRes.body.video as VideoCreateResult + } + + async prepareResumableUpload (options: OverrideCommandOptions & { + attributes: VideoEdit + size: number + mimetype: string + }) { + const { attributes, size, mimetype } = options + + const path = '/api/v1/videos/upload-resumable' + + return this.postUploadRequest({ + ...options, + + path, + headers: { + 'X-Upload-Content-Type': mimetype, + 'X-Upload-Content-Length': size.toString() + }, + fields: { filename: attributes.fixture, ...this.buildUploadFields(options.attributes) }, + implicitToken: true, + defaultExpectedStatus: null + }) + } + + sendResumableChunks (options: OverrideCommandOptions & { + pathUploadId: string + videoFilePath: string + size: number + contentLength?: number + contentRangeBuilder?: (start: number, chunk: any) => string + }) { + const { pathUploadId, videoFilePath, size, contentLength, contentRangeBuilder, expectedStatus = HttpStatusCode.OK_200 } = options + + const path = '/api/v1/videos/upload-resumable' + let start = 0 + + const token = this.buildCommonRequestToken({ ...options, implicitToken: true }) + const url = this.server.url + + const readable = createReadStream(videoFilePath, { highWaterMark: 8 * 1024 }) + return new Promise>((resolve, reject) => { + readable.on('data', async function onData (chunk) { + readable.pause() + + const headers = { + 'Authorization': 'Bearer ' + token, + 'Content-Type': 'application/octet-stream', + 'Content-Range': contentRangeBuilder + ? contentRangeBuilder(start, chunk) + : `bytes ${start}-${start + chunk.length - 1}/${size}`, + 'Content-Length': contentLength ? contentLength + '' : chunk.length + '' + } + + const res = await got<{ video: VideoCreateResult }>({ + url, + method: 'put', + headers, + path: path + '?' + pathUploadId, + body: chunk, + responseType: 'json', + throwHttpErrors: false + }) + + start += chunk.length + + if (res.statusCode === expectedStatus) { + return resolve(res) + } + + if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) { + readable.off('data', onData) + return reject(new Error('Incorrect transient behaviour sending intermediary chunks')) + } + + readable.resume() + }) + }) + } + + quickUpload (options: OverrideCommandOptions & { + name: string + nsfw?: boolean + privacy?: VideoPrivacy + fixture?: string + }) { + const attributes: VideoEdit = { name: options.name } + if (options.nsfw) attributes.nsfw = options.nsfw + if (options.privacy) attributes.privacy = options.privacy + if (options.fixture) attributes.fixture = options.fixture + + return this.upload({ ...options, attributes }) + } + + async randomUpload (options: OverrideCommandOptions & { + wait?: boolean // default true + additionalParams?: VideoEdit & { prefixName: string } + } = {}) { + const { wait = true, additionalParams } = options + const prefixName = additionalParams?.prefixName || '' + const name = prefixName + buildUUID() + + const attributes = { name, additionalParams } + + if (wait) await waitJobs([ this.server ]) + + const result = await this.upload({ ...options, attributes }) + + return { ...result, name } + } + + // --------------------------------------------------------------------------- + + private buildListQuery (options: VideosCommonQuery) { + return pick(options, [ + 'start', + 'count', + 'sort', + 'nsfw', + 'isLive', + 'categoryOneOf', + 'licenceOneOf', + 'languageOneOf', + 'tagsOneOf', + 'tagsAllOf', + 'filter', + 'skipCount' + ]) + } + + private buildUploadFields (attributes: VideoEdit) { + return omit(attributes, [ 'thumbnailfile', 'previewfile' ]) + } + + private buildUploadAttaches (attributes: VideoEdit) { + const attaches: { [ name: string ]: string } = {} + + for (const key of [ 'thumbnailfile', 'previewfile' ]) { + if (attributes[key]) attaches[key] = buildAbsoluteFixturePath(attributes[key]) + } + + if (attributes.fixture) attaches.videofile = buildAbsoluteFixturePath(attributes.fixture) + + return attaches + } +} diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 5e20f8010..19f0df8b8 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts @@ -1,306 +1,16 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ import { expect } from 'chai' -import { createReadStream, pathExists, readdir, readFile, stat } from 'fs-extra' -import got, { Response as GotResponse } from 'got/dist/source' -import * as parseTorrent from 'parse-torrent' +import { pathExists, readdir } from 'fs-extra' import { join } from 'path' -import * as request from 'supertest' -import validator from 'validator' import { getLowercaseExtension } from '@server/helpers/core-utils' -import { buildUUID } from '@server/helpers/uuid' import { HttpStatusCode } from '@shared/core-utils' -import { BooleanBothQuery, VideosCommonQuery } from '@shared/models' -import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' -import { VideoDetails, VideoPrivacy } from '../../models/videos' -import { buildAbsoluteFixturePath, dateIsValid, testImage, wait, webtorrentAdd } from '../miscs' -import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests' -import { waitJobs } from '../server/jobs' +import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' +import { dateIsValid, testImage, webtorrentAdd } from '../miscs' +import { makeRawRequest } from '../requests/requests' +import { waitJobs } from '../server' import { ServerInfo } from '../server/servers' -import { xxxgetMyUserInformation } from '../users' - -loadLanguages() - -type VideoAttributes = { - name?: string - category?: number - licence?: number - language?: string - nsfw?: boolean - commentsEnabled?: boolean - downloadEnabled?: boolean - waitTranscoding?: boolean - description?: string - originallyPublishedAt?: string - tags?: string[] - channelId?: number - privacy?: VideoPrivacy - fixture?: string - support?: string - thumbnailfile?: string - previewfile?: string - scheduleUpdate?: { - updateAt: string - privacy?: VideoPrivacy - } -} - -function getVideoCategories (url: string) { - const path = '/api/v1/videos/categories' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getVideoLicences (url: string) { - const path = '/api/v1/videos/licences' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getVideoLanguages (url: string) { - const path = '/api/v1/videos/languages' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getVideoPrivacies (url: string) { - const path = '/api/v1/videos/privacies' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) { - const path = '/api/v1/videos/' + id - - return request(url) - .get(path) - .set('Accept', 'application/json') - .expect(expectedStatus) -} - -async function getVideoIdFromUUID (url: string, uuid: string) { - const res = await getVideo(url, uuid) - - return res.body.id -} - -function getVideoFileMetadataUrl (url: string) { - return request(url) - .get('/') - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function viewVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204, xForwardedFor?: string) { - const path = '/api/v1/videos/' + id + '/views' - - const req = request(url) - .post(path) - .set('Accept', 'application/json') - - if (xForwardedFor) { - req.set('X-Forwarded-For', xForwardedFor) - } - - return req.expect(expectedStatus) -} - -function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) { - const path = '/api/v1/videos/' + id - - return request(url) - .get(path) - .set('Authorization', 'Bearer ' + token) - .set('Accept', 'application/json') - .expect(expectedStatus) -} - -function getVideoDescription (url: string, descriptionPath: string) { - return request(url) - .get(descriptionPath) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function getVideosList (url: string) { - const path = '/api/v1/videos' - - return request(url) - .get(path) - .query({ sort: 'name' }) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function getVideosListWithToken (url: string, token: string, query: { nsfw?: BooleanBothQuery } = {}) { - const path = '/api/v1/videos' - - return request(url) - .get(path) - .set('Authorization', 'Bearer ' + token) - .query({ sort: 'name', ...query }) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function getLocalVideos (url: string) { - const path = '/api/v1/videos' - - return request(url) - .get(path) - .query({ sort: 'name', filter: 'local' }) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string, search?: string) { - const path = '/api/v1/users/me/videos' - - const req = request(url) - .get(path) - .query({ start: start }) - .query({ count: count }) - .query({ search: search }) - - if (sort) req.query({ sort }) - - return req.set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function getMyVideosWithFilter (url: string, accessToken: string, query: { isLive?: boolean }) { - const path = '/api/v1/users/me/videos' - - return makeGetRequest({ - url, - path, - token: accessToken, - query, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getAccountVideos ( - url: string, - accessToken: string, - accountName: string, - start: number, - count: number, - sort?: string, - query: { - nsfw?: BooleanBothQuery - search?: string - } = {} -) { - const path = '/api/v1/accounts/' + accountName + '/videos' - - return makeGetRequest({ - url, - path, - query: { ...query, start, count, sort }, - token: accessToken, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getVideoChannelVideos ( - url: string, - accessToken: string, - videoChannelName: string, - start: number, - count: number, - sort?: string, - query: { nsfw?: BooleanBothQuery } = {} -) { - const path = '/api/v1/video-channels/' + videoChannelName + '/videos' - - return makeGetRequest({ - url, - path, - query: { ...query, start, count, sort }, - token: accessToken, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getVideosListPagination (url: string, start: number, count: number, sort?: string, skipCount?: boolean) { - const path = '/api/v1/videos' - - const req = request(url) - .get(path) - .query({ start: start }) - .query({ count: count }) - - if (sort) req.query({ sort }) - if (skipCount) req.query({ skipCount }) - - return req.set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function getVideosListSort (url: string, sort: string) { - const path = '/api/v1/videos' - - return request(url) - .get(path) - .query({ sort: sort }) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function getVideosWithFilters (url: string, query: VideosCommonQuery) { - const path = '/api/v1/videos' - - return request(url) - .get(path) - .query(query) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function removeVideo (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { - const path = '/api/v1/videos' - - return request(url) - .delete(path + '/' + id) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + token) - .expect(expectedStatus) -} - -async function removeAllVideos (server: ServerInfo) { - const resVideos = await getVideosList(server.url) - - for (const v of resVideos.body.data) { - await removeVideo(server.url, server.accessToken, v.id) - } -} +import { VideoEdit } from './videos-command' async function checkVideoFilesWereRemoved ( videoUUID: string, @@ -329,280 +39,20 @@ async function checkVideoFilesWereRemoved ( } } -async function uploadVideo ( - url: string, - accessToken: string, - videoAttributesArg: VideoAttributes, - specialStatus = HttpStatusCode.OK_200, - mode: 'legacy' | 'resumable' = 'legacy' -) { - let defaultChannelId = '1' - - try { - const res = await xxxgetMyUserInformation(url, accessToken) - defaultChannelId = res.body.videoChannels[0].id - } catch (e) { /* empty */ } - - // Override default attributes - const attributes = Object.assign({ - name: 'my super video', - category: 5, - licence: 4, - language: 'zh', - channelId: defaultChannelId, - nsfw: true, - waitTranscoding: false, - description: 'my super description', - support: 'my super support text', - tags: [ 'tag' ], - privacy: VideoPrivacy.PUBLIC, - commentsEnabled: true, - downloadEnabled: true, - fixture: 'video_short.webm' - }, videoAttributesArg) - - const res = mode === 'legacy' - ? await buildLegacyUpload(url, accessToken, attributes, specialStatus) - : await buildResumeUpload(url, accessToken, attributes, specialStatus) - - // Wait torrent generation - if (specialStatus === HttpStatusCode.OK_200) { - let video: VideoDetails - do { - const resVideo = await getVideoWithToken(url, accessToken, res.body.video.uuid) - video = resVideo.body - - await wait(50) - } while (!video.files[0].torrentUrl) - } - - return res -} - function checkUploadVideoParam ( - url: string, + server: ServerInfo, token: string, - attributes: Partial, - specialStatus = HttpStatusCode.OK_200, + attributes: Partial, + expectedStatus = HttpStatusCode.OK_200, mode: 'legacy' | 'resumable' = 'legacy' ) { return mode === 'legacy' - ? buildLegacyUpload(url, token, attributes, specialStatus) - : buildResumeUpload(url, token, attributes, specialStatus) -} - -async function buildLegacyUpload (url: string, token: string, attributes: VideoAttributes, specialStatus = HttpStatusCode.OK_200) { - const path = '/api/v1/videos/upload' - const req = request(url) - .post(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + token) - - buildUploadReq(req, attributes) - - if (attributes.fixture !== undefined) { - req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) - } - - return req.expect(specialStatus) -} - -async function buildResumeUpload (url: string, token: string, attributes: VideoAttributes, specialStatus = HttpStatusCode.OK_200) { - let size = 0 - let videoFilePath: string - let mimetype = 'video/mp4' - - if (attributes.fixture) { - videoFilePath = buildAbsoluteFixturePath(attributes.fixture) - size = (await stat(videoFilePath)).size - - if (videoFilePath.endsWith('.mkv')) { - mimetype = 'video/x-matroska' - } else if (videoFilePath.endsWith('.webm')) { - mimetype = 'video/webm' - } - } - - const initializeSessionRes = await prepareResumableUpload({ url, token, attributes, size, mimetype }) - const initStatus = initializeSessionRes.status - - if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) { - const locationHeader = initializeSessionRes.header['location'] - expect(locationHeader).to.not.be.undefined - - const pathUploadId = locationHeader.split('?')[1] - - return sendResumableChunks({ url, token, pathUploadId, videoFilePath, size, specialStatus }) - } - - const expectedInitStatus = specialStatus === HttpStatusCode.OK_200 - ? HttpStatusCode.CREATED_201 - : specialStatus - - expect(initStatus).to.equal(expectedInitStatus) - - return initializeSessionRes -} - -async function prepareResumableUpload (options: { - url: string - token: string - attributes: VideoAttributes - size: number - mimetype: string -}) { - const { url, token, attributes, size, mimetype } = options - - const path = '/api/v1/videos/upload-resumable' - - const req = request(url) - .post(path) - .set('Authorization', 'Bearer ' + token) - .set('X-Upload-Content-Type', mimetype) - .set('X-Upload-Content-Length', size.toString()) - - buildUploadReq(req, attributes) - - if (attributes.fixture) { - req.field('filename', attributes.fixture) - } - - return req -} - -function sendResumableChunks (options: { - url: string - token: string - pathUploadId: string - videoFilePath: string - size: number - specialStatus?: HttpStatusCode - contentLength?: number - contentRangeBuilder?: (start: number, chunk: any) => string -}) { - const { url, token, pathUploadId, videoFilePath, size, specialStatus, contentLength, contentRangeBuilder } = options - - const expectedStatus = specialStatus || HttpStatusCode.OK_200 - - const path = '/api/v1/videos/upload-resumable' - let start = 0 - - const readable = createReadStream(videoFilePath, { highWaterMark: 8 * 1024 }) - return new Promise((resolve, reject) => { - readable.on('data', async function onData (chunk) { - readable.pause() - - const headers = { - 'Authorization': 'Bearer ' + token, - 'Content-Type': 'application/octet-stream', - 'Content-Range': contentRangeBuilder - ? contentRangeBuilder(start, chunk) - : `bytes ${start}-${start + chunk.length - 1}/${size}`, - 'Content-Length': contentLength ? contentLength + '' : chunk.length + '' - } - - const res = await got({ - url, - method: 'put', - headers, - path: path + '?' + pathUploadId, - body: chunk, - responseType: 'json', - throwHttpErrors: false - }) - - start += chunk.length - - if (res.statusCode === expectedStatus) { - return resolve(res) - } - - if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) { - readable.off('data', onData) - return reject(new Error('Incorrect transient behaviour sending intermediary chunks')) - } - - readable.resume() - }) - }) -} - -function updateVideo ( - url: string, - accessToken: string, - id: number | string, - attributes: VideoAttributes, - statusCodeExpected = HttpStatusCode.NO_CONTENT_204 -) { - const path = '/api/v1/videos/' + id - const body = {} - - if (attributes.name) body['name'] = attributes.name - if (attributes.category) body['category'] = attributes.category - if (attributes.licence) body['licence'] = attributes.licence - if (attributes.language) body['language'] = attributes.language - if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw) - if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled) - if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled) - if (attributes.originallyPublishedAt !== undefined) body['originallyPublishedAt'] = attributes.originallyPublishedAt - if (attributes.description) body['description'] = attributes.description - if (attributes.tags) body['tags'] = attributes.tags - if (attributes.privacy) body['privacy'] = attributes.privacy - if (attributes.channelId) body['channelId'] = attributes.channelId - if (attributes.scheduleUpdate) body['scheduleUpdate'] = attributes.scheduleUpdate - - // Upload request - if (attributes.thumbnailfile || attributes.previewfile) { - const attaches: any = {} - if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile - if (attributes.previewfile) attaches.previewfile = attributes.previewfile - - return makeUploadRequest({ - url, - method: 'PUT', - path, - token: accessToken, - fields: body, - attaches, - statusCodeExpected - }) - } - - return makePutBodyRequest({ - url, - path, - fields: body, - token: accessToken, - statusCodeExpected - }) -} - -function rateVideo (url: string, accessToken: string, id: number | string, rating: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { - const path = '/api/v1/videos/' + id + '/rate' - - return request(url) - .put(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .send({ rating }) - .expect(specialStatus) -} - -function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { - return new Promise((res, rej) => { - const torrentName = videoUUID + '-' + resolution + '.torrent' - const torrentPath = server.serversCommand.buildDirectory(join('torrents', torrentName)) - - readFile(torrentPath, (err, data) => { - if (err) return rej(err) - - return res(parseTorrent(data)) - }) - }) + ? server.videosCommand.buildLegacyUpload({ token, attributes, expectedStatus }) + : server.videosCommand.buildResumeUpload({ token, attributes, expectedStatus }) } async function completeVideoCheck ( - url: string, + server: ServerInfo, video: any, attributes: { name: string @@ -644,7 +94,7 @@ async function completeVideoCheck ( if (!attributes.likes) attributes.likes = 0 if (!attributes.dislikes) attributes.dislikes = 0 - const host = new URL(url).host + const host = new URL(server.url).host const originHost = attributes.account.host expect(video.name).to.equal(attributes.name) @@ -681,8 +131,7 @@ async function completeVideoCheck ( expect(video.originallyPublishedAt).to.be.null } - const res = await getVideo(url, video.uuid) - const videoDetails: VideoDetails = res.body + const videoDetails = await server.videosCommand.get({ id: video.uuid }) expect(videoDetails.files).to.have.lengthOf(attributes.files.length) expect(videoDetails.tags).to.deep.equal(attributes.tags) @@ -738,148 +187,33 @@ async function completeVideoCheck ( } expect(videoDetails.thumbnailPath).to.exist - await testImage(url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath) + await testImage(server.url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath) if (attributes.previewfile) { expect(videoDetails.previewPath).to.exist - await testImage(url, attributes.previewfile, videoDetails.previewPath) + await testImage(server.url, attributes.previewfile, videoDetails.previewPath) } } -async function videoUUIDToId (url: string, id: number | string) { - if (validator.isUUID('' + id) === false) return id - - const res = await getVideo(url, id) - return res.body.id -} - -async function uploadVideoAndGetId (options: { - server: ServerInfo - videoName: string - nsfw?: boolean - privacy?: VideoPrivacy - token?: string - fixture?: string -}) { - const videoAttrs: any = { name: options.videoName } - if (options.nsfw) videoAttrs.nsfw = options.nsfw - if (options.privacy) videoAttrs.privacy = options.privacy - if (options.fixture) videoAttrs.fixture = options.fixture - - const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs) - - return res.body.video as { id: number, uuid: string, shortUUID: string } -} - -async function getLocalIdByUUID (url: string, uuid: string) { - const res = await getVideo(url, uuid) - - return res.body.id -} - // serverNumber starts from 1 -async function uploadRandomVideoOnServers (servers: ServerInfo[], serverNumber: number, additionalParams: any = {}) { +async function uploadRandomVideoOnServers ( + servers: ServerInfo[], + serverNumber: number, + additionalParams?: VideoEdit & { prefixName?: string } +) { const server = servers.find(s => s.serverNumber === serverNumber) - const res = await uploadRandomVideo(server, false, additionalParams) + const res = await server.videosCommand.randomUpload({ wait: false, ...additionalParams }) await waitJobs(servers) return res } -async function uploadRandomVideo (server: ServerInfo, wait = true, additionalParams: any = {}) { - const prefixName = additionalParams.prefixName || '' - const name = prefixName + buildUUID() - - const data = Object.assign({ name }, additionalParams) - const res = await uploadVideo(server.url, server.accessToken, data) - - if (wait) await waitJobs([ server ]) - - return { uuid: res.body.video.uuid, name } -} - // --------------------------------------------------------------------------- export { - getVideoDescription, - getVideoCategories, - uploadRandomVideo, - getVideoLicences, - videoUUIDToId, - getVideoPrivacies, - getVideoLanguages, - getMyVideos, - getAccountVideos, - getVideoChannelVideos, - getVideo, - getVideoFileMetadataUrl, - getVideoWithToken, - getVideosList, - removeAllVideos, checkUploadVideoParam, - getVideosListPagination, - getVideosListSort, - removeVideo, - getVideosListWithToken, - uploadVideo, - sendResumableChunks, - getVideosWithFilters, - uploadRandomVideoOnServers, - updateVideo, - rateVideo, - viewVideo, - parseTorrentVideo, - getLocalVideos, completeVideoCheck, - checkVideoFilesWereRemoved, - getMyVideosWithFilter, - uploadVideoAndGetId, - getLocalIdByUUID, - getVideoIdFromUUID, - prepareResumableUpload -} - -// --------------------------------------------------------------------------- - -function buildUploadReq (req: request.Test, attributes: VideoAttributes) { - - for (const key of [ 'name', 'support', 'channelId', 'description', 'originallyPublishedAt' ]) { - if (attributes[key] !== undefined) { - req.field(key, attributes[key]) - } - } - - for (const key of [ 'nsfw', 'commentsEnabled', 'downloadEnabled', 'waitTranscoding' ]) { - if (attributes[key] !== undefined) { - req.field(key, JSON.stringify(attributes[key])) - } - } - - for (const key of [ 'language', 'privacy', 'category', 'licence' ]) { - if (attributes[key] !== undefined) { - req.field(key, attributes[key].toString()) - } - } - - const tags = attributes.tags || [] - for (let i = 0; i < tags.length; i++) { - req.field('tags[' + i + ']', attributes.tags[i]) - } - - for (const key of [ 'thumbnailfile', 'previewfile' ]) { - if (attributes[key] !== undefined) { - req.attach(key, buildAbsoluteFixturePath(attributes[key])) - } - } - - if (attributes.scheduleUpdate) { - if (attributes.scheduleUpdate.updateAt) { - req.field('scheduleUpdate[updateAt]', attributes.scheduleUpdate.updateAt) - } - - if (attributes.scheduleUpdate.privacy) { - req.field('scheduleUpdate[privacy]', attributes.scheduleUpdate.privacy) - } - } + uploadRandomVideoOnServers, + checkVideoFilesWereRemoved } diff --git a/shared/models/search/videos-common-query.model.ts b/shared/models/search/videos-common-query.model.ts index bd02489ea..179266338 100644 --- a/shared/models/search/videos-common-query.model.ts +++ b/shared/models/search/videos-common-query.model.ts @@ -21,6 +21,8 @@ export interface VideosCommonQuery { tagsAllOf?: string[] filter?: VideoFilter + + skipCount?: boolean } export interface VideosWithSearchCommonQuery extends VideosCommonQuery { diff --git a/shared/models/videos/video-update.model.ts b/shared/models/videos/video-update.model.ts index e21ccae04..86653b959 100644 --- a/shared/models/videos/video-update.model.ts +++ b/shared/models/videos/video-update.model.ts @@ -1,5 +1,6 @@ import { VideoPrivacy } from './video-privacy.enum' import { VideoScheduleUpdate } from './video-schedule-update.model' + export interface VideoUpdate { name?: string category?: number -- 2.41.0