From 23a3a8827cb8b862f5cc7ee2819f39918303beca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 14:30:20 +0200 Subject: Introduce overviews command --- server/tests/api/videos/video-nsfw.ts | 35 ++++++++------- server/tests/api/videos/videos-overview.ts | 71 ++++++++++++------------------ 2 files changed, 48 insertions(+), 58 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index b16b484b9..6c98c9f12 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -1,34 +1,33 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index' -import { userLogin } from '../../../../shared/extra-utils/users/login' -import { createUser } from '../../../../shared/extra-utils/users/users' -import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' +import * as chai from 'chai' import { + cleanupTests, + createUser, flushAndRunServer, getAccountVideos, getConfig, getCustomConfig, getMyUserInformation, + getMyVideos, getVideoChannelVideos, + getVideosList, getVideosListWithToken, searchVideo, searchVideoWithToken, + ServerInfo, + setAccessTokensToServers, updateCustomConfig, - updateMyUser -} from '../../../../shared/extra-utils' -import { ServerConfig, VideosOverview } from '../../../../shared/models' -import { CustomConfig } from '../../../../shared/models/server/custom-config.model' -import { User } from '../../../../shared/models/users' -import { getVideosOverview, getVideosOverviewWithToken } from '@shared/extra-utils/overviews/overviews' + updateMyUser, + uploadVideo, + userLogin +} from '@shared/extra-utils' +import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' const expect = chai.expect -function createOverviewRes (res: any) { - const overview = res.body as VideosOverview - +function createOverviewRes (overview: VideosOverview) { const videos = overview.categories[0].videos return { body: { data: videos, total: videos.length } } } @@ -57,7 +56,9 @@ describe('Test video NSFW policy', function () { // Overviews do not support video filters if (!hasQuery) { - promises.push(getVideosOverviewWithToken(server.url, 1, token).then(res => createOverviewRes(res))) + const p = server.overviewsCommand.getVideos({ page: 1, token }) + .then(res => createOverviewRes(res)) + promises.push(p) } return Promise.all(promises) @@ -72,7 +73,9 @@ describe('Test video NSFW policy', function () { // Overviews do not support video filters if (!hasQuery) { - promises.push(getVideosOverview(server.url, 1).then(res => createOverviewRes(res))) + const p = server.overviewsCommand.getVideos({ page: 1 }) + .then(res => createOverviewRes(res)) + promises.push(p) } return Promise.all(promises) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index c266a1dc5..c8e3df4bd 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,8 +2,9 @@ import 'mocha' import * as chai from 'chai' - +import { Response } from 'superagent' import { + addAccountToAccountBlocklist, cleanupTests, flushAndRunServer, generateUserAccessToken, @@ -11,20 +12,15 @@ import { setAccessTokensToServers, uploadVideo, wait -} from '../../../../shared/extra-utils' -import { getVideosOverview, getVideosOverviewWithToken } from '../../../../shared/extra-utils/overviews/overviews' -import { VideosOverview } from '../../../../shared/models/overviews' -import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist' -import { Response } from 'superagent' +} from '@shared/extra-utils' +import { VideosOverview } from '@shared/models' const expect = chai.expect describe('Test a videos overview', function () { let server: ServerInfo = null - function testOverviewCount (res: Response, expected: number) { - const overview: VideosOverview = res.body - + function testOverviewCount (overview: VideosOverview, expected: number) { expect(overview.tags).to.have.lengthOf(expected) expect(overview.categories).to.have.lengthOf(expected) expect(overview.channels).to.have.lengthOf(expected) @@ -39,9 +35,9 @@ describe('Test a videos overview', function () { }) it('Should send empty overview', async function () { - const res = await getVideosOverview(server.url, 1) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - testOverviewCount(res, 0) + testOverviewCount(body, 0) }) it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { @@ -55,34 +51,35 @@ describe('Test a videos overview', function () { tags: [ 'coucou1', 'coucou2' ] }) - const res = await getVideosOverview(server.url, 1) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - testOverviewCount(res, 0) + testOverviewCount(body, 0) }) it('Should upload another video and include all videos in the overview', async function () { this.timeout(30000) - for (let i = 1; i < 6; i++) { - await uploadVideo(server.url, server.accessToken, { - name: 'video ' + i, - category: 3, - tags: [ 'coucou1', 'coucou2' ] - }) + { + for (let i = 1; i < 6; i++) { + await uploadVideo(server.url, server.accessToken, { + name: 'video ' + i, + category: 3, + tags: [ 'coucou1', 'coucou2' ] + }) + } + + await wait(3000) } - await wait(3000) - { - const res = await getVideosOverview(server.url, 1) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - testOverviewCount(res, 1) + testOverviewCount(body, 1) } { - const res = await getVideosOverview(server.url, 2) + const overview = await server.overviewsCommand.getVideos({ page: 2 }) - const overview: VideosOverview = res.body expect(overview.tags).to.have.lengthOf(1) expect(overview.categories).to.have.lengthOf(0) expect(overview.channels).to.have.lengthOf(0) @@ -90,20 +87,10 @@ describe('Test a videos overview', function () { }) it('Should have the correct overview', async function () { - const res1 = await getVideosOverview(server.url, 1) - const res2 = await getVideosOverview(server.url, 2) - - const overview1: VideosOverview = res1.body - const overview2: VideosOverview = res2.body - - const tmp = [ - overview1.tags, - overview1.categories, - overview1.channels, - overview2.tags - ] + const overview1 = await server.overviewsCommand.getVideos({ page: 1 }) + const overview2 = await server.overviewsCommand.getVideos({ page: 2 }) - for (const arr of tmp) { + for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) { expect(arr).to.have.lengthOf(1) const obj = arr[0] @@ -132,15 +119,15 @@ describe('Test a videos overview', function () { await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) { - const res = await getVideosOverview(server.url, 1) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - testOverviewCount(res, 1) + testOverviewCount(body, 1) } { - const res = await getVideosOverviewWithToken(server.url, 1, token) + const body = await server.overviewsCommand.getVideos({ page: 1, token }) - testOverviewCount(res, 0) + testOverviewCount(body, 0) } }) -- cgit v1.2.3 From af971e06c620bd46a5aa64c8833364e7022b5e3d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:22:51 +0200 Subject: Introduce search command --- server/tests/api/videos/video-nsfw.ts | 14 ++++++-------- server/tests/api/videos/videos-history.ts | 15 +++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 6c98c9f12..24a4c6152 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -14,8 +14,6 @@ import { getVideoChannelVideos, getVideosList, getVideosListWithToken, - searchVideo, - searchVideoWithToken, ServerInfo, setAccessTokensToServers, updateCustomConfig, @@ -23,7 +21,7 @@ import { uploadVideo, userLogin } from '@shared/extra-utils' -import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' const expect = chai.expect @@ -37,7 +35,7 @@ describe('Test video NSFW policy', function () { let userAccessToken: string let customConfig: CustomConfig - function getVideosFunctions (token?: string, query = {}) { + function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { return getMyUserInformation(server.url, server.accessToken) .then(res => { const user: User = res.body @@ -49,7 +47,7 @@ describe('Test video NSFW policy', function () { if (token) { promises = [ getVideosListWithToken(server.url, token, query), - searchVideoWithToken(server.url, 'n', token, query), + server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) ] @@ -66,7 +64,7 @@ describe('Test video NSFW policy', function () { promises = [ getVideosList(server.url), - searchVideo(server.url, 'n'), + server.searchCommand.searchVideos({ search: 'n' }), getAccountVideos(server.url, undefined, accountName, 0, 5), getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) ] @@ -230,7 +228,7 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) { + for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { expect(res.body.total).to.equal(1) const videos = res.body.data @@ -240,7 +238,7 @@ describe('Test video NSFW policy', function () { }) it('Should hide NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) { + for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { expect(res.body.total).to.equal(1) const videos = res.body.data diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index b25cff879..209b93014 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, createUser, @@ -10,17 +11,15 @@ import { getVideoWithToken, killallServers, reRunServer, - searchVideoWithToken, ServerInfo, setAccessTokensToServers, updateMyUser, uploadVideo, userLogin, wait -} from '../../../../shared/extra-utils' -import { Video, VideoDetails } from '../../../../shared/models/videos' -import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history' +import { Video, VideoDetails } from '@shared/models' const expect = chai.expect @@ -89,8 +88,8 @@ describe('Test videos history', function () { } { - const res = await searchVideoWithToken(server.url, 'video', server.accessToken) - videosOfVideos.push(res.body.data) + const body = await server.searchCommand.searchVideos({ token: server.accessToken, search: 'video' }) + videosOfVideos.push(body.data) } for (const videos of videosOfVideos) { -- cgit v1.2.3 From 2d1ad5b96063d1e430ca99128a15e2e56cb614e0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:33:39 +0200 Subject: Move AP request in requests file --- server/tests/api/videos/videos-overview.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index c8e3df4bd..b3ab9e070 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { Response } from 'superagent' import { addAccountToAccountBlocklist, cleanupTests, -- cgit v1.2.3 From 883a9019085ff9013079d6b1539b86f2f519175a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 16:02:11 +0200 Subject: Introduce debug command --- server/tests/api/videos/resumable-upload.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 4fc3317df..6c01c7e78 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -12,7 +12,6 @@ import { flushAndRunServer, getMyUserInformation, prepareResumableUpload, - sendDebugCommand, sendResumableChunks, ServerInfo, setAccessTokensToServers, @@ -138,13 +137,13 @@ describe('Test resumable upload', function () { }) it('Should not delete recent uploads', async function () { - await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) + await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) expect(await countResumableUploads()).to.equal(2) }) it('Should delete old uploads', async function () { - await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) + await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) expect(await countResumableUploads()).to.equal(0) }) -- cgit v1.2.3 From c3d29f694bf8c910f917be655626d0f80871124f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:16:40 +0200 Subject: Introduce follows command --- server/tests/api/videos/video-description.ts | 2 +- server/tests/api/videos/video-playlists.ts | 41 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 21 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index b8e98e45f..e1c9afe79 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { cleanupTests, flushAndRunMultipleServers, diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index da8de054b..28f68dcfe 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -2,8 +2,12 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { + addAccountToAccountBlocklist, + addAccountToServerBlocklist, + addServerToAccountBlocklist, + addServerToServerBlocklist, addVideoChannel, addVideoInPlaylist, addVideoToBlacklist, @@ -27,6 +31,10 @@ import { getVideoPlaylistPrivacies, getVideoPlaylistsList, getVideoPlaylistWithToken, + removeAccountFromAccountBlocklist, + removeAccountFromServerBlocklist, + removeServerFromAccountBlocklist, + removeServerFromServerBlocklist, removeUser, removeVideoFromBlacklist, removeVideoFromPlaylist, @@ -35,7 +43,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, testImage, - unfollow, updateVideo, updateVideoPlaylist, updateVideoPlaylistElement, @@ -44,24 +51,18 @@ import { userLogin, wait, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist -} from '../../../../shared/extra-utils/users/blocklist' -import { User } from '../../../../shared/models/users' -import { VideoPlaylistCreateResult, VideoPrivacy } from '../../../../shared/models/videos' -import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' -import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../../shared/models/videos/playlist/video-playlist-element.model' -import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' -import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' -import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model' + User, + VideoExistInPlaylist, + VideoPlaylist, + VideoPlaylistCreateResult, + VideoPlaylistElement, + VideoPlaylistElementType, + VideoPlaylistPrivacy, + VideoPlaylistType, + VideoPrivacy +} from '@shared/models' const expect = chai.expect @@ -1171,7 +1172,7 @@ describe('Test video playlists', function () { expect(finder(res.body.data)).to.not.be.undefined } - await unfollow(servers[2].url, servers[2].accessToken, servers[0]) + await servers[2].followsCommand.unfollow({ target: servers[0] }) { const res = await getVideoPlaylistsList(servers[2].url, 0, 5) -- cgit v1.2.3 From 9c6327f803aaf4200672f1fc40b2f43786daca47 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:34:56 +0200 Subject: Introduce jobs command --- server/tests/api/videos/video-transcoder.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index ea5ffd239..c95053a29 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -16,7 +16,6 @@ import { flushAndRunMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, - getJobsListPaginationAndSort, getMyVideos, getServerFileSize, getVideo, @@ -709,17 +708,14 @@ describe('Test video transcoding', function () { describe('Transcoding job queue', function () { it('Should have the appropriate priorities for transcoding jobs', async function () { - const res = await getJobsListPaginationAndSort({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await servers[1].jobsCommand.getJobsList({ start: 0, count: 100, sort: '-createdAt', jobType: 'video-transcoding' }) - const jobs = res.body.data as Job[] - + const jobs = body.data const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) expect(transcodingJobs).to.have.lengthOf(14) -- cgit v1.2.3 From 65e6e2602c0d5521f3a6740f7469bb92830ecb53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:51:09 +0200 Subject: Introduce config command --- server/tests/api/videos/video-change-ownership.ts | 15 ++-- server/tests/api/videos/video-hls.ts | 41 +++++------ server/tests/api/videos/video-imports.ts | 5 +- server/tests/api/videos/video-nsfw.ts | 25 +++---- server/tests/api/videos/video-transcoder.ts | 86 ++++++++++++----------- 5 files changed, 84 insertions(+), 88 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index a3384851b..89dba14b1 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -20,7 +20,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomSubConfig, uploadVideo, userLogin } from '../../../../shared/extra-utils' @@ -58,12 +57,14 @@ describe('Test video change ownership - nominal', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: false - }, - live: { - enabled: true + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: false + }, + live: { + enabled: true + } } }) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 03ac3f321..3821cfed0 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,6 +3,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, @@ -17,7 +18,6 @@ import { removeVideo, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, updateVideo, uploadVideo, waitJobs, @@ -26,7 +26,6 @@ import { import { VideoDetails } from '../../../../shared/models/videos' import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -192,24 +191,26 @@ describe('Test HLS videos', function () { describe('With only HLS enabled', function () { before(async function () { - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: true, - allowAudioFiles: true, - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - }, - hls: { - enabled: true - }, - webtorrent: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: true, + allowAudioFiles: true, + resolutions: { + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '1440p': true, + '2160p': true + }, + hls: { + enabled: true + }, + webtorrent: { + enabled: false + } } } }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 80834ca86..a4a9132b4 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -14,8 +14,7 @@ import { listVideoCaptions, ServerInfo, setAccessTokensToServers, - testCaptionFile, - updateCustomSubConfig + testCaptionFile } from '../../../../shared/extra-utils' import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' @@ -333,7 +332,7 @@ Ajouter un sous-titre est vraiment facile`) } } } - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) const attributes = { name: 'hdr video', diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 24a4c6152..65813517d 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -7,8 +7,6 @@ import { createUser, flushAndRunServer, getAccountVideos, - getConfig, - getCustomConfig, getMyUserInformation, getMyVideos, getVideoChannelVideos, @@ -16,12 +14,11 @@ import { getVideosListWithToken, ServerInfo, setAccessTokensToServers, - updateCustomConfig, updateMyUser, uploadVideo, userLogin } from '@shared/extra-utils' -import { BooleanBothQuery, CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, User, VideosOverview } from '@shared/models' const expect = chai.expect @@ -97,16 +94,12 @@ describe('Test video NSFW policy', function () { await uploadVideo(server.url, server.accessToken, attributes) } - { - const res = await getCustomConfig(server.url, server.accessToken) - customConfig = res.body - } + customConfig = await server.configCommand.getCustomConfig() }) describe('Instance default NSFW policy', function () { it('Should display NSFW videos with display default NSFW policy', async function () { - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') for (const res of await getVideosFunctions()) { @@ -121,10 +114,9 @@ describe('Test video NSFW policy', function () { it('Should not display NSFW videos with do_not_list default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') for (const res of await getVideosFunctions()) { @@ -138,10 +130,9 @@ describe('Test video NSFW policy', function () { it('Should display NSFW videos with blur default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'blur' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') for (const res of await getVideosFunctions()) { @@ -172,7 +163,7 @@ describe('Test video NSFW policy', function () { it('Should display NSFW videos with blur user NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) for (const res of await getVideosFunctions(userAccessToken)) { expect(res.body.total).to.equal(2) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index c95053a29..e74fb5bef 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { FfprobeData } from 'fluent-ffmpeg' import { omit } from 'lodash' import { join } from 'path' -import { Job } from '@shared/models' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { @@ -24,7 +23,6 @@ import { makeGetRequest, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, uploadVideo, uploadVideoAndGetId, waitJobs, @@ -43,22 +41,24 @@ import { const expect = chai.expect function updateConfigForTranscoding (server: ServerInfo) { - return updateCustomSubConfig(server.url, server.accessToken, { - transcoding: { - enabled: true, - allowAdditionalExtensions: true, - allowAudioFiles: true, - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': false, - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true + return server.configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: true, + allowAdditionalExtensions: true, + allowAudioFiles: true, + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': false, + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '1440p': true, + '2160p': true + } } } }) @@ -363,19 +363,21 @@ describe('Test video transcoding', function () { function runSuite (mode: 'legacy' | 'resumable') { before(async function () { - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { - transcoding: { - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': false, - '240p': false, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false + await servers[1].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': false, + '240p': false, + '360p': false, + '480p': false, + '720p': false, + '1080p': false, + '1440p': false, + '2160p': false + } } } }) @@ -434,14 +436,16 @@ describe('Test video transcoding', function () { it('Should upload an audio file and create an audio version only', async function () { this.timeout(60_000) - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { - transcoding: { - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': true, - '240p': false, - '360p': false + await servers[1].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': true, + '240p': false, + '360p': false + } } } }) @@ -601,7 +605,7 @@ describe('Test video transcoding', function () { it('Should not transcode to an higher bitrate than the original file', async function () { this.timeout(160_000) - const config = { + const newConfig = { transcoding: { enabled: true, resolutions: { @@ -617,7 +621,7 @@ describe('Test video transcoding', function () { hls: { enabled: true } } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig }) const videoAttributes = { name: 'low bitrate', -- cgit v1.2.3 From 5f8bd4cbb178290da7d8f81e996f19f0eccc8e4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:02:46 +0200 Subject: Introduce blocklist command --- server/tests/api/videos/video-playlists.ts | 26 ++++++++++---------------- server/tests/api/videos/videos-overview.ts | 3 +-- 2 files changed, 11 insertions(+), 18 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 28f68dcfe..90189721a 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -4,10 +4,6 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, addVideoChannel, addVideoInPlaylist, addVideoToBlacklist, @@ -31,10 +27,6 @@ import { getVideoPlaylistPrivacies, getVideoPlaylistsList, getVideoPlaylistWithToken, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist, removeUser, removeVideoFromBlacklist, removeVideoFromPlaylist, @@ -760,56 +752,58 @@ describe('Test video playlists', function () { it('Should update the element type if the account or server of the video is blocked', async function () { this.timeout(90000) + const command = servers[0].blocklistCommand + const name = 'video 90' const position = 2 { - await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) + await command.addToMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) } { - await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) + await command.addToMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) } { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) + await command.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) } { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index b3ab9e070..ccbc6f4a4 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addAccountToAccountBlocklist, cleanupTests, flushAndRunServer, generateUserAccessToken, @@ -115,7 +114,7 @@ describe('Test a videos overview', function () { it('Should hide muted accounts', async function () { const token = await generateUserAccessToken(server, 'choco') - await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) + await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) { const body = await server.overviewsCommand.getVideos({ page: 1 }) -- cgit v1.2.3 From 4f2199144e428c16460750305f737b890c1ac322 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:18:40 +0200 Subject: Introduce live command --- server/tests/api/videos/video-change-ownership.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 89dba14b1..88e4d51a2 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -7,7 +7,6 @@ import { acceptChangeOwnership, changeVideoOwnership, cleanupTests, - createLive, createUser, doubleFollow, flushAndRunMultipleServers, @@ -112,9 +111,9 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const res = await createLive(servers[0].url, firstUserAccessToken, attributes) + const video = await servers[0].liveCommand.createLive({ token: firstUserAccessToken, fields: attributes }) - liveId = res.body.video.id + liveId = video.id } await doubleFollow(servers[0], servers[1]) -- cgit v1.2.3 From 04aed76711909507e74905bde3a7fa024d3585c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:25:50 +0200 Subject: Shorter live methods --- server/tests/api/videos/video-change-ownership.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 88e4d51a2..3c33cf015 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -111,7 +111,7 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.createLive({ token: firstUserAccessToken, fields: attributes }) + const video = await servers[0].liveCommand.create({ token: firstUserAccessToken, fields: attributes }) liveId = video.id } -- cgit v1.2.3 From e3d15a6a9aed97a004d9dac1b7a6499d794e080a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 11:17:55 +0200 Subject: Introduce blacklist command --- server/tests/api/videos/video-playlists.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 90189721a..069450453 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -6,7 +6,6 @@ import { HttpStatusCode } from '@shared/core-utils' import { addVideoChannel, addVideoInPlaylist, - addVideoToBlacklist, checkPlaylistFilesWereRemoved, cleanupTests, createUser, @@ -28,7 +27,6 @@ import { getVideoPlaylistsList, getVideoPlaylistWithToken, removeUser, - removeVideoFromBlacklist, removeVideoFromPlaylist, reorderVideosPlaylist, ServerInfo, @@ -728,7 +726,7 @@ describe('Test video playlists', function () { const position = 1 { - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video1, 'reason', true) + await servers[0].blacklistCommand.add({ videoId: video1, reason: 'reason', unfederate: true }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -738,7 +736,7 @@ describe('Test video playlists', function () { } { - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video1) + await servers[0].blacklistCommand.remove({ videoId: video1 }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) -- cgit v1.2.3 From a2470c9f4bfc7f49f4b94de935bacdd53fd54f29 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 11:49:38 +0200 Subject: Introduce captions command --- server/tests/api/videos/video-captions.ts | 77 +++++++++++++------------------ server/tests/api/videos/video-imports.ts | 33 +++++++------ 2 files changed, 48 insertions(+), 62 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 14ecedfa6..83ee809b8 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -1,25 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, flushAndRunMultipleServers, removeVideo, + ServerInfo, + setAccessTokensToServers, + testCaptionFile, uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - createVideoCaption, - deleteVideoCaption, - listVideoCaptions, - testCaptionFile -} from '../../../../shared/extra-utils/videos/video-captions' -import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' + wait, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect @@ -47,26 +42,22 @@ describe('Test video captions', function () { it('Should list the captions and return an empty list', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } }) it('Should create two new captions', async function () { this.timeout(30000) - await createVideoCaption({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].captionsCommand.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good1.vtt' }) - await createVideoCaption({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].captionsCommand.createVideoCaption({ language: 'zh', videoId: videoUUID, fixture: 'subtitle-good2.vtt', @@ -78,17 +69,17 @@ describe('Test video captions', function () { it('Should list these uploaded captions', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const caption1: VideoCaption = res.body.data[0] + const caption1 = body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') - const caption2: VideoCaption = res.body.data[1] + const caption2 = body.data[1] expect(caption2.language.id).to.equal('zh') expect(caption2.language.label).to.equal('Chinese') expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) @@ -99,9 +90,7 @@ describe('Test video captions', function () { it('Should replace an existing caption', async function () { this.timeout(30000) - await createVideoCaption({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].captionsCommand.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good2.vtt' @@ -112,11 +101,11 @@ describe('Test video captions', function () { it('Should have this caption updated', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const caption1: VideoCaption = res.body.data[0] + const caption1 = body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) @@ -127,9 +116,7 @@ describe('Test video captions', function () { it('Should replace an existing caption with a srt file and convert it', async function () { this.timeout(30000) - await createVideoCaption({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].captionsCommand.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good.srt' @@ -143,11 +130,11 @@ describe('Test video captions', function () { it('Should have this caption updated and converted', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const caption1: VideoCaption = res.body.data[0] + const caption1 = body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) @@ -172,18 +159,18 @@ describe('Test video captions', function () { it('Should remove one caption', async function () { this.timeout(30000) - await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar') + await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) await waitJobs(servers) }) it('Should only list the caption that was not deleted', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const caption: VideoCaption = res.body.data[0] + const caption = body.data[0] expect(caption.language.id).to.equal('zh') expect(caption.language.label).to.equal('Chinese') diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index a4a9132b4..14aed604f 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -11,7 +11,6 @@ import { getVideo, getVideosList, immutableAssign, - listVideoCaptions, ServerInfo, setAccessTokensToServers, testCaptionFile @@ -25,7 +24,7 @@ import { getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' +import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' const expect = chai.expect @@ -36,8 +35,8 @@ describe('Test video imports', function () { if (areHttpImportTestsDisabled()) return - async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { - const resHttp = await getVideo(url, idHttp) + async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { + const resHttp = await getVideo(server.url, idHttp) const videoHttp: VideoDetails = resHttp.body expect(videoHttp.name).to.equal('small video - youtube') @@ -55,9 +54,9 @@ describe('Test video imports', function () { expect(originallyPublishedAt.getMonth()).to.equal(0) expect(originallyPublishedAt.getFullYear()).to.equal(2019) - const resMagnet = await getVideo(url, idMagnet) + const resMagnet = await getVideo(server.url, idMagnet) const videoMagnet: VideoDetails = resMagnet.body - const resTorrent = await getVideo(url, idTorrent) + const resTorrent = await getVideo(server.url, idTorrent) const videoTorrent: VideoDetails = resTorrent.body for (const video of [ videoMagnet, videoTorrent ]) { @@ -73,12 +72,12 @@ describe('Test video imports', function () { expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') expect(videoMagnet.name).to.contain('super peertube2 video') - const resCaptions = await listVideoCaptions(url, idHttp) - expect(resCaptions.body.total).to.equal(2) + const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: idHttp }) + expect(bodyCaptions.total).to.equal(2) } - async function checkVideoServer2 (url: string, id: number | string) { - const res = await getVideo(url, id) + async function checkVideoServer2 (server: ServerInfo, id: number | string) { + const res = await getVideo(server.url, id) const video: VideoDetails = res.body expect(video.name).to.equal('my super name') @@ -91,8 +90,8 @@ describe('Test video imports', function () { expect(video.files).to.have.lengthOf(1) - const resCaptions = await listVideoCaptions(url, id) - expect(resCaptions.body.total).to.equal(2) + const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: id }) + expect(bodyCaptions.total).to.equal(2) } before(async function () { @@ -135,8 +134,8 @@ describe('Test video imports', function () { await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) - const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) - const videoCaptions: VideoCaption[] = resCaptions.body.data + const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id }) + const videoCaptions = bodyCaptions.data expect(videoCaptions).to.have.lengthOf(2) const enCaption = videoCaptions.find(caption => caption.language.id === 'en') @@ -241,7 +240,7 @@ Ajouter un sous-titre est vraiment facile`) expect(res.body.data).to.have.lengthOf(3) const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data - await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) + await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) } }) @@ -273,10 +272,10 @@ Ajouter un sous-titre est vraiment facile`) expect(res.body.total).to.equal(4) expect(res.body.data).to.have.lengthOf(4) - await checkVideoServer2(server.url, res.body.data[0].uuid) + await checkVideoServer2(server, res.body.data[0].uuid) const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data - await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) + await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) } }) -- cgit v1.2.3 From 72cbfc5695ec5ebdb9721d3648218f63feeaeac5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 13:56:04 +0200 Subject: Introduce change ownership command --- server/tests/api/videos/video-change-ownership.ts | 185 ++++++++++++---------- 1 file changed, 100 insertions(+), 85 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 3c33cf015..1b81fe047 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -4,8 +4,7 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - acceptChangeOwnership, - changeVideoOwnership, + ChangeOwnershipCommand, cleanupTests, createUser, doubleFollow, @@ -13,9 +12,7 @@ import { flushAndRunServer, getMyUserInformation, getVideo, - getVideoChangeOwnershipList, getVideosList, - refuseChangeOwnership, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -39,16 +36,18 @@ describe('Test video change ownership - nominal', function () { password: 'My other password' } - let firstUserAccessToken = '' + let firstUserToken = '' let firstUserChannelId: number - let secondUserAccessToken = '' + let secondUserToken = '' let secondUserChannelId: number - let lastRequestChangeOwnershipId = '' + let lastRequestId: number let liveId: number + let command: ChangeOwnershipCommand + before(async function () { this.timeout(50000) @@ -83,17 +82,17 @@ describe('Test video change ownership - nominal', function () { videoQuota: videoQuota }) - firstUserAccessToken = await userLogin(servers[0], firstUser) - secondUserAccessToken = await userLogin(servers[0], secondUser) + firstUserToken = await userLogin(servers[0], firstUser) + secondUserToken = await userLogin(servers[0], secondUser) { - const res = await getMyUserInformation(servers[0].url, firstUserAccessToken) + const res = await getMyUserInformation(servers[0].url, firstUserToken) const firstUserInformation: User = res.body firstUserChannelId = firstUserInformation.videoChannels[0].id } { - const res = await getMyUserInformation(servers[0].url, secondUserAccessToken) + const res = await getMyUserInformation(servers[0].url, secondUserToken) const secondUserInformation: User = res.body secondUserChannelId = secondUserInformation.videoChannels[0].id } @@ -103,7 +102,7 @@ describe('Test video change ownership - nominal', function () { name: 'my super name', description: 'my super description' } - const res = await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes) + const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes) const resVideo = await getVideo(servers[0].url, res.body.video.id) servers[0].video = resVideo.body @@ -111,116 +110,129 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.create({ token: firstUserAccessToken, fields: attributes }) + const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes }) liveId = video.id } + command = servers[0].changeOwnershipCommand + await doubleFollow(servers[0], servers[1]) }) it('Should not have video change ownership', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(0) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } }) it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should only return a request to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { this.timeout(10000) - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) }) it('Should not be possible to refuse the change of ownership from first user', async function () { this.timeout(10000) - await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403) + await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should be possible to refuse the change of ownership from second user', async function () { this.timeout(10000) - await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId) + await command.refuse({ token: secondUserToken, ownershipId: lastRequestId }) }) it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should return two requests to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(2) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(2) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should not be possible to accept the change of ownership from first user', async function () { this.timeout(10000) - await acceptChangeOwnership( - servers[0].url, - firstUserAccessToken, - lastRequestChangeOwnershipId, - secondUserChannelId, - HttpStatusCode.FORBIDDEN_403 - ) + await command.accept({ + token: firstUserToken, + ownershipId: lastRequestId, + channelId: secondUserChannelId, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should be possible to accept the change of ownership from second user', async function () { this.timeout(10000) - await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) + await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) await waitJobs(servers) }) @@ -240,20 +252,20 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a live', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, liveId, secondUser.username) + await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username }) - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(3) - expect(resSecondUser.body.data.length).to.equal(3) + expect(body.total).to.equal(3) + expect(body.data.length).to.equal(3) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id }) it('Should accept a live ownership change', async function () { this.timeout(20000) - await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) + await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) await waitJobs(servers) @@ -283,9 +295,9 @@ describe('Test video change ownership - quota too small', function () { username: 'second', password: 'My other password' } - let firstUserAccessToken = '' - let secondUserAccessToken = '' - let lastRequestChangeOwnershipId = '' + let firstUserToken = '' + let secondUserToken = '' + let lastRequestId: number before(async function () { this.timeout(50000) @@ -311,15 +323,15 @@ describe('Test video change ownership - quota too small', function () { videoQuota: limitedVideoQuota }) - firstUserAccessToken = await userLogin(server, firstUser) - secondUserAccessToken = await userLogin(server, secondUser) + firstUserToken = await userLogin(server, firstUser) + secondUserToken = await userLogin(server, secondUser) // Upload some videos on the server const video1Attributes = { name: 'my super name', description: 'my super description' } - await uploadVideo(server.url, firstUserAccessToken, video1Attributes) + await uploadVideo(server.url, firstUserToken, video1Attributes) await waitJobs(server) @@ -334,39 +346,42 @@ describe('Test video change ownership - quota too small', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) + await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username }) }) it('Should only return a request to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) + { + const body = await server.changeOwnershipCommand.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) + { + const body = await server.changeOwnershipCommand.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) + const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken) const secondUserInformation: User = secondUserInformationResponse.body const channelId = secondUserInformation.videoChannels[0].id - await acceptChangeOwnership( - server.url, - secondUserAccessToken, - lastRequestChangeOwnershipId, + await server.changeOwnershipCommand.accept({ + token: secondUserToken, + ownershipId: lastRequestId, channelId, - HttpStatusCode.PAYLOAD_TOO_LARGE_413 - ) + expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 + }) }) after(async function () { -- cgit v1.2.3 From e6346d59e63135cf012ed18c102d3b0179ef565f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 15:54:39 +0200 Subject: Introduce playlist command --- .../tests/api/videos/video-playlist-thumbnails.ts | 123 ++--- server/tests/api/videos/video-playlists.ts | 564 +++++++++------------ 2 files changed, 287 insertions(+), 400 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index a93a0b7de..af5df8d90 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -1,16 +1,11 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { - addVideoInPlaylist, cleanupTests, - createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, - getVideoPlaylistsList, - removeVideoFromPlaylist, - reorderVideosPlaylist, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -25,8 +20,8 @@ const expect = chai.expect describe('Playlist thumbnail', function () { let servers: ServerInfo[] = [] - let playlistWithoutThumbnail: number - let playlistWithThumbnail: number + let playlistWithoutThumbnailId: number + let playlistWithThumbnailId: number let withThumbnailE1: number let withThumbnailE2: number @@ -37,15 +32,15 @@ describe('Playlist thumbnail', function () { let video2: number async function getPlaylistWithoutThumbnail (server: ServerInfo) { - const res = await getVideoPlaylistsList(server.url, 0, 10) + const body = await server.playlistsCommand.list({ start: 0, count: 10 }) - return res.body.data.find(p => p.displayName === 'playlist without thumbnail') + return body.data.find(p => p.displayName === 'playlist without thumbnail') } async function getPlaylistWithThumbnail (server: ServerInfo) { - const res = await getVideoPlaylistsList(server.url, 0, 10) + const body = await server.playlistsCommand.list({ start: 0, count: 10 }) - return res.body.data.find(p => p.displayName === 'playlist with thumbnail') + return body.data.find(p => p.displayName === 'playlist with thumbnail') } before(async function () { @@ -69,24 +64,20 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when adding an element', async function () { this.timeout(30000) - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + const created = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist without thumbnail', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } }) - playlistWithoutThumbnail = res.body.videoPlaylist.id + playlistWithoutThumbnailId = created.id - const res2 = await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - elementAttrs: { videoId: video1 } + const added = await servers[1].playlistsCommand.addElement({ + playlistId: playlistWithoutThumbnailId, + attributes: { videoId: video1 } }) - withoutThumbnailE1 = res2.body.videoPlaylistElement.id + withoutThumbnailE1 = added.id await waitJobs(servers) @@ -99,25 +90,21 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + const created = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist with thumbnail', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id, thumbnailfile: 'thumbnail.jpg' } }) - playlistWithThumbnail = res.body.videoPlaylist.id + playlistWithThumbnailId = created.id - const res2 = await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - elementAttrs: { videoId: video1 } + const added = await servers[1].playlistsCommand.addElement({ + playlistId: playlistWithThumbnailId, + attributes: { videoId: video1 } }) - withThumbnailE1 = res2.body.videoPlaylistElement.id + withThumbnailE1 = added.id await waitJobs(servers) @@ -130,19 +117,15 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when moving the first element', async function () { this.timeout(30000) - const res = await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - elementAttrs: { videoId: video2 } + const added = await servers[1].playlistsCommand.addElement({ + playlistId: playlistWithoutThumbnailId, + attributes: { videoId: video2 } }) - withoutThumbnailE2 = res.body.videoPlaylistElement.id + withoutThumbnailE2 = added.id - await reorderVideosPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - elementAttrs: { + await servers[1].playlistsCommand.reorderElements({ + playlistId: playlistWithoutThumbnailId, + attributes: { startPosition: 1, insertAfterPosition: 2 } @@ -159,19 +142,15 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - const res = await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - elementAttrs: { videoId: video2 } + const added = await servers[1].playlistsCommand.addElement({ + playlistId: playlistWithThumbnailId, + attributes: { videoId: video2 } }) - withThumbnailE2 = res.body.videoPlaylistElement.id + withThumbnailE2 = added.id - await reorderVideosPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - elementAttrs: { + await servers[1].playlistsCommand.reorderElements({ + playlistId: playlistWithThumbnailId, + attributes: { startPosition: 1, insertAfterPosition: 2 } @@ -188,11 +167,9 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when deleting the first element', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - playlistElementId: withoutThumbnailE1 + await servers[1].playlistsCommand.removeElement({ + playlistId: playlistWithoutThumbnailId, + elementId: withoutThumbnailE1 }) await waitJobs(servers) @@ -206,11 +183,9 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - playlistElementId: withThumbnailE1 + await servers[1].playlistsCommand.removeElement({ + playlistId: playlistWithThumbnailId, + elementId: withThumbnailE1 }) await waitJobs(servers) @@ -224,11 +199,9 @@ describe('Playlist thumbnail', function () { it('Should the thumbnail when we delete the last element', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - playlistElementId: withoutThumbnailE2 + await servers[1].playlistsCommand.removeElement({ + playlistId: playlistWithoutThumbnailId, + elementId: withoutThumbnailE2 }) await waitJobs(servers) @@ -242,11 +215,9 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - playlistElementId: withThumbnailE2 + await servers[1].playlistsCommand.removeElement({ + playlistId: playlistWithThumbnailId, + elementId: withThumbnailE2 }) await waitJobs(servers) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 069450453..4de6b3abf 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -5,37 +5,22 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { addVideoChannel, - addVideoInPlaylist, checkPlaylistFilesWereRemoved, cleanupTests, createUser, - createVideoPlaylist, deleteVideoChannel, - deleteVideoPlaylist, doubleFollow, - doVideosExistInMyPlaylist, flushAndRunMultipleServers, generateUserAccessToken, getAccessToken, - getAccountPlaylistsList, - getAccountPlaylistsListWithToken, getMyUserInformation, - getPlaylistVideos, - getVideoChannelPlaylistsList, - getVideoPlaylist, - getVideoPlaylistPrivacies, - getVideoPlaylistsList, - getVideoPlaylistWithToken, + PlaylistsCommand, removeUser, - removeVideoFromPlaylist, - reorderVideosPlaylist, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, testImage, updateVideo, - updateVideoPlaylist, - updateVideoPlaylistElement, uploadVideo, uploadVideoAndGetId, userLogin, @@ -44,10 +29,8 @@ import { } from '@shared/extra-utils' import { User, - VideoExistInPlaylist, VideoPlaylist, VideoPlaylistCreateResult, - VideoPlaylistElement, VideoPlaylistElementType, VideoPlaylistPrivacy, VideoPlaylistType, @@ -65,10 +48,10 @@ async function checkPlaylistElementType ( total: number ) { for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistId, 0, 10) - expect(res.body.total).to.equal(total) + const body = await server.playlistsCommand.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 }) + expect(body.total).to.equal(total) - const videoElement: VideoPlaylistElement = res.body.data.find((e: VideoPlaylistElement) => e.position === position) + const videoElement = body.data.find(e => e.position === position) expect(videoElement.type).to.equal(type, 'On server ' + server.url) if (type === VideoPlaylistElementType.REGULAR) { @@ -85,7 +68,7 @@ describe('Test video playlists', function () { let playlistServer2Id1: number let playlistServer2Id2: number - let playlistServer2UUID2: number + let playlistServer2UUID2: string let playlistServer1Id: number let playlistServer1UUID: string @@ -97,7 +80,9 @@ describe('Test video playlists', function () { let nsfwVideoServer1: number - let userAccessTokenServer1: string + let userTokenServer1: string + + let commands: PlaylistsCommand[] before(async function () { this.timeout(120000) @@ -113,6 +98,8 @@ describe('Test video playlists', function () { // Server 1 and server 3 follow each other await doubleFollow(servers[0], servers[2]) + commands = servers.map(s => s.playlistsCommand) + { servers[0].videos = [] servers[1].videos = [] @@ -137,62 +124,60 @@ describe('Test video playlists', function () { username: 'user1', password: 'password' }) - userAccessTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password') + userTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password') } await waitJobs(servers) }) describe('Get default playlists', function () { + it('Should list video playlist privacies', async function () { - const res = await getVideoPlaylistPrivacies(servers[0].url) + const privacies = await commands[0].getPrivacies() - const privacies = res.body expect(Object.keys(privacies)).to.have.length.at.least(3) - expect(privacies[3]).to.equal('Private') }) it('Should list watch later playlist', async function () { - const url = servers[0].url - const accessToken = servers[0].accessToken + const token = servers[0].accessToken { - const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER) + const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.WATCH_LATER }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlist: VideoPlaylist = res.body.data[0] + const playlist = body.data[0] expect(playlist.displayName).to.equal('Watch later') expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER) expect(playlist.type.label).to.equal('Watch later') } { - const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR) + const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.REGULAR }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } { - const res = await getAccountPlaylistsList(url, 'root', 0, 5) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await commands[0].listByAccount({ handle: 'root' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } }) it('Should get private playlist for a classic user', async function () { const token = await generateUserAccessToken(servers[0], 'toto') - const res = await getAccountPlaylistsListWithToken(servers[0].url, token, 'toto', 0, 5) + const body = await commands[0].listByAccount({ token, handle: 'toto' }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlistId = res.body.data[0].id - await getPlaylistVideos(servers[0].url, token, playlistId, 0, 5) + const playlistId = body.data[0].id + await commands[0].listVideos({ token, playlistId }) }) }) @@ -201,10 +186,8 @@ describe('Test video playlists', function () { it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () { this.timeout(30000) - await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + await commands[0].create({ + attributes: { displayName: 'my super playlist', privacy: VideoPlaylistPrivacy.PUBLIC, description: 'my super description', @@ -218,14 +201,13 @@ describe('Test video playlists', function () { await wait(3000) for (const server of servers) { - const res = await getVideoPlaylistsList(server.url, 0, 5) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await server.playlistsCommand.list({ start: 0, count: 5 }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlistFromList = res.body.data[0] as VideoPlaylist + const playlistFromList = body.data[0] - const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid) - const playlistFromGet = res2.body as VideoPlaylist + const playlistFromGet = await server.playlistsCommand.get({ playlistId: playlistFromList.uuid }) for (const playlist of [ playlistFromGet, playlistFromList ]) { expect(playlist.id).to.be.a('number') @@ -255,23 +237,19 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + const playlist = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist 2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } }) - playlistServer2Id1 = res.body.videoPlaylist.id + playlistServer2Id1 = playlist.id } { - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + const playlist = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist 3', privacy: VideoPlaylistPrivacy.PUBLIC, thumbnailfile: 'thumbnail.jpg', @@ -279,22 +257,18 @@ describe('Test video playlists', function () { } }) - playlistServer2Id2 = res.body.videoPlaylist.id - playlistServer2UUID2 = res.body.videoPlaylist.uuid + playlistServer2Id2 = playlist.id + playlistServer2UUID2 = playlist.uuid } for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) { - await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, + await servers[1].playlistsCommand.addElement({ playlistId: id, - elementAttrs: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 } + attributes: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 } }) - await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, + await servers[1].playlistsCommand.addElement({ playlistId: id, - elementAttrs: { videoId: servers[1].videos[1].id } + attributes: { videoId: servers[1].videos[1].id } }) } @@ -302,20 +276,20 @@ describe('Test video playlists', function () { await wait(3000) for (const server of [ servers[0], servers[1] ]) { - const res = await getVideoPlaylistsList(server.url, 0, 5) + const body = await server.playlistsCommand.list({ start: 0, count: 5 }) - const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2') + const playlist2 = body.data.find(p => p.displayName === 'playlist 2') expect(playlist2).to.not.be.undefined await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath) - const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3') + const playlist3 = body.data.find(p => p.displayName === 'playlist 3') expect(playlist3).to.not.be.undefined await testImage(server.url, 'thumbnail', playlist3.thumbnailPath) } - const res = await getVideoPlaylistsList(servers[2].url, 0, 5) - expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined - expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined + const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + expect(body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined + expect(body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined }) it('Should have the playlist on server 3 after a new follow', async function () { @@ -324,13 +298,13 @@ describe('Test video playlists', function () { // Server 2 and server 3 follow each other await doubleFollow(servers[1], servers[2]) - const res = await getVideoPlaylistsList(servers[2].url, 0, 5) + const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) - const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2') + const playlist2 = body.data.find(p => p.displayName === 'playlist 2') expect(playlist2).to.not.be.undefined await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath) - expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined + expect(body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined }) }) @@ -340,22 +314,20 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await getVideoPlaylistsList(servers[2].url, 1, 2, 'createdAt') + const body = await servers[2].playlistsCommand.list({ start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(3) - expect(res.body.total).to.equal(3) - - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(2) expect(data[0].displayName).to.equal('playlist 2') expect(data[1].displayName).to.equal('playlist 3') } { - const res = await getVideoPlaylistsList(servers[2].url, 1, 2, '-createdAt') - - expect(res.body.total).to.equal(3) + const body = await servers[2].playlistsCommand.list({ start: 1, count: 2, sort: '-createdAt' }) + expect(body.total).to.equal(3) - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(2) expect(data[0].displayName).to.equal('playlist 2') expect(data[1].displayName).to.equal('my super playlist') @@ -366,11 +338,10 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await getVideoChannelPlaylistsList(servers[0].url, 'root_channel', 0, 2, '-createdAt') + const body = await commands[0].listByChannel({ handle: 'root_channel', start: 0, count: 2, sort: '-createdAt' }) + expect(body.total).to.equal(1) - expect(res.body.total).to.equal(1) - - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].displayName).to.equal('my super playlist') } @@ -380,41 +351,37 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, '-createdAt') - - expect(res.body.total).to.equal(2) + const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' }) + expect(body.total).to.equal(2) - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].displayName).to.equal('playlist 2') } { - const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, 'createdAt') + const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].displayName).to.equal('playlist 3') } { - const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '3') - - expect(res.body.total).to.equal(1) + const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' }) + expect(body.total).to.equal(1) - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].displayName).to.equal('playlist 3') } { - const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '4') - - expect(res.body.total).to.equal(0) + const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' }) + expect(body.total).to.equal(0) - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(0) } }) @@ -428,28 +395,22 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + unlistedPlaylist = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist unlisted', privacy: VideoPlaylistPrivacy.UNLISTED, videoChannelId: servers[1].videoChannel.id } }) - unlistedPlaylist = res.body.videoPlaylist } { - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + privatePlaylist = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist private', privacy: VideoPlaylistPrivacy.PRIVATE } }) - privatePlaylist = res.body.videoPlaylist } await waitJobs(servers) @@ -459,15 +420,15 @@ describe('Test video playlists', function () { it('Should not list unlisted or private playlists', async function () { for (const server of servers) { const results = [ - await getAccountPlaylistsList(server.url, 'root@localhost:' + servers[1].port, 0, 5, '-createdAt'), - await getVideoPlaylistsList(server.url, 0, 2, '-createdAt') + await server.playlistsCommand.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }), + await server.playlistsCommand.list({ start: 0, count: 2, sort: '-createdAt' }) ] - expect(results[0].body.total).to.equal(2) - expect(results[1].body.total).to.equal(3) + expect(results[0].total).to.equal(2) + expect(results[1].total).to.equal(3) - for (const res of results) { - const data: VideoPlaylist[] = res.body.data + for (const body of results) { + const data = body.data expect(data).to.have.lengthOf(2) expect(data[0].displayName).to.equal('playlist 3') expect(data[1].displayName).to.equal('playlist 2') @@ -476,23 +437,23 @@ describe('Test video playlists', function () { }) it('Should not get unlisted playlist using only the id', async function () { - await getVideoPlaylist(servers[1].url, unlistedPlaylist.id, 404) + await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 }) }) it('Should get unlisted plyaylist using uuid or shortUUID', async function () { - await getVideoPlaylist(servers[1].url, unlistedPlaylist.uuid) - await getVideoPlaylist(servers[1].url, unlistedPlaylist.shortUUID) + await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.uuid }) + await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.shortUUID }) }) it('Should not get private playlist without token', async function () { for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { - await getVideoPlaylist(servers[1].url, id, 401) + await servers[1].playlistsCommand.get({ playlistId: id, expectedStatus: 401 }) } }) it('Should get private playlist with a token', async function () { for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { - await getVideoPlaylistWithToken(servers[1].url, servers[1].accessToken, id) + await servers[1].playlistsCommand.get({ token: servers[1].accessToken, playlistId: id }) } }) }) @@ -502,10 +463,8 @@ describe('Test video playlists', function () { it('Should update a playlist', async function () { this.timeout(30000) - await updateVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + await servers[1].playlistsCommand.update({ + attributes: { displayName: 'playlist 3 updated', description: 'description updated', privacy: VideoPlaylistPrivacy.UNLISTED, @@ -518,8 +477,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideoPlaylist(server.url, playlistServer2UUID2) - const playlist: VideoPlaylist = res.body + const playlist = await server.playlistsCommand.get({ playlistId: playlistServer2UUID2 }) expect(playlist.displayName).to.equal('playlist 3 updated') expect(playlist.description).to.equal('description updated') @@ -545,39 +503,37 @@ describe('Test video playlists', function () { it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () { this.timeout(30000) - const addVideo = (elementAttrs: any) => { - return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs }) + const addVideo = (attributes: any) => { + return commands[0].addElement({ playlistId: playlistServer1Id, attributes }) } - const res = await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + const playlist = await commands[0].create({ + attributes: { displayName: 'playlist 4', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } }) - playlistServer1Id = res.body.videoPlaylist.id - playlistServer1UUID = res.body.videoPlaylist.uuid + playlistServer1Id = playlist.id + playlistServer1UUID = playlist.uuid await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 }) await addVideo({ videoId: servers[2].videos[2].uuid }) { - const res = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 }) - playlistElementServer1Video4 = res.body.videoPlaylistElement.id + const element = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 }) + playlistElementServer1Video4 = element.id } { - const res = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) - playlistElementServer1Video5 = res.body.videoPlaylistElement.id + const element = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) + playlistElementServer1Video5 = element.id } { - const res = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 }) - playlistElementNSFW = res.body.videoPlaylistElement.id + const element = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 }) + playlistElementNSFW = element.id await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 4 }) await addVideo({ videoId: nsfwVideoServer1 }) @@ -590,55 +546,59 @@ describe('Test video playlists', function () { this.timeout(30000) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - - expect(res.body.total).to.equal(8) - - const videoElements: VideoPlaylistElement[] = res.body.data - expect(videoElements).to.have.lengthOf(8) - - expect(videoElements[0].video.name).to.equal('video 0 server 1') - expect(videoElements[0].position).to.equal(1) - expect(videoElements[0].startTimestamp).to.equal(15) - expect(videoElements[0].stopTimestamp).to.equal(28) - - expect(videoElements[1].video.name).to.equal('video 1 server 3') - expect(videoElements[1].position).to.equal(2) - expect(videoElements[1].startTimestamp).to.equal(35) - expect(videoElements[1].stopTimestamp).to.be.null - - expect(videoElements[2].video.name).to.equal('video 2 server 3') - expect(videoElements[2].position).to.equal(3) - expect(videoElements[2].startTimestamp).to.be.null - expect(videoElements[2].stopTimestamp).to.be.null - - expect(videoElements[3].video.name).to.equal('video 3 server 1') - expect(videoElements[3].position).to.equal(4) - expect(videoElements[3].startTimestamp).to.be.null - expect(videoElements[3].stopTimestamp).to.equal(35) - - expect(videoElements[4].video.name).to.equal('video 4 server 1') - expect(videoElements[4].position).to.equal(5) - expect(videoElements[4].startTimestamp).to.equal(45) - expect(videoElements[4].stopTimestamp).to.equal(60) - - expect(videoElements[5].video.name).to.equal('NSFW video') - expect(videoElements[5].position).to.equal(6) - expect(videoElements[5].startTimestamp).to.equal(5) - expect(videoElements[5].stopTimestamp).to.be.null - - expect(videoElements[6].video.name).to.equal('NSFW video') - expect(videoElements[6].position).to.equal(7) - expect(videoElements[6].startTimestamp).to.equal(4) - expect(videoElements[6].stopTimestamp).to.be.null - - expect(videoElements[7].video.name).to.equal('NSFW video') - expect(videoElements[7].position).to.equal(8) - expect(videoElements[7].startTimestamp).to.be.null - expect(videoElements[7].stopTimestamp).to.be.null - - const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2) - expect(res3.body.data).to.have.lengthOf(2) + { + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + + expect(body.total).to.equal(8) + + const videoElements = body.data + expect(videoElements).to.have.lengthOf(8) + + expect(videoElements[0].video.name).to.equal('video 0 server 1') + expect(videoElements[0].position).to.equal(1) + expect(videoElements[0].startTimestamp).to.equal(15) + expect(videoElements[0].stopTimestamp).to.equal(28) + + expect(videoElements[1].video.name).to.equal('video 1 server 3') + expect(videoElements[1].position).to.equal(2) + expect(videoElements[1].startTimestamp).to.equal(35) + expect(videoElements[1].stopTimestamp).to.be.null + + expect(videoElements[2].video.name).to.equal('video 2 server 3') + expect(videoElements[2].position).to.equal(3) + expect(videoElements[2].startTimestamp).to.be.null + expect(videoElements[2].stopTimestamp).to.be.null + + expect(videoElements[3].video.name).to.equal('video 3 server 1') + expect(videoElements[3].position).to.equal(4) + expect(videoElements[3].startTimestamp).to.be.null + expect(videoElements[3].stopTimestamp).to.equal(35) + + expect(videoElements[4].video.name).to.equal('video 4 server 1') + expect(videoElements[4].position).to.equal(5) + expect(videoElements[4].startTimestamp).to.equal(45) + expect(videoElements[4].stopTimestamp).to.equal(60) + + expect(videoElements[5].video.name).to.equal('NSFW video') + expect(videoElements[5].position).to.equal(6) + expect(videoElements[5].startTimestamp).to.equal(5) + expect(videoElements[5].stopTimestamp).to.be.null + + expect(videoElements[6].video.name).to.equal('NSFW video') + expect(videoElements[6].position).to.equal(7) + expect(videoElements[6].startTimestamp).to.equal(4) + expect(videoElements[6].stopTimestamp).to.be.null + + expect(videoElements[7].video.name).to.equal('NSFW video') + expect(videoElements[7].position).to.equal(8) + expect(videoElements[7].startTimestamp).to.be.null + expect(videoElements[7].stopTimestamp).to.be.null + } + + { + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 }) + expect(body.data).to.have.lengthOf(2) + } } }) }) @@ -656,29 +616,28 @@ describe('Test video playlists', function () { before(async function () { this.timeout(60000) - groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ] + groupUser1 = [ Object.assign({}, servers[0], { accessToken: userTokenServer1 }) ] groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ] group1 = [ servers[0] ] group2 = [ servers[1], servers[2] ] - const res = await createVideoPlaylist({ - url: servers[0].url, - token: userAccessTokenServer1, - playlistAttrs: { + const playlist = await commands[0].create({ + token: userTokenServer1, + attributes: { displayName: 'playlist 56', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } }) - const playlistServer1Id2 = res.body.videoPlaylist.id - playlistServer1UUID2 = res.body.videoPlaylist.uuid + const playlistServer1Id2 = playlist.id + playlistServer1UUID2 = playlist.uuid - const addVideo = (elementAttrs: any) => { - return addVideoInPlaylist({ url: servers[0].url, token: userAccessTokenServer1, playlistId: playlistServer1Id2, elementAttrs }) + const addVideo = (attributes: any) => { + return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes }) } - video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userAccessTokenServer1 })).uuid + 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 @@ -756,26 +715,26 @@ describe('Test video playlists', function () { const position = 2 { - await command.addToMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port }) + await command.addToMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await command.removeFromMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port }) + await command.removeFromMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) } { - await command.addToMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port }) + await command.addToMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await command.removeFromMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port }) + await command.removeFromMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -809,10 +768,10 @@ describe('Test video playlists', function () { }) it('Should hide the video if it is NSFW', async function () { - const res = await getPlaylistVideos(servers[0].url, userAccessTokenServer1, playlistServer1UUID2, 0, 10, { nsfw: false }) - expect(res.body.total).to.equal(3) + const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } }) + expect(body.total).to.equal(3) - const elements: VideoPlaylistElement[] = res.body.data + const elements = body.data const element = elements.find(e => e.position === 3) expect(element).to.exist @@ -828,11 +787,9 @@ describe('Test video playlists', function () { this.timeout(30000) { - await reorderVideosPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].reorderElements({ playlistId: playlistServer1Id, - elementAttrs: { + attributes: { startPosition: 2, insertAfterPosition: 3 } @@ -841,8 +798,8 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const names = body.data.map(v => v.video.name) expect(names).to.deep.equal([ 'video 0 server 1', @@ -858,11 +815,9 @@ describe('Test video playlists', function () { } { - await reorderVideosPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].reorderElements({ playlistId: playlistServer1Id, - elementAttrs: { + attributes: { startPosition: 1, reorderLength: 3, insertAfterPosition: 4 @@ -872,8 +827,8 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const names = body.data.map(v => v.video.name) expect(names).to.deep.equal([ 'video 3 server 1', @@ -889,11 +844,9 @@ describe('Test video playlists', function () { } { - await reorderVideosPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].reorderElements({ playlistId: playlistServer1Id, - elementAttrs: { + attributes: { startPosition: 6, insertAfterPosition: 3 } @@ -902,8 +855,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - const elements: VideoPlaylistElement[] = res.body.data + const { data: elements } = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) const names = elements.map(v => v.video.name) expect(names).to.deep.equal([ @@ -927,22 +879,18 @@ describe('Test video playlists', function () { it('Should update startTimestamp/endTimestamp of some elements', async function () { this.timeout(30000) - await updateVideoPlaylistElement({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].updateElement({ playlistId: playlistServer1Id, - playlistElementId: playlistElementServer1Video4, - elementAttrs: { + elementId: playlistElementServer1Video4, + attributes: { startTimestamp: 1 } }) - await updateVideoPlaylistElement({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].updateElement({ playlistId: playlistServer1Id, - playlistElementId: playlistElementServer1Video5, - elementAttrs: { + elementId: playlistElementServer1Video5, + attributes: { stopTimestamp: null } }) @@ -950,8 +898,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - const elements: VideoPlaylistElement[] = res.body.data + const { data: elements } = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) expect(elements[0].video.name).to.equal('video 3 server 1') expect(elements[0].position).to.equal(1) @@ -973,8 +920,7 @@ describe('Test video playlists', function () { 43000, servers[0].videos[4].id ] - const res = await doVideosExistInMyPlaylist(servers[0].url, servers[0].accessToken, videoIds) - const obj = res.body as VideoExistInPlaylist + const obj = await commands[0].videosExist({ videoIds }) { const elem = obj[servers[0].videos[0].id] @@ -1011,39 +957,26 @@ describe('Test video playlists', function () { const videoId = servers[1].videos[5].id async function getPlaylistNames () { - const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt') + const { data } = await server.playlistsCommand.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' }) - return (res.body.data as VideoPlaylist[]).map(p => p.displayName) + return data.map(p => p.displayName) } - const elementAttrs = { videoId } - const res1 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs }) - const res2 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs }) - - const element1 = res1.body.videoPlaylistElement.id - const element2 = res2.body.videoPlaylistElement.id + const attributes = { videoId } + const element1 = await server.playlistsCommand.addElement({ playlistId: playlistServer2Id1, attributes }) + const element2 = await server.playlistsCommand.addElement({ playlistId: playlistServer2Id2, attributes }) const names1 = await getPlaylistNames() expect(names1[0]).to.equal('playlist 3 updated') expect(names1[1]).to.equal('playlist 2') - await removeVideoFromPlaylist({ - url: server.url, - token: server.accessToken, - playlistId: playlistServer2Id1, - playlistElementId: element1 - }) + await server.playlistsCommand.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id }) const names2 = await getPlaylistNames() expect(names2[0]).to.equal('playlist 2') expect(names2[1]).to.equal('playlist 3 updated') - await removeVideoFromPlaylist({ - url: server.url, - token: server.accessToken, - playlistId: playlistServer2Id2, - playlistElementId: element2 - }) + await server.playlistsCommand.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id }) const names3 = await getPlaylistNames() expect(names3[0]).to.equal('playlist 3 updated') @@ -1053,28 +986,16 @@ describe('Test video playlists', function () { it('Should delete some elements', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistId: playlistServer1Id, - playlistElementId: playlistElementServer1Video4 - }) - - await removeVideoFromPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistId: playlistServer1Id, - playlistElementId: playlistElementNSFW - }) + await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementServer1Video4 }) + await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementNSFW }) await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - - expect(res.body.total).to.equal(6) + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + expect(body.total).to.equal(6) - const elements: VideoPlaylistElement[] = res.body.data + const elements = body.data expect(elements).to.have.lengthOf(6) expect(elements[0].video.name).to.equal('video 0 server 1') @@ -1100,34 +1021,31 @@ describe('Test video playlists', function () { it('Should be able to create a public playlist, and set it to private', async function () { this.timeout(30000) - const res = await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + const videoPlaylistIds = await commands[0].create({ + attributes: { displayName: 'my super public playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } }) - const videoPlaylistIds = res.body.videoPlaylist await waitJobs(servers) for (const server of servers) { - await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.OK_200) + await server.playlistsCommand.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) } - const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE } - await updateVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: videoPlaylistIds.id, playlistAttrs }) + const attributes = { privacy: VideoPlaylistPrivacy.PRIVATE } + await commands[0].update({ playlistId: videoPlaylistIds.id, attributes }) await waitJobs(servers) for (const server of [ servers[1], servers[2] ]) { - await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.NOT_FOUND_404) + await server.playlistsCommand.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } - await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, HttpStatusCode.UNAUTHORIZED_401) - await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, HttpStatusCode.OK_200) + await commands[0].get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await commands[0].get({ token: servers[0].accessToken, playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -1136,12 +1054,12 @@ describe('Test video playlists', function () { it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () { this.timeout(30000) - await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id) + await commands[0].delete({ playlistId: playlistServer1Id }) await waitJobs(servers) for (const server of servers) { - await getVideoPlaylist(server.url, playlistServer1UUID, HttpStatusCode.NOT_FOUND_404) + await server.playlistsCommand.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -1156,21 +1074,22 @@ describe('Test video playlists', function () { it('Should unfollow servers 1 and 2 and hide their playlists', async function () { this.timeout(30000) - const finder = data => data.find(p => p.displayName === 'my super playlist') + const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'my super playlist') { - const res = await getVideoPlaylistsList(servers[2].url, 0, 5) - expect(res.body.total).to.equal(3) - expect(finder(res.body.data)).to.not.be.undefined + const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + expect(body.total).to.equal(3) + + expect(finder(body.data)).to.not.be.undefined } await servers[2].followsCommand.unfollow({ target: servers[0] }) { - const res = await getVideoPlaylistsList(servers[2].url, 0, 5) - expect(res.body.total).to.equal(1) + const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + expect(body.total).to.equal(1) - expect(finder(res.body.data)).to.be.undefined + expect(finder(body.data)).to.be.undefined } }) @@ -1180,16 +1099,13 @@ describe('Test video playlists', function () { const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' }) const videoChannelId = res.body.videoChannel.id - const res2 = await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + const playlistCreated = await commands[0].create({ + attributes: { displayName: 'channel playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId } }) - const videoPlaylistUUID = res2.body.videoPlaylist.uuid await waitJobs(servers) @@ -1197,11 +1113,11 @@ describe('Test video playlists', function () { await waitJobs(servers) - const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID) - expect(res3.body.displayName).to.equal('channel playlist') - expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) + const body = await commands[0].get({ token: servers[0].accessToken, playlistId: playlistCreated.uuid }) + expect(body.displayName).to.equal('channel playlist') + expect(body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) - await getVideoPlaylist(servers[1].url, videoPlaylistUUID, HttpStatusCode.NOT_FOUND_404) + await servers[1].playlistsCommand.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should delete an account and delete its playlists', async function () { @@ -1221,10 +1137,8 @@ describe('Test video playlists', function () { const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) const userChannel = (resChannel.body as User).videoChannels[0] - await createVideoPlaylist({ - url: servers[0].url, - token: userAccessToken, - playlistAttrs: { + await commands[0].create({ + attributes: { displayName: 'playlist to be deleted', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: userChannel.id @@ -1233,12 +1147,13 @@ describe('Test video playlists', function () { await waitJobs(servers) - const finder = data => data.find(p => p.displayName === 'playlist to be deleted') + const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'playlist to be deleted') { for (const server of [ servers[0], servers[1] ]) { - const res = await getVideoPlaylistsList(server.url, 0, 15) - expect(finder(res.body.data)).to.not.be.undefined + const body = await server.playlistsCommand.list({ start: 0, count: 15 }) + + expect(finder(body.data)).to.not.be.undefined } } @@ -1247,8 +1162,9 @@ describe('Test video playlists', function () { { for (const server of [ servers[0], servers[1] ]) { - const res = await getVideoPlaylistsList(server.url, 0, 15) - expect(finder(res.body.data)).to.be.undefined + const body = await server.playlistsCommand.list({ start: 0, count: 15 }) + + expect(finder(body.data)).to.be.undefined } } }) -- cgit v1.2.3 From 313228e9c3b5bcef5391228c9b949d05d32ad7bb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:21:42 +0200 Subject: Introduce history command --- server/tests/api/videos/videos-history.ts | 59 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 209b93014..731447135 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -9,6 +9,7 @@ import { flushAndRunServer, getVideosListWithToken, getVideoWithToken, + HistoryCommand, killallServers, reRunServer, ServerInfo, @@ -18,7 +19,6 @@ import { userLogin, wait } from '@shared/extra-utils' -import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history' import { Video, VideoDetails } from '@shared/models' const expect = chai.expect @@ -30,6 +30,7 @@ describe('Test videos history', function () { let video3UUID: string let video3WatchedDate: Date let userAccessToken: string + let command: HistoryCommand before(async function () { this.timeout(30000) @@ -38,6 +39,8 @@ describe('Test videos history', function () { await setAccessTokensToServers([ server ]) + command = server.historyCommand + { const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) video1UUID = res.body.video.uuid @@ -75,8 +78,8 @@ describe('Test videos history', function () { }) it('Should watch the first and second video', async function () { - await userWatchVideo(server.url, server.accessToken, video2UUID, 8) - await userWatchVideo(server.url, server.accessToken, video1UUID, 3) + await command.wathVideo({ videoId: video2UUID, currentTime: 8 }) + await command.wathVideo({ videoId: video1UUID, currentTime: 3 }) }) it('Should return the correct history when listing, searching and getting videos', async function () { @@ -132,44 +135,42 @@ describe('Test videos history', function () { it('Should have these videos when listing my history', async function () { video3WatchedDate = new Date() - await userWatchVideo(server.url, server.accessToken, video3UUID, 2) + await command.wathVideo({ videoId: video3UUID, currentTime: 2 }) - const res = await listMyVideosHistory(server.url, server.accessToken) + const body = await command.list() - expect(res.body.total).to.equal(3) + expect(body.total).to.equal(3) - const videos: Video[] = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 3') expect(videos[1].name).to.equal('video 1') expect(videos[2].name).to.equal('video 2') }) it('Should not have videos history on another user', async function () { - const res = await listMyVideosHistory(server.url, userAccessToken) + const body = await command.list({ token: userAccessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should be able to search through videos in my history', async function () { - const res = await listMyVideosHistory(server.url, server.accessToken, '2') - - expect(res.body.total).to.equal(1) + const body = await command.list({ search: '2' }) + expect(body.total).to.equal(1) - const videos: Video[] = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 2') }) it('Should clear my history', async function () { - await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) + await command.remove({ beforeDate: video3WatchedDate.toISOString() }) }) it('Should have my history cleared', async function () { - const res = await listMyVideosHistory(server.url, server.accessToken) - - expect(res.body.total).to.equal(1) + const body = await command.list() + expect(body.total).to.equal(1) - const videos: Video[] = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 3') }) @@ -180,7 +181,7 @@ describe('Test videos history', function () { videosHistoryEnabled: false }) - await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409) + await command.wathVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 }) }) it('Should re-enable videos history', async function () { @@ -190,13 +191,12 @@ describe('Test videos history', function () { videosHistoryEnabled: true }) - await userWatchVideo(server.url, server.accessToken, video1UUID, 8) - - const res = await listMyVideosHistory(server.url, server.accessToken) + await command.wathVideo({ videoId: video1UUID, currentTime: 8 }) - expect(res.body.total).to.equal(2) + const body = await command.list() + expect(body.total).to.equal(2) - const videos: Video[] = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 1') expect(videos[1].name).to.equal('video 3') }) @@ -212,9 +212,8 @@ describe('Test videos history', function () { // Should still have history - const res = await listMyVideosHistory(server.url, server.accessToken) - - expect(res.body.total).to.equal(2) + const body = await command.list() + expect(body.total).to.equal(2) }) it('Should clean old history', async function () { @@ -226,8 +225,8 @@ describe('Test videos history', function () { await wait(6000) - const res = await listMyVideosHistory(server.url, server.accessToken) - expect(res.body.total).to.equal(0) + const body = await command.list() + expect(body.total).to.equal(0) }) after(async function () { -- cgit v1.2.3 From 6910f20f114b5bd020258a3a9a3f2117819a60c2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:49:51 +0200 Subject: Introduce import command --- server/tests/api/videos/video-imports.ts | 72 +++++++++++++++----------------- 1 file changed, 33 insertions(+), 39 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 14aed604f..4f9ecbe8e 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -3,6 +3,7 @@ import 'mocha' import * as chai from 'chai' import { + areHttpImportTestsDisabled, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -11,20 +12,14 @@ import { getVideo, getVideosList, immutableAssign, + ImportsCommand, ServerInfo, setAccessTokensToServers, - testCaptionFile -} from '../../../../shared/extra-utils' -import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - getMagnetURI, - getMyVideoImports, - getYoutubeHDRVideoUrl, - getYoutubeVideoUrl, - importVideo -} from '../../../../shared/extra-utils/videos/video-imports' -import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' + testCaptionFile, + testImage, + waitJobs +} from '@shared/extra-utils' +import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models' const expect = chai.expect @@ -124,17 +119,17 @@ describe('Test video imports', function () { } { - const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - expect(res.body.video.name).to.equal('small video - youtube') + const attributes = immutableAssign(baseAttributes, { targetUrl: ImportsCommand.getYoutubeVideoUrl() }) + const { video } = await servers[0].importsCommand.importVideo({ attributes }) + expect(video.name).to.equal('small video - youtube') - expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) - expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) + expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) + expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) - await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) - await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) + await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath) + await testImage(servers[0].url, 'video_import_preview', video.previewPath) - const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id }) + const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: video.id }) const videoCaptions = bodyCaptions.data expect(videoCaptions).to.have.lengthOf(2) @@ -175,12 +170,12 @@ Ajouter un sous-titre est vraiment facile`) { const attributes = immutableAssign(baseAttributes, { - magnetUri: getMagnetURI(), + magnetUri: ImportsCommand.getMagnetURI(), description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] }) - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - expect(res.body.video.name).to.equal('super peertube2 video') + const { video } = await servers[0].importsCommand.importVideo({ attributes }) + expect(video.name).to.equal('super peertube2 video') } { @@ -189,8 +184,8 @@ Ajouter un sous-titre est vraiment facile`) description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] }) - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - expect(res.body.video.name).to.equal('你好 世界 720p.mp4') + const { video } = await servers[0].importsCommand.importVideo({ attributes }) + expect(video.name).to.equal('你好 世界 720p.mp4') } }) @@ -207,19 +202,18 @@ Ajouter un sous-titre est vraiment facile`) }) it('Should list the videos to import in my imports on server 1', async function () { - const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt') + const { total, data: videoImports } = await servers[0].importsCommand.getMyVideoImports({ sort: '-createdAt' }) + expect(total).to.equal(3) - expect(res.body.total).to.equal(3) - const videoImports: VideoImport[] = res.body.data expect(videoImports).to.have.lengthOf(3) - expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl()) + expect(videoImports[2].targetUrl).to.equal(ImportsCommand.getYoutubeVideoUrl()) expect(videoImports[2].magnetUri).to.be.null expect(videoImports[2].torrentName).to.be.null expect(videoImports[2].video.name).to.equal('small video - youtube') expect(videoImports[1].targetUrl).to.be.null - expect(videoImports[1].magnetUri).to.equal(getMagnetURI()) + expect(videoImports[1].magnetUri).to.equal(ImportsCommand.getMagnetURI()) expect(videoImports[1].torrentName).to.be.null expect(videoImports[1].video.name).to.equal('super peertube2 video') @@ -248,7 +242,7 @@ Ajouter un sous-titre est vraiment facile`) this.timeout(60_000) const attributes = { - targetUrl: getYoutubeVideoUrl(), + targetUrl: ImportsCommand.getYoutubeVideoUrl(), channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC, category: 10, @@ -258,8 +252,8 @@ Ajouter un sous-titre est vraiment facile`) description: 'my super description', tags: [ 'supertag1', 'supertag2' ] } - const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) - expect(res.body.video.name).to.equal('my super name') + const { video } = await servers[1].importsCommand.importVideo({ attributes }) + expect(video.name).to.equal('my super name') }) it('Should have the videos listed on the two instances', async function () { @@ -284,12 +278,12 @@ Ajouter un sous-titre est vraiment facile`) const attributes = { name: 'transcoded video', - magnetUri: getMagnetURI(), + magnetUri: ImportsCommand.getMagnetURI(), channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC } - const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) - const videoUUID = res.body.video.uuid + const { video } = await servers[1].importsCommand.importVideo({ attributes }) + const videoUUID = video.uuid await waitJobs(servers) @@ -335,12 +329,12 @@ Ajouter un sous-titre est vraiment facile`) const attributes = { name: 'hdr video', - targetUrl: getYoutubeHDRVideoUrl(), + targetUrl: ImportsCommand.getYoutubeHDRVideoUrl(), channelId: channelIdServer1, privacy: VideoPrivacy.PUBLIC } - const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes) - const videoUUID = res1.body.video.uuid + const { video: videoImported } = await servers[0].importsCommand.importVideo({ attributes }) + const videoUUID = videoImported.uuid await waitJobs(servers) -- cgit v1.2.3 From 57f879a540551c3b958b0991c8e1e3657a4481d8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 10:21:10 +0200 Subject: Introduce streaming playlists command --- server/tests/api/videos/video-hls.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 3821cfed0..3dd8c9066 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -12,7 +12,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getPlaylist, getVideo, makeRawRequest, removeVideo, @@ -67,10 +66,9 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn } { - await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions) + await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) - const res = await getPlaylist(hlsPlaylist.playlistUrl) - const masterPlaylist = res.text + const masterPlaylist = await server.streamingPlaylistsCommand.get({ url: hlsPlaylist.playlistUrl }) for (const resolution of resolutions) { expect(masterPlaylist).to.contain(`${resolution}.m3u8`) @@ -80,9 +78,10 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn { for (const resolution of resolutions) { - const res = await getPlaylist(`${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) + const subPlaylist = await server.streamingPlaylistsCommand.get({ + url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8` + }) - const subPlaylist = res.text expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) } } @@ -91,7 +90,14 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls' for (const resolution of resolutions) { - await checkSegmentHash(baseUrlAndPath, baseUrlAndPath, videoUUID, resolution, hlsPlaylist) + await checkSegmentHash({ + server, + baseUrlPlaylist: baseUrlAndPath, + baseUrlSegment: baseUrlAndPath, + videoUUID, + resolution, + hlsPlaylist + }) } } } -- cgit v1.2.3 From a54618880c394ad7571f3f3222dc96ec2dd10d9a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 11:21:30 +0200 Subject: Introduce channels command --- server/tests/api/videos/multiple-servers.ts | 8 +- server/tests/api/videos/video-channels.ts | 249 ++++++++++------------------ server/tests/api/videos/video-playlists.ts | 9 +- 3 files changed, 94 insertions(+), 172 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index a8c8a889b..a59d5a858 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import * as request from 'supertest' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - addVideoChannel, buildAbsoluteFixturePath, checkTmpIsEmpty, checkVideoFilesWereRemoved, @@ -17,7 +16,6 @@ import { flushAndRunMultipleServers, getLocalVideos, getVideo, - getVideoChannelsList, getVideosList, rateVideo, removeVideo, @@ -64,9 +62,9 @@ describe('Test multiple servers', function () { displayName: 'my channel', description: 'super channel' } - await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) - const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) - videoChannelId = channelRes.body.data[0].id + await servers[0].channelsCommand.create({ attributes: videoChannel }) + const { data } = await servers[0].channelsCommand.list({ start: 0, count: 1 }) + videoChannelId = data[0].id } // Server 1 and server 2 follow each other diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 865098777..daf066eb1 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -7,43 +7,29 @@ import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { cleanupTests, createUser, - deleteVideoChannelImage, doubleFollow, flushAndRunMultipleServers, getActorImage, getVideo, - getVideoChannel, getVideoChannelVideos, setDefaultVideoChannel, testFileExistsOrNot, testImage, updateVideo, - updateVideoChannelImage, uploadVideo, userLogin, wait } from '../../../../shared/extra-utils' -import { - addVideoChannel, - deleteVideoChannel, - getAccountVideoChannelsList, - getMyUserInformation, - getVideoChannelsList, - ServerInfo, - setAccessTokensToServers, - updateVideoChannel, - viewVideo -} from '../../../../shared/extra-utils/index' +import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' const expect = chai.expect async function findChannel (server: ServerInfo, channelId: number) { - const res = await getVideoChannelsList(server.url, 0, 5, '-name') - const videoChannel = res.body.data.find(c => c.id === channelId) + const body = await server.channelsCommand.list({ sort: '-name' }) - return videoChannel as VideoChannel + return body.data.find(c => c.id === channelId) } describe('Test video channels', function () { @@ -69,11 +55,11 @@ describe('Test video channels', function () { }) it('Should have one video channel (created with root)', async () => { - const res = await getVideoChannelsList(servers[0].url, 0, 2) + const body = await servers[0].channelsCommand.list({ start: 0, count: 2 }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) }) it('Should create another video channel', async function () { @@ -86,8 +72,8 @@ describe('Test video channels', function () { description: 'super video channel description', support: 'super video channel support text' } - const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) - secondVideoChannelId = res.body.videoChannel.id + const created = await servers[0].channelsCommand.create({ attributes: videoChannel }) + secondVideoChannelId = created.id } // The channel is 1 is propagated to servers 2 @@ -120,16 +106,14 @@ describe('Test video channels', function () { }) it('Should have two video channels when getting account channels on server 1', async function () { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName - }) + const body = await servers[0].channelsCommand.listByAccount({ accountName }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(2) + const videoChannels = body.data + + expect(videoChannels).to.be.an('array') + expect(videoChannels).to.have.lengthOf(2) - const videoChannels = res.body.data expect(videoChannels[0].name).to.equal('root_channel') expect(videoChannels[0].displayName).to.equal('Main root channel') @@ -141,79 +125,69 @@ describe('Test video channels', function () { it('Should paginate and sort account channels', async function () { { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, + const body = await servers[0].channelsCommand.listByAccount({ accountName, start: 0, count: 1, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(1) - const videoChannel: VideoChannel = res.body.data[0] + const videoChannel: VideoChannel = body.data[0] expect(videoChannel.name).to.equal('root_channel') } { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, + const body = await servers[0].channelsCommand.listByAccount({ accountName, start: 0, count: 1, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(1) - - const videoChannel: VideoChannel = res.body.data[0] - expect(videoChannel.name).to.equal('second_video_channel') + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('second_video_channel') } { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, + const body = await servers[0].channelsCommand.listByAccount({ accountName, start: 1, count: 1, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(1) - - const videoChannel: VideoChannel = res.body.data[0] - expect(videoChannel.name).to.equal('root_channel') + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('root_channel') } }) it('Should have one video channel when getting account channels on server 2', async function () { - const res = await getAccountVideoChannelsList({ - url: servers[1].url, - accountName - }) + const body = await servers[1].channelsCommand.listByAccount({ accountName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) - const videoChannels = res.body.data - expect(videoChannels[0].name).to.equal('second_video_channel') - expect(videoChannels[0].displayName).to.equal('second video channel') - expect(videoChannels[0].description).to.equal('super video channel description') - expect(videoChannels[0].support).to.equal('super video channel support text') + const videoChannel = body.data[0] + expect(videoChannel.name).to.equal('second_video_channel') + expect(videoChannel.displayName).to.equal('second video channel') + expect(videoChannel.description).to.equal('super video channel description') + expect(videoChannel.support).to.equal('super video channel support text') }) it('Should list video channels', async function () { - const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name') + const body = await servers[0].channelsCommand.list({ start: 1, count: 1, sort: '-name' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('root_channel') - expect(res.body.data[0].displayName).to.equal('Main root channel') + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('root_channel') + expect(body.data[0].displayName).to.equal('Main root channel') }) it('Should update video channel', async function () { @@ -225,22 +199,23 @@ describe('Test video channels', function () { support: 'support updated' } - await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) + await servers[0].channelsCommand.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) await waitJobs(servers) }) it('Should have video channel updated', async function () { for (const server of servers) { - const res = await getVideoChannelsList(server.url, 0, 1, '-name') - - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('second_video_channel') - expect(res.body.data[0].displayName).to.equal('video channel updated') - expect(res.body.data[0].description).to.equal('video channel description updated') - expect(res.body.data[0].support).to.equal('support updated') + const body = await server.channelsCommand.list({ start: 0, count: 1, sort: '-name' }) + + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + + expect(body.data[0].name).to.equal('second_video_channel') + expect(body.data[0].displayName).to.equal('video channel updated') + expect(body.data[0].description).to.equal('video channel description updated') + expect(body.data[0].support).to.equal('support updated') } }) @@ -261,7 +236,7 @@ describe('Test video channels', function () { bulkVideosSupportUpdate: true } - await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) + await servers[0].channelsCommand.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) await waitJobs(servers) @@ -278,10 +253,8 @@ describe('Test video channels', function () { const fixture = 'avatar.png' - await updateVideoChannelImage({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoChannelName: 'second_video_channel', + await servers[0].channelsCommand.updateImage({ + channelName: 'second_video_channel', fixture, type: 'avatar' }) @@ -306,10 +279,8 @@ describe('Test video channels', function () { const fixture = 'banner.jpg' - await updateVideoChannelImage({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoChannelName: 'second_video_channel', + await servers[0].channelsCommand.updateImage({ + channelName: 'second_video_channel', fixture, type: 'banner' }) @@ -317,8 +288,7 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host) - const videoChannel = res.body + const videoChannel = await server.channelsCommand.get({ channelName: 'second_video_channel@' + servers[0].host }) bannerPaths[server.port] = videoChannel.banner.path await testImage(server.url, 'banner-resized', bannerPaths[server.port]) @@ -333,12 +303,7 @@ describe('Test video channels', function () { it('Should delete the video channel avatar', async function () { this.timeout(15000) - await deleteVideoChannelImage({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoChannelName: 'second_video_channel', - type: 'avatar' - }) + await servers[0].channelsCommand.deleteImage({ channelName: 'second_video_channel', type: 'avatar' }) await waitJobs(servers) @@ -353,12 +318,7 @@ describe('Test video channels', function () { it('Should delete the video channel banner', async function () { this.timeout(15000) - await deleteVideoChannelImage({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoChannelName: 'second_video_channel', - type: 'banner' - }) + await servers[0].channelsCommand.deleteImage({ channelName: 'second_video_channel', type: 'banner' }) await waitJobs(servers) @@ -411,23 +371,23 @@ describe('Test video channels', function () { }) it('Should delete video channel', async function () { - await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel') + await servers[0].channelsCommand.delete({ channelName: 'second_video_channel' }) }) it('Should have video channel deleted', async function () { - const res = await getVideoChannelsList(servers[0].url, 0, 10) + const body = await servers[0].channelsCommand.list({ start: 0, count: 10 }) - 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].displayName).to.equal('Main root channel') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('Main root channel') }) it('Should create the main channel with an uuid if there is a conflict', async function () { { const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } - const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) - totoChannel = res.body.videoChannel.id + const created = await servers[0].channelsCommand.create({ attributes: videoChannel }) + totoChannel = created.id } { @@ -444,15 +404,9 @@ describe('Test video channels', function () { this.timeout(10000) { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - withStats: true - }) - - const channels: VideoChannel[] = res.body.data + const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) - for (const channel of channels) { + for (const channel of data) { expect(channel).to.haveOwnProperty('viewsPerDay') expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today @@ -471,26 +425,17 @@ describe('Test video channels', function () { // Wait the repeatable job await wait(8000) - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - withStats: true - }) - const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === servers[0].videoChannel.id) + const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) + const channelWithView = data.find(channel => channel.id === servers[0].videoChannel.id) expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) } }) it('Should report correct videos count', async function () { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - withStats: true - }) - const channels: VideoChannel[] = res.body.data + const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) - const totoChannel = channels.find(c => c.name === 'toto_channel') - const rootChannel = channels.find(c => c.name === 'root_channel') + const totoChannel = data.find(c => c.name === 'toto_channel') + const rootChannel = data.find(c => c.name === 'root_channel') expect(rootChannel.videosCount).to.equal(1) expect(totoChannel.videosCount).to.equal(0) @@ -498,26 +443,18 @@ describe('Test video channels', function () { it('Should search among account video channels', async function () { { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - search: 'root' - }) - expect(res.body.total).to.equal(1) + const body = await servers[0].channelsCommand.listByAccount({ accountName, search: 'root' }) + expect(body.total).to.equal(1) - const channels = res.body.data + const channels = body.data expect(channels).to.have.lengthOf(1) } { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - search: 'does not exist' - }) - expect(res.body.total).to.equal(0) + const body = await servers[0].channelsCommand.listByAccount({ accountName, search: 'does not exist' }) + expect(body.total).to.equal(0) - const channels = res.body.data + const channels = body.data expect(channels).to.have.lengthOf(0) } }) @@ -529,30 +466,20 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const res = await getAccountVideoChannelsList({ - url: server.url, - accountName, - sort: '-updatedAt' - }) + const { data } = await server.channelsCommand.listByAccount({ accountName, sort: '-updatedAt' }) - const channels: VideoChannel[] = res.body.data - expect(channels[0].name).to.equal('toto_channel') - expect(channels[1].name).to.equal('root_channel') + expect(data[0].name).to.equal('toto_channel') + expect(data[1].name).to.equal('root_channel') } await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: servers[0].videoChannel.id }) await waitJobs(servers) for (const server of servers) { - const res = await getAccountVideoChannelsList({ - url: server.url, - accountName, - sort: '-updatedAt' - }) + const { data } = await server.channelsCommand.listByAccount({ accountName, sort: '-updatedAt' }) - const channels: VideoChannel[] = res.body.data - expect(channels[0].name).to.equal('root_channel') - expect(channels[1].name).to.equal('toto_channel') + expect(data[0].name).to.equal('root_channel') + expect(data[1].name).to.equal('toto_channel') } }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 4de6b3abf..2bb019348 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -4,11 +4,9 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - addVideoChannel, checkPlaylistFilesWereRemoved, cleanupTests, createUser, - deleteVideoChannel, doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, @@ -1096,20 +1094,19 @@ describe('Test video playlists', function () { it('Should delete a channel and put the associated playlist in private mode', async function () { this.timeout(30000) - const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' }) - const videoChannelId = res.body.videoChannel.id + const channel = await servers[0].channelsCommand.create({ attributes: { name: 'super_channel', displayName: 'super channel' } }) const playlistCreated = await commands[0].create({ attributes: { displayName: 'channel playlist', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId + videoChannelId: channel.id } }) await waitJobs(servers) - await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel') + await servers[0].channelsCommand.delete({ channelName: 'super_channel' }) await waitJobs(servers) -- cgit v1.2.3 From 12edc1495a36b2199f1bf1ba37f50c7b694be382 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 14:15:11 +0200 Subject: Introduce comments command --- server/tests/api/videos/multiple-servers.ts | 99 +++++++------- server/tests/api/videos/video-comments.ts | 193 +++++++++++++--------------- 2 files changed, 132 insertions(+), 160 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index a59d5a858..2148d8e1c 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import * as request from 'supertest' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, checkTmpIsEmpty, @@ -27,18 +27,10 @@ import { userLogin, viewVideo, wait, + waitJobs, webtorrentAdd -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addVideoCommentReply, - addVideoCommentThread, - deleteVideoComment, - findCommentId, - getVideoCommentThreads, - getVideoThreadComments -} from '../../../../shared/extra-utils/videos/video-comments' -import { VideoComment, VideoCommentThreadTree, VideoPrivacy } from '../../../../shared/models/videos' +} from '@shared/extra-utils' +import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -762,36 +754,36 @@ describe('Test multiple servers', function () { { const text = 'my super first comment' - await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, text) + await servers[0].commentsCommand.createThread({ videoId: videoUUID, text }) } { const text = 'my super second comment' - await addVideoCommentThread(servers[2].url, servers[2].accessToken, videoUUID, text) + await servers[2].commentsCommand.createThread({ videoId: videoUUID, text }) } await waitJobs(servers) { - const threadId = await findCommentId(servers[1].url, videoUUID, 'my super first comment') + const threadId = await servers[1].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) const text = 'my super answer to thread 1' - await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID, threadId, text) + await servers[1].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text }) } await waitJobs(servers) { - const threadId = await findCommentId(servers[2].url, videoUUID, 'my super first comment') + const threadId = await servers[2].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) - const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId) - const childCommentId = res2.body.children[0].comment.id + const body = await servers[2].commentsCommand.getThread({ videoId: videoUUID, threadId }) + const childCommentId = body.children[0].comment.id const text3 = 'my second answer to thread 1' - await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, threadId, text3) + await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 }) const text2 = 'my super answer to answer of thread 1' - await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, childCommentId, text2) + await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 }) } await waitJobs(servers) @@ -799,14 +791,14 @@ describe('Test multiple servers', function () { it('Should have these threads', async function () { for (const server of servers) { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) { - const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment') + const comment = body.data.find(c => c.text === 'my super first comment') expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') @@ -817,7 +809,7 @@ describe('Test multiple servers', function () { } { - const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment') + const comment = body.data.find(c => c.text === 'my super second comment') expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') @@ -831,12 +823,11 @@ describe('Test multiple servers', function () { it('Should have these comments', async function () { for (const server of servers) { - const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) - const threadId = res1.body.data.find(c => c.text === 'my super first comment').id + const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const threadId = body.data.find(c => c.text === 'my super first comment').id - const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) + const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId }) - const tree: VideoCommentThreadTree = res2.body expect(tree.comment.text).equal('my super first comment') expect(tree.comment.account.name).equal('root') expect(tree.comment.account.host).equal('localhost:' + servers[0].port) @@ -865,19 +856,17 @@ describe('Test multiple servers', function () { it('Should delete a reply', async function () { this.timeout(10000) - await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id) + await servers[2].commentsCommand.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id }) await waitJobs(servers) }) it('Should have this comment marked as deleted', async function () { for (const server of servers) { - const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) - const threadId = res1.body.data.find(c => c.text === 'my super first comment').id - - const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) + const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const threadId = data.find(c => c.text === 'my super first comment').id - const tree: VideoCommentThreadTree = res2.body + const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId }) expect(tree.comment.text).equal('my super first comment') const firstChild = tree.children[0] @@ -898,23 +887,23 @@ describe('Test multiple servers', function () { it('Should delete the thread comments', async function () { this.timeout(10000) - const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) - const threadId = res.body.data.find(c => c.text === 'my super first comment').id - await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) + const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID }) + const commentId = data.find(c => c.text === 'my super first comment').id + await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId }) await waitJobs(servers) }) it('Should have the threads marked as deleted on other servers too', async function () { for (const server of servers) { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) { - const comment: VideoComment = res.body.data[0] + const comment = body.data[0] expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') @@ -925,7 +914,7 @@ describe('Test multiple servers', function () { } { - const deletedComment: VideoComment = res.body.data[1] + const deletedComment = body.data[1] expect(deletedComment).to.not.be.undefined expect(deletedComment.isDeleted).to.be.true expect(deletedComment.deletedAt).to.not.be.null @@ -943,22 +932,22 @@ describe('Test multiple servers', function () { it('Should delete a remote thread by the origin server', async function () { this.timeout(5000) - const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) - const threadId = res.body.data.find(c => c.text === 'my super second comment').id - await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) + const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID }) + const commentId = data.find(c => c.text === 'my super second comment').id + await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId }) await waitJobs(servers) }) it('Should have the threads marked as deleted on other servers too', async function () { for (const server of servers) { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) { - const comment: VideoComment = res.body.data[0] + const comment = body.data[0] expect(comment.text).to.equal('') expect(comment.isDeleted).to.be.true expect(comment.createdAt).to.not.be.null @@ -968,7 +957,7 @@ describe('Test multiple servers', function () { } { - const comment: VideoComment = res.body.data[1] + const comment = body.data[1] expect(comment.text).to.equal('') expect(comment.isDeleted).to.be.true expect(comment.createdAt).to.not.be.null @@ -997,7 +986,7 @@ describe('Test multiple servers', function () { expect(res.body.downloadEnabled).to.be.false const text = 'my super forbidden comment' - await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, HttpStatusCode.CONFLICT_409) + await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) } }) }) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index b6b002307..548d9fbf5 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -2,38 +2,33 @@ import 'mocha' import * as chai from 'chai' -import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '@shared/models' -import { cleanupTests, testImage } from '../../../../shared/extra-utils' import { + cleanupTests, + CommentsCommand, createUser, dateIsValid, flushAndRunServer, getAccessToken, ServerInfo, setAccessTokensToServers, + testImage, updateMyAvatar, uploadVideo -} from '../../../../shared/extra-utils/index' -import { - addVideoCommentReply, - addVideoCommentThread, - deleteVideoComment, - getAdminVideoComments, - getVideoCommentThreads, - getVideoThreadComments -} from '../../../../shared/extra-utils/videos/video-comments' +} from '@shared/extra-utils' const expect = chai.expect describe('Test video comments', function () { let server: ServerInfo - let videoId - let videoUUID - let threadId + let videoId: number + let videoUUID: string + let threadId: number let replyToDeleteId: number let userAccessTokenServer1: string + let command: CommentsCommand + before(async function () { this.timeout(30000) @@ -58,24 +53,25 @@ describe('Test video comments', function () { password: 'password' }) userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') + + command = server.commentsCommand }) describe('User comments', function () { it('Should not have threads on this video', async function () { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await command.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(0) - expect(res.body.totalNotDeletedComments).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.totalNotDeletedComments).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) }) it('Should create a thread in this video', async function () { const text = 'my super first comment' - const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) - const comment = res.body.comment + const comment = await command.createThread({ videoId: videoUUID, text }) expect(comment.inReplyToCommentId).to.be.null expect(comment.text).equal('my super first comment') @@ -91,14 +87,14 @@ describe('Test video comments', function () { }) it('Should list threads of this video', async function () { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await command.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(1) - expect(res.body.totalNotDeletedComments).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.totalNotDeletedComments).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) - const comment: VideoComment = res.body.data[0] + const comment = body.data[0] expect(comment.inReplyToCommentId).to.be.null expect(comment.text).equal('my super first comment') expect(comment.videoId).to.equal(videoId) @@ -117,9 +113,9 @@ describe('Test video comments', function () { }) it('Should get all the thread created', async function () { - const res = await getVideoThreadComments(server.url, videoUUID, threadId) + const body = await command.getThread({ videoId: videoUUID, threadId }) - const rootComment = res.body.comment + const rootComment = body.comment expect(rootComment.inReplyToCommentId).to.be.null expect(rootComment.text).equal('my super first comment') expect(rootComment.videoId).to.equal(videoId) @@ -129,20 +125,19 @@ describe('Test video comments', function () { it('Should create multiple replies in this thread', async function () { const text1 = 'my super answer to thread 1' - const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) - const childCommentId = childCommentRes.body.comment.id + const created = await command.addReply({ videoId, toCommentId: threadId, text: text1 }) + const childCommentId = created.id const text2 = 'my super answer to answer of thread 1' - await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) + await command.addReply({ videoId, toCommentId: childCommentId, text: text2 }) const text3 = 'my second answer to thread 1' - await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) + await command.addReply({ videoId, toCommentId: threadId, text: text3 }) }) it('Should get correctly the replies', async function () { - const res = await getVideoThreadComments(server.url, videoUUID, threadId) + const tree = await command.getThread({ videoId: videoUUID, threadId }) - const tree: VideoCommentThreadTree = res.body expect(tree.comment.text).equal('my super first comment') expect(tree.children).to.have.lengthOf(2) @@ -163,42 +158,41 @@ describe('Test video comments', function () { it('Should create other threads', async function () { const text1 = 'super thread 2' - await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) + await command.createThread({ videoId: videoUUID, text: text1 }) const text2 = 'super thread 3' - await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) + await command.createThread({ videoId: videoUUID, text: text2 }) }) it('Should list the threads', async function () { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') - - expect(res.body.total).to.equal(3) - expect(res.body.totalNotDeletedComments).to.equal(6) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(3) - - expect(res.body.data[0].text).to.equal('my super first comment') - expect(res.body.data[0].totalReplies).to.equal(3) - expect(res.body.data[1].text).to.equal('super thread 2') - expect(res.body.data[1].totalReplies).to.equal(0) - expect(res.body.data[2].text).to.equal('super thread 3') - expect(res.body.data[2].totalReplies).to.equal(0) + const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' }) + + expect(body.total).to.equal(3) + expect(body.totalNotDeletedComments).to.equal(6) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(3) + + expect(body.data[0].text).to.equal('my super first comment') + expect(body.data[0].totalReplies).to.equal(3) + expect(body.data[1].text).to.equal('super thread 2') + expect(body.data[1].totalReplies).to.equal(0) + expect(body.data[2].text).to.equal('super thread 3') + expect(body.data[2].totalReplies).to.equal(0) }) it('Should delete a reply', async function () { - await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId) + await command.delete({ videoId, commentId: replyToDeleteId }) { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') + const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' }) - expect(res.body.total).to.equal(3) - expect(res.body.totalNotDeletedComments).to.equal(5) + expect(body.total).to.equal(3) + expect(body.totalNotDeletedComments).to.equal(5) } { - const res = await getVideoThreadComments(server.url, videoUUID, threadId) + const tree = await command.getThread({ videoId: videoUUID, threadId }) - const tree: VideoCommentThreadTree = res.body expect(tree.comment.text).equal('my super first comment') expect(tree.children).to.have.lengthOf(2) @@ -220,99 +214,88 @@ describe('Test video comments', function () { }) it('Should delete a complete thread', async function () { - await deleteVideoComment(server.url, server.accessToken, videoId, threadId) - - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') - expect(res.body.total).to.equal(3) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(3) - - expect(res.body.data[0].text).to.equal('') - expect(res.body.data[0].isDeleted).to.be.true - expect(res.body.data[0].deletedAt).to.not.be.null - expect(res.body.data[0].account).to.be.null - expect(res.body.data[0].totalReplies).to.equal(2) - expect(res.body.data[1].text).to.equal('super thread 2') - expect(res.body.data[1].totalReplies).to.equal(0) - expect(res.body.data[2].text).to.equal('super thread 3') - expect(res.body.data[2].totalReplies).to.equal(0) + await command.delete({ videoId, commentId: threadId }) + + const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' }) + expect(body.total).to.equal(3) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(3) + + expect(body.data[0].text).to.equal('') + expect(body.data[0].isDeleted).to.be.true + expect(body.data[0].deletedAt).to.not.be.null + expect(body.data[0].account).to.be.null + expect(body.data[0].totalReplies).to.equal(2) + expect(body.data[1].text).to.equal('super thread 2') + expect(body.data[1].totalReplies).to.equal(0) + expect(body.data[2].text).to.equal('super thread 3') + expect(body.data[2].totalReplies).to.equal(0) }) it('Should count replies from the video author correctly', async function () { - const text = 'my super first comment' - await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) - let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) - const comment: VideoComment = res.body.data[0] - const threadId2 = comment.threadId + await command.createThread({ videoId: videoUUID, text: 'my super first comment' }) + + const { data } = await command.listThreads({ videoId: videoUUID }) + const threadId2 = data[0].threadId const text2 = 'a first answer to thread 4 by a third party' - await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2) + await command.addReply({ token: userAccessTokenServer1, videoId, toCommentId: threadId2, text: text2 }) const text3 = 'my second answer to thread 4' - await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3) + await command.addReply({ videoId, toCommentId: threadId2, text: text3 }) - res = await getVideoThreadComments(server.url, videoUUID, threadId2) - const tree: VideoCommentThreadTree = res.body + const tree = await command.getThread({ videoId: videoUUID, threadId: threadId2 }) expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1) }) }) describe('All instance comments', function () { - async function getComments (options: any = {}) { - const res = await getAdminVideoComments(Object.assign({ - url: server.url, - token: server.accessToken, - start: 0, - count: 10 - }, options)) - - return { comments: res.body.data as VideoCommentAdmin[], total: res.body.total as number } - } it('Should list instance comments as admin', async function () { - const { comments } = await getComments({ start: 0, count: 1 }) + const { data } = await command.listForAdmin({ start: 0, count: 1 }) - expect(comments[0].text).to.equal('my second answer to thread 4') + expect(data[0].text).to.equal('my second answer to thread 4') }) it('Should filter instance comments by isLocal', async function () { - const { total, comments } = await getComments({ isLocal: false }) + const { total, data } = await command.listForAdmin({ isLocal: false }) - expect(comments).to.have.lengthOf(0) + expect(data).to.have.lengthOf(0) expect(total).to.equal(0) }) it('Should search instance comments by account', async function () { - const { total, comments } = await getComments({ searchAccount: 'user' }) + const { total, data } = await command.listForAdmin({ searchAccount: 'user' }) - expect(comments).to.have.lengthOf(1) + expect(data).to.have.lengthOf(1) expect(total).to.equal(1) - expect(comments[0].text).to.equal('a first answer to thread 4 by a third party') + expect(data[0].text).to.equal('a first answer to thread 4 by a third party') }) it('Should search instance comments by video', async function () { { - const { total, comments } = await getComments({ searchVideo: 'video' }) + const { total, data } = await command.listForAdmin({ searchVideo: 'video' }) - expect(comments).to.have.lengthOf(7) + expect(data).to.have.lengthOf(7) expect(total).to.equal(7) } { - const { total, comments } = await getComments({ searchVideo: 'hello' }) + const { total, data } = await command.listForAdmin({ searchVideo: 'hello' }) - expect(comments).to.have.lengthOf(0) + expect(data).to.have.lengthOf(0) expect(total).to.equal(0) } }) it('Should search instance comments', async function () { - const { total, comments } = await getComments({ search: 'super thread 3' }) + const { total, data } = await command.listForAdmin({ search: 'super thread 3' }) - expect(comments).to.have.lengthOf(1) expect(total).to.equal(1) - expect(comments[0].text).to.equal('super thread 3') + + expect(data).to.have.lengthOf(1) + expect(data[0].text).to.equal('super thread 3') }) }) -- cgit v1.2.3 From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- server/tests/api/videos/video-channels.ts | 5 ++--- server/tests/api/videos/videos-history.ts | 4 ++-- server/tests/api/videos/videos-views-cleaner.ts | 20 ++++++++------------ 3 files changed, 12 insertions(+), 17 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index daf066eb1..e441ebbd4 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -9,7 +9,6 @@ import { createUser, doubleFollow, flushAndRunMultipleServers, - getActorImage, getVideo, getVideoChannelVideos, setDefaultVideoChannel, @@ -268,7 +267,7 @@ describe('Test video channels', function () { await testImage(server.url, 'avatar-resized', avatarPaths[server.port], '.png') await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true) - const row = await getActorImage(server.internalServerNumber, basename(avatarPaths[server.port])) + const row = await server.sqlCommand.getActorImage(basename(avatarPaths[server.port])) expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height) expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width) } @@ -294,7 +293,7 @@ describe('Test video channels', function () { await testImage(server.url, 'banner-resized', bannerPaths[server.port]) await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true) - const row = await getActorImage(server.internalServerNumber, basename(bannerPaths[server.port])) + const row = await server.sqlCommand.getActorImage(basename(bannerPaths[server.port])) expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height) expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width) } diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 731447135..9a7635c35 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -204,7 +204,7 @@ describe('Test videos history', function () { it('Should not clean old history', async function () { this.timeout(50000) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server, { history: { videos: { max_age: '10 days' } } }) @@ -219,7 +219,7 @@ describe('Test videos history', function () { it('Should clean old history', async function () { this.timeout(50000) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } }) diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index b89f33217..b6cde6b50 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -1,11 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { cleanupTests, - closeAllSequelize, - countVideoViewsOf, doubleFollow, flushAndRunMultipleServers, killallServers, @@ -50,7 +48,7 @@ describe('Test video views cleaner', function () { it('Should not clean old video views', async function () { this.timeout(50000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } }) @@ -60,14 +58,14 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1) + const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1) expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') } } { for (const server of servers) { - const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer2) + const total = await server.sqlCommand.countVideoViewsOf(videoIdServer2) expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') } } @@ -76,7 +74,7 @@ describe('Test video views cleaner', function () { it('Should clean old video views', async function () { this.timeout(50000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } }) @@ -86,23 +84,21 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1) + const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1) expect(total).to.equal(2) } } { - const totalServer1 = await countVideoViewsOf(servers[0].internalServerNumber, videoIdServer2) + const totalServer1 = await servers[0].sqlCommand.countVideoViewsOf(videoIdServer2) expect(totalServer1).to.equal(0) - const totalServer2 = await countVideoViewsOf(servers[1].internalServerNumber, videoIdServer2) + const totalServer2 = await servers[1].sqlCommand.countVideoViewsOf(videoIdServer2) expect(totalServer2).to.equal(2) } }) after(async function () { - await closeAllSequelize(servers) - await cleanupTests(servers) }) }) -- cgit v1.2.3 From dd0ebb715123dfa126a82d4e4fe3a04064ae77b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 16:23:01 +0200 Subject: Introduce notifications command --- server/tests/api/videos/video-hls.ts | 1 + server/tests/api/videos/video-nsfw.ts | 142 +++++++++++++++++----------------- 2 files changed, 71 insertions(+), 72 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 3dd8c9066..428e1316d 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -109,6 +109,7 @@ describe('Test HLS videos', function () { let videoAudioUUID = '' function runTestSuite (hlsOnly: boolean) { + it('Should upload a video and transcode it to HLS', async function () { this.timeout(120000) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 65813517d..5f30939cc 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -18,13 +18,13 @@ import { uploadVideo, userLogin } from '@shared/extra-utils' -import { BooleanBothQuery, CustomConfig, User, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' const expect = chai.expect function createOverviewRes (overview: VideosOverview) { const videos = overview.categories[0].videos - return { body: { data: videos, total: videos.length } } + return { data: videos, total: videos.length } } describe('Test video NSFW policy', function () { @@ -32,49 +32,47 @@ describe('Test video NSFW policy', function () { let userAccessToken: string let customConfig: CustomConfig - function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { - return getMyUserInformation(server.url, server.accessToken) - .then(res => { - const user: User = res.body - const videoChannelName = user.videoChannels[0].name - const accountName = user.account.name + '@' + user.account.host - const hasQuery = Object.keys(query).length !== 0 - let promises: Promise[] - - if (token) { - promises = [ - getVideosListWithToken(server.url, token, query), - server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), - getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), - getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) - ] - - // Overviews do not support video filters - if (!hasQuery) { - const p = server.overviewsCommand.getVideos({ page: 1, token }) - .then(res => createOverviewRes(res)) - promises.push(p) - } - - return Promise.all(promises) - } - - promises = [ - getVideosList(server.url), - server.searchCommand.searchVideos({ search: 'n' }), - getAccountVideos(server.url, undefined, accountName, 0, 5), - getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) - ] - - // Overviews do not support video filters - if (!hasQuery) { - const p = server.overviewsCommand.getVideos({ page: 1 }) - .then(res => createOverviewRes(res)) - promises.push(p) - } - - return Promise.all(promises) - }) + async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { + const res = await getMyUserInformation(server.url, server.accessToken) + const user: User = res.body + const videoChannelName = user.videoChannels[0].name + const accountName = user.account.name + '@' + user.account.host + const hasQuery = Object.keys(query).length !== 0 + let promises: Promise>[] + + if (token) { + promises = [ + getVideosListWithToken(server.url, token, query).then(res => res.body), + server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...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) + ] + + // Overviews do not support video filters + if (!hasQuery) { + const p = server.overviewsCommand.getVideos({ page: 1, token }) + .then(res => createOverviewRes(res)) + promises.push(p) + } + + return Promise.all(promises) + } + + promises = [ + getVideosList(server.url).then(res => res.body), + server.searchCommand.searchVideos({ search: 'n' }), + getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body), + getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body) + ] + + // Overviews do not support video filters + if (!hasQuery) { + const p = server.overviewsCommand.getVideos({ page: 1 }) + .then(res => createOverviewRes(res)) + promises.push(p) + } + + return Promise.all(promises) } before(async function () { @@ -102,10 +100,10 @@ describe('Test video NSFW policy', function () { const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') - for (const res of await getVideosFunctions()) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions()) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') @@ -119,10 +117,10 @@ describe('Test video NSFW policy', function () { const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') - for (const res of await getVideosFunctions()) { - expect(res.body.total).to.equal(1) + for (const body of await getVideosFunctions()) { + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('normal') } @@ -135,10 +133,10 @@ describe('Test video NSFW policy', function () { const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') - for (const res of await getVideosFunctions()) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions()) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') @@ -165,10 +163,10 @@ describe('Test video NSFW policy', function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) - for (const res of await getVideosFunctions(userAccessToken)) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions(userAccessToken)) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') @@ -182,10 +180,10 @@ describe('Test video NSFW policy', function () { nsfwPolicy: 'display' }) - for (const res of await getVideosFunctions(server.accessToken)) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions(server.accessToken)) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') @@ -199,10 +197,10 @@ describe('Test video NSFW policy', function () { nsfwPolicy: 'do_not_list' }) - for (const res of await getVideosFunctions(server.accessToken)) { - expect(res.body.total).to.equal(1) + for (const body of await getVideosFunctions(server.accessToken)) { + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('normal') } @@ -219,30 +217,30 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { - expect(res.body.total).to.equal(1) + for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('nsfw') } }) it('Should hide NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { - expect(res.body.total).to.equal(1) + for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('normal') } }) it('Should display both videos when the nsfw param === both', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') -- cgit v1.2.3 From 0d8ecb7592577f54012413a2b5a9b159cfc90399 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 08:33:02 +0200 Subject: Fix NSFW tests --- server/tests/api/videos/multiple-servers.ts | 1 + server/tests/api/videos/video-nsfw.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 2148d8e1c..1b6f0f48a 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -582,6 +582,7 @@ describe('Test multiple servers', function () { await waitJobs(servers) await wait(5000) + await waitJobs(servers) let baseVideos = null for (const server of servers) { diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 5f30939cc..c9c3792eb 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -43,7 +43,7 @@ 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', ...query } }), + 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) ] @@ -60,7 +60,7 @@ describe('Test video NSFW policy', function () { promises = [ getVideosList(server.url).then(res => res.body), - server.searchCommand.searchVideos({ search: 'n' }), + 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) ] -- cgit v1.2.3 From 6c5065a011b099618681a37bd77eaa7bd3db752e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 09:43:59 +0200 Subject: Introduce server commands --- server/tests/api/videos/audio-only.ts | 5 ++--- server/tests/api/videos/multiple-servers.ts | 4 ++-- server/tests/api/videos/resumable-upload.ts | 5 ++--- server/tests/api/videos/single-server.ts | 2 +- server/tests/api/videos/video-captions.ts | 2 +- server/tests/api/videos/video-imports.ts | 13 +++++++------ server/tests/api/videos/video-transcoder.ts | 22 ++++++++++------------ 7 files changed, 25 insertions(+), 28 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index 7ddbd5cd9..9b516af81 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' import { - buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -81,8 +80,8 @@ describe('Test audio only video transcoding', function () { it('0p transcoded video should not have video', async function () { const paths = [ - buildServerDirectory(servers[0], join('videos', videoUUID + '-0.mp4')), - buildServerDirectory(servers[0], join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) + servers[0].serversCommand.buildDirectory(join('videos', videoUUID + '-0.mp4')), + servers[0].serversCommand.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) ] for (const path of paths) { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 1b6f0f48a..1905aac83 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -689,8 +689,8 @@ describe('Test multiple servers', function () { it('Should not have files of videos 3 and 3-2 on each server', async function () { for (const server of servers) { - await checkVideoFilesWereRemoved(toRemove[0].uuid, server.internalServerNumber) - await checkVideoFilesWereRemoved(toRemove[1].uuid, server.internalServerNumber) + await checkVideoFilesWereRemoved(toRemove[0].uuid, server) + await checkVideoFilesWereRemoved(toRemove[1].uuid, server) } }) diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 6c01c7e78..5845efc86 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -7,7 +7,6 @@ import { join } from 'path' import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, - buildServerDirectory, cleanupTests, flushAndRunServer, getMyUserInformation, @@ -82,7 +81,7 @@ describe('Test resumable upload', function () { const uploadId = uploadIdArg.replace(/^upload_id=/, '') const subPath = join('tmp', 'resumable-uploads', uploadId) - const filePath = buildServerDirectory(server, subPath) + const filePath = server.serversCommand.buildDirectory(subPath) const exists = await pathExists(filePath) if (expectedSize === null) { @@ -97,7 +96,7 @@ describe('Test resumable upload', function () { async function countResumableUploads () { const subPath = join('tmp', 'resumable-uploads') - const filePath = buildServerDirectory(server, subPath) + const filePath = server.serversCommand.buildDirectory(subPath) const files = await readdir(filePath) return files.length diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 1058a1e9c..af1703e02 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -230,7 +230,7 @@ describe('Test a single server', function () { it('Should remove the video', async function () { await removeVideo(server.url, server.accessToken, videoId) - await checkVideoFilesWereRemoved(videoUUID, 1) + await checkVideoFilesWereRemoved(videoUUID, server) }) it('Should not have videos', async function () { diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 83ee809b8..d4a5385ab 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -182,7 +182,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 checkVideoFilesWereRemoved(videoUUID, 1) + await checkVideoFilesWereRemoved(videoUUID, servers[0]) }) after(async function () { diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 4f9ecbe8e..f6ae8cab1 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -11,7 +11,6 @@ import { getMyVideos, getVideo, getVideosList, - immutableAssign, ImportsCommand, ServerInfo, setAccessTokensToServers, @@ -119,7 +118,7 @@ describe('Test video imports', function () { } { - const attributes = immutableAssign(baseAttributes, { targetUrl: ImportsCommand.getYoutubeVideoUrl() }) + const attributes = { ...baseAttributes, targetUrl: ImportsCommand.getYoutubeVideoUrl() } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('small video - youtube') @@ -169,21 +168,23 @@ Ajouter un sous-titre est vraiment facile`) } { - const attributes = immutableAssign(baseAttributes, { + const attributes = { + ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI(), description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] - }) + } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('super peertube2 video') } { - const attributes = immutableAssign(baseAttributes, { + const attributes = { + ...baseAttributes, torrentfile: 'video-720p.torrent' as any, description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] - }) + } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('你好 世界 720p.mp4') } diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index e74fb5bef..f16b22bae 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -9,14 +9,12 @@ import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { buildAbsoluteFixturePath, - buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, getMyVideos, - getServerFileSize, getVideo, getVideoFileMetadataUrl, getVideosList, @@ -285,7 +283,7 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(4) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) if (probe.audioStream) { @@ -316,7 +314,7 @@ describe('Test video transcoding', function () { const videoDetails: VideoDetails = res2.body expect(videoDetails.files).to.have.lengthOf(4) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) expect(probe).to.not.have.property('audioStream') } @@ -344,7 +342,7 @@ describe('Test video transcoding', function () { const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const videoProbe = await getAudioStream(path) @@ -506,13 +504,13 @@ describe('Test video transcoding', function () { expect(videoDetails.files[3].fps).to.be.below(31) for (const resolution of [ '240', '360', '480' ]) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.below(31) } - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.above(58).and.below(62) @@ -547,13 +545,13 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(25) } { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(59) } @@ -590,7 +588,7 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) for (const resolution of [ '240', '360', '480', '720', '1080' ]) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) @@ -636,7 +634,7 @@ describe('Test video transcoding', function () { const resolutions = [ 240, 360, 480, 720, 1080 ] for (const r of resolutions) { const path = `videos/${videoUUID}-${r}.mp4` - const size = await getServerFileSize(servers[1], path) + const size = await servers[1].serversCommand.getServerFileSize(path) expect(size, `${path} not below ${60_000}`).to.be.below(60_000) } }) @@ -651,7 +649,7 @@ describe('Test video transcoding', function () { await waitJobs(servers) { - const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) const metadata = await getMetadataFromFile(path) // expected format properties -- cgit v1.2.3 From 41d1d075011174e73dccb74006181a92a618d7b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 11:05:15 +0200 Subject: Introduce login command --- server/tests/api/videos/multiple-servers.ts | 3 +-- server/tests/api/videos/video-change-ownership.ts | 11 +++++------ server/tests/api/videos/video-channels.ts | 3 +-- server/tests/api/videos/video-comments.ts | 3 +-- server/tests/api/videos/video-nsfw.ts | 5 ++--- server/tests/api/videos/video-playlists.ts | 6 ++---- server/tests/api/videos/video-privacy.ts | 23 ++++++++++++----------- server/tests/api/videos/videos-filter.ts | 11 +++++------ server/tests/api/videos/videos-history.ts | 3 +-- 9 files changed, 30 insertions(+), 38 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 1905aac83..740314bfd 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -24,7 +24,6 @@ import { testImage, updateVideo, uploadVideo, - userLogin, viewVideo, wait, waitJobs, @@ -155,7 +154,7 @@ describe('Test multiple servers', function () { password: 'super_password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - const userAccessToken = await userLogin(servers[1], user) + const userAccessToken = await servers[1].loginCommand.getAccessToken(user) const videoAttributes = { name: 'my super name for server 2', diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 1b81fe047..17c738e6f 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -16,8 +16,7 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, - userLogin + uploadVideo } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { User } from '../../../../shared/models/users' @@ -82,8 +81,8 @@ describe('Test video change ownership - nominal', function () { videoQuota: videoQuota }) - firstUserToken = await userLogin(servers[0], firstUser) - secondUserToken = await userLogin(servers[0], secondUser) + firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser) + secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser) { const res = await getMyUserInformation(servers[0].url, firstUserToken) @@ -323,8 +322,8 @@ describe('Test video change ownership - quota too small', function () { videoQuota: limitedVideoQuota }) - firstUserToken = await userLogin(server, firstUser) - secondUserToken = await userLogin(server, secondUser) + firstUserToken = await server.loginCommand.getAccessToken(firstUser) + secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server const video1Attributes = { diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index e441ebbd4..83645640c 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -16,7 +16,6 @@ import { testImage, updateVideo, uploadVideo, - userLogin, wait } from '../../../../shared/extra-utils' import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' @@ -391,7 +390,7 @@ describe('Test video channels', function () { { await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) - const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' }) + const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' }) const res = await getMyUserInformation(servers[0].url, accessToken) const videoChannel = res.body.videoChannels[0] diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 548d9fbf5..f9bd23646 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -8,7 +8,6 @@ import { createUser, dateIsValid, flushAndRunServer, - getAccessToken, ServerInfo, setAccessTokensToServers, testImage, @@ -52,7 +51,7 @@ describe('Test video comments', function () { username: 'user1', password: 'password' }) - userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') + userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password') command = server.commentsCommand }) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index c9c3792eb..a30b11ace 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -15,8 +15,7 @@ import { ServerInfo, setAccessTokensToServers, updateMyUser, - uploadVideo, - userLogin + uploadVideo } from '@shared/extra-utils' import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' @@ -151,7 +150,7 @@ describe('Test video NSFW policy', function () { const password = 'my super password' await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) - userAccessToken = await userLogin(server, { username, password }) + userAccessToken = await server.loginCommand.getAccessToken({ username, password }) const res = await getMyUserInformation(server.url, userAccessToken) const user = res.body diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 2bb019348..38133e2ce 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -10,7 +10,6 @@ import { doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, - getAccessToken, getMyUserInformation, PlaylistsCommand, removeUser, @@ -21,7 +20,6 @@ import { updateVideo, uploadVideo, uploadVideoAndGetId, - userLogin, wait, waitJobs } from '@shared/extra-utils' @@ -122,7 +120,7 @@ describe('Test video playlists', function () { username: 'user1', password: 'password' }) - userTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password') + userTokenServer1 = await servers[0].loginCommand.getAccessToken('user1', 'password') } await waitJobs(servers) @@ -1129,7 +1127,7 @@ describe('Test video playlists', function () { }) const userId = res.body.user.id - const userAccessToken = await userLogin(servers[0], user) + const userAccessToken = await servers[0].loginCommand.getAccessToken(user) const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) const userChannel = (resChannel.body as User).videoChannels[0] diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 950aeb7cf..f831dd8a9 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -2,23 +2,24 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { Video, VideoCreateResult } from '@shared/models' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, + createUser, + doubleFollow, flushAndRunServer, + getMyVideos, + getVideo, getVideosList, getVideosListWithToken, + getVideoWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { userLogin } from '../../../../shared/extra-utils/users/login' -import { createUser } from '../../../../shared/extra-utils/users/users' -import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' + updateVideo, + uploadVideo, + waitJobs +} from '@shared/extra-utils' +import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -126,7 +127,7 @@ describe('Test video privacy', function () { } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - anotherUserToken = await userLogin(servers[0], user) + anotherUserToken = await servers[0].loginCommand.getAccessToken(user) await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) }) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 7428b82c5..519dad646 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, createUser, @@ -10,12 +11,10 @@ import { makeGetRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, - userLogin + uploadVideo } from '../../../../shared/extra-utils' -import { Video, VideoPrivacy } from '../../../../shared/models/videos' import { UserRole } from '../../../../shared/models/users' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { Video, VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect @@ -72,7 +71,7 @@ describe('Test videos filter', function () { role: UserRole.MODERATOR } ) - server['moderatorAccessToken'] = await userLogin(server, moderator) + server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 9a7635c35..256271bd0 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -16,7 +16,6 @@ import { setAccessTokensToServers, updateMyUser, uploadVideo, - userLogin, wait } from '@shared/extra-utils' import { Video, VideoDetails } from '@shared/models' @@ -61,7 +60,7 @@ describe('Test videos history', function () { password: 'super password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) it('Should get videos, without watching history', async function () { -- cgit v1.2.3 From 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 14:23:01 +0200 Subject: Introduce user command --- server/tests/api/videos/multiple-servers.ts | 3 +- server/tests/api/videos/resumable-upload.ts | 17 ++--- server/tests/api/videos/video-change-ownership.ts | 89 ++++++----------------- server/tests/api/videos/video-channels.ts | 22 +++--- server/tests/api/videos/video-comments.ts | 16 +--- server/tests/api/videos/video-imports.ts | 9 +-- server/tests/api/videos/video-nsfw.ts | 26 ++----- server/tests/api/videos/video-playlists.ts | 34 ++------- server/tests/api/videos/video-privacy.ts | 3 +- server/tests/api/videos/videos-filter.ts | 13 +--- server/tests/api/videos/videos-history.ts | 12 +-- server/tests/api/videos/videos-overview.ts | 12 +-- 12 files changed, 63 insertions(+), 193 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 740314bfd..169bb2e23 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -10,7 +10,6 @@ import { checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, - createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, @@ -153,7 +152,7 @@ describe('Test multiple servers', function () { username: 'user1', password: 'super_password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + await servers[1].usersCommand.create({ username: user.username, password: user.password }) const userAccessToken = await servers[1].loginCommand.getAccessToken(user) const videoAttributes = { diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 5845efc86..642c115d0 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -9,15 +9,13 @@ import { buildAbsoluteFixturePath, cleanupTests, flushAndRunServer, - getMyUserInformation, prepareResumableUpload, sendResumableChunks, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - updateUser + setDefaultVideoChannel } from '@shared/extra-utils' -import { MyUser, VideoPrivacy } from '@shared/models' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -109,15 +107,10 @@ describe('Test resumable upload', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const res = await getMyUserInformation(server.url, server.accessToken) - rootId = (res.body as MyUser).id + const body = await server.usersCommand.getMyInfo() + rootId = body.id - await updateUser({ - url: server.url, - userId: rootId, - accessToken: server.accessToken, - videoQuota: 10_000_000 - }) + await server.usersCommand.update({ userId: rootId, videoQuota: 10_000_000 }) }) describe('Directory cleaning', function () { diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 17c738e6f..b0bbd5a0d 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -6,11 +6,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c import { ChangeOwnershipCommand, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, flushAndRunServer, - getMyUserInformation, getVideo, getVideosList, ServerInfo, @@ -19,21 +17,15 @@ import { uploadVideo } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { User } from '../../../../shared/models/users' import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect describe('Test video change ownership - nominal', function () { let servers: ServerInfo[] = [] - const firstUser = { - username: 'first', - password: 'My great password' - } - const secondUser = { - username: 'second', - password: 'My other password' - } + + const firstUser = 'first' + const secondUser = 'second' let firstUserToken = '' let firstUserChannelId: number @@ -65,35 +57,17 @@ describe('Test video change ownership - nominal', function () { } }) - const videoQuota = 42000000 - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: firstUser.username, - password: firstUser.password, - videoQuota: videoQuota - }) - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: secondUser.username, - password: secondUser.password, - videoQuota: videoQuota - }) - - firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser) - secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser) + firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser) + secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser) { - const res = await getMyUserInformation(servers[0].url, firstUserToken) - const firstUserInformation: User = res.body - firstUserChannelId = firstUserInformation.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken }) + firstUserChannelId = videoChannels[0].id } { - const res = await getMyUserInformation(servers[0].url, secondUserToken) - const secondUserInformation: User = res.body - secondUserChannelId = secondUserInformation.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken }) + secondUserChannelId = videoChannels[0].id } { @@ -140,7 +114,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -166,7 +140,7 @@ describe('Test video change ownership - nominal', function () { it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { @@ -194,7 +168,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should return two requests to change ownership for the second user', async function () { @@ -251,7 +225,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a live', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: liveId, username: secondUser }) const body = await command.list({ token: secondUserToken }) @@ -286,14 +260,9 @@ describe('Test video change ownership - nominal', function () { describe('Test video change ownership - quota too small', function () { let server: ServerInfo - const firstUser = { - username: 'first', - password: 'My great password' - } - const secondUser = { - username: 'second', - password: 'My other password' - } + const firstUser = 'first' + const secondUser = 'second' + let firstUserToken = '' let secondUserToken = '' let lastRequestId: number @@ -305,24 +274,9 @@ describe('Test video change ownership - quota too small', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - const videoQuota = 42000000 - const limitedVideoQuota = 10 - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: firstUser.username, - password: firstUser.password, - videoQuota: videoQuota - }) - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: secondUser.username, - password: secondUser.password, - videoQuota: limitedVideoQuota - }) + await server.usersCommand.create({ username: secondUser, videoQuota: 10 }) - firstUserToken = await server.loginCommand.getAccessToken(firstUser) + firstUserToken = await server.usersCommand.generateUserAndToken(firstUser) secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server @@ -345,7 +299,7 @@ describe('Test video change ownership - quota too small', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username }) + await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -371,9 +325,8 @@ describe('Test video change ownership - quota too small', function () { it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken) - const secondUserInformation: User = secondUserInformationResponse.body - const channelId = secondUserInformation.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken }) + const channelId = videoChannels[0].id await server.changeOwnershipCommand.accept({ token: secondUserToken, diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 83645640c..2e57cbbff 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -6,21 +6,22 @@ import { basename } from 'path' import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getVideo, getVideoChannelVideos, + ServerInfo, + setAccessTokensToServers, setDefaultVideoChannel, testFileExistsOrNot, testImage, updateVideo, uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' + viewVideo, + wait, + waitJobs +} from '@shared/extra-utils' +import { User, Video, VideoChannel, VideoDetails } from '@shared/models' const expect = chai.expect @@ -85,8 +86,7 @@ describe('Test video channels', function () { }) it('Should have two video channels when getting my information', async () => { - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - userInfo = res.body + userInfo = await servers[0].usersCommand.getMyInfo() expect(userInfo.videoChannels).to.be.an('array') expect(userInfo.videoChannels).to.have.lengthOf(2) @@ -389,11 +389,11 @@ describe('Test video channels', function () { } { - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) + await servers[0].usersCommand.create({ username: 'toto', password: 'password' }) const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' }) - const res = await getMyUserInformation(servers[0].url, accessToken) - const videoChannel = res.body.videoChannels[0] + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: accessToken }) + const videoChannel = videoChannels[0] expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) } }) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index f9bd23646..266824d58 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -5,13 +5,11 @@ import * as chai from 'chai' import { cleanupTests, CommentsCommand, - createUser, dateIsValid, flushAndRunServer, ServerInfo, setAccessTokensToServers, testImage, - updateMyAvatar, uploadVideo } from '@shared/extra-utils' @@ -39,19 +37,9 @@ describe('Test video comments', function () { videoUUID = res.body.video.uuid videoId = res.body.video.id - await updateMyAvatar({ - url: server.url, - accessToken: server.accessToken, - fixture: 'avatar.png' - }) + await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: 'user1', - password: 'password' - }) - userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password') + userAccessTokenServer1 = await server.usersCommand.generateUserAndToken('user1') command = server.commentsCommand }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index f6ae8cab1..052c052b4 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -7,7 +7,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyUserInformation, getMyVideos, getVideo, getVideosList, @@ -97,13 +96,13 @@ describe('Test video imports', function () { await setAccessTokensToServers(servers) { - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - channelIdServer1 = res.body.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo() + channelIdServer1 = videoChannels[0].id } { - const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) - channelIdServer2 = res.body.videoChannels[0].id + const { videoChannels } = await servers[1].usersCommand.getMyInfo() + channelIdServer2 = videoChannels[0].id } await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index a30b11ace..9dc26fca6 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -4,20 +4,17 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, flushAndRunServer, getAccountVideos, - getMyUserInformation, getMyVideos, getVideoChannelVideos, getVideosList, getVideosListWithToken, ServerInfo, setAccessTokensToServers, - updateMyUser, uploadVideo } from '@shared/extra-utils' -import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' const expect = chai.expect @@ -32,8 +29,7 @@ describe('Test video NSFW policy', function () { let customConfig: CustomConfig async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { - const res = await getMyUserInformation(server.url, server.accessToken) - const user: User = res.body + const user = await server.usersCommand.getMyInfo() const videoChannelName = user.videoChannels[0].name const accountName = user.account.name + '@' + user.account.host const hasQuery = Object.keys(query).length !== 0 @@ -148,13 +144,11 @@ describe('Test video NSFW policy', function () { it('Should create a user having the default nsfw policy', async function () { const username = 'user1' const password = 'my super password' - await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) + await server.usersCommand.create({ username: username, password: password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password }) - const res = await getMyUserInformation(server.url, userAccessToken) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: userAccessToken }) expect(user.nsfwPolicy).to.equal('blur') }) @@ -173,11 +167,7 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos with display user NSFW policy', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, - nsfwPolicy: 'display' - }) + await server.usersCommand.updateMe({ nsfwPolicy: 'display' }) for (const body of await getVideosFunctions(server.accessToken)) { expect(body.total).to.equal(2) @@ -190,11 +180,7 @@ describe('Test video NSFW policy', function () { }) it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, - nsfwPolicy: 'do_not_list' - }) + await server.usersCommand.updateMe({ nsfwPolicy: 'do_not_list' }) for (const body of await getVideosFunctions(server.accessToken)) { expect(body.total).to.equal(1) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 38133e2ce..e57d86c14 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -6,13 +6,9 @@ import { HttpStatusCode } from '@shared/core-utils' import { checkPlaylistFilesWereRemoved, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, - generateUserAccessToken, - getMyUserInformation, PlaylistsCommand, - removeUser, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -24,7 +20,6 @@ import { waitJobs } from '@shared/extra-utils' import { - User, VideoPlaylist, VideoPlaylistCreateResult, VideoPlaylistElementType, @@ -113,15 +108,7 @@ describe('Test video playlists', function () { nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id - { - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: 'user1', - password: 'password' - }) - userTokenServer1 = await servers[0].loginCommand.getAccessToken('user1', 'password') - } + userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1') await waitJobs(servers) }) @@ -165,7 +152,7 @@ describe('Test video playlists', function () { }) it('Should get private playlist for a classic user', async function () { - const token = await generateUserAccessToken(servers[0], 'toto') + const token = await servers[0].usersCommand.generateUserAndToken('toto') const body = await commands[0].listByAccount({ token, handle: 'toto' }) @@ -1118,19 +1105,10 @@ describe('Test video playlists', function () { it('Should delete an account and delete its playlists', async function () { this.timeout(30000) - const user = { username: 'user_1', password: 'password' } - const res = await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: user.username, - password: user.password - }) - - const userId = res.body.user.id - const userAccessToken = await servers[0].loginCommand.getAccessToken(user) + const { userId, token } = await servers[0].usersCommand.generate('user_1') - const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) - const userChannel = (resChannel.body as User).videoChannels[0] + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token }) + const userChannel = videoChannels[0] await commands[0].create({ attributes: { @@ -1152,7 +1130,7 @@ describe('Test video playlists', function () { } } - await removeUser(servers[0].url, userId, servers[0].accessToken) + await servers[0].usersCommand.remove({ userId }) await waitJobs(servers) { diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index f831dd8a9..4e349e350 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - createUser, doubleFollow, flushAndRunServer, getMyVideos, @@ -125,7 +124,7 @@ describe('Test video privacy', function () { username: 'hello', password: 'super password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) + 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) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 519dad646..4aa00cfc4 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, makeGetRequest, @@ -60,17 +59,7 @@ describe('Test videos filter', function () { for (const server of servers) { const moderator = { username: 'moderator', password: 'my super password' } - await createUser( - { - url: server.url, - accessToken: server.accessToken, - username: moderator.username, - password: moderator.password, - videoQuota: undefined, - videoQuotaDaily: undefined, - role: UserRole.MODERATOR - } - ) + 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 }) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 256271bd0..aa0623f7d 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - createUser, flushAndRunServer, getVideosListWithToken, getVideoWithToken, @@ -14,7 +13,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - updateMyUser, uploadVideo, wait } from '@shared/extra-utils' @@ -59,7 +57,7 @@ describe('Test videos history', function () { username: 'user_1', password: 'super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) @@ -174,9 +172,7 @@ describe('Test videos history', function () { }) it('Should disable videos history', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, + await server.usersCommand.updateMe({ videosHistoryEnabled: false }) @@ -184,9 +180,7 @@ describe('Test videos history', function () { }) it('Should re-enable videos history', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, + await server.usersCommand.updateMe({ videosHistoryEnabled: true }) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index ccbc6f4a4..a2da2eaef 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,15 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - flushAndRunServer, - generateUserAccessToken, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - wait -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils' import { VideosOverview } from '@shared/models' const expect = chai.expect @@ -112,7 +104,7 @@ describe('Test a videos overview', function () { }) it('Should hide muted accounts', async function () { - const token = await generateUserAccessToken(server, 'choco') + const token = await server.usersCommand.generateUserAndToken('choco') await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/api/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 +- server/tests/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 +-- .../tests/api/videos/video-playlist-thumbnails.ts | 5 +- server/tests/api/videos/video-playlists.ts | 19 +- server/tests/api/videos/video-privacy.ts | 146 ++++----- server/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 +- server/tests/api/videos/videos-views-cleaner.ts | 14 +- 21 files changed, 642 insertions(+), 830 deletions(-) (limited to 'server/tests/api/videos') 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) }) -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- server/tests/api/videos/audio-only.ts | 8 +- server/tests/api/videos/multiple-servers.ts | 168 +++++++++---------- server/tests/api/videos/resumable-upload.ts | 18 +- server/tests/api/videos/single-server.ts | 90 +++++----- server/tests/api/videos/video-captions.ts | 24 +-- server/tests/api/videos/video-change-ownership.ts | 50 +++--- server/tests/api/videos/video-channels.ts | 92 +++++------ server/tests/api/videos/video-comments.ts | 8 +- server/tests/api/videos/video-description.ts | 16 +- server/tests/api/videos/video-hls.ts | 22 +-- server/tests/api/videos/video-imports.ts | 44 ++--- server/tests/api/videos/video-nsfw.ts | 52 +++--- .../tests/api/videos/video-playlist-thumbnails.ts | 36 ++-- server/tests/api/videos/video-playlists.ts | 184 ++++++++++----------- server/tests/api/videos/video-privacy.ts | 56 +++---- server/tests/api/videos/video-schedule-update.ts | 20 +-- server/tests/api/videos/video-transcoder.ts | 122 +++++++------- server/tests/api/videos/videos-filter.ts | 10 +- server/tests/api/videos/videos-history.ts | 30 ++-- server/tests/api/videos/videos-overview.ts | 24 +-- server/tests/api/videos/videos-views-cleaner.ts | 22 +-- 21 files changed, 548 insertions(+), 548 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index e31905b36..b2952e38b 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -48,13 +48,13 @@ describe('Test audio only video transcoding', function () { it('Should upload a video and transcode it', async function () { this.timeout(120000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'audio only' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'audio only' } }) videoUUID = uuid await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) for (const files of [ video.files, video.streamingPlaylists[0].files ]) { @@ -68,8 +68,8 @@ describe('Test audio only video transcoding', function () { it('0p transcoded video should not have video', async function () { const paths = [ - servers[0].serversCommand.buildDirectory(join('videos', videoUUID + '-0.mp4')), - servers[0].serversCommand.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) + servers[0].servers.buildDirectory(join('videos', videoUUID + '-0.mp4')), + servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) ] for (const path of paths) { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 5c13ac629..89d842307 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -44,8 +44,8 @@ describe('Test multiple servers', function () { displayName: 'my channel', description: 'super channel' } - await servers[0].channelsCommand.create({ attributes: videoChannel }) - const { data } = await servers[0].channelsCommand.list({ start: 0, count: 1 }) + await servers[0].channels.create({ attributes: videoChannel }) + const { data } = await servers[0].channels.list({ start: 0, count: 1 }) videoChannelId = data[0].id } @@ -59,7 +59,7 @@ describe('Test multiple servers', function () { it('Should not have videos for all servers', async function () { for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(0) } @@ -82,7 +82,7 @@ describe('Test multiple servers', function () { channelId: videoChannelId, fixture: 'video_short1.webm' } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) @@ -125,7 +125,7 @@ describe('Test multiple servers', function () { ] } - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(1) const video = data[0] @@ -142,8 +142,8 @@ describe('Test multiple servers', function () { username: 'user1', password: 'super_password' } - await servers[1].usersCommand.create({ username: user.username, password: user.password }) - const userAccessToken = await servers[1].loginCommand.getAccessToken(user) + await servers[1].users.create({ username: user.username, password: user.password }) + const userAccessToken = await servers[1].login.getAccessToken(user) const attributes = { name: 'my super name for server 2', @@ -158,7 +158,7 @@ describe('Test multiple servers', function () { thumbnailfile: 'thumbnail.jpg', previewfile: 'preview.jpg' } - await servers[1].videosCommand.upload({ token: userAccessToken, attributes, mode: 'resumable' }) + await servers[1].videos.upload({ token: userAccessToken, attributes, mode: 'resumable' }) // Transcoding await waitJobs(servers) @@ -213,7 +213,7 @@ describe('Test multiple servers', function () { previewfile: 'preview' } - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(2) const video = data[1] @@ -237,7 +237,7 @@ describe('Test multiple servers', function () { tags: [ 'tag1p3' ], fixture: 'video_short3.webm' } - await servers[2].videosCommand.upload({ attributes }) + await servers[2].videos.upload({ attributes }) } { @@ -252,7 +252,7 @@ describe('Test multiple servers', function () { tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], fixture: 'video_short.webm' } - await servers[2].videosCommand.upload({ attributes }) + await servers[2].videos.upload({ attributes }) } await waitJobs(servers) @@ -260,7 +260,7 @@ describe('Test multiple servers', function () { // All servers should have this video for (const server of servers) { const isLocal = server.url === 'http://localhost:' + servers[2].port - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(4) @@ -349,7 +349,7 @@ describe('Test multiple servers', function () { describe('It should list local videos', function () { it('Should list only local videos on server 1', async function () { - const { data, total } = await servers[0].videosCommand.list({ filter: 'local' }) + const { data, total } = await servers[0].videos.list({ filter: 'local' }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -358,7 +358,7 @@ describe('Test multiple servers', function () { }) it('Should list only local videos on server 2', async function () { - const { data, total } = await servers[1].videosCommand.list({ filter: 'local' }) + const { data, total } = await servers[1].videos.list({ filter: 'local' }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -367,7 +367,7 @@ describe('Test multiple servers', function () { }) it('Should list only local videos on server 3', async function () { - const { data, total } = await servers[2].videosCommand.list({ filter: 'local' }) + const { data, total } = await servers[2].videos.list({ filter: 'local' }) expect(total).to.equal(2) expect(data).to.be.an('array') @@ -381,13 +381,13 @@ describe('Test multiple servers', function () { it('Should add the file 1 by asking server 3', async function () { this.timeout(10000) - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() const video = data[0] toRemove.push(data[2]) toRemove.push(data[3]) - const videoDetails = await servers[2].videosCommand.get({ id: video.id }) + const videoDetails = await servers[2].videos.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) @@ -397,10 +397,10 @@ describe('Test multiple servers', function () { it('Should add the file 2 by asking server 1', async function () { this.timeout(10000) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() const video = data[1] - const videoDetails = await servers[0].videosCommand.get({ id: video.id }) + const videoDetails = await servers[0].videos.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') @@ -411,10 +411,10 @@ describe('Test multiple servers', function () { it('Should add the file 3 by asking server 2', async function () { this.timeout(10000) - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() const video = data[2] - const videoDetails = await servers[1].videosCommand.get({ id: video.id }) + const videoDetails = await servers[1].videos.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') @@ -425,10 +425,10 @@ describe('Test multiple servers', function () { it('Should add the file 3-2 by asking server 1', async function () { this.timeout(10000) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() const video = data[3] - const videoDetails = await servers[0].videosCommand.get({ id: video.id }) + const videoDetails = await servers[0].videos.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) expect(torrent.files).to.be.an('array') @@ -439,10 +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 { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() const video = data.find(v => v.name === 'my super name for server 2') - const videoDetails = await servers[0].videosCommand.get({ id: video.id }) + const videoDetails = await servers[0].videos.get({ id: video.id }) const file = videoDetails.files.find(f => f.resolution.id === 360) expect(file).not.to.be.undefined @@ -462,17 +462,17 @@ describe('Test multiple servers', function () { before(async function () { { - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid) } { - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid) } { - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid) remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid) } @@ -481,16 +481,16 @@ describe('Test multiple servers', function () { it('Should view multiple videos on owned servers', async function () { this.timeout(30000) - await servers[2].videosCommand.view({ id: localVideosServer3[0] }) + await servers[2].videos.view({ id: localVideosServer3[0] }) await wait(1000) - await servers[2].videosCommand.view({ id: localVideosServer3[0] }) - await servers[2].videosCommand.view({ id: localVideosServer3[1] }) + await servers[2].videos.view({ id: localVideosServer3[0] }) + await servers[2].videos.view({ id: localVideosServer3[1] }) await wait(1000) - await servers[2].videosCommand.view({ id: localVideosServer3[0] }) - await servers[2].videosCommand.view({ id: localVideosServer3[0] }) + await servers[2].videos.view({ id: localVideosServer3[0] }) + await servers[2].videos.view({ id: localVideosServer3[0] }) await waitJobs(servers) @@ -500,7 +500,7 @@ describe('Test multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video0 = data.find(v => v.uuid === localVideosServer3[0]) const video1 = data.find(v => v.uuid === localVideosServer3[1]) @@ -514,16 +514,16 @@ describe('Test multiple servers', function () { this.timeout(45000) const tasks: Promise[] = [] - 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] })) + tasks.push(servers[0].videos.view({ id: remoteVideosServer1[0] })) + tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] })) + tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] })) + tasks.push(servers[2].videos.view({ id: remoteVideosServer3[0] })) + tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) await Promise.all(tasks) @@ -537,7 +537,7 @@ describe('Test multiple servers', function () { let baseVideos = null for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() // Initialize base videos for future comparisons if (baseVideos === null) { @@ -555,17 +555,17 @@ describe('Test multiple servers', function () { it('Should like and dislikes videos on different services', async function () { this.timeout(50000) - await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' }) + await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' }) await wait(500) - await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'dislike' }) + await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'dislike' }) await wait(500) - await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' }) - await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'like' }) + await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' }) + await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'like' }) await wait(500) - await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'dislike' }) - await servers[2].videosCommand.rate({ id: remoteVideosServer3[1], rating: 'dislike' }) + await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'dislike' }) + await servers[2].videos.rate({ id: remoteVideosServer3[1], rating: 'dislike' }) await wait(500) - await servers[2].videosCommand.rate({ id: remoteVideosServer3[0], rating: 'like' }) + await servers[2].videos.rate({ id: remoteVideosServer3[0], rating: 'like' }) await waitJobs(servers) await wait(5000) @@ -573,7 +573,7 @@ describe('Test multiple servers', function () { let baseVideos = null for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() // Initialize base videos for future comparisons if (baseVideos === null) { @@ -608,7 +608,7 @@ describe('Test multiple servers', function () { previewfile: 'preview.jpg' } - await servers[2].videosCommand.update({ id: toRemove[0].id, attributes }) + await servers[2].videos.update({ id: toRemove[0].id, attributes }) await waitJobs(servers) }) @@ -617,7 +617,7 @@ describe('Test multiple servers', function () { this.timeout(10000) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const videoUpdated = data.find(video => video.name === 'my super video updated') expect(!!videoUpdated).to.be.true @@ -665,8 +665,8 @@ describe('Test multiple servers', function () { it('Should remove the videos 3 and 3-2 by asking server 3', async function () { this.timeout(10000) - await servers[2].videosCommand.remove({ id: toRemove[0].id }) - await servers[2].videosCommand.remove({ id: toRemove[1].id }) + await servers[2].videos.remove({ id: toRemove[0].id }) + await servers[2].videos.remove({ id: toRemove[1].id }) await waitJobs(servers) }) @@ -680,7 +680,7 @@ describe('Test multiple servers', function () { it('Should have videos 1 and 3 on each server', async function () { for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(2) @@ -697,7 +697,7 @@ describe('Test multiple servers', function () { it('Should get the same video by UUID on each server', async function () { let baseVideo = null for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) if (baseVideo === null) { baseVideo = video @@ -720,7 +720,7 @@ describe('Test multiple servers', function () { it('Should get the preview from each server', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) await testImage(server.url, 'video_short1-preview.webm', video.previewPath) } @@ -735,36 +735,36 @@ describe('Test multiple servers', function () { { const text = 'my super first comment' - await servers[0].commentsCommand.createThread({ videoId: videoUUID, text }) + await servers[0].comments.createThread({ videoId: videoUUID, text }) } { const text = 'my super second comment' - await servers[2].commentsCommand.createThread({ videoId: videoUUID, text }) + await servers[2].comments.createThread({ videoId: videoUUID, text }) } await waitJobs(servers) { - const threadId = await servers[1].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) + const threadId = await servers[1].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) const text = 'my super answer to thread 1' - await servers[1].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text }) + await servers[1].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text }) } await waitJobs(servers) { - const threadId = await servers[2].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) + const threadId = await servers[2].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) - const body = await servers[2].commentsCommand.getThread({ videoId: videoUUID, threadId }) + const body = await servers[2].comments.getThread({ videoId: videoUUID, threadId }) const childCommentId = body.children[0].comment.id const text3 = 'my second answer to thread 1' - await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 }) + await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 }) const text2 = 'my super answer to answer of thread 1' - await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 }) + await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 }) } await waitJobs(servers) @@ -772,7 +772,7 @@ describe('Test multiple servers', function () { it('Should have these threads', async function () { for (const server of servers) { - const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const body = await server.comments.listThreads({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -804,10 +804,10 @@ describe('Test multiple servers', function () { it('Should have these comments', async function () { for (const server of servers) { - const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const body = await server.comments.listThreads({ videoId: videoUUID }) const threadId = body.data.find(c => c.text === 'my super first comment').id - const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId }) + const tree = await server.comments.getThread({ videoId: videoUUID, threadId }) expect(tree.comment.text).equal('my super first comment') expect(tree.comment.account.name).equal('root') @@ -837,17 +837,17 @@ describe('Test multiple servers', function () { it('Should delete a reply', async function () { this.timeout(10000) - await servers[2].commentsCommand.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id }) + await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id }) await waitJobs(servers) }) it('Should have this comment marked as deleted', async function () { for (const server of servers) { - const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const { data } = await server.comments.listThreads({ videoId: videoUUID }) const threadId = data.find(c => c.text === 'my super first comment').id - const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId }) + const tree = await server.comments.getThread({ videoId: videoUUID, threadId }) expect(tree.comment.text).equal('my super first comment') const firstChild = tree.children[0] @@ -868,16 +868,16 @@ describe('Test multiple servers', function () { it('Should delete the thread comments', async function () { this.timeout(10000) - const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID }) + const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) const commentId = data.find(c => c.text === 'my super first comment').id - await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId }) + await servers[0].comments.delete({ videoId: videoUUID, commentId }) await waitJobs(servers) }) it('Should have the threads marked as deleted on other servers too', async function () { for (const server of servers) { - const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const body = await server.comments.listThreads({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -913,16 +913,16 @@ describe('Test multiple servers', function () { it('Should delete a remote thread by the origin server', async function () { this.timeout(5000) - const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID }) + const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) const commentId = data.find(c => c.text === 'my super second comment').id - await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId }) + await servers[0].comments.delete({ videoId: videoUUID, commentId }) await waitJobs(servers) }) it('Should have the threads marked as deleted on other servers too', async function () { for (const server of servers) { - const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const body = await server.comments.listThreads({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -957,17 +957,17 @@ describe('Test multiple servers', function () { downloadEnabled: false } - await servers[0].videosCommand.update({ id: videoUUID, attributes }) + await servers[0].videos.update({ id: videoUUID, attributes }) await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.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 }) + await server.comments.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) } }) }) @@ -992,7 +992,7 @@ describe('Test multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === 'minimum parameters') const isLocal = server.url === 'http://localhost:' + servers[1].port diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index b7756a4a8..2f1cf8a55 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -36,14 +36,14 @@ describe('Test resumable upload', function () { const attributes = { name: 'video', - channelId: server.videoChannel.id, + channelId: server.store.channel.id, privacy: VideoPrivacy.PUBLIC, fixture: defaultFixture } const mimetype = 'video/mp4' - const res = await server.videosCommand.prepareResumableUpload({ attributes, size, mimetype }) + const res = await server.videos.prepareResumableUpload({ attributes, size, mimetype }) return res.header['location'].split('?')[1] } @@ -61,7 +61,7 @@ describe('Test resumable upload', function () { const size = await buildSize(defaultFixture, options.size) const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture) - return server.videosCommand.sendResumableChunks({ + return server.videos.sendResumableChunks({ pathUploadId, videoFilePath: absoluteFilePath, size, @@ -75,7 +75,7 @@ describe('Test resumable upload', function () { const uploadId = uploadIdArg.replace(/^upload_id=/, '') const subPath = join('tmp', 'resumable-uploads', uploadId) - const filePath = server.serversCommand.buildDirectory(subPath) + const filePath = server.servers.buildDirectory(subPath) const exists = await pathExists(filePath) if (expectedSize === null) { @@ -90,7 +90,7 @@ describe('Test resumable upload', function () { async function countResumableUploads () { const subPath = join('tmp', 'resumable-uploads') - const filePath = server.serversCommand.buildDirectory(subPath) + const filePath = server.servers.buildDirectory(subPath) const files = await readdir(filePath) return files.length @@ -103,10 +103,10 @@ describe('Test resumable upload', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const body = await server.usersCommand.getMyInfo() + const body = await server.users.getMyInfo() rootId = body.id - await server.usersCommand.update({ userId: rootId, videoQuota: 10_000_000 }) + await server.users.update({ userId: rootId, videoQuota: 10_000_000 }) }) describe('Directory cleaning', function () { @@ -125,13 +125,13 @@ describe('Test resumable upload', function () { }) it('Should not delete recent uploads', async function () { - await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) + await server.debug.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) expect(await countResumableUploads()).to.equal(2) }) it('Should delete old uploads', async function () { - await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) + await server.debug.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) expect(await countResumableUploads()).to.equal(0) }) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index da0b2011e..12c1f7b2f 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -100,35 +100,35 @@ describe('Test a single server', function () { }) it('Should list video categories', async function () { - const categories = await server.videosCommand.getCategories() + const categories = await server.videos.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 licences = await server.videosCommand.getLicences() + const licences = await server.videos.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 languages = await server.videosCommand.getLanguages() + const languages = await server.videos.getLanguages() expect(Object.keys(languages)).to.have.length.above(5) expect(languages['ru']).to.equal('Russian') }) it('Should list video privacies', async function () { - const privacies = await server.videosCommand.getPrivacies() + const privacies = await server.videos.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 { data, total } = await server.videosCommand.list() + const { data, total } = await server.videos.list() expect(total).to.equal(0) expect(data).to.be.an('array') @@ -145,7 +145,7 @@ describe('Test a single server', function () { licence: 6, tags: [ 'tag1', 'tag2', 'tag3' ] } - const video = await server.videosCommand.upload({ attributes, mode }) + const video = await server.videos.upload({ attributes, mode }) expect(video).to.not.be.undefined expect(video.id).to.equal(1) expect(video.uuid).to.have.length.above(5) @@ -157,7 +157,7 @@ describe('Test a single server', function () { it('Should get and seed the uploaded video', async function () { this.timeout(5000) - const { data, total } = await server.videosCommand.list() + const { data, total } = await server.videos.list() expect(total).to.equal(1) expect(data).to.be.an('array') @@ -170,42 +170,42 @@ describe('Test a single server', function () { it('Should get the video by UUID', async function () { this.timeout(5000) - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) await completeVideoCheck(server, video, getCheckAttributes()) }) it('Should have the views updated', async function () { this.timeout(20000) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) await wait(1500) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) await wait(1500) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) // Wait the repeatable job await wait(8000) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.views).to.equal(3) }) it('Should remove the video', async function () { - await server.videosCommand.remove({ id: videoId }) + await server.videos.remove({ id: videoId }) await checkVideoFilesWereRemoved(videoUUID, server) }) it('Should not have videos', async function () { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(0) expect(data).to.be.an('array') @@ -232,12 +232,12 @@ describe('Test a single server', function () { fixture: video } - await server.videosCommand.upload({ attributes, mode }) + await server.videos.upload({ attributes, mode }) } }) it('Should have the correct durations', async function () { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(6) expect(data).to.be.an('array') @@ -255,7 +255,7 @@ describe('Test a single server', function () { }) it('Should have the correct thumbnails', async function () { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() // For the next test videosListBase = data @@ -267,7 +267,7 @@ describe('Test a single server', function () { }) it('Should list only the two first videos', async function () { - const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: 'name' }) + const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' }) expect(total).to.equal(6) expect(data.length).to.equal(2) @@ -276,7 +276,7 @@ describe('Test a single server', function () { }) it('Should list only the next three videos', async function () { - const { total, data } = await server.videosCommand.list({ start: 2, count: 3, sort: 'name' }) + const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' }) expect(total).to.equal(6) expect(data.length).to.equal(3) @@ -286,7 +286,7 @@ describe('Test a single server', function () { }) it('Should list the last video', async function () { - const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name' }) + const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' }) expect(total).to.equal(6) expect(data.length).to.equal(1) @@ -294,7 +294,7 @@ describe('Test a single server', function () { }) it('Should not have the total field', async function () { - const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name', skipCount: true }) + const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true }) expect(total).to.not.exist expect(data.length).to.equal(1) @@ -302,7 +302,7 @@ describe('Test a single server', function () { }) it('Should list and sort by name in descending order', async function () { - const { total, data } = await server.videosCommand.list({ sort: '-name' }) + const { total, data } = await server.videos.list({ sort: '-name' }) expect(total).to.equal(6) expect(data.length).to.equal(6) @@ -318,21 +318,21 @@ describe('Test a single server', function () { }) it('Should list and sort by trending in descending order', async function () { - const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-trending' }) + const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' }) expect(total).to.equal(6) expect(data.length).to.equal(2) }) it('Should list and sort by hotness in descending order', async function () { - const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-hot' }) + const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' }) expect(total).to.equal(6) expect(data.length).to.equal(2) }) it('Should list and sort by best in descending order', async function () { - const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-best' }) + const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' }) expect(total).to.equal(6) expect(data.length).to.equal(2) @@ -350,18 +350,18 @@ describe('Test a single server', function () { downloadEnabled: false, tags: [ 'tagup1', 'tagup2' ] } - await server.videosCommand.update({ id: videoId, attributes }) + await server.videos.update({ id: videoId, attributes }) }) it('Should filter by tags and category', async function () { { - const { data, total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) + const { data, total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) expect(total).to.equal(1) expect(data[0].name).to.equal('my super video updated') } { - const { total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) + const { total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) expect(total).to.equal(0) } }) @@ -369,7 +369,7 @@ describe('Test a single server', function () { it('Should have the video updated', async function () { this.timeout(60000) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) await completeVideoCheck(server, video, updateCheckAttributes()) }) @@ -378,9 +378,9 @@ describe('Test a single server', function () { const attributes = { tags: [ 'supertag', 'tag1', 'tag2' ] } - await server.videosCommand.update({ id: videoId, attributes }) + await server.videos.update({ id: videoId, attributes }) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes)) }) @@ -389,27 +389,27 @@ describe('Test a single server', function () { const attributes = { description: 'hello everybody' } - await server.videosCommand.update({ id: videoId, attributes }) + await server.videos.update({ id: videoId, attributes }) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) await completeVideoCheck(server, video, expectedAttributes) }) it('Should like a video', async function () { - await server.videosCommand.rate({ id: videoId, rating: 'like' }) + await server.videos.rate({ id: videoId, rating: 'like' }) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.likes).to.equal(1) expect(video.dislikes).to.equal(0) }) it('Should dislike the same video', async function () { - await server.videosCommand.rate({ id: videoId, rating: 'dislike' }) + await server.videos.rate({ id: videoId, rating: 'dislike' }) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(1) @@ -419,9 +419,9 @@ describe('Test a single server', function () { { const now = new Date() const attributes = { originallyPublishedAt: now.toISOString() } - await server.videosCommand.update({ id: videoId, attributes }) + await server.videos.update({ id: videoId, attributes }) - const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' }) + const { data } = await server.videos.list({ sort: '-originallyPublishedAt' }) const names = data.map(v => v.name) expect(names[0]).to.equal('my super video updated') @@ -435,9 +435,9 @@ describe('Test a single server', function () { { const now = new Date() const attributes = { originallyPublishedAt: now.toISOString() } - await server.videosCommand.update({ id: videoId2, attributes }) + await server.videos.update({ id: videoId2, attributes }) - const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' }) + const { data } = await server.videos.list({ sort: '-originallyPublishedAt' }) const names = data.map(v => v.name) expect(names[0]).to.equal('video_short1.webm name') diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 4c67e96f7..abc07194d 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -32,7 +32,7 @@ describe('Test video captions', function () { await waitJobs(servers) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'my video name' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video name' } }) videoUUID = uuid await waitJobs(servers) @@ -40,7 +40,7 @@ describe('Test video captions', function () { it('Should list the captions and return an empty list', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(0) expect(body.data).to.have.lengthOf(0) } @@ -49,13 +49,13 @@ describe('Test video captions', function () { it('Should create two new captions', async function () { this.timeout(30000) - await servers[0].captionsCommand.createVideoCaption({ + await servers[0].captions.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good1.vtt' }) - await servers[0].captionsCommand.createVideoCaption({ + await servers[0].captions.createVideoCaption({ language: 'zh', videoId: videoUUID, fixture: 'subtitle-good2.vtt', @@ -67,7 +67,7 @@ describe('Test video captions', function () { it('Should list these uploaded captions', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -88,7 +88,7 @@ describe('Test video captions', function () { it('Should replace an existing caption', async function () { this.timeout(30000) - await servers[0].captionsCommand.createVideoCaption({ + await servers[0].captions.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good2.vtt' @@ -99,7 +99,7 @@ describe('Test video captions', function () { it('Should have this caption updated', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -114,7 +114,7 @@ describe('Test video captions', function () { it('Should replace an existing caption with a srt file and convert it', async function () { this.timeout(30000) - await servers[0].captionsCommand.createVideoCaption({ + await servers[0].captions.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good.srt' @@ -128,7 +128,7 @@ describe('Test video captions', function () { it('Should have this caption updated and converted', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -157,14 +157,14 @@ describe('Test video captions', function () { it('Should remove one caption', async function () { this.timeout(30000) - await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) + await servers[0].captions.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) await waitJobs(servers) }) it('Should only list the caption that was not deleted', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) @@ -178,7 +178,7 @@ describe('Test video captions', function () { }) it('Should remove the video, and thus all video captions', async function () { - await servers[0].videosCommand.remove({ id: videoUUID }) + await servers[0].videos.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 b85edd920..352eb5ea3 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -43,7 +43,7 @@ describe('Test video change ownership - nominal', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: false @@ -54,16 +54,16 @@ describe('Test video change ownership - nominal', function () { } }) - firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser) - secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser) + firstUserToken = await servers[0].users.generateUserAndToken(firstUser) + secondUserToken = await servers[0].users.generateUserAndToken(secondUser) { - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: firstUserToken }) firstUserChannelId = videoChannels[0].id } { - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: secondUserToken }) secondUserChannelId = videoChannels[0].id } @@ -72,19 +72,19 @@ describe('Test video change ownership - nominal', function () { name: 'my super name', description: 'my super description' } - const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes }) + const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes }) - servers[0].video = await servers[0].videosCommand.get({ id }) + servers[0].store.video = await servers[0].videos.get({ id }) } { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes }) + const video = await servers[0].live.create({ token: firstUserToken, fields: attributes }) liveId = video.id } - command = servers[0].changeOwnershipCommand + command = servers[0].changeOwnership await doubleFollow(servers[0], servers[1]) }) @@ -110,7 +110,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -136,7 +136,7 @@ describe('Test video change ownership - nominal', function () { it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { @@ -164,7 +164,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should return two requests to change ownership for the second user', async function () { @@ -208,7 +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 video = await server.videosCommand.get({ id: servers[0].video.uuid }) + const video = await server.videos.get({ id: servers[0].store.video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -237,7 +237,7 @@ describe('Test video change ownership - nominal', function () { await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: servers[0].video.uuid }) + const video = await server.videos.get({ id: servers[0].store.video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -266,35 +266,35 @@ describe('Test video change ownership - quota too small', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await server.usersCommand.create({ username: secondUser, videoQuota: 10 }) + await server.users.create({ username: secondUser, videoQuota: 10 }) - firstUserToken = await server.usersCommand.generateUserAndToken(firstUser) - secondUserToken = await server.loginCommand.getAccessToken(secondUser) + firstUserToken = await server.users.generateUserAndToken(firstUser) + secondUserToken = await server.login.getAccessToken(secondUser) // Upload some videos on the server const attributes = { name: 'my super name', description: 'my super description' } - await server.videosCommand.upload({ token: firstUserToken, attributes }) + await server.videos.upload({ token: firstUserToken, attributes }) await waitJobs(server) - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.length).to.equal(1) - server.video = data.find(video => video.name === 'my super name') + server.store.video = data.find(video => video.name === 'my super name') }) it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser }) + await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { { - const body = await server.changeOwnershipCommand.list({ token: firstUserToken }) + const body = await server.changeOwnership.list({ token: firstUserToken }) expect(body.total).to.equal(0) expect(body.data).to.be.an('array') @@ -302,7 +302,7 @@ describe('Test video change ownership - quota too small', function () { } { - const body = await server.changeOwnershipCommand.list({ token: secondUserToken }) + const body = await server.changeOwnership.list({ token: secondUserToken }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -315,10 +315,10 @@ describe('Test video change ownership - quota too small', function () { it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken }) + const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken }) const channelId = videoChannels[0].id - await server.changeOwnershipCommand.accept({ + await server.changeOwnership.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId, diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 170cc942e..1efef932c 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -21,7 +21,7 @@ import { User, VideoChannel } from '@shared/models' const expect = chai.expect async function findChannel (server: ServerInfo, channelId: number) { - const body = await server.channelsCommand.list({ sort: '-name' }) + const body = await server.channels.list({ sort: '-name' }) return body.data.find(c => c.id === channelId) } @@ -49,7 +49,7 @@ describe('Test video channels', function () { }) it('Should have one video channel (created with root)', async () => { - const body = await servers[0].channelsCommand.list({ start: 0, count: 2 }) + const body = await servers[0].channels.list({ start: 0, count: 2 }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -66,14 +66,14 @@ describe('Test video channels', function () { description: 'super video channel description', support: 'super video channel support text' } - const created = await servers[0].channelsCommand.create({ attributes: videoChannel }) + const created = await servers[0].channels.create({ attributes: videoChannel }) secondVideoChannelId = created.id } // The channel is 1 is propagated to servers 2 { const attributes = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } - const { uuid } = await servers[0].videosCommand.upload({ attributes }) + const { uuid } = await servers[0].videos.upload({ attributes }) videoUUID = uuid } @@ -81,7 +81,7 @@ describe('Test video channels', function () { }) it('Should have two video channels when getting my information', async () => { - userInfo = await servers[0].usersCommand.getMyInfo() + userInfo = await servers[0].users.getMyInfo() expect(userInfo.videoChannels).to.be.an('array') expect(userInfo.videoChannels).to.have.lengthOf(2) @@ -99,7 +99,7 @@ describe('Test video channels', function () { }) it('Should have two video channels when getting account channels on server 1', async function () { - const body = await servers[0].channelsCommand.listByAccount({ accountName }) + const body = await servers[0].channels.listByAccount({ accountName }) expect(body.total).to.equal(2) const videoChannels = body.data @@ -118,7 +118,7 @@ describe('Test video channels', function () { it('Should paginate and sort account channels', async function () { { - const body = await servers[0].channelsCommand.listByAccount({ + const body = await servers[0].channels.listByAccount({ accountName, start: 0, count: 1, @@ -133,7 +133,7 @@ describe('Test video channels', function () { } { - const body = await servers[0].channelsCommand.listByAccount({ + const body = await servers[0].channels.listByAccount({ accountName, start: 0, count: 1, @@ -146,7 +146,7 @@ describe('Test video channels', function () { } { - const body = await servers[0].channelsCommand.listByAccount({ + const body = await servers[0].channels.listByAccount({ accountName, start: 1, count: 1, @@ -160,7 +160,7 @@ describe('Test video channels', function () { }) it('Should have one video channel when getting account channels on server 2', async function () { - const body = await servers[1].channelsCommand.listByAccount({ accountName }) + const body = await servers[1].channels.listByAccount({ accountName }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -174,7 +174,7 @@ describe('Test video channels', function () { }) it('Should list video channels', async function () { - const body = await servers[0].channelsCommand.list({ start: 1, count: 1, sort: '-name' }) + const body = await servers[0].channels.list({ start: 1, count: 1, sort: '-name' }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -192,14 +192,14 @@ describe('Test video channels', function () { support: 'support updated' } - await servers[0].channelsCommand.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) + await servers[0].channels.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) await waitJobs(servers) }) it('Should have video channel updated', async function () { for (const server of servers) { - const body = await server.channelsCommand.list({ start: 0, count: 1, sort: '-name' }) + const body = await server.channels.list({ start: 0, count: 1, sort: '-name' }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -214,7 +214,7 @@ describe('Test video channels', function () { it('Should not have updated the video support field', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.support).to.equal('video support field') } }) @@ -227,12 +227,12 @@ describe('Test video channels', function () { bulkVideosSupportUpdate: true } - await servers[0].channelsCommand.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) + await servers[0].channels.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.support).to.equal(videoChannelAttributes.support) } }) @@ -242,7 +242,7 @@ describe('Test video channels', function () { const fixture = 'avatar.png' - await servers[0].channelsCommand.updateImage({ + await servers[0].channels.updateImage({ channelName: 'second_video_channel', fixture, type: 'avatar' @@ -257,7 +257,7 @@ describe('Test video channels', function () { await testImage(server.url, 'avatar-resized', avatarPaths[server.port], '.png') await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true) - const row = await server.sqlCommand.getActorImage(basename(avatarPaths[server.port])) + const row = await server.sql.getActorImage(basename(avatarPaths[server.port])) expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height) expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width) } @@ -268,7 +268,7 @@ describe('Test video channels', function () { const fixture = 'banner.jpg' - await servers[0].channelsCommand.updateImage({ + await servers[0].channels.updateImage({ channelName: 'second_video_channel', fixture, type: 'banner' @@ -277,13 +277,13 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const videoChannel = await server.channelsCommand.get({ channelName: 'second_video_channel@' + servers[0].host }) + const videoChannel = await server.channels.get({ channelName: 'second_video_channel@' + servers[0].host }) bannerPaths[server.port] = videoChannel.banner.path await testImage(server.url, 'banner-resized', bannerPaths[server.port]) await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true) - const row = await server.sqlCommand.getActorImage(basename(bannerPaths[server.port])) + const row = await server.sql.getActorImage(basename(bannerPaths[server.port])) expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height) expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width) } @@ -292,7 +292,7 @@ describe('Test video channels', function () { it('Should delete the video channel avatar', async function () { this.timeout(15000) - await servers[0].channelsCommand.deleteImage({ channelName: 'second_video_channel', type: 'avatar' }) + await servers[0].channels.deleteImage({ channelName: 'second_video_channel', type: 'avatar' }) await waitJobs(servers) @@ -307,7 +307,7 @@ describe('Test video channels', function () { it('Should delete the video channel banner', async function () { this.timeout(15000) - await servers[0].channelsCommand.deleteImage({ channelName: 'second_video_channel', type: 'banner' }) + await servers[0].channels.deleteImage({ channelName: 'second_video_channel', type: 'banner' }) await waitJobs(servers) @@ -324,7 +324,7 @@ describe('Test video channels', function () { for (const server of servers) { const channelURI = 'second_video_channel@localhost:' + servers[0].port - const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI }) + const { total, data } = await server.videos.listByChannel({ videoChannelName: channelURI }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -336,7 +336,7 @@ describe('Test video channels', function () { it('Should change the video channel of a video', async function () { this.timeout(10000) - await servers[0].videosCommand.update({ id: videoUUID, attributes: { channelId: servers[0].videoChannel.id } }) + await servers[0].videos.update({ id: videoUUID, attributes: { channelId: servers[0].store.channel.id } }) await waitJobs(servers) }) @@ -347,13 +347,13 @@ describe('Test video channels', function () { for (const server of servers) { { const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port - const { total } = await server.videosCommand.listByChannel({ videoChannelName: secondChannelURI }) + const { total } = await server.videos.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 }) + const { total, data } = await server.videos.listByChannel({ videoChannelName: channelURI }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -364,11 +364,11 @@ describe('Test video channels', function () { }) it('Should delete video channel', async function () { - await servers[0].channelsCommand.delete({ channelName: 'second_video_channel' }) + await servers[0].channels.delete({ channelName: 'second_video_channel' }) }) it('Should have video channel deleted', async function () { - const body = await servers[0].channelsCommand.list({ start: 0, count: 10 }) + const body = await servers[0].channels.list({ start: 0, count: 10 }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -379,15 +379,15 @@ describe('Test video channels', function () { it('Should create the main channel with an uuid if there is a conflict', async function () { { const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } - const created = await servers[0].channelsCommand.create({ attributes: videoChannel }) + const created = await servers[0].channels.create({ attributes: videoChannel }) totoChannel = created.id } { - await servers[0].usersCommand.create({ username: 'toto', password: 'password' }) - const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' }) + await servers[0].users.create({ username: 'toto', password: 'password' }) + const accessToken = await servers[0].login.getAccessToken({ username: 'toto', password: 'password' }) - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: accessToken }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: accessToken }) const videoChannel = videoChannels[0] expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) } @@ -397,7 +397,7 @@ describe('Test video channels', function () { this.timeout(10000) { - const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) + const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true }) for (const channel of data) { expect(channel).to.haveOwnProperty('viewsPerDay') @@ -411,21 +411,21 @@ describe('Test video channels', function () { } { - // video has been posted on channel servers[0].videoChannel.id since last update - 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' }) + // video has been posted on channel servers[0].store.videoChannel.id since last update + await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' }) + await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) - const channelWithView = data.find(channel => channel.id === servers[0].videoChannel.id) + const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true }) + const channelWithView = data.find(channel => channel.id === servers[0].store.channel.id) expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) } }) it('Should report correct videos count', async function () { - const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) + const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true }) const totoChannel = data.find(c => c.name === 'toto_channel') const rootChannel = data.find(c => c.name === 'root_channel') @@ -436,7 +436,7 @@ describe('Test video channels', function () { it('Should search among account video channels', async function () { { - const body = await servers[0].channelsCommand.listByAccount({ accountName, search: 'root' }) + const body = await servers[0].channels.listByAccount({ accountName, search: 'root' }) expect(body.total).to.equal(1) const channels = body.data @@ -444,7 +444,7 @@ describe('Test video channels', function () { } { - const body = await servers[0].channelsCommand.listByAccount({ accountName, search: 'does not exist' }) + const body = await servers[0].channels.listByAccount({ accountName, search: 'does not exist' }) expect(body.total).to.equal(0) const channels = body.data @@ -455,21 +455,21 @@ describe('Test video channels', function () { it('Should list channels by updatedAt desc if a video has been uploaded', async function () { this.timeout(30000) - await servers[0].videosCommand.upload({ attributes: { channelId: totoChannel } }) + await servers[0].videos.upload({ attributes: { channelId: totoChannel } }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.channelsCommand.listByAccount({ accountName, sort: '-updatedAt' }) + const { data } = await server.channels.listByAccount({ accountName, sort: '-updatedAt' }) expect(data[0].name).to.equal('toto_channel') expect(data[1].name).to.equal('root_channel') } - await servers[0].videosCommand.upload({ attributes: { channelId: servers[0].videoChannel.id } }) + await servers[0].videos.upload({ attributes: { channelId: servers[0].store.channel.id } }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.channelsCommand.listByAccount({ accountName, sort: '-updatedAt' }) + const { data } = await server.channels.listByAccount({ accountName, sort: '-updatedAt' }) expect(data[0].name).to.equal('root_channel') expect(data[1].name).to.equal('toto_channel') diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 41be54c81..adb59bd74 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -32,15 +32,15 @@ describe('Test video comments', function () { await setAccessTokensToServers([ server ]) - const { id, uuid } = await server.videosCommand.upload() + const { id, uuid } = await server.videos.upload() videoUUID = uuid videoId = id - await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) + await server.users.updateMyAvatar({ fixture: 'avatar.png' }) - userAccessTokenServer1 = await server.usersCommand.generateUserAndToken('user1') + userAccessTokenServer1 = await server.users.generateUserAndToken('user1') - command = server.commentsCommand + command = server.comments }) describe('User comments', function () { diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index 6ac9206f5..b89247288 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -31,11 +31,11 @@ describe('Test video description', function () { const attributes = { description: longDescription } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() videoId = data[0].id videoUUID = data[0].uuid @@ -43,7 +43,7 @@ describe('Test video description', function () { it('Should have a truncated description on each server', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) // 30 characters * 6 -> 240 characters const truncatedDescription = 'my super description for server 1'.repeat(7) + @@ -55,9 +55,9 @@ describe('Test video description', function () { it('Should fetch long description on each server', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) - const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath }) + const { description } = await server.videos.getDescription({ descriptionPath: video.descriptionPath }) expect(description).to.equal(longDescription) } }) @@ -68,18 +68,18 @@ describe('Test video description', function () { const attributes = { description: 'short description' } - await servers[0].videosCommand.update({ id: videoId, attributes }) + await servers[0].videos.update({ id: videoId, attributes }) await waitJobs(servers) }) it('Should have a small description on each server', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.description).to.equal('short description') - const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath }) + const { description } = await server.videos.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 d63b81694..9d79f2683 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -25,7 +25,7 @@ const expect = chai.expect async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id: videoUUID }) + const videoDetails = await server.videos.get({ id: videoUUID }) const baseUrl = `http://${videoDetails.account.host}` expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) @@ -62,7 +62,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn { await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) - const masterPlaylist = await server.streamingPlaylistsCommand.get({ url: hlsPlaylist.playlistUrl }) + const masterPlaylist = await server.streamingPlaylists.get({ url: hlsPlaylist.playlistUrl }) for (const resolution of resolutions) { expect(masterPlaylist).to.contain(`${resolution}.m3u8`) @@ -72,7 +72,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn { for (const resolution of resolutions) { - const subPlaylist = await server.streamingPlaylistsCommand.get({ + const subPlaylist = await server.streamingPlaylists.get({ url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8` }) @@ -107,7 +107,7 @@ describe('Test HLS videos', function () { it('Should upload a video and transcode it to HLS', async function () { this.timeout(120000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } }) videoUUID = uuid await waitJobs(servers) @@ -118,7 +118,7 @@ describe('Test HLS videos', function () { it('Should upload an audio file and transcode it to HLS', async function () { this.timeout(120000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } }) videoAudioUUID = uuid await waitJobs(servers) @@ -129,7 +129,7 @@ describe('Test HLS videos', function () { it('Should update the video', async function () { this.timeout(10000) - await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video 1 updated' } }) + await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video 1 updated' } }) await waitJobs(servers) @@ -139,14 +139,14 @@ describe('Test HLS videos', function () { it('Should delete videos', async function () { this.timeout(10000) - await servers[0].videosCommand.remove({ id: videoUUID }) - await servers[0].videosCommand.remove({ id: videoAudioUUID }) + await servers[0].videos.remove({ id: videoUUID }) + await servers[0].videos.remove({ id: videoAudioUUID }) await waitJobs(servers) for (const server of servers) { - await server.videosCommand.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await server.videosCommand.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videos.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videos.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -192,7 +192,7 @@ describe('Test HLS videos', function () { describe('With only HLS enabled', function () { before(async function () { - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: true, diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 31fdfe12e..8b6542aa4 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -26,7 +26,7 @@ describe('Test video imports', function () { if (areHttpImportTestsDisabled()) return async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { - const videoHttp = await server.videosCommand.get({ id: idHttp }) + const videoHttp = await server.videos.get({ id: idHttp }) expect(videoHttp.name).to.equal('small video - youtube') // FIXME: youtube-dl seems broken @@ -43,8 +43,8 @@ describe('Test video imports', function () { expect(originallyPublishedAt.getMonth()).to.equal(0) expect(originallyPublishedAt.getFullYear()).to.equal(2019) - const videoMagnet = await server.videosCommand.get({ id: idMagnet }) - const videoTorrent = await server.videosCommand.get({ id: idTorrent }) + const videoMagnet = await server.videos.get({ id: idMagnet }) + const videoTorrent = await server.videos.get({ id: idTorrent }) for (const video of [ videoMagnet, videoTorrent ]) { expect(video.category.label).to.equal('Misc') @@ -59,12 +59,12 @@ describe('Test video imports', function () { expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') expect(videoMagnet.name).to.contain('super peertube2 video') - const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: idHttp }) + const bodyCaptions = await server.captions.listVideoCaptions({ videoId: idHttp }) expect(bodyCaptions.total).to.equal(2) } async function checkVideoServer2 (server: ServerInfo, id: number | string) { - const video = await server.videosCommand.get({ id }) + const video = await server.videos.get({ id }) expect(video.name).to.equal('my super name') expect(video.category.label).to.equal('Entertainment') @@ -76,7 +76,7 @@ describe('Test video imports', function () { expect(video.files).to.have.lengthOf(1) - const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: id }) + const bodyCaptions = await server.captions.listVideoCaptions({ videoId: id }) expect(bodyCaptions.total).to.equal(2) } @@ -89,12 +89,12 @@ describe('Test video imports', function () { await setAccessTokensToServers(servers) { - const { videoChannels } = await servers[0].usersCommand.getMyInfo() + const { videoChannels } = await servers[0].users.getMyInfo() channelIdServer1 = videoChannels[0].id } { - const { videoChannels } = await servers[1].usersCommand.getMyInfo() + const { videoChannels } = await servers[1].users.getMyInfo() channelIdServer2 = videoChannels[0].id } @@ -111,7 +111,7 @@ describe('Test video imports', function () { { const attributes = { ...baseAttributes, targetUrl: ImportsCommand.getYoutubeVideoUrl() } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) expect(video.name).to.equal('small video - youtube') expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) @@ -120,7 +120,7 @@ describe('Test video imports', function () { await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath) await testImage(servers[0].url, 'video_import_preview', video.previewPath) - const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: video.id }) + const bodyCaptions = await servers[0].captions.listVideoCaptions({ videoId: video.id }) const videoCaptions = bodyCaptions.data expect(videoCaptions).to.have.lengthOf(2) @@ -166,7 +166,7 @@ Ajouter un sous-titre est vraiment facile`) description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) expect(video.name).to.equal('super peertube2 video') } @@ -177,13 +177,13 @@ Ajouter un sous-titre est vraiment facile`) description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) expect(video.name).to.equal('你好 世界 720p.mp4') } }) it('Should list the videos to import in my videos on server 1', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos({ sort: 'createdAt' }) + const { total, data } = await servers[0].videos.listMyVideos({ sort: 'createdAt' }) expect(total).to.equal(3) @@ -194,7 +194,7 @@ Ajouter un sous-titre est vraiment facile`) }) it('Should list the videos to import in my imports on server 1', async function () { - const { total, data: videoImports } = await servers[0].importsCommand.getMyVideoImports({ sort: '-createdAt' }) + const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ sort: '-createdAt' }) expect(total).to.equal(3) expect(videoImports).to.have.lengthOf(3) @@ -221,7 +221,7 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(3) expect(data).to.have.lengthOf(3) @@ -244,7 +244,7 @@ Ajouter un sous-titre est vraiment facile`) description: 'my super description', tags: [ 'supertag1', 'supertag2' ] } - const { video } = await servers[1].importsCommand.importVideo({ attributes }) + const { video } = await servers[1].imports.importVideo({ attributes }) expect(video.name).to.equal('my super name') }) @@ -254,7 +254,7 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(4) expect(data).to.have.lengthOf(4) @@ -274,13 +274,13 @@ Ajouter un sous-titre est vraiment facile`) channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC } - const { video } = await servers[1].importsCommand.importVideo({ attributes }) + const { video } = await servers[1].imports.importVideo({ attributes }) const videoUUID = video.uuid await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.name).to.equal('transcoded video') expect(video.files).to.have.lengthOf(4) @@ -316,7 +316,7 @@ Ajouter un sous-titre est vraiment facile`) } } } - await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) + await servers[0].config.updateCustomSubConfig({ newConfig: config }) const attributes = { name: 'hdr video', @@ -324,13 +324,13 @@ Ajouter un sous-titre est vraiment facile`) channelId: channelIdServer1, privacy: VideoPrivacy.PUBLIC } - const { video: videoImported } = await servers[0].importsCommand.importVideo({ attributes }) + const { video: videoImported } = await servers[0].imports.importVideo({ attributes }) const videoUUID = videoImported.uuid await waitJobs(servers) // test resolution - const video = await servers[0].videosCommand.get({ id: videoUUID }) + const video = await servers[0].videos.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 b8fff096d..95395a582 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -18,7 +18,7 @@ describe('Test video NSFW policy', function () { let customConfig: CustomConfig async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { - const user = await server.usersCommand.getMyInfo() + const user = await server.users.getMyInfo() const videoChannelName = user.videoChannels[0].name const accountName = user.account.name + '@' + user.account.host const hasQuery = Object.keys(query).length !== 0 @@ -26,15 +26,15 @@ describe('Test video NSFW policy', function () { if (token) { promises = [ - server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), - server.videosCommand.listWithToken({ token, ...query }), - server.videosCommand.listByAccount({ token, accountName, ...query }), - server.videosCommand.listByChannel({ token, videoChannelName, ...query }) + server.search.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), + server.videos.listWithToken({ token, ...query }), + server.videos.listByAccount({ token, accountName, ...query }), + server.videos.listByChannel({ token, videoChannelName, ...query }) ] // Overviews do not support video filters if (!hasQuery) { - const p = server.overviewsCommand.getVideos({ page: 1, token }) + const p = server.overviews.getVideos({ page: 1, token }) .then(res => createOverviewRes(res)) promises.push(p) } @@ -43,15 +43,15 @@ describe('Test video NSFW policy', function () { } promises = [ - server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }), - server.videosCommand.list(), - server.videosCommand.listByAccount({ accountName }), - server.videosCommand.listByChannel({ videoChannelName }) + server.search.searchVideos({ search: 'n', sort: '-publishedAt' }), + server.videos.list(), + server.videos.listByAccount({ accountName }), + server.videos.listByChannel({ videoChannelName }) ] // Overviews do not support video filters if (!hasQuery) { - const p = server.overviewsCommand.getVideos({ page: 1 }) + const p = server.overviews.getVideos({ page: 1 }) .then(res => createOverviewRes(res)) promises.push(p) } @@ -68,20 +68,20 @@ describe('Test video NSFW policy', function () { { const attributes = { name: 'nsfw', nsfw: true, category: 1 } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) } { const attributes = { name: 'normal', nsfw: false, category: 1 } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) } - customConfig = await server.configCommand.getCustomConfig() + customConfig = await server.config.getCustomConfig() }) describe('Instance default NSFW policy', function () { it('Should display NSFW videos with display default NSFW policy', async function () { - const serverConfig = await server.configCommand.getConfig() + const serverConfig = await server.config.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') for (const body of await getVideosFunctions()) { @@ -96,9 +96,9 @@ describe('Test video NSFW policy', function () { it('Should not display NSFW videos with do_not_list default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) + await server.config.updateCustomConfig({ newCustomConfig: customConfig }) - const serverConfig = await server.configCommand.getConfig() + const serverConfig = await server.config.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') for (const body of await getVideosFunctions()) { @@ -112,9 +112,9 @@ describe('Test video NSFW policy', function () { it('Should display NSFW videos with blur default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'blur' - await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) + await server.config.updateCustomConfig({ newCustomConfig: customConfig }) - const serverConfig = await server.configCommand.getConfig() + const serverConfig = await server.config.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') for (const body of await getVideosFunctions()) { @@ -133,17 +133,17 @@ describe('Test video NSFW policy', function () { it('Should create a user having the default nsfw policy', async function () { const username = 'user1' const password = 'my super password' - await server.usersCommand.create({ username: username, password: password }) + await server.users.create({ username: username, password: password }) - userAccessToken = await server.loginCommand.getAccessToken({ username, password }) + userAccessToken = await server.login.getAccessToken({ username, password }) - const user = await server.usersCommand.getMyInfo({ token: userAccessToken }) + const user = await server.users.getMyInfo({ token: userAccessToken }) expect(user.nsfwPolicy).to.equal('blur') }) it('Should display NSFW videos with blur user NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) + await server.config.updateCustomConfig({ newCustomConfig: customConfig }) for (const body of await getVideosFunctions(userAccessToken)) { expect(body.total).to.equal(2) @@ -156,7 +156,7 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos with display user NSFW policy', async function () { - await server.usersCommand.updateMe({ nsfwPolicy: 'display' }) + await server.users.updateMe({ nsfwPolicy: 'display' }) for (const body of await getVideosFunctions(server.accessToken)) { expect(body.total).to.equal(2) @@ -169,7 +169,7 @@ describe('Test video NSFW policy', function () { }) it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { - await server.usersCommand.updateMe({ nsfwPolicy: 'do_not_list' }) + await server.users.updateMe({ nsfwPolicy: 'do_not_list' }) for (const body of await getVideosFunctions(server.accessToken)) { expect(body.total).to.equal(1) @@ -181,7 +181,7 @@ 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 { total, data } = await server.videosCommand.listMyVideos() + const { total, data } = await server.videos.listMyVideos() expect(total).to.equal(2) expect(data).to.have.lengthOf(2) diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index 14739af20..709f64c4d 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -31,13 +31,13 @@ describe('Playlist thumbnail', function () { let video2: number async function getPlaylistWithoutThumbnail (server: ServerInfo) { - const body = await server.playlistsCommand.list({ start: 0, count: 10 }) + const body = await server.playlists.list({ start: 0, count: 10 }) return body.data.find(p => p.displayName === 'playlist without thumbnail') } async function getPlaylistWithThumbnail (server: ServerInfo) { - const body = await server.playlistsCommand.list({ start: 0, count: 10 }) + const body = await server.playlists.list({ start: 0, count: 10 }) return body.data.find(p => p.displayName === 'playlist with thumbnail') } @@ -54,8 +54,8 @@ describe('Playlist thumbnail', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).id - video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).id + video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id + video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id await waitJobs(servers) }) @@ -63,16 +63,16 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when adding an element', async function () { this.timeout(30000) - const created = await servers[1].playlistsCommand.create({ + const created = await servers[1].playlists.create({ attributes: { displayName: 'playlist without thumbnail', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } }) playlistWithoutThumbnailId = created.id - const added = await servers[1].playlistsCommand.addElement({ + const added = await servers[1].playlists.addElement({ playlistId: playlistWithoutThumbnailId, attributes: { videoId: video1 } }) @@ -89,17 +89,17 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - const created = await servers[1].playlistsCommand.create({ + const created = await servers[1].playlists.create({ attributes: { displayName: 'playlist with thumbnail', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[1].videoChannel.id, + videoChannelId: servers[1].store.channel.id, thumbnailfile: 'thumbnail.jpg' } }) playlistWithThumbnailId = created.id - const added = await servers[1].playlistsCommand.addElement({ + const added = await servers[1].playlists.addElement({ playlistId: playlistWithThumbnailId, attributes: { videoId: video1 } }) @@ -116,13 +116,13 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when moving the first element', async function () { this.timeout(30000) - const added = await servers[1].playlistsCommand.addElement({ + const added = await servers[1].playlists.addElement({ playlistId: playlistWithoutThumbnailId, attributes: { videoId: video2 } }) withoutThumbnailE2 = added.id - await servers[1].playlistsCommand.reorderElements({ + await servers[1].playlists.reorderElements({ playlistId: playlistWithoutThumbnailId, attributes: { startPosition: 1, @@ -141,13 +141,13 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - const added = await servers[1].playlistsCommand.addElement({ + const added = await servers[1].playlists.addElement({ playlistId: playlistWithThumbnailId, attributes: { videoId: video2 } }) withThumbnailE2 = added.id - await servers[1].playlistsCommand.reorderElements({ + await servers[1].playlists.reorderElements({ playlistId: playlistWithThumbnailId, attributes: { startPosition: 1, @@ -166,7 +166,7 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when deleting the first element', async function () { this.timeout(30000) - await servers[1].playlistsCommand.removeElement({ + await servers[1].playlists.removeElement({ playlistId: playlistWithoutThumbnailId, elementId: withoutThumbnailE1 }) @@ -182,7 +182,7 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - await servers[1].playlistsCommand.removeElement({ + await servers[1].playlists.removeElement({ playlistId: playlistWithThumbnailId, elementId: withThumbnailE1 }) @@ -198,7 +198,7 @@ describe('Playlist thumbnail', function () { it('Should the thumbnail when we delete the last element', async function () { this.timeout(30000) - await servers[1].playlistsCommand.removeElement({ + await servers[1].playlists.removeElement({ playlistId: playlistWithoutThumbnailId, elementId: withoutThumbnailE2 }) @@ -214,7 +214,7 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - await servers[1].playlistsCommand.removeElement({ + await servers[1].playlists.removeElement({ playlistId: playlistWithThumbnailId, elementId: withThumbnailE2 }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 40f61ca19..0dc53d4c0 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -36,7 +36,7 @@ async function checkPlaylistElementType ( total: number ) { for (const server of servers) { - const body = await server.playlistsCommand.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 }) expect(body.total).to.equal(total) const videoElement = body.data.find(e => e.position === position) @@ -86,26 +86,26 @@ describe('Test video playlists', function () { // Server 1 and server 3 follow each other await doubleFollow(servers[0], servers[2]) - commands = servers.map(s => s.playlistsCommand) + commands = servers.map(s => s.playlists) { - servers[0].videos = [] - servers[1].videos = [] - servers[2].videos = [] + servers[0].store.videos = [] + servers[1].store.videos = [] + servers[2].store.videos = [] for (const server of servers) { for (let i = 0; i < 7; i++) { const name = `video ${i} server ${server.serverNumber}` - const video = await server.videosCommand.upload({ attributes: { name, nsfw: false } }) + const video = await server.videos.upload({ attributes: { name, nsfw: false } }) - server.videos.push(video) + server.store.videos.push(video) } } } - nsfwVideoServer1 = (await servers[0].videosCommand.quickUpload({ name: 'NSFW video', nsfw: true })).id + nsfwVideoServer1 = (await servers[0].videos.quickUpload({ name: 'NSFW video', nsfw: true })).id - userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1') + userTokenServer1 = await servers[0].users.generateUserAndToken('user1') await waitJobs(servers) }) @@ -149,7 +149,7 @@ describe('Test video playlists', function () { }) it('Should get private playlist for a classic user', async function () { - const token = await servers[0].usersCommand.generateUserAndToken('toto') + const token = await servers[0].users.generateUserAndToken('toto') const body = await commands[0].listByAccount({ token, handle: 'toto' }) @@ -172,7 +172,7 @@ describe('Test video playlists', function () { privacy: VideoPlaylistPrivacy.PUBLIC, description: 'my super description', thumbnailfile: 'thumbnail.jpg', - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } }) @@ -181,13 +181,13 @@ describe('Test video playlists', function () { await wait(3000) for (const server of servers) { - const body = await server.playlistsCommand.list({ start: 0, count: 5 }) + const body = await server.playlists.list({ start: 0, count: 5 }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) const playlistFromList = body.data[0] - const playlistFromGet = await server.playlistsCommand.get({ playlistId: playlistFromList.uuid }) + const playlistFromGet = await server.playlists.get({ playlistId: playlistFromList.uuid }) for (const playlist of [ playlistFromGet, playlistFromList ]) { expect(playlist.id).to.be.a('number') @@ -217,23 +217,23 @@ describe('Test video playlists', function () { this.timeout(30000) { - const playlist = await servers[1].playlistsCommand.create({ + const playlist = await servers[1].playlists.create({ attributes: { displayName: 'playlist 2', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } }) playlistServer2Id1 = playlist.id } { - const playlist = await servers[1].playlistsCommand.create({ + const playlist = await servers[1].playlists.create({ attributes: { displayName: 'playlist 3', privacy: VideoPlaylistPrivacy.PUBLIC, thumbnailfile: 'thumbnail.jpg', - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } }) @@ -242,13 +242,13 @@ describe('Test video playlists', function () { } for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) { - await servers[1].playlistsCommand.addElement({ + await servers[1].playlists.addElement({ playlistId: id, - attributes: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 } + attributes: { videoId: servers[1].store.videos[0].id, startTimestamp: 1, stopTimestamp: 2 } }) - await servers[1].playlistsCommand.addElement({ + await servers[1].playlists.addElement({ playlistId: id, - attributes: { videoId: servers[1].videos[1].id } + attributes: { videoId: servers[1].store.videos[1].id } }) } @@ -256,7 +256,7 @@ describe('Test video playlists', function () { await wait(3000) for (const server of [ servers[0], servers[1] ]) { - const body = await server.playlistsCommand.list({ start: 0, count: 5 }) + const body = await server.playlists.list({ start: 0, count: 5 }) const playlist2 = body.data.find(p => p.displayName === 'playlist 2') expect(playlist2).to.not.be.undefined @@ -267,7 +267,7 @@ describe('Test video playlists', function () { await testImage(server.url, 'thumbnail', playlist3.thumbnailPath) } - const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + const body = await servers[2].playlists.list({ start: 0, count: 5 }) expect(body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined expect(body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined }) @@ -278,7 +278,7 @@ describe('Test video playlists', function () { // Server 2 and server 3 follow each other await doubleFollow(servers[1], servers[2]) - const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + const body = await servers[2].playlists.list({ start: 0, count: 5 }) const playlist2 = body.data.find(p => p.displayName === 'playlist 2') expect(playlist2).to.not.be.undefined @@ -294,7 +294,7 @@ describe('Test video playlists', function () { this.timeout(30000) { - const body = await servers[2].playlistsCommand.list({ start: 1, count: 2, sort: 'createdAt' }) + const body = await servers[2].playlists.list({ start: 1, count: 2, sort: 'createdAt' }) expect(body.total).to.equal(3) const data = body.data @@ -304,7 +304,7 @@ describe('Test video playlists', function () { } { - const body = await servers[2].playlistsCommand.list({ start: 1, count: 2, sort: '-createdAt' }) + const body = await servers[2].playlists.list({ start: 1, count: 2, sort: '-createdAt' }) expect(body.total).to.equal(3) const data = body.data @@ -331,7 +331,7 @@ describe('Test video playlists', function () { this.timeout(30000) { - const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' }) + const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' }) expect(body.total).to.equal(2) const data = body.data @@ -340,7 +340,7 @@ describe('Test video playlists', function () { } { - const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' }) + const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' }) expect(body.total).to.equal(2) const data = body.data @@ -349,7 +349,7 @@ describe('Test video playlists', function () { } { - const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' }) + const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' }) expect(body.total).to.equal(1) const data = body.data @@ -358,7 +358,7 @@ describe('Test video playlists', function () { } { - const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' }) + const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' }) expect(body.total).to.equal(0) const data = body.data @@ -375,17 +375,17 @@ describe('Test video playlists', function () { this.timeout(30000) { - unlistedPlaylist = await servers[1].playlistsCommand.create({ + unlistedPlaylist = await servers[1].playlists.create({ attributes: { displayName: 'playlist unlisted', privacy: VideoPlaylistPrivacy.UNLISTED, - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } }) } { - privatePlaylist = await servers[1].playlistsCommand.create({ + privatePlaylist = await servers[1].playlists.create({ attributes: { displayName: 'playlist private', privacy: VideoPlaylistPrivacy.PRIVATE @@ -400,8 +400,8 @@ describe('Test video playlists', function () { it('Should not list unlisted or private playlists', async function () { for (const server of servers) { const results = [ - await server.playlistsCommand.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }), - await server.playlistsCommand.list({ start: 0, count: 2, sort: '-createdAt' }) + await server.playlists.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }), + await server.playlists.list({ start: 0, count: 2, sort: '-createdAt' }) ] expect(results[0].total).to.equal(2) @@ -417,23 +417,23 @@ describe('Test video playlists', function () { }) it('Should not get unlisted playlist using only the id', async function () { - await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 }) + await servers[1].playlists.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 }) }) it('Should get unlisted plyaylist using uuid or shortUUID', async function () { - await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.uuid }) - await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.shortUUID }) + await servers[1].playlists.get({ playlistId: unlistedPlaylist.uuid }) + await servers[1].playlists.get({ playlistId: unlistedPlaylist.shortUUID }) }) it('Should not get private playlist without token', async function () { for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { - await servers[1].playlistsCommand.get({ playlistId: id, expectedStatus: 401 }) + await servers[1].playlists.get({ playlistId: id, expectedStatus: 401 }) } }) it('Should get private playlist with a token', async function () { for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { - await servers[1].playlistsCommand.get({ token: servers[1].accessToken, playlistId: id }) + await servers[1].playlists.get({ token: servers[1].accessToken, playlistId: id }) } }) }) @@ -443,13 +443,13 @@ describe('Test video playlists', function () { it('Should update a playlist', async function () { this.timeout(30000) - await servers[1].playlistsCommand.update({ + await servers[1].playlists.update({ attributes: { displayName: 'playlist 3 updated', description: 'description updated', privacy: VideoPlaylistPrivacy.UNLISTED, thumbnailfile: 'thumbnail.jpg', - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id }, playlistId: playlistServer2Id2 }) @@ -457,7 +457,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const playlist = await server.playlistsCommand.get({ playlistId: playlistServer2UUID2 }) + const playlist = await server.playlists.get({ playlistId: playlistServer2UUID2 }) expect(playlist.displayName).to.equal('playlist 3 updated') expect(playlist.description).to.equal('description updated') @@ -491,23 +491,23 @@ describe('Test video playlists', function () { attributes: { displayName: 'playlist 4', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } }) playlistServer1Id = playlist.id playlistServer1UUID = playlist.uuid - await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) - await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 }) - await addVideo({ videoId: servers[2].videos[2].uuid }) + await addVideo({ videoId: servers[0].store.videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) + await addVideo({ videoId: servers[2].store.videos[1].uuid, startTimestamp: 35 }) + await addVideo({ videoId: servers[2].store.videos[2].uuid }) { - const element = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 }) + const element = await addVideo({ videoId: servers[0].store.videos[3].uuid, stopTimestamp: 35 }) playlistElementServer1Video4 = element.id } { - const element = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) + const element = await addVideo({ videoId: servers[0].store.videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) playlistElementServer1Video5 = element.id } @@ -527,7 +527,7 @@ describe('Test video playlists', function () { for (const server of servers) { { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) expect(body.total).to.equal(8) @@ -576,7 +576,7 @@ describe('Test video playlists', function () { } { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 }) expect(body.data).to.have.lengthOf(2) } } @@ -606,7 +606,7 @@ describe('Test video playlists', function () { attributes: { displayName: 'playlist 56', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } }) @@ -617,9 +617,9 @@ describe('Test video playlists', function () { return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes }) } - 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 + video1 = (await servers[0].videos.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid + video2 = (await servers[1].videos.quickUpload({ name: 'video 90' })).uuid + video3 = (await servers[0].videos.quickUpload({ name: 'video 91', nsfw: true })).uuid await waitJobs(servers) @@ -637,7 +637,7 @@ describe('Test video playlists', function () { const position = 1 { - await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } }) + await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -647,7 +647,7 @@ describe('Test video playlists', function () { } { - await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } }) + await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -665,7 +665,7 @@ describe('Test video playlists', function () { const position = 1 { - await servers[0].blacklistCommand.add({ videoId: video1, reason: 'reason', unfederate: true }) + await servers[0].blacklist.add({ videoId: video1, reason: 'reason', unfederate: true }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -675,7 +675,7 @@ describe('Test video playlists', function () { } { - await servers[0].blacklistCommand.remove({ videoId: video1 }) + await servers[0].blacklist.remove({ videoId: video1 }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -689,7 +689,7 @@ describe('Test video playlists', function () { it('Should update the element type if the account or server of the video is blocked', async function () { this.timeout(90000) - const command = servers[0].blocklistCommand + const command = servers[0].blocklist const name = 'video 90' const position = 2 @@ -778,7 +778,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) const names = body.data.map(v => v.video.name) expect(names).to.deep.equal([ @@ -807,7 +807,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) const names = body.data.map(v => v.video.name) expect(names).to.deep.equal([ @@ -835,7 +835,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const { data: elements } = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) const names = elements.map(v => v.video.name) expect(names).to.deep.equal([ @@ -878,7 +878,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const { data: elements } = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) expect(elements[0].video.name).to.equal('video 3 server 1') expect(elements[0].position).to.equal(1) @@ -894,16 +894,16 @@ describe('Test video playlists', function () { it('Should check videos existence in my playlist', async function () { const videoIds = [ - servers[0].videos[0].id, + servers[0].store.videos[0].id, 42000, - servers[0].videos[3].id, + servers[0].store.videos[3].id, 43000, - servers[0].videos[4].id + servers[0].store.videos[4].id ] const obj = await commands[0].videosExist({ videoIds }) { - const elem = obj[servers[0].videos[0].id] + const elem = obj[servers[0].store.videos[0].id] expect(elem).to.have.lengthOf(1) expect(elem[0].playlistElementId).to.exist expect(elem[0].playlistId).to.equal(playlistServer1Id) @@ -912,7 +912,7 @@ describe('Test video playlists', function () { } { - const elem = obj[servers[0].videos[3].id] + const elem = obj[servers[0].store.videos[3].id] expect(elem).to.have.lengthOf(1) expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4) expect(elem[0].playlistId).to.equal(playlistServer1Id) @@ -921,7 +921,7 @@ describe('Test video playlists', function () { } { - const elem = obj[servers[0].videos[4].id] + const elem = obj[servers[0].store.videos[4].id] expect(elem).to.have.lengthOf(1) expect(elem[0].playlistId).to.equal(playlistServer1Id) expect(elem[0].startTimestamp).to.equal(45) @@ -934,29 +934,29 @@ describe('Test video playlists', function () { it('Should automatically update updatedAt field of playlists', async function () { const server = servers[1] - const videoId = servers[1].videos[5].id + const videoId = servers[1].store.videos[5].id async function getPlaylistNames () { - const { data } = await server.playlistsCommand.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' }) + const { data } = await server.playlists.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' }) return data.map(p => p.displayName) } const attributes = { videoId } - const element1 = await server.playlistsCommand.addElement({ playlistId: playlistServer2Id1, attributes }) - const element2 = await server.playlistsCommand.addElement({ playlistId: playlistServer2Id2, attributes }) + const element1 = await server.playlists.addElement({ playlistId: playlistServer2Id1, attributes }) + const element2 = await server.playlists.addElement({ playlistId: playlistServer2Id2, attributes }) const names1 = await getPlaylistNames() expect(names1[0]).to.equal('playlist 3 updated') expect(names1[1]).to.equal('playlist 2') - await server.playlistsCommand.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id }) + await server.playlists.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id }) const names2 = await getPlaylistNames() expect(names2[0]).to.equal('playlist 2') expect(names2[1]).to.equal('playlist 3 updated') - await server.playlistsCommand.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id }) + await server.playlists.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id }) const names3 = await getPlaylistNames() expect(names3[0]).to.equal('playlist 3 updated') @@ -972,7 +972,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) expect(body.total).to.equal(6) const elements = body.data @@ -1005,14 +1005,14 @@ describe('Test video playlists', function () { attributes: { displayName: 'my super public playlist', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } }) await waitJobs(servers) for (const server of servers) { - await server.playlistsCommand.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) + await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) } const attributes = { privacy: VideoPlaylistPrivacy.PRIVATE } @@ -1021,7 +1021,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of [ servers[1], servers[2] ]) { - await server.playlistsCommand.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } await commands[0].get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -1039,7 +1039,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - await server.playlistsCommand.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.playlists.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -1057,16 +1057,16 @@ describe('Test video playlists', function () { const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'my super playlist') { - const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + const body = await servers[2].playlists.list({ start: 0, count: 5 }) expect(body.total).to.equal(3) expect(finder(body.data)).to.not.be.undefined } - await servers[2].followsCommand.unfollow({ target: servers[0] }) + await servers[2].follows.unfollow({ target: servers[0] }) { - const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + const body = await servers[2].playlists.list({ start: 0, count: 5 }) expect(body.total).to.equal(1) expect(finder(body.data)).to.be.undefined @@ -1076,7 +1076,7 @@ describe('Test video playlists', function () { it('Should delete a channel and put the associated playlist in private mode', async function () { this.timeout(30000) - const channel = await servers[0].channelsCommand.create({ attributes: { name: 'super_channel', displayName: 'super channel' } }) + const channel = await servers[0].channels.create({ attributes: { name: 'super_channel', displayName: 'super channel' } }) const playlistCreated = await commands[0].create({ attributes: { @@ -1088,7 +1088,7 @@ describe('Test video playlists', function () { await waitJobs(servers) - await servers[0].channelsCommand.delete({ channelName: 'super_channel' }) + await servers[0].channels.delete({ channelName: 'super_channel' }) await waitJobs(servers) @@ -1096,15 +1096,15 @@ describe('Test video playlists', function () { expect(body.displayName).to.equal('channel playlist') expect(body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) - await servers[1].playlistsCommand.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[1].playlists.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should delete an account and delete its playlists', async function () { this.timeout(30000) - const { userId, token } = await servers[0].usersCommand.generate('user_1') + const { userId, token } = await servers[0].users.generate('user_1') - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token }) + const { videoChannels } = await servers[0].users.getMyInfo({ token }) const userChannel = videoChannels[0] await commands[0].create({ @@ -1121,18 +1121,18 @@ describe('Test video playlists', function () { { for (const server of [ servers[0], servers[1] ]) { - const body = await server.playlistsCommand.list({ start: 0, count: 15 }) + const body = await server.playlists.list({ start: 0, count: 15 }) expect(finder(body.data)).to.not.be.undefined } } - await servers[0].usersCommand.remove({ userId }) + await servers[0].users.remove({ userId }) await waitJobs(servers) { for (const server of [ servers[0], servers[1] ]) { - const body = await server.playlistsCommand.list({ start: 0, count: 15 }) + const body = await server.playlists.list({ start: 0, count: 15 }) expect(finder(body.data)).to.be.undefined } diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index bcf431edb..de08a9e7b 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -52,28 +52,28 @@ describe('Test video privacy', function () { for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { const attributes = { privacy } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) } await waitJobs(servers) }) it('Should not have these private and internal videos on server 2', async function () { - const { total, data } = await servers[1].videosCommand.list() + const { total, data } = await servers[1].videos.list() 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 { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() 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 { total, data } = await servers[0].videosCommand.listWithToken() + const { total, data } = await servers[0].videos.listWithToken() expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -82,7 +82,7 @@ describe('Test video privacy', function () { }) it('Should list my (private and internal) videos', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(2) expect(data).to.have.lengthOf(2) @@ -97,8 +97,8 @@ describe('Test video privacy', function () { }) it('Should not be able to watch the private/internal video with non authenticated user', async function () { - await servers[0].videosCommand.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await servers[0].videosCommand.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].videos.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].videos.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to watch the private video with another user', async function () { @@ -108,11 +108,11 @@ describe('Test video privacy', function () { username: 'hello', password: 'super password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - anotherUserToken = await servers[0].loginCommand.getAccessToken(user) + anotherUserToken = await servers[0].login.getAccessToken(user) - await servers[0].videosCommand.getWithToken({ + await servers[0].videos.getWithToken({ token: anotherUserToken, id: privateVideoUUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 @@ -120,11 +120,11 @@ describe('Test video privacy', function () { }) it('Should be able to watch the internal video with another user', async function () { - await servers[0].videosCommand.getWithToken({ token: anotherUserToken, id: internalVideoUUID }) + await servers[0].videos.getWithToken({ token: anotherUserToken, id: internalVideoUUID }) }) it('Should be able to watch the private video with the correct user', async function () { - await servers[0].videosCommand.getWithToken({ id: privateVideoUUID }) + await servers[0].videos.getWithToken({ id: privateVideoUUID }) }) }) @@ -137,7 +137,7 @@ describe('Test video privacy', function () { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) // Server 2 has transcoding enabled await waitJobs(servers) @@ -145,7 +145,7 @@ 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 { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(0) expect(data).to.have.lengthOf(0) @@ -153,7 +153,7 @@ describe('Test video privacy', function () { }) it('Should list my (unlisted) videos', async function () { - const { total, data } = await servers[1].videosCommand.listMyVideos() + const { total, data } = await servers[1].videos.listMyVideos() expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -162,13 +162,13 @@ describe('Test video privacy', function () { }) it('Should not be able to get this unlisted video using its id', async function () { - await servers[1].videosCommand.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[1].videos.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 video = await server.videosCommand.get({ id }) + const video = await server.videos.get({ id }) expect(video.name).to.equal('unlisted video') } @@ -182,13 +182,13 @@ describe('Test video privacy', function () { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) }) it('Should list my new unlisted video', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(3) expect(data).to.have.lengthOf(3) @@ -197,13 +197,13 @@ describe('Test video privacy', function () { }) it('Should be able to get non-federated unlisted video from origin', async function () { - const video = await servers[0].videosCommand.get({ id: nonFederatedUnlistedVideoUUID }) + const video = await servers[0].videos.get({ id: nonFederatedUnlistedVideoUUID }) expect(video.name).to.equal('unlisted video') }) it('Should not be able to get non-federated unlisted video from federated server', async function () { - await servers[1].videosCommand.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[1].videos.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -220,7 +220,7 @@ describe('Test video privacy', function () { privacy: VideoPrivacy.PUBLIC } - await servers[0].videosCommand.update({ id: privateVideoId, attributes }) + await servers[0].videos.update({ id: privateVideoId, attributes }) } { @@ -228,7 +228,7 @@ describe('Test video privacy', function () { name: 'internal video becomes public', privacy: VideoPrivacy.PUBLIC } - await servers[0].videosCommand.update({ id: internalVideoId, attributes }) + await servers[0].videos.update({ id: internalVideoId, attributes }) } await waitJobs(servers) @@ -236,7 +236,7 @@ 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 { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(2) expect(data).to.have.lengthOf(2) @@ -258,20 +258,20 @@ describe('Test video privacy', function () { it('Should set these videos as private and internal', async function () { this.timeout(10000) - await servers[0].videosCommand.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } }) - await servers[0].videosCommand.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } }) + await servers[0].videos.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } }) + await servers[0].videos.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } }) await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(0) expect(data).to.have.lengthOf(0) } { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(3) expect(data).to.have.lengthOf(3) diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 635ae6ff1..3938b47c8 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -49,25 +49,25 @@ describe('Test video update scheduler', function () { } } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) }) it('Should not list the video (in privacy mode)', async function () { for (const server of servers) { - const { total } = await server.videosCommand.list() + const { total } = await server.videos.list() expect(total).to.equal(0) } }) it('Should have my scheduled video in my account videos', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(1) const videoFromList = data[0] - const videoFromGet = await servers[0].videosCommand.getWithToken({ id: videoFromList.uuid }) + const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid }) for (const video of [ videoFromList, videoFromGet ]) { expect(video.name).to.equal('video 1') @@ -84,7 +84,7 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(1) expect(data[0].name).to.equal('video 1') @@ -99,7 +99,7 @@ describe('Test video update scheduler', function () { privacy: VideoPrivacy.PRIVATE } - const { uuid } = await servers[0].videosCommand.upload({ attributes }) + const { uuid } = await servers[0].videos.upload({ attributes }) video2UUID = uuid await waitJobs(servers) @@ -116,20 +116,20 @@ describe('Test video update scheduler', function () { } } - await servers[0].videosCommand.update({ id: video2UUID, attributes }) + await servers[0].videos.update({ id: video2UUID, attributes }) await waitJobs(servers) }) it('Should not display the updated video', async function () { for (const server of servers) { - const { total } = await server.videosCommand.list() + const { total } = await server.videos.list() expect(total).to.equal(1) } }) it('Should have my scheduled updated video in my account videos', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(2) const video = data.find(v => v.uuid === video2UUID) @@ -149,7 +149,7 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(2) const video = data.find(v => v.uuid === video2UUID) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index b41c68283..37450eeeb 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -32,7 +32,7 @@ import { const expect = chai.expect function updateConfigForTranscoding (server: ServerInfo) { - return server.configCommand.updateCustomSubConfig({ + return server.config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: true, @@ -82,15 +82,15 @@ describe('Test video transcoding', function () { description: 'my super description for server 1', fixture: 'video_short.webm' } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data[0] - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) const magnetUri = videoDetails.files[0].magnetUri @@ -111,15 +111,15 @@ describe('Test video transcoding', function () { description: 'my super description for server 2', fixture: 'video_short.webm' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) @@ -143,11 +143,11 @@ describe('Test video transcoding', function () { fixture: 'video_short1.webm', waitTranscoding: true } - const { uuid } = await servers[1].videosCommand.upload({ attributes }) + const { uuid } = await servers[1].videos.upload({ attributes }) const videoId = uuid // Should be in transcode state - const body = await servers[1].videosCommand.get({ id: videoId }) + const body = await servers[1].videos.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') @@ -155,7 +155,7 @@ describe('Test video transcoding', function () { { // Should have my video - const { data } = await servers[1].videosCommand.listMyVideos() + const { data } = await servers[1].videos.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) @@ -165,23 +165,23 @@ describe('Test video transcoding', function () { { // Should not list this video - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() const videoToFindInList = data.find(v => v.name === attributes.name) expect(videoToFindInList).to.be.undefined } // Server 1 should not have the video yet - await servers[0].videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const videoToFind = data.find(v => v.name === 'waiting video') expect(videoToFind).not.to.be.undefined - const videoDetails = await server.videosCommand.get({ id: videoToFind.id }) + const videoDetails = await server.videos.get({ id: videoToFind.id }) expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) expect(videoDetails.state.label).to.equal('Published') @@ -207,15 +207,15 @@ describe('Test video transcoding', function () { fixture } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) const magnetUri = videoDetails.files[0].magnetUri @@ -232,7 +232,7 @@ describe('Test video transcoding', function () { fixture: 'video_short_4k.mp4' } - const { uuid } = await servers[1].videosCommand.upload({ attributes }) + const { uuid } = await servers[1].videos.upload({ attributes }) video4k = uuid await waitJobs(servers) @@ -240,7 +240,7 @@ describe('Test video transcoding', function () { const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id: video4k }) + const videoDetails = await server.videos.get({ id: video4k }) expect(videoDetails.files).to.have.lengthOf(resolutions.length) for (const r of resolutions) { @@ -260,19 +260,19 @@ describe('Test video transcoding', function () { name: 'mp3_256k', fixture: 'video_short_mp3_256k.mp4' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) if (probe.audioStream) { @@ -291,18 +291,18 @@ describe('Test video transcoding', function () { name: 'no_audio', fixture: 'video_short_no_audio.mp4' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) expect(probe).to.not.have.property('audioStream') } @@ -315,21 +315,21 @@ describe('Test video transcoding', function () { name: 'untouched_audio', fixture: 'video_short.mp4' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) const fixturePath = buildAbsoluteFixturePath(attributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) const videoProbe = await getAudioStream(path) @@ -348,7 +348,7 @@ describe('Test video transcoding', function () { function runSuite (mode: 'legacy' | 'resumable') { before(async function () { - await servers[1].configCommand.updateCustomSubConfig({ + await servers[1].config.updateCustomSubConfig({ newConfig: { transcoding: { hls: { enabled: true }, @@ -372,15 +372,15 @@ describe('Test video transcoding', function () { this.timeout(60_000) const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } - await servers[1].videosCommand.upload({ attributes, mode }) + await servers[1].videos.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === 'audio_with_preview') - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) @@ -396,15 +396,15 @@ describe('Test video transcoding', function () { this.timeout(60_000) const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' } - await servers[1].videosCommand.upload({ attributes, mode }) + await servers[1].videos.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === 'audio_without_preview') - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) @@ -419,7 +419,7 @@ describe('Test video transcoding', function () { it('Should upload an audio file and create an audio version only', async function () { this.timeout(60_000) - await servers[1].configCommand.updateCustomSubConfig({ + await servers[1].config.updateCustomSubConfig({ newConfig: { transcoding: { hls: { enabled: true }, @@ -434,12 +434,12 @@ describe('Test video transcoding', function () { }) const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } - const { id } = await servers[1].videosCommand.upload({ attributes, mode }) + const { id } = await servers[1].videos.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id }) + const videoDetails = await server.videos.get({ id }) for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { expect(files).to.have.lengthOf(2) @@ -470,15 +470,15 @@ describe('Test video transcoding', function () { description: 'my super 30fps description for server 2', fixture: '60fps_720p_small.mp4' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) @@ -487,13 +487,13 @@ describe('Test video transcoding', function () { expect(videoDetails.files[3].fps).to.be.below(31) for (const resolution of [ '240', '360', '480' ]) { - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.below(31) } - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.above(58).and.below(62) @@ -518,23 +518,23 @@ describe('Test video transcoding', function () { fixture: tempFixturePath } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) { - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(25) } { - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(59) } @@ -561,17 +561,17 @@ describe('Test video transcoding', function () { fixture: tempFixturePath } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() 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')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) @@ -602,21 +602,21 @@ describe('Test video transcoding', function () { hls: { enabled: true } } } - await servers[1].configCommand.updateCustomSubConfig({ newConfig }) + await servers[1].config.updateCustomSubConfig({ newConfig }) const attributes = { name: 'low bitrate', fixture: 'low-bitrate.mp4' } - const { uuid } = await servers[1].videosCommand.upload({ attributes }) + const { uuid } = await servers[1].videos.upload({ attributes }) await waitJobs(servers) const resolutions = [ 240, 360, 480, 720, 1080 ] for (const r of resolutions) { const path = `videos/${uuid}-${r}.mp4` - const size = await servers[1].serversCommand.getServerFileSize(path) + const size = await servers[1].servers.getServerFileSize(path) expect(size, `${path} not below ${60_000}`).to.be.below(60_000) } }) @@ -627,11 +627,11 @@ describe('Test video transcoding', function () { it('Should provide valid ffprobe data', async function () { this.timeout(160_000) - const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'ffprobe data' })).uuid + const videoUUID = (await servers[1].videos.quickUpload({ name: 'ffprobe data' })).uuid await waitJobs(servers) { - const path = servers[1].serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', videoUUID + '-240.mp4')) const metadata = await getMetadataFromFile(path) // expected format properties @@ -661,7 +661,7 @@ describe('Test video transcoding', function () { } for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id: videoUUID }) + const videoDetails = await server.videos.get({ id: videoUUID }) const videoFiles = videoDetails.files .concat(videoDetails.streamingPlaylists[0].files) @@ -673,7 +673,7 @@ describe('Test video transcoding', function () { expect(file.metadataUrl).to.contain(servers[1].url) expect(file.metadataUrl).to.contain(videoUUID) - const metadata = await server.videosCommand.getFileMetadata({ url: file.metadataUrl }) + const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl }) expect(metadata).to.have.nested.property('format.size') } } @@ -690,7 +690,7 @@ describe('Test video transcoding', function () { describe('Transcoding job queue', function () { it('Should have the appropriate priorities for transcoding jobs', async function () { - const body = await servers[1].jobsCommand.getJobsList({ + const body = await servers[1].jobs.getJobsList({ start: 0, count: 100, sort: '-createdAt', diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 4a5a83ee6..af1541dbd 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -55,19 +55,19 @@ describe('Test videos filter', function () { for (const server of servers) { const moderator = { username: 'moderator', password: 'my super password' } - await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) - server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) + await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) + server['moderatorAccessToken'] = await server.login.getAccessToken(moderator) - await server.videosCommand.upload({ attributes: { name: 'public ' + server.serverNumber } }) + await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } }) { const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) } { const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) } } diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 8614078f1..4b5e581d1 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -33,20 +33,20 @@ describe('Test videos history', function () { await setAccessTokensToServers([ server ]) - command = server.historyCommand + command = server.history { - const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 1' } }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 1' } }) video1UUID = uuid } { - const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 2' } }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } }) video2UUID = uuid } { - const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 3' } }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 3' } }) video3UUID = uuid } @@ -54,15 +54,15 @@ describe('Test videos history', function () { username: 'user_1', password: 'super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) it('Should get videos, without watching history', async function () { - const { data } = await server.videosCommand.listWithToken() + const { data } = await server.videos.listWithToken() for (const video of data) { - const videoDetails = await server.videosCommand.getWithToken({ id: video.id }) + const videoDetails = await server.videos.getWithToken({ id: video.id }) expect(video.userHistory).to.be.undefined expect(videoDetails.userHistory).to.be.undefined @@ -78,12 +78,12 @@ describe('Test videos history', function () { const videosOfVideos: Video[][] = [] { - const { data } = await server.videosCommand.listWithToken() + const { data } = await server.videos.listWithToken() videosOfVideos.push(data) } { - const body = await server.searchCommand.searchVideos({ token: server.accessToken, search: 'video' }) + const body = await server.search.searchVideos({ token: server.accessToken, search: 'video' }) videosOfVideos.push(body.data) } @@ -102,21 +102,21 @@ describe('Test videos history', function () { } { - const videoDetails = await server.videosCommand.getWithToken({ id: video1UUID }) + const videoDetails = await server.videos.getWithToken({ id: video1UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(3) } { - const videoDetails = await server.videosCommand.getWithToken({ id: video2UUID }) + const videoDetails = await server.videos.getWithToken({ id: video2UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(8) } { - const videoDetails = await server.videosCommand.getWithToken({ id: video3UUID }) + const videoDetails = await server.videos.getWithToken({ id: video3UUID }) expect(videoDetails.userHistory).to.be.undefined } @@ -164,7 +164,7 @@ describe('Test videos history', function () { }) it('Should disable videos history', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ videosHistoryEnabled: false }) @@ -172,7 +172,7 @@ describe('Test videos history', function () { }) it('Should re-enable videos history', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ videosHistoryEnabled: true }) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index 969393842..f0657b334 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -25,7 +25,7 @@ describe('Test a videos overview', function () { }) it('Should send empty overview', async function () { - const body = await server.overviewsCommand.getVideos({ page: 1 }) + const body = await server.overviews.getVideos({ page: 1 }) testOverviewCount(body, 0) }) @@ -35,7 +35,7 @@ describe('Test a videos overview', function () { await wait(3000) - await server.videosCommand.upload({ + await server.videos.upload({ attributes: { name: 'video 0', category: 3, @@ -43,7 +43,7 @@ describe('Test a videos overview', function () { } }) - const body = await server.overviewsCommand.getVideos({ page: 1 }) + const body = await server.overviews.getVideos({ page: 1 }) testOverviewCount(body, 0) }) @@ -53,7 +53,7 @@ describe('Test a videos overview', function () { { for (let i = 1; i < 6; i++) { - await server.videosCommand.upload({ + await server.videos.upload({ attributes: { name: 'video ' + i, category: 3, @@ -66,13 +66,13 @@ describe('Test a videos overview', function () { } { - const body = await server.overviewsCommand.getVideos({ page: 1 }) + const body = await server.overviews.getVideos({ page: 1 }) testOverviewCount(body, 1) } { - const overview = await server.overviewsCommand.getVideos({ page: 2 }) + const overview = await server.overviews.getVideos({ page: 2 }) expect(overview.tags).to.have.lengthOf(1) expect(overview.categories).to.have.lengthOf(0) @@ -81,8 +81,8 @@ describe('Test a videos overview', function () { }) it('Should have the correct overview', async function () { - const overview1 = await server.overviewsCommand.getVideos({ page: 1 }) - const overview2 = await server.overviewsCommand.getVideos({ page: 2 }) + const overview1 = await server.overviews.getVideos({ page: 1 }) + const overview2 = await server.overviews.getVideos({ page: 2 }) for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) { expect(arr).to.have.lengthOf(1) @@ -108,18 +108,18 @@ describe('Test a videos overview', function () { }) it('Should hide muted accounts', async function () { - const token = await server.usersCommand.generateUserAndToken('choco') + const token = await server.users.generateUserAndToken('choco') - await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) + await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host }) { - const body = await server.overviewsCommand.getVideos({ page: 1 }) + const body = await server.overviews.getVideos({ page: 1 }) testOverviewCount(body, 1) } { - const body = await server.overviewsCommand.getVideos({ page: 1, token }) + const body = await server.overviews.getVideos({ page: 1, token }) testOverviewCount(body, 0) } diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index 7ded1bf38..238662cf3 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -30,15 +30,15 @@ describe('Test video views cleaner', function () { await doubleFollow(servers[0], servers[1]) - videoIdServer1 = (await servers[0].videosCommand.quickUpload({ name: 'video server 1' })).uuid - videoIdServer2 = (await servers[1].videosCommand.quickUpload({ name: 'video server 2' })).uuid + videoIdServer1 = (await servers[0].videos.quickUpload({ name: 'video server 1' })).uuid + videoIdServer2 = (await servers[1].videos.quickUpload({ name: 'video server 2' })).uuid await waitJobs(servers) - 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 servers[0].videos.view({ id: videoIdServer1 }) + await servers[1].videos.view({ id: videoIdServer1 }) + await servers[0].videos.view({ id: videoIdServer2 }) + await servers[1].videos.view({ id: videoIdServer2 }) await waitJobs(servers) }) @@ -56,14 +56,14 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1) + const total = await server.sql.countVideoViewsOf(videoIdServer1) expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') } } { for (const server of servers) { - const total = await server.sqlCommand.countVideoViewsOf(videoIdServer2) + const total = await server.sql.countVideoViewsOf(videoIdServer2) expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') } } @@ -82,16 +82,16 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1) + const total = await server.sql.countVideoViewsOf(videoIdServer1) expect(total).to.equal(2) } } { - const totalServer1 = await servers[0].sqlCommand.countVideoViewsOf(videoIdServer2) + const totalServer1 = await servers[0].sql.countVideoViewsOf(videoIdServer2) expect(totalServer1).to.equal(0) - const totalServer2 = await servers[1].sqlCommand.countVideoViewsOf(videoIdServer2) + const totalServer2 = await servers[1].sql.countVideoViewsOf(videoIdServer2) expect(totalServer2).to.equal(2) } }) -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- server/tests/api/videos/audio-only.ts | 6 +++--- server/tests/api/videos/multiple-servers.ts | 8 ++++---- server/tests/api/videos/resumable-upload.ts | 8 ++++---- server/tests/api/videos/single-server.ts | 8 ++++---- server/tests/api/videos/video-captions.ts | 8 ++++---- server/tests/api/videos/video-change-ownership.ts | 14 +++++++------- server/tests/api/videos/video-channels.ts | 10 +++++----- server/tests/api/videos/video-comments.ts | 8 ++++---- server/tests/api/videos/video-description.ts | 6 +++--- server/tests/api/videos/video-hls.ts | 10 +++++----- server/tests/api/videos/video-imports.ts | 12 ++++++------ server/tests/api/videos/video-nsfw.ts | 6 +++--- server/tests/api/videos/video-playlist-thumbnails.ts | 12 ++++++------ server/tests/api/videos/video-playlists.ts | 18 +++++++++--------- server/tests/api/videos/video-privacy.ts | 8 ++++---- server/tests/api/videos/video-schedule-update.ts | 8 ++++---- server/tests/api/videos/video-transcoder.ts | 10 +++++----- server/tests/api/videos/videos-filter.ts | 10 +++++----- server/tests/api/videos/videos-history.ts | 13 ++++++------- server/tests/api/videos/videos-overview.ts | 6 +++--- server/tests/api/videos/videos-views-cleaner.ts | 13 ++++++------- 21 files changed, 100 insertions(+), 102 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index b2952e38b..b9bf96650 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -4,12 +4,12 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' -import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect describe('Test audio only video transcoding', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID: string before(async function () { @@ -36,7 +36,7 @@ describe('Test audio only video transcoding', function () { } } } - servers = await flushAndRunMultipleServers(2, configOverride) + servers = await createMultipleServers(2, configOverride) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 89d842307..562079a15 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -12,8 +12,8 @@ import { completeVideoCheck, dateIsValid, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, testImage, wait, @@ -25,7 +25,7 @@ import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test multiple servers', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] const toRemove = [] let videoUUID = '' let videoChannelId: number @@ -33,7 +33,7 @@ describe('Test multiple servers', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 2f1cf8a55..b4fc5ee09 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -8,8 +8,8 @@ import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' @@ -21,7 +21,7 @@ const expect = chai.expect describe('Test resumable upload', function () { const defaultFixture = 'video_short.mp4' - let server: ServerInfo + let server: PeerTubeServer let rootId: number async function buildSize (fixture: string, size?: number) { @@ -99,7 +99,7 @@ describe('Test resumable upload', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 12c1f7b2f..c0535be09 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -6,8 +6,8 @@ import { checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, testImage, wait @@ -19,7 +19,7 @@ const expect = chai.expect describe('Test a single server', function () { function runSuite (mode: 'legacy' | 'resumable') { - let server: ServerInfo = null + let server: PeerTubeServer = null let videoId: number | string let videoId2: string let videoUUID = '' @@ -94,7 +94,7 @@ describe('Test a single server', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index abc07194d..6caba6aa6 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -6,8 +6,8 @@ import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, testCaptionFile, wait, @@ -19,13 +19,13 @@ const expect = chai.expect describe('Test video captions', function () { const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoUUID: string before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 352eb5ea3..cefddb68e 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -7,9 +7,9 @@ import { ChangeOwnershipCommand, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - flushAndRunServer, - ServerInfo, + createMultipleServers, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs @@ -19,7 +19,7 @@ import { VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test video change ownership - nominal', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] const firstUser = 'first' const secondUser = 'second' @@ -39,7 +39,7 @@ describe('Test video change ownership - nominal', function () { before(async function () { this.timeout(50000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) @@ -251,7 +251,7 @@ describe('Test video change ownership - nominal', function () { }) describe('Test video change ownership - quota too small', function () { - let server: ServerInfo + let server: PeerTubeServer const firstUser = 'first' const secondUser = 'second' @@ -263,7 +263,7 @@ describe('Test video change ownership - quota too small', function () { this.timeout(50000) // Run one server - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await server.users.create({ username: secondUser, videoQuota: 10 }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 1efef932c..140fee7fe 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -7,8 +7,8 @@ import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, testFileExistsOrNot, @@ -20,14 +20,14 @@ import { User, VideoChannel } from '@shared/models' const expect = chai.expect -async function findChannel (server: ServerInfo, channelId: number) { +async function findChannel (server: PeerTubeServer, channelId: number) { const body = await server.channels.list({ sort: '-name' }) return body.data.find(c => c.id === channelId) } describe('Test video channels', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let userInfo: User let secondVideoChannelId: number let totoChannel: number @@ -40,7 +40,7 @@ describe('Test video channels', function () { before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index adb59bd74..9709e0628 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -6,8 +6,8 @@ import { cleanupTests, CommentsCommand, dateIsValid, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, testImage } from '@shared/extra-utils' @@ -15,7 +15,7 @@ import { const expect = chai.expect describe('Test video comments', function () { - let server: ServerInfo + let server: PeerTubeServer let videoId: number let videoUUID: string let threadId: number @@ -28,7 +28,7 @@ describe('Test video comments', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index b89247288..ce45eac80 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -2,12 +2,12 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect describe('Test video description', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID = '' let videoId: number const longDescription = 'my super description for server 1'.repeat(50) @@ -16,7 +16,7 @@ describe('Test video description', function () { this.timeout(40000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 9d79f2683..4c4b18887 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -11,9 +11,9 @@ import { checkTmpIsEmpty, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeRawRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd @@ -23,7 +23,7 @@ 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 ]) { +async function checkHlsPlaylist (servers: PeerTubeServer[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { for (const server of servers) { const videoDetails = await server.videos.get({ id: videoUUID }) const baseUrl = `http://${videoDetails.account.host}` @@ -98,7 +98,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn } describe('Test HLS videos', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID = '' let videoAudioUUID = '' @@ -176,7 +176,7 @@ describe('Test HLS videos', function () { } } } - servers = await flushAndRunMultipleServers(2, configOverride) + servers = await createMultipleServers(2, configOverride) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 8b6542aa4..4ef55c3af 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -6,9 +6,9 @@ import { areHttpImportTestsDisabled, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, ImportsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, testCaptionFile, testImage, @@ -19,13 +19,13 @@ import { VideoPrivacy, VideoResolution } from '@shared/models' const expect = chai.expect describe('Test video imports', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let channelIdServer1: number let channelIdServer2: number if (areHttpImportTestsDisabled()) return - async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { + async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) { const videoHttp = await server.videos.get({ id: idHttp }) expect(videoHttp.name).to.equal('small video - youtube') @@ -63,7 +63,7 @@ describe('Test video imports', function () { expect(bodyCaptions.total).to.equal(2) } - async function checkVideoServer2 (server: ServerInfo, id: number | string) { + async function checkVideoServer2 (server: PeerTubeServer, id: number | string) { const video = await server.videos.get({ id }) expect(video.name).to.equal('my super name') @@ -84,7 +84,7 @@ describe('Test video imports', function () { this.timeout(30_000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 95395a582..b25dcda20 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' const expect = chai.expect @@ -13,7 +13,7 @@ function createOverviewRes (overview: VideosOverview) { } describe('Test video NSFW policy', function () { - let server: ServerInfo + let server: PeerTubeServer let userAccessToken: string let customConfig: CustomConfig @@ -61,7 +61,7 @@ describe('Test video NSFW policy', function () { before(async function () { this.timeout(50000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) // Get the access tokens await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index 709f64c4d..9a682c12b 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, testImage, @@ -17,7 +17,7 @@ import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/ const expect = chai.expect describe('Playlist thumbnail', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let playlistWithoutThumbnailId: number let playlistWithThumbnailId: number @@ -30,13 +30,13 @@ describe('Playlist thumbnail', function () { let video1: number let video2: number - async function getPlaylistWithoutThumbnail (server: ServerInfo) { + async function getPlaylistWithoutThumbnail (server: PeerTubeServer) { const body = await server.playlists.list({ start: 0, count: 10 }) return body.data.find(p => p.displayName === 'playlist without thumbnail') } - async function getPlaylistWithThumbnail (server: ServerInfo) { + async function getPlaylistWithThumbnail (server: PeerTubeServer) { const body = await server.playlists.list({ start: 0, count: 10 }) return body.data.find(p => p.displayName === 'playlist with thumbnail') @@ -45,7 +45,7 @@ describe('Playlist thumbnail', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } }) + servers = await createMultipleServers(2, { transcoding: { enabled: false } }) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 0dc53d4c0..71ca3e63a 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -7,9 +7,9 @@ import { checkPlaylistFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, PlaylistsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, testImage, @@ -28,7 +28,7 @@ import { const expect = chai.expect async function checkPlaylistElementType ( - servers: ServerInfo[], + servers: PeerTubeServer[], playlistId: string, type: VideoPlaylistElementType, position: number, @@ -52,7 +52,7 @@ async function checkPlaylistElementType ( } describe('Test video playlists', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let playlistServer2Id1: number let playlistServer2Id2: number @@ -75,7 +75,7 @@ describe('Test video playlists', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } }) + servers = await createMultipleServers(3, { transcoding: { enabled: false } }) // Get the access tokens await setAccessTokensToServers(servers) @@ -584,10 +584,10 @@ describe('Test video playlists', function () { }) describe('Element type', function () { - let groupUser1: ServerInfo[] - let groupWithoutToken1: ServerInfo[] - let group1: ServerInfo[] - let group2: ServerInfo[] + let groupUser1: PeerTubeServer[] + let groupWithoutToken1: PeerTubeServer[] + let group1: PeerTubeServer[] + let group2: PeerTubeServer[] let video1: string let video2: string diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index de08a9e7b..5ec626155 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -3,13 +3,13 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, doubleFollow, flushAndRunServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test video privacy', function () { - const servers: ServerInfo[] = [] + const servers: PeerTubeServer[] = [] let anotherUserToken: string let privateVideoId: number @@ -35,8 +35,8 @@ describe('Test video privacy', function () { this.timeout(50000) // Run servers - servers.push(await flushAndRunServer(1, dontFederateUnlistedConfig)) - servers.push(await flushAndRunServer(2)) + servers.push(await createSingleServer(1, dontFederateUnlistedConfig)) + servers.push(await createSingleServer(2)) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 3938b47c8..22b5cf1c2 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -23,14 +23,14 @@ function in10Seconds () { } describe('Test video update scheduler', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let video2UUID: string before(async function () { this.timeout(30000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 37450eeeb..2465d2d89 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -9,11 +9,11 @@ import { buildAbsoluteFixturePath, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, makeGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd @@ -31,7 +31,7 @@ import { const expect = chai.expect -function updateConfigForTranscoding (server: ServerInfo) { +function updateConfigForTranscoding (server: PeerTubeServer) { return server.config.updateCustomSubConfig({ newConfig: { transcoding: { @@ -56,14 +56,14 @@ function updateConfigForTranscoding (server: ServerInfo) { } describe('Test video transcoding', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let video4k: string before(async function () { this.timeout(30_000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index af1541dbd..db9150655 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -6,14 +6,14 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeGetRequest, - ServerInfo, + PeerTubeServer, 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) { +async function getVideosNames (server: PeerTubeServer, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', @@ -42,14 +42,14 @@ async function getVideosNames (server: ServerInfo, token: string, filter: string } describe('Test videos filter', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] // --------------------------------------------------------------- before(async function () { this.timeout(160000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 4b5e581d1..55e53cb94 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -5,11 +5,10 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, HistoryCommand, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' @@ -18,7 +17,7 @@ import { Video } from '@shared/models' const expect = chai.expect describe('Test videos history', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let video1UUID: string let video2UUID: string let video3UUID: string @@ -29,7 +28,7 @@ describe('Test videos history', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) @@ -191,7 +190,7 @@ describe('Test videos history', function () { await killallServers([ server ]) - await reRunServer(server, { history: { videos: { max_age: '10 days' } } }) + await server.run({ history: { videos: { max_age: '10 days' } } }) await wait(6000) @@ -206,7 +205,7 @@ describe('Test videos history', function () { await killallServers([ server ]) - await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } }) + await server.run({ history: { videos: { max_age: '5 seconds' } } }) await wait(6000) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index f0657b334..70aa66549 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,13 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' import { VideosOverview } from '@shared/models' const expect = chai.expect describe('Test a videos overview', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null function testOverviewCount (overview: VideosOverview, expected: number) { expect(overview.tags).to.have.lengthOf(expected) @@ -19,7 +19,7 @@ describe('Test a videos overview', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index 238662cf3..0be03ddd2 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -5,10 +5,9 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -17,7 +16,7 @@ import { const expect = chai.expect describe('Test video views cleaner', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoIdServer1: string let videoIdServer2: string @@ -25,7 +24,7 @@ describe('Test video views cleaner', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await doubleFollow(servers[0], servers[1]) @@ -48,7 +47,7 @@ describe('Test video views cleaner', function () { await killallServers([ servers[0] ]) - await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } }) + await servers[0].run({ views: { videos: { remote: { max_age: '10 days' } } } }) await wait(6000) @@ -74,7 +73,7 @@ describe('Test video views cleaner', function () { await killallServers([ servers[0] ]) - await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } }) + await servers[0].run({ views: { videos: { remote: { max_age: '5 seconds' } } } }) await wait(6000) -- cgit v1.2.3 From 59bbcced37005dd511daca9bd58ae2998cb931b1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:19:16 +0200 Subject: Centralize test URLs --- server/tests/api/videos/video-imports.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 4ef55c3af..192f5232e 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -5,9 +5,9 @@ import * as chai from 'chai' import { areHttpImportTestsDisabled, cleanupTests, - doubleFollow, createMultipleServers, - ImportsCommand, + doubleFollow, + FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, testCaptionFile, @@ -110,7 +110,7 @@ describe('Test video imports', function () { } { - const attributes = { ...baseAttributes, targetUrl: ImportsCommand.getYoutubeVideoUrl() } + const attributes = { ...baseAttributes, targetUrl: FIXTURE_URLS.youtube } const { video } = await servers[0].imports.importVideo({ attributes }) expect(video.name).to.equal('small video - youtube') @@ -162,7 +162,7 @@ Ajouter un sous-titre est vraiment facile`) { const attributes = { ...baseAttributes, - magnetUri: ImportsCommand.getMagnetURI(), + magnetUri: FIXTURE_URLS.magnet, description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] } @@ -199,13 +199,13 @@ Ajouter un sous-titre est vraiment facile`) expect(videoImports).to.have.lengthOf(3) - expect(videoImports[2].targetUrl).to.equal(ImportsCommand.getYoutubeVideoUrl()) + expect(videoImports[2].targetUrl).to.equal(FIXTURE_URLS.youtube) expect(videoImports[2].magnetUri).to.be.null expect(videoImports[2].torrentName).to.be.null expect(videoImports[2].video.name).to.equal('small video - youtube') expect(videoImports[1].targetUrl).to.be.null - expect(videoImports[1].magnetUri).to.equal(ImportsCommand.getMagnetURI()) + expect(videoImports[1].magnetUri).to.equal(FIXTURE_URLS.magnet) expect(videoImports[1].torrentName).to.be.null expect(videoImports[1].video.name).to.equal('super peertube2 video') @@ -234,7 +234,7 @@ Ajouter un sous-titre est vraiment facile`) this.timeout(60_000) const attributes = { - targetUrl: ImportsCommand.getYoutubeVideoUrl(), + targetUrl: FIXTURE_URLS.youtube, channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC, category: 10, @@ -270,7 +270,7 @@ Ajouter un sous-titre est vraiment facile`) const attributes = { name: 'transcoded video', - magnetUri: ImportsCommand.getMagnetURI(), + magnetUri: FIXTURE_URLS.magnet, channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC } @@ -320,7 +320,7 @@ Ajouter un sous-titre est vraiment facile`) const attributes = { name: 'hdr video', - targetUrl: ImportsCommand.getYoutubeHDRVideoUrl(), + targetUrl: FIXTURE_URLS.youtubeHDR, channelId: channelIdServer1, privacy: VideoPrivacy.PUBLIC } -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- server/tests/api/videos/multiple-servers.ts | 2 +- server/tests/api/videos/resumable-upload.ts | 2 +- server/tests/api/videos/video-change-ownership.ts | 2 +- server/tests/api/videos/video-channels.ts | 6 +++--- server/tests/api/videos/video-hls.ts | 2 +- server/tests/api/videos/video-nsfw.ts | 12 +++++++----- server/tests/api/videos/video-playlists.ts | 2 +- server/tests/api/videos/video-privacy.ts | 2 +- server/tests/api/videos/video-transcoder.ts | 10 +++++----- server/tests/api/videos/videos-filter.ts | 6 +++--- server/tests/api/videos/videos-history.ts | 2 +- 11 files changed, 25 insertions(+), 23 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 562079a15..edf2773cd 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import * as request from 'supertest' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkTmpIsEmpty, diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index b4fc5ee09..0e62972c2 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { pathExists, readdir, stat } from 'fs-extra' import { join } from 'path' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index cefddb68e..792550101 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { ChangeOwnershipCommand, cleanupTests, diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 140fee7fe..eeaec5ad2 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -324,7 +324,7 @@ describe('Test video channels', function () { for (const server of servers) { const channelURI = 'second_video_channel@localhost:' + servers[0].port - const { total, data } = await server.videos.listByChannel({ videoChannelName: channelURI }) + const { total, data } = await server.videos.listByChannel({ handle: channelURI }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -347,13 +347,13 @@ describe('Test video channels', function () { for (const server of servers) { { const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port - const { total } = await server.videos.listByChannel({ videoChannelName: secondChannelURI }) + const { total } = await server.videos.listByChannel({ handle: secondChannelURI }) expect(total).to.equal(0) } { const channelURI = 'root_channel@localhost:' + servers[0].port - const { total, data } = await server.videos.listByChannel({ videoChannelName: channelURI }) + const { total, data } = await server.videos.listByChannel({ handle: channelURI }) expect(total).to.equal(1) expect(data).to.be.an('array') diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 4c4b18887..df030110b 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' +import { HttpStatusCode } from '@shared/models' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index b25dcda20..0a9e5ce3f 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -19,8 +19,10 @@ describe('Test video NSFW policy', function () { async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { const user = await server.users.getMyInfo() - const videoChannelName = user.videoChannels[0].name + + const channelName = user.videoChannels[0].name const accountName = user.account.name + '@' + user.account.host + const hasQuery = Object.keys(query).length !== 0 let promises: Promise>[] @@ -28,8 +30,8 @@ describe('Test video NSFW policy', function () { promises = [ server.search.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), server.videos.listWithToken({ token, ...query }), - server.videos.listByAccount({ token, accountName, ...query }), - server.videos.listByChannel({ token, videoChannelName, ...query }) + server.videos.listByAccount({ token, handle: channelName, ...query }), + server.videos.listByChannel({ token, handle: accountName, ...query }) ] // Overviews do not support video filters @@ -45,8 +47,8 @@ describe('Test video NSFW policy', function () { promises = [ server.search.searchVideos({ search: 'n', sort: '-publishedAt' }), server.videos.list(), - server.videos.listByAccount({ accountName }), - server.videos.listByChannel({ videoChannelName }) + server.videos.listByAccount({ handle: channelName }), + server.videos.listByChannel({ handle: accountName }) ] // Overviews do not support video filters diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 71ca3e63a..9a28a421a 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkPlaylistFilesWereRemoved, cleanupTests, diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 5ec626155..06011082d 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, doubleFollow, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { VideoCreateResult, VideoPrivacy } from '@shared/models' diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 2465d2d89..7510472e3 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { join } from 'path' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, @@ -384,8 +384,8 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(1) - await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) - await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 }) const magnetUri = videoDetails.files[0].magnetUri expect(magnetUri).to.contain('.mp4') @@ -408,8 +408,8 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(1) - await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) - await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 }) const magnetUri = videoDetails.files[0].magnetUri expect(magnetUri).to.contain('.mp4') diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index db9150655..88dff3e7f 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, doubleFollow, @@ -13,7 +13,7 @@ import { } from '@shared/extra-utils' import { UserRole, Video, VideoPrivacy } from '@shared/models' -async function getVideosNames (server: PeerTubeServer, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { +async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', @@ -32,7 +32,7 @@ async function getVideosNames (server: PeerTubeServer, token: string, filter: st sort: 'createdAt', filter }, - statusCodeExpected + expectedStatus }) videosResults.push(res.body.data.map(v => v.name)) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 55e53cb94..acb9d1a46 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/tests/api/videos/audio-only.ts | 2 +- server/tests/api/videos/multiple-servers.ts | 5 ++--- server/tests/api/videos/resumable-upload.ts | 3 +-- server/tests/api/videos/video-captions.ts | 2 +- server/tests/api/videos/video-change-ownership.ts | 5 ++--- server/tests/api/videos/video-channels.ts | 2 +- server/tests/api/videos/video-comments.ts | 2 +- server/tests/api/videos/video-description.ts | 2 +- server/tests/api/videos/video-hls.ts | 5 ++--- server/tests/api/videos/video-nsfw.ts | 9 +++++---- server/tests/api/videos/video-playlist-thumbnails.ts | 2 +- server/tests/api/videos/video-playlists.ts | 6 +++--- server/tests/api/videos/video-privacy.ts | 7 +++---- server/tests/api/videos/video-schedule-update.ts | 2 +- server/tests/api/videos/video-transcoder.ts | 5 ++--- server/tests/api/videos/videos-filter.ts | 5 ++--- server/tests/api/videos/videos-history.ts | 3 +-- server/tests/api/videos/videos-views-cleaner.ts | 2 +- 18 files changed, 31 insertions(+), 38 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index b9bf96650..15c3ae6d6 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index edf2773cd..d916abb09 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -3,16 +3,15 @@ import 'mocha' import * as chai from 'chai' import * as request from 'supertest' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkTmpIsEmpty, checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, + createMultipleServers, dateIsValid, doubleFollow, - createMultipleServers, PeerTubeServer, setAccessTokensToServers, testImage, @@ -20,7 +19,7 @@ import { waitJobs, webtorrentAdd } from '@shared/extra-utils' -import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 0e62972c2..13e47c85e 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { pathExists, readdir, stat } from 'fs-extra' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, @@ -13,7 +12,7 @@ import { setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' -import { VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 6caba6aa6..e3d46e619 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { checkVideoFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, testCaptionFile, diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 792550101..6ae6d3004 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,19 +2,18 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { ChangeOwnershipCommand, cleanupTests, - doubleFollow, createMultipleServers, createSingleServer, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs } from '@shared/extra-utils' -import { VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index eeaec5ad2..c25754eb6 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -6,8 +6,8 @@ import { basename } from 'path' import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 9709e0628..61ee54540 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, CommentsCommand, - dateIsValid, createSingleServer, + dateIsValid, PeerTubeServer, setAccessTokensToServers, testImage diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index ce45eac80..d22b4ed96 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index df030110b..7845f7334 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,22 +3,21 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, checkSegmentHash, checkTmpIsEmpty, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeRawRequest, PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd } from '@shared/extra-utils' -import { VideoStreamingPlaylistType } from '@shared/models' +import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' const expect = chai.expect diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 0a9e5ce3f..b5d183d62 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -30,8 +30,8 @@ describe('Test video NSFW policy', function () { promises = [ server.search.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), server.videos.listWithToken({ token, ...query }), - server.videos.listByAccount({ token, handle: channelName, ...query }), - server.videos.listByChannel({ token, handle: accountName, ...query }) + server.videos.listByAccount({ token, handle: accountName, ...query }), + server.videos.listByChannel({ token, handle: channelName, ...query }) ] // Overviews do not support video filters @@ -47,8 +47,8 @@ describe('Test video NSFW policy', function () { promises = [ server.search.searchVideos({ search: 'n', sort: '-publishedAt' }), server.videos.list(), - server.videos.listByAccount({ handle: channelName }), - server.videos.listByChannel({ handle: accountName }) + server.videos.listByAccount({ token: null, handle: accountName }), + server.videos.listByChannel({ token: null, handle: channelName }) ] // Overviews do not support video filters @@ -82,6 +82,7 @@ describe('Test video NSFW policy', function () { }) describe('Instance default NSFW policy', function () { + it('Should display NSFW videos with display default NSFW policy', async function () { const serverConfig = await server.config.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index 9a682c12b..f0b2ca169 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 9a28a421a..f42aee2ff 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -2,14 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { checkPlaylistFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, - PlaylistsCommand, + doubleFollow, PeerTubeServer, + PlaylistsCommand, setAccessTokensToServers, setDefaultVideoChannel, testImage, @@ -17,6 +16,7 @@ import { waitJobs } from '@shared/extra-utils' import { + HttpStatusCode, VideoPlaylist, VideoPlaylistCreateResult, VideoPlaylistElementType, diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 06011082d..b51b3bcdd 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -2,9 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' -import { cleanupTests, doubleFollow, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' -import { VideoCreateResult, VideoPrivacy } from '@shared/models' +import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -162,7 +161,7 @@ describe('Test video privacy', function () { }) it('Should not be able to get this unlisted video using its id', async function () { - await servers[1].videos.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[1].videos.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should be able to get this unlisted video using its uuid/shortUUID', async function () { diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 22b5cf1c2..3f7738784 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, wait, diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 7510472e3..e4892bb24 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -4,12 +4,11 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, generateHighBitrateVideo, generateVideoWithFramerate, makeGetRequest, @@ -18,7 +17,7 @@ import { waitJobs, webtorrentAdd } from '@shared/extra-utils' -import { getMaxBitrate, VideoResolution, VideoState } from '@shared/models' +import { getMaxBitrate, HttpStatusCode, VideoResolution, VideoState } from '@shared/models' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { canDoQuickTranscode, diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 88dff3e7f..2306807bf 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -2,16 +2,15 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { UserRole, Video, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, UserRole, Video, VideoPrivacy } from '@shared/models' async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) { const paths = [ diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index acb9d1a46..e4bc0bb3a 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -12,7 +11,7 @@ import { setAccessTokensToServers, wait } from '@shared/extra-utils' -import { Video } from '@shared/models' +import { HttpStatusCode, Video } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index 0be03ddd2..82268b1be 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, killallServers, PeerTubeServer, setAccessTokensToServers, -- cgit v1.2.3 From c63830f15403ac4e750829f27d8bbbdc9a59282c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Jul 2021 13:58:35 +0200 Subject: Rename captions commands --- server/tests/api/videos/video-captions.ts | 20 ++++++++++---------- server/tests/api/videos/video-imports.ts | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index e3d46e619..4c8e28adf 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -40,7 +40,7 @@ describe('Test video captions', function () { it('Should list the captions and return an empty list', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(0) expect(body.data).to.have.lengthOf(0) } @@ -49,13 +49,13 @@ describe('Test video captions', function () { it('Should create two new captions', async function () { this.timeout(30000) - await servers[0].captions.createVideoCaption({ + await servers[0].captions.add({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good1.vtt' }) - await servers[0].captions.createVideoCaption({ + await servers[0].captions.add({ language: 'zh', videoId: videoUUID, fixture: 'subtitle-good2.vtt', @@ -67,7 +67,7 @@ describe('Test video captions', function () { it('Should list these uploaded captions', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -88,7 +88,7 @@ describe('Test video captions', function () { it('Should replace an existing caption', async function () { this.timeout(30000) - await servers[0].captions.createVideoCaption({ + await servers[0].captions.add({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good2.vtt' @@ -99,7 +99,7 @@ describe('Test video captions', function () { it('Should have this caption updated', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -114,7 +114,7 @@ describe('Test video captions', function () { it('Should replace an existing caption with a srt file and convert it', async function () { this.timeout(30000) - await servers[0].captions.createVideoCaption({ + await servers[0].captions.add({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good.srt' @@ -128,7 +128,7 @@ describe('Test video captions', function () { it('Should have this caption updated and converted', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -157,14 +157,14 @@ describe('Test video captions', function () { it('Should remove one caption', async function () { this.timeout(30000) - await servers[0].captions.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) + await servers[0].captions.delete({ videoId: videoUUID, language: 'ar' }) await waitJobs(servers) }) it('Should only list the caption that was not deleted', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 192f5232e..2eac130d2 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -59,7 +59,7 @@ describe('Test video imports', function () { expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') expect(videoMagnet.name).to.contain('super peertube2 video') - const bodyCaptions = await server.captions.listVideoCaptions({ videoId: idHttp }) + const bodyCaptions = await server.captions.list({ videoId: idHttp }) expect(bodyCaptions.total).to.equal(2) } @@ -76,7 +76,7 @@ describe('Test video imports', function () { expect(video.files).to.have.lengthOf(1) - const bodyCaptions = await server.captions.listVideoCaptions({ videoId: id }) + const bodyCaptions = await server.captions.list({ videoId: id }) expect(bodyCaptions.total).to.equal(2) } @@ -120,7 +120,7 @@ describe('Test video imports', function () { await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath) await testImage(servers[0].url, 'video_import_preview', video.previewPath) - const bodyCaptions = await servers[0].captions.listVideoCaptions({ videoId: video.id }) + const bodyCaptions = await servers[0].captions.list({ videoId: video.id }) const videoCaptions = bodyCaptions.data expect(videoCaptions).to.have.lengthOf(2) -- cgit v1.2.3