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