Introduce videos command

This commit is contained in:
Chocobozzz 2021-07-15 10:02:54 +02:00
parent 7926c5f9b3
commit d23dd9fbfc
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
108 changed files with 2484 additions and 3100 deletions

View File

@ -1,6 +1,6 @@
import * as autocannon from 'autocannon' import * as autocannon from 'autocannon'
import { writeJson } from 'fs-extra' import { writeJson } from 'fs-extra'
import { flushAndRunServer, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' import { flushAndRunServer, killallServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models' import { Video, VideoPrivacy } from '@shared/models'
import { registerTSPaths } from '../server/helpers/register-ts-paths' import { registerTSPaths } from '../server/helpers/register-ts-paths'
@ -197,7 +197,7 @@ async function prepare () {
}) })
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const videoAttributes = { const attributes = {
name: 'my super video', name: 'my super video',
category: 2, category: 2,
nsfw: true, nsfw: true,
@ -210,12 +210,11 @@ async function prepare () {
} }
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
Object.assign(videoAttributes, { name: 'my super video ' + i }) await server.videosCommand.upload({ attributes: { ...attributes, name: 'my super video ' + i } })
await uploadVideo(server.url, server.accessToken, videoAttributes)
} }
const resVideos = await getVideosList(server.url) const { data } = await server.videosCommand.list()
video = resVideos.body.data.find(v => v.name === 'my super video 1') video = data.find(v => v.name === 'my super video 1')
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
const text = 'my super first comment' const text = 'my super first comment'

View File

@ -6,11 +6,8 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
rateVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideoAndGetId,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -49,9 +46,9 @@ describe('Test AP cleaner', function () {
// Create 1 comment per video // Create 1 comment per video
// Update 1 remote URL and 1 local URL on // Update 1 remote URL and 1 local URL on
videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid
videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid
videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid
videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ]
@ -59,7 +56,7 @@ describe('Test AP cleaner', function () {
for (const server of servers) { for (const server of servers) {
for (const uuid of videoUUIDs) { for (const uuid of videoUUIDs) {
await rateVideo(server.url, server.accessToken, uuid, 'like') await server.videosCommand.rate({ id: uuid, rating: 'like' })
await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' })
} }
} }
@ -70,9 +67,10 @@ describe('Test AP cleaner', function () {
it('Should have the correct likes', async function () { it('Should have the correct likes', async function () {
for (const server of servers) { for (const server of servers) {
for (const uuid of videoUUIDs) { for (const uuid of videoUUIDs) {
const res = await getVideo(server.url, uuid) const video = await server.videosCommand.get({ id: uuid })
expect(res.body.likes).to.equal(3)
expect(res.body.dislikes).to.equal(0) expect(video.likes).to.equal(3)
expect(video.dislikes).to.equal(0)
} }
} }
}) })
@ -90,16 +88,16 @@ describe('Test AP cleaner', function () {
// Updated rates of my video // Updated rates of my video
{ {
const res = await getVideo(servers[0].url, videoUUID1) const video = await servers[0].videosCommand.get({ id: videoUUID1 })
expect(res.body.likes).to.equal(2) expect(video.likes).to.equal(2)
expect(res.body.dislikes).to.equal(0) expect(video.dislikes).to.equal(0)
} }
// Did not update rates of a remote video // Did not update rates of a remote video
{ {
const res = await getVideo(servers[0].url, videoUUID2) const video = await servers[0].videosCommand.get({ id: videoUUID2 })
expect(res.body.likes).to.equal(3) expect(video.likes).to.equal(3)
expect(res.body.dislikes).to.equal(0) expect(video.dislikes).to.equal(0)
} }
}) })
@ -108,7 +106,7 @@ describe('Test AP cleaner', function () {
for (const server of servers) { for (const server of servers) {
for (const uuid of videoUUIDs) { for (const uuid of videoUUIDs) {
await rateVideo(server.url, server.accessToken, uuid, 'dislike') await server.videosCommand.rate({ id: uuid, rating: 'dislike' })
} }
} }
@ -116,9 +114,9 @@ describe('Test AP cleaner', function () {
for (const server of servers) { for (const server of servers) {
for (const uuid of videoUUIDs) { for (const uuid of videoUUIDs) {
const res = await getVideo(server.url, uuid) const video = await server.videosCommand.get({ id: uuid })
expect(res.body.likes).to.equal(0) expect(video.likes).to.equal(0)
expect(res.body.dislikes).to.equal(3) expect(video.dislikes).to.equal(3)
} }
} }
}) })
@ -137,16 +135,16 @@ describe('Test AP cleaner', function () {
// Updated rates of my video // Updated rates of my video
{ {
const res = await getVideo(servers[0].url, videoUUID1) const video = await servers[0].videosCommand.get({ id: videoUUID1 })
expect(res.body.likes).to.equal(0) expect(video.likes).to.equal(0)
expect(res.body.dislikes).to.equal(2) expect(video.dislikes).to.equal(2)
} }
// Did not update rates of a remote video // Did not update rates of a remote video
{ {
const res = await getVideo(servers[0].url, videoUUID2) const video = await servers[0].videosCommand.get({ id: videoUUID2 })
expect(res.body.likes).to.equal(0) expect(video.likes).to.equal(0)
expect(res.body.dislikes).to.equal(3) expect(video.dislikes).to.equal(3)
} }
}) })

View File

@ -2,8 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { VideoPlaylistPrivacy } from '@shared/models' import { HttpStatusCode } from '@shared/core-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
@ -11,9 +10,9 @@ import {
makeActivityPubGetRequest, makeActivityPubGetRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel
uploadVideoAndGetId } from '@shared/extra-utils'
} from '../../../../shared/extra-utils' import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -69,7 +68,7 @@ describe('Test activitypub', function () {
await setDefaultVideoChannel(servers) await setDefaultVideoChannel(servers)
{ {
video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' }) video = await await servers[0].videosCommand.quickUpload({ name: 'video' })
} }
{ {

View File

@ -2,17 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideosListSort,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
waitJobs
} from '../../../../shared/extra-utils'
import { Video } from '../../../../shared/models/videos'
const expect = chai.expect const expect = chai.expect
@ -36,10 +26,9 @@ describe('Test ActivityPub fetcher', function () {
const userAccessToken = await servers[0].loginCommand.getAccessToken(user) const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) await servers[0].videosCommand.upload({ attributes: { name: 'video root' } })
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'bad video root' } })
const badVideoUUID = res.body.video.uuid await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'video user' } })
await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
{ {
const to = 'http://localhost:' + servers[0].port + '/accounts/user1' const to = 'http://localhost:' + servers[0].port + '/accounts/user1'
@ -48,8 +37,8 @@ describe('Test ActivityPub fetcher', function () {
} }
{ {
const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid
await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value) await servers[0].sqlCommand.setVideoField(uuid, 'url', value)
} }
}) })
@ -60,20 +49,18 @@ describe('Test ActivityPub fetcher', function () {
await waitJobs(servers) await waitJobs(servers)
{ {
const res = await getVideosListSort(servers[0].url, 'createdAt') const { total, data } = await servers[0].videosCommand.list({ sort: 'createdAt' })
expect(res.body.total).to.equal(3)
const data: Video[] = res.body.data expect(total).to.equal(3)
expect(data[0].name).to.equal('video root') expect(data[0].name).to.equal('video root')
expect(data[1].name).to.equal('bad video root') expect(data[1].name).to.equal('bad video root')
expect(data[2].name).to.equal('video user') expect(data[2].name).to.equal('video user')
} }
{ {
const res = await getVideosListSort(servers[1].url, 'createdAt') const { total, data } = await servers[1].videosCommand.list({ sort: 'createdAt' })
expect(res.body.total).to.equal(1)
const data: Video[] = res.body.data expect(total).to.equal(1)
expect(data[0].name).to.equal('video root') expect(data[0].name).to.equal('video root')
} }
}) })

View File

@ -6,14 +6,11 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
killallServers, killallServers,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
uploadVideo,
uploadVideoAndGetId,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -37,17 +34,17 @@ describe('Test AP refresher', function () {
await setDefaultVideoChannel(servers) await setDefaultVideoChannel(servers)
{ {
videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid videoUUID1 = (await servers[1].videosCommand.quickUpload({ name: 'video1' })).uuid
videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'video2' })).uuid
videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid videoUUID3 = (await servers[1].videosCommand.quickUpload({ name: 'video3' })).uuid
} }
{ {
const a1 = await servers[1].usersCommand.generateUserAndToken('user1') const token1 = await servers[1].usersCommand.generateUserAndToken('user1')
await uploadVideo(servers[1].url, a1, { name: 'video4' }) await servers[1].videosCommand.upload({ token: token1, attributes: { name: 'video4' } })
const a2 = await servers[1].usersCommand.generateUserAndToken('user2') const token2 = await servers[1].usersCommand.generateUserAndToken('user2')
await uploadVideo(servers[1].url, a2, { name: 'video5' }) await servers[1].videosCommand.upload({ token: token2, attributes: { name: 'video5' } })
} }
{ {
@ -75,13 +72,13 @@ describe('Test AP refresher', function () {
// Change UUID so the remote server returns a 404 // Change UUID so the remote server returns a 404
await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
await getVideo(servers[0].url, videoUUID1) await servers[0].videosCommand.get({ id: videoUUID1 })
await getVideo(servers[0].url, videoUUID2) await servers[0].videosCommand.get({ id: videoUUID2 })
await waitJobs(servers) await waitJobs(servers)
await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404) await servers[0].videosCommand.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200) await servers[0].videosCommand.get({ id: videoUUID2 })
}) })
it('Should not update a remote video if the remote instance is down', async function () { it('Should not update a remote video if the remote instance is down', async function () {
@ -94,13 +91,13 @@ describe('Test AP refresher', function () {
// Video will need a refresh // Video will need a refresh
await wait(10000) await wait(10000)
await getVideo(servers[0].url, videoUUID3) await servers[0].videosCommand.get({ id: videoUUID3 })
// The refresh should fail // The refresh should fail
await waitJobs([ servers[0] ]) await waitJobs([ servers[0] ])
await reRunServer(servers[1]) await reRunServer(servers[1])
await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200) await servers[0].videosCommand.get({ id: videoUUID3 })
}) })
}) })

View File

@ -10,12 +10,10 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunServer, flushAndRunServer,
getVideoIdFromUUID,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { AbuseCreate, AbuseState } from '@shared/models' import { AbuseCreate, AbuseState } from '@shared/models'
@ -41,15 +39,10 @@ describe('Test abuses API validators', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const username = 'user1' userToken = await server.usersCommand.generateUserAndToken('user_1')
const password = 'my super password'
await server.usersCommand.create({ username: username, password: password })
userToken = await server.loginCommand.getAccessToken({ username, password })
userToken2 = await server.usersCommand.generateUserAndToken('user_2') userToken2 = await server.usersCommand.generateUserAndToken('user_2')
const res = await uploadVideo(server.url, server.accessToken, {}) server.video = await server.videosCommand.upload()
server.video = res.body.video
command = server.abusesCommand command = server.abusesCommand
}) })
@ -421,7 +414,7 @@ describe('Test abuses API validators', function () {
await doubleFollow(anotherServer, server) await doubleFollow(anotherServer, server)
const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) const server2VideoId = await anotherServer.videosCommand.getId({ uuid: server.video.uuid })
await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId }) await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId })
await waitJobs([ server, anotherServer ]) await waitJobs([ server, anotherServer ])

View File

@ -13,8 +13,7 @@ import {
sendRTMPStream, sendRTMPStream,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
stopFfmpeg, stopFfmpeg
uploadVideoAndGetId
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoCreateResult, VideoPrivacy } from '@shared/models' import { VideoCreateResult, VideoPrivacy } from '@shared/models'
@ -58,7 +57,7 @@ describe('Test video lives API validator', function () {
} }
{ {
videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id videoIdNotLive = (await server.videosCommand.quickUpload({ name: 'not live' })).id
} }
command = server.liveCommand command = server.liveCommand

View File

@ -10,14 +10,12 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
makeDeleteRequest, makeDeleteRequest,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
makePutBodyRequest, makePutBodyRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideoAndGetId,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
@ -45,14 +43,13 @@ describe('Test server redundancy API validators', function () {
await servers[0].usersCommand.create({ username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(user) userAccessToken = await servers[0].loginCommand.getAccessToken(user)
videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id videoIdLocal = (await servers[0].videosCommand.quickUpload({ name: 'video' })).id
const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid const remoteUUID = (await servers[1].videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs(servers) await waitJobs(servers)
const resVideo = await getVideo(servers[0].url, remoteUUID) videoRemote = await servers[0].videosCommand.get({ id: remoteUUID })
videoRemote = resVideo.body
}) })
describe('When listing redundancies', function () { describe('When listing redundancies', function () {

View File

@ -1,17 +1,16 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import { VideoPlaylistPrivacy } from '@shared/models' import { HttpStatusCode } from '@shared/core-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
makeGetRequest, makeGetRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel
uploadVideo } from '@shared/extra-utils'
} from '../../../../shared/extra-utils' import { VideoPlaylistPrivacy } from '@shared/models'
describe('Test services API validators', function () { describe('Test services API validators', function () {
let server: ServerInfo let server: ServerInfo
@ -26,10 +25,7 @@ describe('Test services API validators', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ]) await setDefaultVideoChannel([ server ])
{ server.video = await server.videosCommand.upload({ attributes: { name: 'my super name' } })
const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
server.video = res.body.video
}
{ {
const created = await server.playlistsCommand.create({ const created = await server.playlistsCommand.create({

View File

@ -3,7 +3,6 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { HttpStatusCode, randomInt } from '@shared/core-utils' import { HttpStatusCode, randomInt } from '@shared/core-utils'
import { VideoImportState, VideoPrivacy } from '@shared/models'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
@ -11,13 +10,15 @@ import {
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
uploadVideo, VideosCommand,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { VideoImportState, VideoPrivacy } from '@shared/models'
describe('Test upload quota', function () { describe('Test upload quota', function () {
let server: ServerInfo let server: ServerInfo
let rootId: number let rootId: number
let command: VideosCommand
// --------------------------------------------------------------- // ---------------------------------------------------------------
@ -32,6 +33,8 @@ describe('Test upload quota', function () {
rootId = user.id rootId = user.id
await server.usersCommand.update({ userId: rootId, videoQuota: 42 }) await server.usersCommand.update({ userId: rootId, videoQuota: 42 })
command = server.videosCommand
}) })
describe('When having a video quota', function () { describe('When having a video quota', function () {
@ -41,14 +44,14 @@ describe('Test upload quota', function () {
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
await server.usersCommand.register(user) await server.usersCommand.register(user)
const userAccessToken = await server.loginCommand.getAccessToken(user) const userToken = await server.loginCommand.getAccessToken(user)
const videoAttributes = { fixture: 'video_short2.webm' } const attributes = { fixture: 'video_short2.webm' }
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
await uploadVideo(server.url, userAccessToken, videoAttributes) await command.upload({ token: userToken, attributes })
} }
await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
}) })
it('Should fail with a registered user having too many videos with resumable upload', async function () { it('Should fail with a registered user having too many videos with resumable upload', async function () {
@ -56,14 +59,14 @@ describe('Test upload quota', function () {
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
await server.usersCommand.register(user) await server.usersCommand.register(user)
const userAccessToken = await server.loginCommand.getAccessToken(user) const userToken = await server.loginCommand.getAccessToken(user)
const videoAttributes = { fixture: 'video_short2.webm' } const attributes = { fixture: 'video_short2.webm' }
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
await uploadVideo(server.url, userAccessToken, videoAttributes) await command.upload({ token: userToken, attributes })
} }
await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
}) })
it('Should fail to import with HTTP/Torrent/magnet', async function () { it('Should fail to import with HTTP/Torrent/magnet', async function () {
@ -97,8 +100,8 @@ describe('Test upload quota', function () {
it('Should fail with a user having too many videos daily', async function () { it('Should fail with a user having too many videos daily', async function () {
await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 }) await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 })
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
}) })
}) })
@ -110,8 +113,8 @@ describe('Test upload quota', function () {
videoQuotaDaily: 1024 * 1024 * 1024 videoQuotaDaily: 1024 * 1024 * 1024
}) })
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
}) })
it('Should fail if exceeding daily quota', async function () { it('Should fail if exceeding daily quota', async function () {
@ -121,8 +124,8 @@ describe('Test upload quota', function () {
videoQuotaDaily: 42 videoQuotaDaily: 42
}) })
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
}) })
}) })

View File

@ -2,10 +2,12 @@
import 'mocha' import 'mocha'
import { omit } from 'lodash' import { omit } from 'lodash'
import { UserRole, VideoCreateResult } from '../../../../shared' import { HttpStatusCode } from '@shared/core-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination,
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
killallServers, killallServers,
@ -13,19 +15,13 @@ import {
makePostBodyRequest, makePostBodyRequest,
makePutBodyRequest, makePutBodyRequest,
makeUploadRequest, makeUploadRequest,
MockSmtpServer,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
UsersCommand UsersCommand
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models'
import {
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination
} from '../../../../shared/extra-utils/requests/check-api-params'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
describe('Test users API validators', function () { describe('Test users API validators', function () {
const path = '/api/v1/users/' const path = '/api/v1/users/'
@ -80,8 +76,7 @@ describe('Test users API validators', function () {
} }
{ {
const res = await uploadVideo(server.url, server.accessToken, {}) video = await server.videosCommand.upload()
video = res.body.video
} }
{ {

View File

@ -11,20 +11,17 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
getVideoWithToken,
makePostBodyRequest, makePostBodyRequest,
makePutBodyRequest, makePutBodyRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoBlacklistType, VideoDetails } from '@shared/models' import { VideoBlacklistType } from '@shared/models'
describe('Test video blacklist API validators', function () { describe('Test video blacklist API validators', function () {
let servers: ServerInfo[] let servers: ServerInfo[]
let notBlacklistedVideoId: number let notBlacklistedVideoId: string
let remoteVideoUUID: string let remoteVideoUUID: string
let userAccessToken1 = '' let userAccessToken1 = ''
let userAccessToken2 = '' let userAccessToken2 = ''
@ -55,18 +52,17 @@ describe('Test video blacklist API validators', function () {
} }
{ {
const res = await uploadVideo(servers[0].url, userAccessToken1, {}) servers[0].video = await servers[0].videosCommand.upload({ token: userAccessToken1 })
servers[0].video = res.body.video
} }
{ {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, {}) const { uuid } = await servers[0].videosCommand.upload()
notBlacklistedVideoId = res.body.video.uuid notBlacklistedVideoId = uuid
} }
{ {
const res = await uploadVideo(servers[1].url, servers[1].accessToken, {}) const { uuid } = await servers[1].videosCommand.upload()
remoteVideoUUID = res.body.video.uuid remoteVideoUUID = uuid
} }
await waitJobs(servers) await waitJobs(servers)
@ -204,17 +200,19 @@ describe('Test video blacklist API validators', function () {
describe('When getting blacklisted video', function () { describe('When getting blacklisted video', function () {
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) await servers[0].videosCommand.get({ id: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should fail with another user', async function () { it('Should fail with another user', async function () {
await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) await servers[0].videosCommand.getWithToken({
token: userAccessToken2,
id: servers[0].video.uuid,
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
}) })
it('Should succeed with the owner authenticated user', async function () { it('Should succeed with the owner authenticated user', async function () {
const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200) const video = await servers[0].videosCommand.getWithToken({ token: userAccessToken1, id: servers[0].video.uuid })
const video: VideoDetails = res.body
expect(video.blacklisted).to.be.true expect(video.blacklisted).to.be.true
}) })
@ -222,9 +220,7 @@ describe('Test video blacklist API validators', function () {
const video = servers[0].video const video = servers[0].video
for (const id of [ video.id, video.uuid, video.shortUUID ]) { for (const id of [ video.id, video.uuid, video.shortUUID ]) {
const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id, HttpStatusCode.OK_200) const video = await servers[0].videosCommand.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 })
const video: VideoDetails = res.body
expect(video.blacklisted).to.be.true expect(video.blacklisted).to.be.true
} }
}) })

View File

@ -10,8 +10,7 @@ import {
makeGetRequest, makeGetRequest,
makeUploadRequest, makeUploadRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers
uploadVideo
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoCreateResult } from '@shared/models' import { VideoCreateResult } from '@shared/models'
@ -31,10 +30,7 @@ describe('Test video captions API validator', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
{ video = await server.videosCommand.upload()
const res = await uploadVideo(server.url, server.accessToken, {})
video = res.body.video
}
{ {
const user = { const user = {

View File

@ -13,8 +13,7 @@ import {
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers
uploadVideo
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoCreateResult } from '@shared/models' import { VideoCreateResult } from '@shared/models'
@ -39,8 +38,7 @@ describe('Test video comments API validator', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
{ {
const res = await uploadVideo(server.url, server.accessToken, {}) const video = await server.videosCommand.upload({ attributes: {} })
video = res.body.video
pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
} }
@ -291,8 +289,8 @@ describe('Test video comments API validator', function () {
let anotherVideoUUID: string let anotherVideoUUID: string
{ {
const res = await uploadVideo(server.url, userAccessToken, { name: 'video' }) const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes: { name: 'video' } })
anotherVideoUUID = res.body.video.uuid anotherVideoUUID = uuid
} }
{ {
@ -318,8 +316,7 @@ describe('Test video comments API validator', function () {
describe('When a video has comments disabled', function () { describe('When a video has comments disabled', function () {
before(async function () { before(async function () {
const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) video = await server.videosCommand.upload({ attributes: { commentsEnabled: false } })
video = res.body.video
pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
}) })

View File

@ -2,15 +2,6 @@
import 'mocha' import 'mocha'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import {
VideoPlaylistCreate,
VideoPlaylistCreateResult,
VideoPlaylistElementCreate,
VideoPlaylistElementUpdate,
VideoPlaylistPrivacy,
VideoPlaylistReorder,
VideoPlaylistType
} from '@shared/models'
import { import {
checkBadCountPagination, checkBadCountPagination,
checkBadSortPagination, checkBadSortPagination,
@ -21,9 +12,17 @@ import {
PlaylistsCommand, PlaylistsCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel
uploadVideoAndGetId } from '@shared/extra-utils'
} from '../../../../shared/extra-utils' import {
VideoPlaylistCreate,
VideoPlaylistCreateResult,
VideoPlaylistElementCreate,
VideoPlaylistElementUpdate,
VideoPlaylistPrivacy,
VideoPlaylistReorder,
VideoPlaylistType
} from '@shared/models'
describe('Test video playlists API validator', function () { describe('Test video playlists API validator', function () {
let server: ServerInfo let server: ServerInfo
@ -49,7 +48,7 @@ describe('Test video playlists API validator', function () {
await setDefaultVideoChannel([ server ]) await setDefaultVideoChannel([ server ])
userAccessToken = await server.usersCommand.generateUserAndToken('user1') userAccessToken = await server.usersCommand.generateUserAndToken('user1')
videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id videoId = (await server.videosCommand.quickUpload({ name: 'video 1' })).id
command = server.playlistsCommand command = server.playlistsCommand
@ -486,8 +485,8 @@ describe('Test video playlists API validator', function () {
} }
before(async function () { before(async function () {
videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id videoId3 = (await server.videosCommand.quickUpload({ name: 'video 3' })).id
videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id videoId4 = (await server.videosCommand.quickUpload({ name: 'video 4' })).id
for (const id of [ videoId3, videoId4 ]) { for (const id of [ videoId3, videoId4 ]) {
await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } }) await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } })

View File

@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import { HttpStatusCode } from '@shared/core-utils'
import { import {
checkBadCountPagination, checkBadCountPagination,
checkBadStartPagination, checkBadStartPagination,
@ -10,10 +11,8 @@ import {
makePostBodyRequest, makePostBodyRequest,
makePutBodyRequest, makePutBodyRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers
uploadVideo } from '@shared/extra-utils'
} from '../../../../shared/extra-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test videos history API validator', function () { describe('Test videos history API validator', function () {
const myHistoryPath = '/api/v1/users/me/history/videos' const myHistoryPath = '/api/v1/users/me/history/videos'
@ -30,10 +29,8 @@ describe('Test videos history API validator', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const res = await uploadVideo(server.url, server.accessToken, {}) const { uuid } = await server.videosCommand.upload()
const videoUUID = res.body.video.uuid watchingPath = '/api/v1/videos/' + uuid + '/watching'
watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
}) })
describe('When notifying a user is watching a video', function () { describe('When notifying a user is watching a video', function () {

View File

@ -4,30 +4,23 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { omit } from 'lodash' import { omit } from 'lodash'
import { join } from 'path' import { join } from 'path'
import { randomInt } from '@shared/core-utils' import { HttpStatusCode, randomInt } from '@shared/core-utils'
import { PeerTubeProblemDocument, VideoCreateResult } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination,
checkUploadVideoParam, checkUploadVideoParam,
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getVideo,
getVideosList,
makeDeleteRequest, makeDeleteRequest,
makeGetRequest, makeGetRequest,
makePutBodyRequest, makePutBodyRequest,
makeUploadRequest, makeUploadRequest,
removeVideo,
root, root,
ServerInfo, ServerInfo,
setAccessTokensToServers setAccessTokensToServers
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { import { PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models'
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination
} from '../../../../shared/extra-utils/requests/check-api-params'
import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
const expect = chai.expect const expect = chai.expect
@ -210,70 +203,70 @@ describe('Test videos API validator', function () {
it('Should fail with nothing', async function () { it('Should fail with nothing', async function () {
const fields = {} const fields = {}
const attaches = {} const attaches = {}
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail without name', async function () { it('Should fail without name', async function () {
const fields = omit(baseCorrectParams, 'name') const fields = omit(baseCorrectParams, 'name')
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a long name', async function () { it('Should fail with a long name', async function () {
const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a bad category', async function () { it('Should fail with a bad category', async function () {
const fields = { ...baseCorrectParams, category: 125 } const fields = { ...baseCorrectParams, category: 125 }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a bad licence', async function () { it('Should fail with a bad licence', async function () {
const fields = { ...baseCorrectParams, licence: 125 } const fields = { ...baseCorrectParams, licence: 125 }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a bad language', async function () { it('Should fail with a bad language', async function () {
const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a long description', async function () { it('Should fail with a long description', async function () {
const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a long support text', async function () { it('Should fail with a long support text', async function () {
const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail without a channel', async function () { it('Should fail without a channel', async function () {
const fields = omit(baseCorrectParams, 'channelId') const fields = omit(baseCorrectParams, 'channelId')
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a bad channel', async function () { it('Should fail with a bad channel', async function () {
const fields = { ...baseCorrectParams, channelId: 545454 } const fields = { ...baseCorrectParams, channelId: 545454 }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with another user channel', async function () { it('Should fail with another user channel', async function () {
@ -290,35 +283,35 @@ describe('Test videos API validator', function () {
const fields = { ...baseCorrectParams, channelId: customChannelId } const fields = { ...baseCorrectParams, channelId: customChannelId }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with too many tags', async function () { it('Should fail with too many tags', async function () {
const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a tag length too low', async function () { it('Should fail with a tag length too low', async function () {
const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a tag length too big', async function () { it('Should fail with a tag length too big', async function () {
const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a bad schedule update (miss updateAt)', async function () { it('Should fail with a bad schedule update (miss updateAt)', async function () {
const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a bad schedule update (wrong updateAt)', async function () { it('Should fail with a bad schedule update (wrong updateAt)', async function () {
@ -332,20 +325,20 @@ describe('Test videos API validator', function () {
} }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a bad originally published at attribute', async function () { it('Should fail with a bad originally published at attribute', async function () {
const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail without an input file', async function () { it('Should fail without an input file', async function () {
const fields = baseCorrectParams const fields = baseCorrectParams
const attaches = {} const attaches = {}
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with an incorrect input file', async function () { it('Should fail with an incorrect input file', async function () {
@ -353,7 +346,7 @@ describe('Test videos API validator', function () {
let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
await checkUploadVideoParam( await checkUploadVideoParam(
server.url, server,
server.accessToken, server.accessToken,
{ ...fields, ...attaches }, { ...fields, ...attaches },
HttpStatusCode.UNPROCESSABLE_ENTITY_422, HttpStatusCode.UNPROCESSABLE_ENTITY_422,
@ -362,7 +355,7 @@ describe('Test videos API validator', function () {
attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
await checkUploadVideoParam( await checkUploadVideoParam(
server.url, server,
server.accessToken, server.accessToken,
{ ...fields, ...attaches }, { ...fields, ...attaches },
HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
@ -377,7 +370,7 @@ describe('Test videos API validator', function () {
fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
} }
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a big thumbnail file', async function () { it('Should fail with a big thumbnail file', async function () {
@ -387,7 +380,7 @@ describe('Test videos API validator', function () {
fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
} }
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with an incorrect preview file', async function () { it('Should fail with an incorrect preview file', async function () {
@ -397,7 +390,7 @@ describe('Test videos API validator', function () {
fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
} }
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should fail with a big preview file', async function () { it('Should fail with a big preview file', async function () {
@ -407,7 +400,7 @@ describe('Test videos API validator', function () {
fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
} }
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
}) })
it('Should report the appropriate error', async function () { it('Should report the appropriate error', async function () {
@ -415,9 +408,9 @@ describe('Test videos API validator', function () {
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
const attributes = { ...fields, ...attaches } const attributes = { ...fields, ...attaches }
const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode) const body = await checkUploadVideoParam(server, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
const error = res.body as PeerTubeProblemDocument const error = body as unknown as PeerTubeProblemDocument
if (mode === 'legacy') { if (mode === 'legacy') {
expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy') expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy')
@ -442,7 +435,7 @@ describe('Test videos API validator', function () {
{ {
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
} }
{ {
@ -452,7 +445,7 @@ describe('Test videos API validator', function () {
videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
} }
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
} }
{ {
@ -462,7 +455,7 @@ describe('Test videos API validator', function () {
videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
} }
await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
} }
}) })
} }
@ -491,8 +484,8 @@ describe('Test videos API validator', function () {
} }
before(async function () { before(async function () {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
video = res.body.data[0] video = data[0]
}) })
it('Should fail with nothing', async function () { it('Should fail with nothing', async function () {
@ -717,16 +710,16 @@ describe('Test videos API validator', function () {
}) })
it('Should fail without a correct uuid', async function () { it('Should fail without a correct uuid', async function () {
await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400) await server.videosCommand.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}) })
it('Should return 404 with an incorrect video', async function () { it('Should return 404 with an incorrect video', async function () {
await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) await server.videosCommand.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}) })
it('Shoud report the appropriate error', async function () { it('Shoud report the appropriate error', async function () {
const res = await getVideo(server.url, 'hi', HttpStatusCode.BAD_REQUEST_400) const body = await server.videosCommand.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
const error = res.body as PeerTubeProblemDocument const error = body as unknown as PeerTubeProblemDocument
expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo') expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo')
@ -741,16 +734,16 @@ describe('Test videos API validator', function () {
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
await getVideo(server.url, video.shortUUID) await server.videosCommand.get({ id: video.shortUUID })
}) })
}) })
describe('When rating a video', function () { describe('When rating a video', function () {
let videoId let videoId: number
before(async function () { before(async function () {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
videoId = res.body.data[0].id videoId = data[0].id
}) })
it('Should fail without a valid uuid', async function () { it('Should fail without a valid uuid', async function () {
@ -804,22 +797,22 @@ describe('Test videos API validator', function () {
}) })
it('Should fail without a correct uuid', async function () { it('Should fail without a correct uuid', async function () {
await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}) })
it('Should fail with a video which does not exist', async function () { it('Should fail with a video which does not exist', async function () {
await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) await server.videosCommand.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}) })
it('Should fail with a video of another user without the appropriate right', async function () { it('Should fail with a video of another user without the appropriate right', async function () {
await removeVideo(server.url, userAccessToken, video.uuid, HttpStatusCode.FORBIDDEN_403) await server.videosCommand.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}) })
it('Should fail with a video of another server') it('Should fail with a video of another server')
it('Shoud report the appropriate error', async function () { it('Shoud report the appropriate error', async function () {
const res = await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) const body = await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
const error = res.body as PeerTubeProblemDocument const error = body as unknown as PeerTubeProblemDocument
expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo') expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo')
@ -834,7 +827,7 @@ describe('Test videos API validator', function () {
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
await removeVideo(server.url, server.accessToken, video.uuid) await server.videosCommand.remove({ id: video.uuid })
}) })
}) })

View File

@ -2,14 +2,13 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { VideoDetails, VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
import { import {
checkLiveCleanup, checkLiveCleanup,
cleanupTests, cleanupTests,
ConfigCommand, ConfigCommand,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
@ -39,9 +38,7 @@ describe('Test live constraints', function () {
async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
const video: VideoDetails = res.body
expect(video.isLive).to.be.false expect(video.isLive).to.be.false
expect(video.duration).to.be.greaterThan(0) expect(video.duration).to.be.greaterThan(0)
} }

View File

@ -2,13 +2,12 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
import { import {
cleanupTests, cleanupTests,
ConfigCommand, ConfigCommand,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
@ -38,8 +37,8 @@ describe('Permanent live', function () {
async function checkVideoState (videoId: string, state: VideoState) { async function checkVideoState (videoId: string, state: VideoState) {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
expect((res.body as VideoDetails).state.id).to.equal(state) expect(video.state.id).to.equal(state)
} }
} }
@ -123,9 +122,7 @@ describe('Permanent live', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const videoDetails = await server.videosCommand.get({ id: videoUUID })
const videoDetails = res.body as VideoDetails
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
} }
}) })

View File

@ -3,26 +3,22 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { FfmpegCommand } from 'fluent-ffmpeg' import { FfmpegCommand } from 'fluent-ffmpeg'
import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' import { HttpStatusCode } from '@shared/core-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
checkLiveCleanup, checkLiveCleanup,
cleanupTests, cleanupTests,
ConfigCommand, ConfigCommand,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
getVideosList,
removeVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
stopFfmpeg, stopFfmpeg,
testFfmpegStreamError, testFfmpegStreamError,
updateVideo,
wait, wait,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -34,7 +30,7 @@ describe('Save replay setting', function () {
async function createLiveWrapper (saveReplay: boolean) { async function createLiveWrapper (saveReplay: boolean) {
if (liveVideoUUID) { if (liveVideoUUID) {
try { try {
await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) await servers[0].videosCommand.remove({ id: liveVideoUUID })
await waitJobs(servers) await waitJobs(servers)
} catch {} } catch {}
} }
@ -50,24 +46,24 @@ describe('Save replay setting', function () {
return uuid return uuid
} }
async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) { async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) {
for (const server of servers) { for (const server of servers) {
const length = existsInList ? 1 : 0 const length = existsInList ? 1 : 0
const resVideos = await getVideosList(server.url) const { data, total } = await server.videosCommand.list()
expect(resVideos.body.data).to.have.lengthOf(length) expect(data).to.have.lengthOf(length)
expect(resVideos.body.total).to.equal(length) expect(total).to.equal(length)
if (getStatus) { if (expectedStatus) {
await getVideo(server.url, videoId, getStatus) await server.videosCommand.get({ id: videoId, expectedStatus })
} }
} }
} }
async function checkVideoState (videoId: string, state: VideoState) { async function checkVideoState (videoId: string, state: VideoState) {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
expect((res.body as VideoDetails).state.id).to.equal(state) expect(video.state.id).to.equal(state)
} }
} }
@ -179,8 +175,8 @@ describe('Save replay setting', function () {
await checkVideosExist(liveVideoUUID, false) await checkVideosExist(liveVideoUUID, false)
await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await wait(5000) await wait(5000)
await waitJobs(servers) await waitJobs(servers)
@ -201,7 +197,7 @@ describe('Save replay setting', function () {
await Promise.all([ await Promise.all([
testFfmpegStreamError(ffmpegCommand, true), testFfmpegStreamError(ffmpegCommand, true),
removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) servers[0].videosCommand.remove({ id: liveVideoUUID })
]) ])
await wait(5000) await wait(5000)
@ -253,13 +249,13 @@ describe('Save replay setting', function () {
it('Should update the saved live and correctly federate the updated attributes', async function () { it('Should update the saved live and correctly federate the updated attributes', async function () {
this.timeout(30000) this.timeout(30000)
await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' }) await servers[0].videosCommand.update({ id: liveVideoUUID, attributes: { name: 'video updated' } })
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, liveVideoUUID) const video = await server.videosCommand.get({ id: liveVideoUUID })
expect(res.body.name).to.equal('video updated') expect(video.name).to.equal('video updated')
expect(res.body.isLive).to.be.false expect(video.isLive).to.be.false
} }
}) })
@ -287,8 +283,8 @@ describe('Save replay setting', function () {
await checkVideosExist(liveVideoUUID, false) await checkVideosExist(liveVideoUUID, false)
await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await wait(5000) await wait(5000)
await waitJobs(servers) await waitJobs(servers)
@ -307,7 +303,7 @@ describe('Save replay setting', function () {
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([ await Promise.all([
removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), servers[0].videosCommand.remove({ id: liveVideoUUID }),
testFfmpegStreamError(ffmpegCommand, true) testFfmpegStreamError(ffmpegCommand, true)
]) ])

View File

@ -7,12 +7,10 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideoIdFromUUID,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
stopFfmpeg, stopFfmpeg,
viewVideo,
wait, wait,
waitJobs, waitJobs,
waitUntilLivePublishedOnAllServers waitUntilLivePublishedOnAllServers
@ -71,7 +69,7 @@ describe('Test live', function () {
await waitJobs(servers) await waitJobs(servers)
{ {
const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
localSocket.on('state-change', data => localStateChanges.push(data.state)) localSocket.on('state-change', data => localStateChanges.push(data.state))
@ -79,7 +77,7 @@ describe('Test live', function () {
} }
{ {
const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID })
const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) remoteSocket.on('state-change', data => remoteStateChanges.push(data.state))
@ -119,7 +117,7 @@ describe('Test live', function () {
await waitJobs(servers) await waitJobs(servers)
{ {
const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
localSocket.on('views-change', data => { localLastVideoViews = data.views }) localSocket.on('views-change', data => { localLastVideoViews = data.views })
@ -127,7 +125,7 @@ describe('Test live', function () {
} }
{ {
const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID })
const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views })
@ -142,8 +140,8 @@ describe('Test live', function () {
expect(localLastVideoViews).to.equal(0) expect(localLastVideoViews).to.equal(0)
expect(remoteLastVideoViews).to.equal(0) expect(remoteLastVideoViews).to.equal(0)
await viewVideo(servers[0].url, liveVideoUUID) await servers[0].videosCommand.view({ id: liveVideoUUID })
await viewVideo(servers[1].url, liveVideoUUID) await servers[1].videosCommand.view({ id: liveVideoUUID })
await waitJobs(servers) await waitJobs(servers)
await wait(5000) await wait(5000)
@ -163,7 +161,7 @@ describe('Test live', function () {
const liveVideoUUID = await createLiveWrapper() const liveVideoUUID = await createLiveWrapper()
await waitJobs(servers) await waitJobs(servers)
const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
const socket = servers[0].socketIOCommand.getLiveNotificationSocket() const socket = servers[0].socketIOCommand.getLiveNotificationSocket()
socket.on('state-change', data => stateChanges.push(data.state)) socket.on('state-change', data => stateChanges.push(data.state))

View File

@ -3,17 +3,15 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { FfmpegCommand } from 'fluent-ffmpeg' import { FfmpegCommand } from 'fluent-ffmpeg'
import { VideoDetails, VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
stopFfmpeg, stopFfmpeg,
viewVideo,
wait, wait,
waitJobs, waitJobs,
waitUntilLivePublishedOnAllServers waitUntilLivePublishedOnAllServers
@ -55,9 +53,7 @@ describe('Test live', function () {
async function countViews (expected: number) { async function countViews (expected: number) {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, liveVideoId) const video = await server.videosCommand.get({ id: liveVideoId })
const video: VideoDetails = res.body
expect(video.views).to.equal(expected) expect(video.views).to.equal(expected)
} }
} }
@ -86,8 +82,8 @@ describe('Test live', function () {
it('Should view a live twice and display 1 view', async function () { it('Should view a live twice and display 1 view', async function () {
this.timeout(30000) this.timeout(30000)
await viewVideo(servers[0].url, liveVideoId) await servers[0].videosCommand.view({ id: liveVideoId })
await viewVideo(servers[0].url, liveVideoId) await servers[0].videosCommand.view({ id: liveVideoId })
await wait(7000) await wait(7000)
@ -108,9 +104,9 @@ describe('Test live', function () {
it('Should view a live on a remote and on local and display 2 views', async function () { it('Should view a live on a remote and on local and display 2 views', async function () {
this.timeout(30000) this.timeout(30000)
await viewVideo(servers[0].url, liveVideoId) await servers[0].videosCommand.view({ id: liveVideoId })
await viewVideo(servers[1].url, liveVideoId) await servers[1].videosCommand.view({ id: liveVideoId })
await viewVideo(servers[1].url, liveVideoId) await servers[1].videosCommand.view({ id: liveVideoId })
await wait(7000) await wait(7000)
await waitJobs(servers) await waitJobs(servers)

View File

@ -4,8 +4,7 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { join } from 'path' import { join } from 'path'
import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' import { HttpStatusCode } from '@shared/core-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
checkLiveCleanup, checkLiveCleanup,
checkLiveSegmentHash, checkLiveSegmentHash,
@ -13,14 +12,9 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getMyVideosWithFilter,
getVideo,
getVideosList,
getVideosWithFilters,
killallServers, killallServers,
LiveCommand, LiveCommand,
makeRawRequest, makeRawRequest,
removeVideo,
reRunServer, reRunServer,
sendRTMPStream, sendRTMPStream,
ServerInfo, ServerInfo,
@ -29,11 +23,11 @@ import {
stopFfmpeg, stopFfmpeg,
testFfmpegStreamError, testFfmpegStreamError,
testImage, testImage,
uploadVideoAndGetId,
wait, wait,
waitJobs, waitJobs,
waitUntilLivePublishedOnAllServers waitUntilLivePublishedOnAllServers
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -99,8 +93,7 @@ describe('Test live', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const resVideo = await getVideo(server.url, liveVideoUUID) const video = await server.videosCommand.get({ id: liveVideoUUID })
const video: VideoDetails = resVideo.body
expect(video.category.id).to.equal(1) expect(video.category.id).to.equal(1)
expect(video.licence.id).to.equal(2) expect(video.licence.id).to.equal(2)
@ -154,9 +147,7 @@ describe('Test live', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const resVideo = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
const video: VideoDetails = resVideo.body
expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
expect(video.nsfw).to.be.true expect(video.nsfw).to.be.true
@ -167,10 +158,10 @@ describe('Test live', function () {
it('Should not have the live listed since nobody streams into', async function () { it('Should not have the live listed since nobody streams into', async function () {
for (const server of 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(total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0) expect(data).to.have.lengthOf(0)
} }
}) })
@ -204,13 +195,13 @@ describe('Test live', function () {
it('Delete the live', async function () { it('Delete the live', async function () {
this.timeout(10000) this.timeout(10000)
await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) await servers[0].videosCommand.remove({ id: liveVideoUUID })
await waitJobs(servers) await waitJobs(servers)
}) })
it('Should have the live deleted', async function () { it('Should have the live deleted', async function () {
for (const server of servers) { for (const server of servers) {
await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) await server.videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
} }
}) })
@ -224,7 +215,7 @@ describe('Test live', function () {
before(async function () { before(async function () {
this.timeout(120000) this.timeout(120000)
vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid vodVideoId = (await servers[0].videosCommand.quickUpload({ name: 'vod video' })).uuid
const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id }
const live = await commands[0].create({ fields: liveOptions }) const live = await commands[0].create({ fields: liveOptions })
@ -236,19 +227,19 @@ describe('Test live', function () {
}) })
it('Should only display lives', async function () { it('Should only display lives', async function () {
const res = await getVideosWithFilters(servers[0].url, { isLive: true }) const { data, total } = await servers[0].videosCommand.list({ isLive: true })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
expect(res.body.data[0].name).to.equal('live') expect(data[0].name).to.equal('live')
}) })
it('Should not display lives', async function () { it('Should not display lives', async function () {
const res = await getVideosWithFilters(servers[0].url, { isLive: false }) const { data, total } = await servers[0].videosCommand.list({ isLive: false })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
expect(res.body.data[0].name).to.equal('vod video') expect(data[0].name).to.equal('vod video')
}) })
it('Should display my lives', async function () { it('Should display my lives', async function () {
@ -257,24 +248,22 @@ describe('Test live', function () {
await stopFfmpeg(ffmpegCommand) await stopFfmpeg(ffmpegCommand)
await waitJobs(servers) await waitJobs(servers)
const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) const { data } = await servers[0].videosCommand.listMyVideos({ isLive: true })
const videos = res.body.data as Video[]
const result = videos.every(v => v.isLive) const result = data.every(v => v.isLive)
expect(result).to.be.true expect(result).to.be.true
}) })
it('Should not display my lives', async function () { it('Should not display my lives', async function () {
const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: false }) const { data } = await servers[0].videosCommand.listMyVideos({ isLive: false })
const videos = res.body.data as Video[]
const result = videos.every(v => !v.isLive) const result = data.every(v => !v.isLive)
expect(result).to.be.true expect(result).to.be.true
}) })
after(async function () { after(async function () {
await removeVideo(servers[0].url, servers[0].accessToken, vodVideoId) await servers[0].videosCommand.remove({ id: vodVideoId })
await removeVideo(servers[0].url, servers[0].accessToken, liveVideoId) await servers[0].videosCommand.remove({ id: liveVideoId })
}) })
}) })
@ -297,9 +286,9 @@ describe('Test live', function () {
const { uuid } = await commands[0].create({ fields: liveAttributes }) const { uuid } = await commands[0].create({ fields: liveAttributes })
const live = await commands[0].get({ videoId: uuid }) const live = await commands[0].get({ videoId: uuid })
const resVideo = await getVideo(servers[0].url, uuid) const video = await servers[0].videosCommand.get({ id: uuid })
return Object.assign(resVideo.body as VideoDetails, live) return Object.assign(video, live)
} }
it('Should not allow a stream without the appropriate path', async function () { it('Should not allow a stream without the appropriate path', async function () {
@ -327,13 +316,12 @@ describe('Test live', function () {
it('Should list this live now someone stream into it', async function () { it('Should list this live now someone stream into it', async function () {
for (const server of 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(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
const video: Video = res.body.data[0]
const video = data[0]
expect(video.name).to.equal('user live') expect(video.name).to.equal('user live')
expect(video.isLive).to.be.true expect(video.isLive).to.be.true
} }
@ -355,7 +343,7 @@ describe('Test live', function () {
liveVideo = await createLiveWrapper() liveVideo = await createLiveWrapper()
await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid) await servers[0].videosCommand.remove({ id: liveVideo.uuid })
const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
await testFfmpegStreamError(command, true) await testFfmpegStreamError(command, true)
@ -379,13 +367,10 @@ describe('Test live', function () {
async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { async function testVideoResolutions (liveVideoId: string, resolutions: number[]) {
for (const server of servers) { for (const server of servers) {
const resList = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos: Video[] = resList.body.data expect(data.find(v => v.uuid === liveVideoId)).to.exist
expect(videos.find(v => v.uuid === liveVideoId)).to.exist const video = await server.videosCommand.get({ id: liveVideoId })
const resVideo = await getVideo(server.url, liveVideoId)
const video: VideoDetails = resVideo.body
expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists).to.have.lengthOf(1)
@ -505,8 +490,7 @@ describe('Test live', function () {
} }
for (const server of servers) { for (const server of servers) {
const resVideo = await getVideo(server.url, liveVideoId) const video = await server.videosCommand.get({ id: liveVideoId })
const video: VideoDetails = resVideo.body
expect(video.state.id).to.equal(VideoState.PUBLISHED) expect(video.state.id).to.equal(VideoState.PUBLISHED)
expect(video.duration).to.be.greaterThan(1) expect(video.duration).to.be.greaterThan(1)

View File

@ -7,13 +7,8 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideoIdFromUUID,
getVideosList,
removeVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
uploadVideoAndGetId,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
@ -47,28 +42,30 @@ describe('Test abuses', function () {
this.timeout(50000) this.timeout(50000)
// Upload some videos on each servers // Upload some videos on each servers
const video1Attributes = { {
name: 'my super name for server 1', const attributes = {
description: 'my super description for server 1' name: 'my super name for server 1',
description: 'my super description for server 1'
}
await servers[0].videosCommand.upload({ attributes })
} }
await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
const video2Attributes = { {
name: 'my super name for server 2', const attributes = {
description: 'my super description for server 2' name: 'my super name for server 2',
description: 'my super description for server 2'
}
await servers[1].videosCommand.upload({ attributes })
} }
await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
// Wait videos propagation, server 2 has transcoding enabled // Wait videos propagation, server 2 has transcoding enabled
await waitJobs(servers) await waitJobs(servers)
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const videos = res.body.data expect(data.length).to.equal(2)
expect(videos.length).to.equal(2) servers[0].video = data.find(video => video.name === 'my super name for server 1')
servers[1].video = data.find(video => video.name === 'my super name for server 2')
servers[0].video = videos.find(video => video.name === 'my super name for server 1')
servers[1].video = videos.find(video => video.name === 'my super name for server 2')
}) })
it('Should not have abuses', async function () { it('Should not have abuses', async function () {
@ -130,7 +127,7 @@ describe('Test abuses', function () {
this.timeout(10000) this.timeout(10000)
const reason = 'my super bad reason 2' const reason = 'my super bad reason 2'
const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid })
await commands[0].report({ videoId, reason }) await commands[0].report({ videoId, reason })
// We wait requests propagation // We wait requests propagation
@ -203,7 +200,7 @@ describe('Test abuses', function () {
this.timeout(10000) this.timeout(10000)
{ {
const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid })
await commands[1].report({ videoId, reason: 'will mute this' }) await commands[1].report({ videoId, reason: 'will mute this' })
await waitJobs(servers) await waitJobs(servers)
@ -255,7 +252,7 @@ describe('Test abuses', function () {
it('Should keep the video abuse when deleting the video', async function () { it('Should keep the video abuse when deleting the video', async function () {
this.timeout(10000) this.timeout(10000)
await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid })
await waitJobs(servers) await waitJobs(servers)
@ -279,12 +276,12 @@ describe('Test abuses', function () {
const userAccessToken = await servers[0].loginCommand.getAccessToken(user) const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
// upload a third video via this user // upload a third video via this user
const video3Attributes = { const attributes = {
name: 'my second super name for server 1', name: 'my second super name for server 1',
description: 'my second super description for server 1' description: 'my second super description for server 1'
} }
const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
const video3Id = resUpload.body.video.id const video3Id = id
// resume with the test // resume with the test
const reason3 = 'my super bad reason 3' const reason3 = 'my super bad reason 3'
@ -394,7 +391,7 @@ describe('Test abuses', function () {
async function getComment (server: ServerInfo, videoIdArg: number | string) { async function getComment (server: ServerInfo, videoIdArg: number | string) {
const videoId = typeof videoIdArg === 'string' const videoId = typeof videoIdArg === 'string'
? await getVideoIdFromUUID(server.url, videoIdArg) ? await server.videosCommand.getId({ uuid: videoIdArg })
: videoIdArg : videoIdArg
const { data } = await server.commentsCommand.listThreads({ videoId }) const { data } = await server.commentsCommand.listThreads({ videoId })
@ -405,8 +402,8 @@ describe('Test abuses', function () {
before(async function () { before(async function () {
this.timeout(50000) this.timeout(50000)
servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' })
servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' })
await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
@ -604,7 +601,7 @@ describe('Test abuses', function () {
await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' })
const token = await servers[1].usersCommand.generateUserAndToken('user_2') const token = await servers[1].usersCommand.generateUserAndToken('user_2')
await uploadVideo(servers[1].url, token, { name: 'super video' }) await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } })
await waitJobs(servers) await waitJobs(servers)
}) })
@ -766,7 +763,7 @@ describe('Test abuses', function () {
await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid })
await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
}) })

View File

@ -2,15 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { UserNotificationType } from '@shared/models' import { UserNotificationType } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -44,8 +36,8 @@ describe('Test blocklist', function () {
await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
{ {
const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } })
videoUUID = res.body.video.uuid videoUUID = uuid
await waitJobs(servers) await waitJobs(servers)
} }
@ -83,7 +75,7 @@ describe('Test blocklist', function () {
}) })
userToken1 = await servers[0].loginCommand.getAccessToken(user) userToken1 = await servers[0].loginCommand.getAccessToken(user)
await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } })
} }
{ {

View File

@ -8,28 +8,23 @@ import {
CommentsCommand, CommentsCommand,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList,
getVideosListWithToken,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { UserNotificationType, Video } from '@shared/models' import { UserNotificationType } from '@shared/models'
const expect = chai.expect const expect = chai.expect
async function checkAllVideos (server: ServerInfo, token: string) { async function checkAllVideos (server: ServerInfo, token: string) {
{ {
const res = await getVideosListWithToken(server.url, token) const { data } = await server.videosCommand.listWithToken({ token })
expect(data).to.have.lengthOf(5)
expect(res.body.data).to.have.lengthOf(5)
} }
{ {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
expect(data).to.have.lengthOf(5)
expect(res.body.data).to.have.lengthOf(5)
} }
} }
@ -93,7 +88,7 @@ describe('Test blocklist', function () {
await servers[0].usersCommand.create({ username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
userToken1 = await servers[0].loginCommand.getAccessToken(user) userToken1 = await servers[0].loginCommand.getAccessToken(user)
await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } })
} }
{ {
@ -108,22 +103,22 @@ describe('Test blocklist', function () {
await servers[1].usersCommand.create({ username: user.username, password: user.password }) await servers[1].usersCommand.create({ username: user.username, password: user.password })
userToken2 = await servers[1].loginCommand.getAccessToken(user) userToken2 = await servers[1].loginCommand.getAccessToken(user)
await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } })
} }
{ {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } })
videoUUID1 = res.body.video.uuid videoUUID1 = uuid
} }
{ {
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } })
videoUUID2 = res.body.video.uuid videoUUID2 = uuid
} }
{ {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } })
videoUUID3 = res.body.video.uuid videoUUID3 = uuid
} }
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
@ -164,12 +159,11 @@ describe('Test blocklist', function () {
}) })
it('Should hide its videos', async function () { it('Should hide its videos', async function () {
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) const { data } = await servers[0].videosCommand.listWithToken()
const videos: Video[] = res.body.data expect(data).to.have.lengthOf(4)
expect(videos).to.have.lengthOf(4)
const v = videos.find(v => v.name === 'video user 2') const v = data.find(v => v.name === 'video user 2')
expect(v).to.be.undefined expect(v).to.be.undefined
}) })
@ -178,12 +172,11 @@ describe('Test blocklist', function () {
}) })
it('Should hide its videos', async function () { it('Should hide its videos', async function () {
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) const { data } = await servers[0].videosCommand.listWithToken()
const videos: Video[] = res.body.data expect(data).to.have.lengthOf(3)
expect(videos).to.have.lengthOf(3)
const v = videos.find(v => v.name === 'video user 1') const v = data.find(v => v.name === 'video user 1')
expect(v).to.be.undefined expect(v).to.be.undefined
}) })
@ -313,12 +306,10 @@ describe('Test blocklist', function () {
}) })
it('Should display its videos', async function () { it('Should display its videos', async function () {
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) const { data } = await servers[0].videosCommand.listWithToken()
expect(data).to.have.lengthOf(4)
const videos: Video[] = res.body.data const v = data.find(v => v.name === 'video user 2')
expect(videos).to.have.lengthOf(4)
const v = videos.find(v => v.name === 'video user 2')
expect(v).not.to.be.undefined expect(v).not.to.be.undefined
}) })
@ -387,13 +378,12 @@ describe('Test blocklist', function () {
}) })
it('Should hide its videos', async function () { it('Should hide its videos', async function () {
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) const { data } = await servers[0].videosCommand.listWithToken()
const videos: Video[] = res.body.data expect(data).to.have.lengthOf(3)
expect(videos).to.have.lengthOf(3)
const v1 = videos.find(v => v.name === 'video user 2') const v1 = data.find(v => v.name === 'video user 2')
const v2 = videos.find(v => v.name === 'video server 2') const v2 = data.find(v => v.name === 'video server 2')
expect(v1).to.be.undefined expect(v1).to.be.undefined
expect(v2).to.be.undefined expect(v2).to.be.undefined
@ -498,12 +488,11 @@ describe('Test blocklist', function () {
it('Should hide its videos', async function () { it('Should hide its videos', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) { for (const token of [ userModeratorToken, servers[0].accessToken ]) {
const res = await getVideosListWithToken(servers[0].url, token) const { data } = await servers[0].videosCommand.listWithToken({ token })
const videos: Video[] = res.body.data expect(data).to.have.lengthOf(4)
expect(videos).to.have.lengthOf(4)
const v = videos.find(v => v.name === 'video user 2') const v = data.find(v => v.name === 'video user 2')
expect(v).to.be.undefined expect(v).to.be.undefined
} }
}) })
@ -514,12 +503,11 @@ describe('Test blocklist', function () {
it('Should hide its videos', async function () { it('Should hide its videos', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) { for (const token of [ userModeratorToken, servers[0].accessToken ]) {
const res = await getVideosListWithToken(servers[0].url, token) const { data } = await servers[0].videosCommand.listWithToken({ token })
const videos: Video[] = res.body.data expect(data).to.have.lengthOf(3)
expect(videos).to.have.lengthOf(3)
const v = videos.find(v => v.name === 'video user 1') const v = data.find(v => v.name === 'video user 1')
expect(v).to.be.undefined expect(v).to.be.undefined
} }
}) })
@ -593,12 +581,10 @@ describe('Test blocklist', function () {
it('Should display its videos', async function () { it('Should display its videos', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) { for (const token of [ userModeratorToken, servers[0].accessToken ]) {
const res = await getVideosListWithToken(servers[0].url, token) const { data } = await servers[0].videosCommand.listWithToken({ token })
expect(data).to.have.lengthOf(4)
const videos: Video[] = res.body.data const v = data.find(v => v.name === 'video user 2')
expect(videos).to.have.lengthOf(4)
const v = videos.find(v => v.name === 'video user 2')
expect(v).not.to.be.undefined expect(v).not.to.be.undefined
} }
}) })
@ -652,15 +638,17 @@ describe('Test blocklist', function () {
it('Should hide its videos', async function () { it('Should hide its videos', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) { for (const token of [ userModeratorToken, servers[0].accessToken ]) {
const res1 = await getVideosList(servers[0].url) const requests = [
const res2 = await getVideosListWithToken(servers[0].url, token) servers[0].videosCommand.list(),
servers[0].videosCommand.listWithToken({ token })
]
for (const res of [ res1, res2 ]) { for (const req of requests) {
const videos: Video[] = res.body.data const { data } = await req
expect(videos).to.have.lengthOf(3) expect(data).to.have.lengthOf(3)
const v1 = videos.find(v => v.name === 'video user 2') const v1 = data.find(v => v.name === 'video user 2')
const v2 = videos.find(v => v.name === 'video server 2') const v2 = data.find(v => v.name === 'video server 2')
expect(v1).to.be.undefined expect(v1).to.be.undefined
expect(v2).to.be.undefined expect(v2).to.be.undefined

View File

@ -8,15 +8,11 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getMyVideos,
getVideosList,
ImportsCommand, ImportsCommand,
killallServers, killallServers,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
@ -29,10 +25,9 @@ describe('Test video blacklist', function () {
let command: BlacklistCommand let command: BlacklistCommand
async function blacklistVideosOnServer (server: ServerInfo) { async function blacklistVideosOnServer (server: ServerInfo) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data for (const video of data) {
for (const video of videos) {
await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' })
} }
} }
@ -50,8 +45,8 @@ describe('Test video blacklist', function () {
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
// Upload 2 videos on server 2 // Upload 2 videos on server 2
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } })
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } })
// Wait videos propagation, server 2 has transcoding enabled // Wait videos propagation, server 2 has transcoding enabled
await waitJobs(servers) await waitJobs(servers)
@ -66,11 +61,11 @@ describe('Test video blacklist', function () {
it('Should not have the video blacklisted in videos list/search on server 1', async function () { it('Should not have the video blacklisted in videos list/search on server 1', async function () {
{ {
const res = await getVideosList(servers[0].url) const { total, data } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(0) expect(total).to.equal(0)
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data.length).to.equal(0) expect(data.length).to.equal(0)
} }
{ {
@ -84,11 +79,11 @@ describe('Test video blacklist', function () {
it('Should have the blacklisted video in videos list/search on server 2', async function () { it('Should have the blacklisted video in videos list/search on server 2', async function () {
{ {
const res = await getVideosList(servers[1].url) const { total, data } = await servers[1].videosCommand.list()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data.length).to.equal(2) expect(data.length).to.equal(2)
} }
{ {
@ -186,12 +181,12 @@ describe('Test video blacklist', function () {
it('Should display blacklisted videos', async function () { it('Should display blacklisted videos', async function () {
await blacklistVideosOnServer(servers[1]) await blacklistVideosOnServer(servers[1])
const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) const { total, data } = await servers[1].videosCommand.listMyVideos()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
expect(res.body.data).to.have.lengthOf(2) expect(data).to.have.lengthOf(2)
for (const video of res.body.data) { for (const video of data) {
expect(video.blacklisted).to.be.true expect(video.blacklisted).to.be.true
expect(video.blacklistedReason).to.equal('super reason') expect(video.blacklistedReason).to.equal('super reason')
} }
@ -203,10 +198,10 @@ describe('Test video blacklist', function () {
let blacklist = [] let blacklist = []
it('Should not have any video in videos list on server 1', async function () { it('Should not have any video in videos list 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(total).to.equal(0)
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data.length).to.equal(0) expect(data.length).to.equal(0)
}) })
it('Should remove a video from the blacklist on server 1', async function () { it('Should remove a video from the blacklist on server 1', async function () {
@ -220,15 +215,14 @@ describe('Test video blacklist', function () {
}) })
it('Should have the ex-blacklisted video in videos list on server 1', async function () { it('Should have the ex-blacklisted video in videos list 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(1) expect(total).to.equal(1)
const videos = res.body.data expect(data).to.be.an('array')
expect(videos).to.be.an('array') expect(data.length).to.equal(1)
expect(videos.length).to.equal(1)
expect(videos[0].name).to.equal(videoToRemove.video.name) expect(data[0].name).to.equal(videoToRemove.video.name)
expect(videos[0].id).to.equal(videoToRemove.video.id) expect(data[0].id).to.equal(videoToRemove.video.id)
}) })
it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
@ -250,12 +244,12 @@ describe('Test video blacklist', function () {
this.timeout(10000) this.timeout(10000)
{ {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } })
video3UUID = res.body.video.uuid video3UUID = uuid
} }
{ {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } })
video4UUID = res.body.video.uuid video4UUID = uuid
} }
await waitJobs(servers) await waitJobs(servers)
@ -269,13 +263,13 @@ describe('Test video blacklist', function () {
await waitJobs(servers) await waitJobs(servers)
{ {
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined expect(data.find(v => v.uuid === video3UUID)).to.be.undefined
} }
{ {
const res = await getVideosList(servers[1].url) const { data } = await servers[1].videosCommand.list()
expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined
} }
}) })
@ -287,21 +281,21 @@ describe('Test video blacklist', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
} }
}) })
it('Should have the video unfederated even after an Update AP message', async function () { it('Should have the video unfederated even after an Update AP message', async function () {
this.timeout(10000) this.timeout(10000)
await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } })
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
} }
}) })
@ -324,8 +318,8 @@ describe('Test video blacklist', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined
} }
}) })
@ -383,7 +377,7 @@ describe('Test video blacklist', function () {
}) })
it('Should auto blacklist a video on upload', async function () { it('Should auto blacklist a video on upload', async function () {
await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } })
const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
expect(body.total).to.equal(1) expect(body.total).to.equal(1)
@ -419,7 +413,7 @@ describe('Test video blacklist', function () {
}) })
it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } })
const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
expect(body.total).to.equal(3) expect(body.total).to.equal(3)

View File

@ -10,7 +10,6 @@ import {
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
ServerInfo, ServerInfo,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { UserNotification } from '@shared/models' import { UserNotification } from '@shared/models'
@ -53,8 +52,7 @@ describe('Test comments notifications', function () {
it('Should not send a new comment notification after a comment on another video', async function () { it('Should not send a new comment notification after a comment on another video', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id const commentId = created.id
@ -66,8 +64,7 @@ describe('Test comments notifications', function () {
it('Should not send a new comment notification if I comment my own video', async function () { it('Should not send a new comment notification if I comment my own video', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' }) const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
const commentId = created.id const commentId = created.id
@ -81,8 +78,7 @@ describe('Test comments notifications', function () {
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id const commentId = created.id
@ -96,8 +92,7 @@ describe('Test comments notifications', function () {
it('Should send a new comment notification after a local comment on my video', async function () { it('Should send a new comment notification after a local comment on my video', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id const commentId = created.id
@ -109,8 +104,7 @@ describe('Test comments notifications', function () {
it('Should send a new comment notification after a remote comment on my video', async function () { it('Should send a new comment notification after a remote comment on my video', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
await waitJobs(servers) await waitJobs(servers)
@ -128,8 +122,7 @@ describe('Test comments notifications', function () {
it('Should send a new comment notification after a local reply on my video', async function () { it('Should send a new comment notification after a local reply on my video', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
@ -142,8 +135,7 @@ describe('Test comments notifications', function () {
it('Should send a new comment notification after a remote reply on my video', async function () { it('Should send a new comment notification after a remote reply on my video', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
await waitJobs(servers) await waitJobs(servers)
{ {
@ -169,8 +161,7 @@ describe('Test comments notifications', function () {
it('Should convert markdown in comment to html', async function () { it('Should convert markdown in comment to html', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'cool video' } })
const uuid = resVideo.body.video.uuid
await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText }) await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText })
@ -199,8 +190,7 @@ describe('Test comments notifications', function () {
it('Should not send a new mention comment notification if I mention the video owner', async function () { it('Should not send a new mention comment notification if I mention the video owner', async function () {
this.timeout(10000) this.timeout(10000)
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
@ -211,8 +201,7 @@ describe('Test comments notifications', function () {
it('Should not send a new mention comment notification if I mention myself', async function () { it('Should not send a new mention comment notification if I mention myself', async function () {
this.timeout(10000) this.timeout(10000)
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
@ -225,8 +214,7 @@ describe('Test comments notifications', function () {
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
@ -239,8 +227,7 @@ describe('Test comments notifications', function () {
it('Should not send a new mention notification if the remote account mention a local account', async function () { it('Should not send a new mention notification if the remote account mention a local account', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
await waitJobs(servers) await waitJobs(servers)
const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
@ -252,8 +239,7 @@ describe('Test comments notifications', function () {
it('Should send a new mention notification after local comments', async function () { it('Should send a new mention notification after local comments', async function () {
this.timeout(10000) this.timeout(10000)
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
@ -269,8 +255,7 @@ describe('Test comments notifications', function () {
it('Should send a new mention notification after remote comments', async function () { it('Should send a new mention notification after remote comments', async function () {
this.timeout(20000) this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
await waitJobs(servers) await waitJobs(servers)
@ -301,8 +286,7 @@ describe('Test comments notifications', function () {
it('Should convert markdown in comment to html', async function () { it('Should convert markdown in comment to html', async function () {
this.timeout(10000) this.timeout(10000)
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const uuid = resVideo.body.video.uuid
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' })

View File

@ -17,12 +17,10 @@ import {
checkVideoAutoBlacklistForModerators, checkVideoAutoBlacklistForModerators,
checkVideoIsPublished, checkVideoIsPublished,
cleanupTests, cleanupTests,
getVideoIdFromUUID,
MockInstancesIndex, MockInstancesIndex,
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
ServerInfo, ServerInfo,
uploadVideo,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -64,8 +62,7 @@ describe('Test moderation notifications', function () {
this.timeout(20000) this.timeout(20000)
const name = 'video for abuse ' + buildUUID() const name = 'video for abuse ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const video = resVideo.body.video
await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' }) await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' })
@ -77,12 +74,11 @@ describe('Test moderation notifications', function () {
this.timeout(20000) this.timeout(20000)
const name = 'video for abuse ' + buildUUID() const name = 'video for abuse ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const video = resVideo.body.video
await waitJobs(servers) await waitJobs(servers)
const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) const videoId = await servers[1].videosCommand.getId({ uuid: video.uuid })
await servers[1].abusesCommand.report({ videoId, reason: 'super reason' }) await servers[1].abusesCommand.report({ videoId, reason: 'super reason' })
await waitJobs(servers) await waitJobs(servers)
@ -93,8 +89,7 @@ describe('Test moderation notifications', function () {
this.timeout(20000) this.timeout(20000)
const name = 'video for abuse ' + buildUUID() const name = 'video for abuse ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const video = resVideo.body.video
const comment = await servers[0].commentsCommand.createThread({ const comment = await servers[0].commentsCommand.createThread({
token: userAccessToken, token: userAccessToken,
videoId: video.id, videoId: video.id,
@ -113,8 +108,7 @@ describe('Test moderation notifications', function () {
this.timeout(20000) this.timeout(20000)
const name = 'video for abuse ' + buildUUID() const name = 'video for abuse ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const video = resVideo.body.video
await servers[0].commentsCommand.createThread({ await servers[0].commentsCommand.createThread({
token: userAccessToken, token: userAccessToken,
@ -150,7 +144,7 @@ describe('Test moderation notifications', function () {
const username = 'user' + new Date().getTime() const username = 'user' + new Date().getTime()
const tmpToken = await servers[0].usersCommand.generateUserAndToken(username) const tmpToken = await servers[0].usersCommand.generateUserAndToken(username)
await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) await servers[0].videosCommand.upload({ token: tmpToken, attributes: { name: 'super video' } })
await waitJobs(servers) await waitJobs(servers)
@ -175,8 +169,7 @@ describe('Test moderation notifications', function () {
} }
const name = 'abuse ' + buildUUID() const name = 'abuse ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const video = resVideo.body.video
const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
abuseId = body.abuse.id abuseId = body.abuse.id
@ -223,8 +216,7 @@ describe('Test moderation notifications', function () {
} }
const name = 'abuse ' + buildUUID() const name = 'abuse ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const video = resVideo.body.video
{ {
const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
@ -294,8 +286,7 @@ describe('Test moderation notifications', function () {
this.timeout(10000) this.timeout(10000)
const name = 'video for abuse ' + buildUUID() const name = 'video for abuse ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const uuid = resVideo.body.video.uuid
await servers[0].blacklistCommand.add({ videoId: uuid }) await servers[0].blacklistCommand.add({ videoId: uuid })
@ -307,8 +298,7 @@ describe('Test moderation notifications', function () {
this.timeout(10000) this.timeout(10000)
const name = 'video for abuse ' + buildUUID() const name = 'video for abuse ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const uuid = resVideo.body.video.uuid
await servers[0].blacklistCommand.add({ videoId: uuid }) await servers[0].blacklistCommand.add({ videoId: uuid })
@ -497,8 +487,8 @@ describe('Test moderation notifications', function () {
this.timeout(40000) this.timeout(40000)
videoName = 'video with auto-blacklist ' + buildUUID() videoName = 'video with auto-blacklist ' + buildUUID()
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: videoName } })
videoUUID = resVideo.body.video.uuid videoUUID = uuid
await waitJobs(servers) await waitJobs(servers)
await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
@ -544,17 +534,16 @@ describe('Test moderation notifications', function () {
const name = 'video with auto-blacklist and future schedule ' + buildUUID() const name = 'video with auto-blacklist and future schedule ' + buildUUID()
const data = { const attributes = {
name, name,
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: { scheduleUpdate: {
updateAt: updateAt.toISOString(), updateAt: updateAt.toISOString(),
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
} }
} }
const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
const uuid = resVideo.body.video.uuid
await servers[0].blacklistCommand.remove({ videoId: uuid }) await servers[0].blacklistCommand.remove({ videoId: uuid })
@ -577,17 +566,16 @@ describe('Test moderation notifications', function () {
const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() const name = 'video with schedule done and still auto-blacklisted ' + buildUUID()
const data = { const attributes = {
name, name,
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: { scheduleUpdate: {
updateAt: updateAt.toISOString(), updateAt: updateAt.toISOString(),
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
} }
} }
const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
const uuid = resVideo.body.video.uuid
await wait(6000) await wait(6000)
await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
@ -601,8 +589,7 @@ describe('Test moderation notifications', function () {
const name = 'video without auto-blacklist ' + buildUUID() const name = 'video without auto-blacklist ' + buildUUID()
// admin with blacklist right will not be auto-blacklisted // admin with blacklist right will not be auto-blacklisted
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name } })
const uuid = resVideo.body.video.uuid
await waitJobs(servers) await waitJobs(servers)
await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')

View File

@ -10,7 +10,6 @@ import {
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
ServerInfo, ServerInfo,
uploadRandomVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { UserNotification, UserNotificationSettingValue } from '@shared/models' import { UserNotification, UserNotificationSettingValue } from '@shared/models'
@ -35,7 +34,7 @@ describe('Test notifications API', function () {
await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
await uploadRandomVideo(server, false) await server.videosCommand.randomUpload({ wait: false })
} }
await waitJobs([ server ]) await waitJobs([ server ])
@ -112,7 +111,7 @@ describe('Test notifications API', function () {
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
} }
const { name, uuid } = await uploadRandomVideo(server) const { name, uuid } = await server.videosCommand.randomUpload()
const check = { web: true, mail: true } const check = { web: true, mail: true }
await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
@ -131,7 +130,7 @@ describe('Test notifications API', function () {
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
} }
const { name, uuid } = await uploadRandomVideo(server) const { name, uuid } = await server.videosCommand.randomUpload()
{ {
const check = { mail: true, web: false } const check = { mail: true, web: false }
@ -157,7 +156,7 @@ describe('Test notifications API', function () {
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
} }
const { name, uuid } = await uploadRandomVideo(server) const { name, uuid } = await server.videosCommand.randomUpload()
{ {
const check = { mail: false, web: true } const check = { mail: false, web: true }
@ -188,7 +187,7 @@ describe('Test notifications API', function () {
) )
} }
const { name, uuid } = await uploadRandomVideo(server) const { name, uuid } = await server.videosCommand.randomUpload()
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
}) })

View File

@ -14,7 +14,6 @@ import {
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
ServerInfo, ServerInfo,
updateVideo,
uploadRandomVideoOnServers, uploadRandomVideoOnServers,
wait, wait,
waitJobs waitJobs
@ -99,7 +98,7 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: { scheduleUpdate: {
updateAt: updateAt.toISOString(), updateAt: updateAt.toISOString(),
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
} }
} }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
@ -118,7 +117,7 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: { scheduleUpdate: {
updateAt: updateAt.toISOString(), updateAt: updateAt.toISOString(),
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
} }
} }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
@ -137,7 +136,7 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: { scheduleUpdate: {
updateAt: updateAt.toISOString(), updateAt: updateAt.toISOString(),
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
} }
} }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
@ -154,7 +153,7 @@ describe('Test user notifications', function () {
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
await waitJobs(servers) await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
@ -168,7 +167,7 @@ describe('Test user notifications', function () {
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
await waitJobs(servers) await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
@ -180,7 +179,7 @@ describe('Test user notifications', function () {
const data = { privacy: VideoPrivacy.PRIVATE } const data = { privacy: VideoPrivacy.PRIVATE }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
}) })
@ -191,7 +190,7 @@ describe('Test user notifications', function () {
const data = { privacy: VideoPrivacy.PRIVATE } const data = { privacy: VideoPrivacy.PRIVATE }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
await waitJobs(servers) await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
@ -295,7 +294,7 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: { scheduleUpdate: {
updateAt: updateAt.toISOString(), updateAt: updateAt.toISOString(),
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
} }
} }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
@ -313,7 +312,7 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: { scheduleUpdate: {
updateAt: updateAt.toISOString(), updateAt: updateAt.toISOString(),
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
} }
} }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)

View File

@ -6,12 +6,9 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getLocalIdByUUID,
RedundancyCommand, RedundancyCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
uploadVideoAndGetId,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
@ -59,13 +56,13 @@ describe('Test manage videos redundancy', function () {
commands = servers.map(s => s.redundancyCommand) commands = servers.map(s => s.redundancyCommand)
{ {
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
video1Server2UUID = res.body.video.uuid video1Server2UUID = uuid
} }
{ {
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' }) const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2' } })
video2Server2UUID = res.body.video.uuid video2Server2UUID = uuid
} }
await waitJobs(servers) await waitJobs(servers)
@ -206,9 +203,9 @@ describe('Test manage videos redundancy', function () {
it('Should manually add a redundancy and list it', async function () { it('Should manually add a redundancy and list it', async function () {
this.timeout(120000) this.timeout(120000)
const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid const uuid = (await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
await waitJobs(servers) await waitJobs(servers)
const videoId = await getLocalIdByUUID(servers[0].url, uuid) const videoId = await servers[0].videosCommand.getId({ uuid })
await commands[0].addVideo({ videoId }) await commands[0].addVideo({ videoId })

View File

@ -9,8 +9,6 @@ import {
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
@ -38,11 +36,11 @@ describe('Test redundancy constraints', function () {
async function uploadWrapper (videoName: string) { async function uploadWrapper (videoName: string) {
// Wait for transcoding // Wait for transcoding
const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE }) const { id } = await localServer.videosCommand.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
await waitJobs([ localServer ]) await waitJobs([ localServer ])
// Update video to schedule a federation // Update video to schedule a federation
await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC }) await localServer.videosCommand.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
} }
async function getTotalRedundanciesLocalServer () { async function getTotalRedundanciesLocalServer () {
@ -80,7 +78,7 @@ describe('Test redundancy constraints', function () {
// Get the access tokens // Get the access tokens
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' }) await localServer.videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
await waitJobs(servers) await waitJobs(servers)

View File

@ -12,22 +12,16 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
getVideoWithToken,
killallServers, killallServers,
makeGetRequest, makeGetRequest,
removeVideo,
reRunServer, reRunServer,
root, root,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo,
uploadVideo,
viewVideo,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -84,11 +78,11 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
{ {
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) const { uuid, id } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
video1Server2UUID = res.body.video.uuid video1Server2UUID = uuid
video1Server2Id = res.body.video.id video1Server2Id = id
await viewVideo(servers[1].url, video1Server2UUID) await servers[1].videosCommand.view({ id: video1Server2UUID })
} }
await waitJobs(servers) await waitJobs(servers)
@ -112,9 +106,8 @@ async function check1WebSeed (videoUUID?: string) {
for (const server of servers) { for (const server of servers) {
// With token to avoid issues with video follow constraints // With token to avoid issues with video follow constraints
const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) const video = await server.videosCommand.getWithToken({ id: videoUUID })
const video: VideoDetails = res.body
for (const f of video.files) { for (const f of video.files) {
checkMagnetWebseeds(f, webseeds, server) checkMagnetWebseeds(f, webseeds, server)
} }
@ -130,9 +123,7 @@ async function check2Webseeds (videoUUID?: string) {
] ]
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video: VideoDetails = res.body
for (const file of video.files) { for (const file of video.files) {
checkMagnetWebseeds(file, webseeds, server) checkMagnetWebseeds(file, webseeds, server)
@ -172,8 +163,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) {
for (const server of servers) { for (const server of servers) {
// With token to avoid issues with video follow constraints // With token to avoid issues with video follow constraints
const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) const video = await server.videosCommand.getWithToken({ id: videoUUID })
const video: VideoDetails = res.body
expect(video.streamingPlaylists).to.be.an('array') expect(video.streamingPlaylists).to.be.an('array')
expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists).to.have.lengthOf(1)
@ -185,8 +175,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) {
if (!videoUUID) videoUUID = video1Server2UUID if (!videoUUID) videoUUID = video1Server2UUID
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video: VideoDetails = res.body
expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists).to.have.lengthOf(1)
expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1)
@ -199,8 +188,8 @@ async function check1PlaylistRedundancies (videoUUID?: string) {
const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls'
const baseUrlSegment = servers[0].url + '/static/redundancy/hls' const baseUrlSegment = servers[0].url + '/static/redundancy/hls'
const res = await getVideo(servers[0].url, videoUUID) const video = await servers[0].videosCommand.get({ id: videoUUID })
const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] const hlsPlaylist = video.streamingPlaylists[0]
for (const resolution of [ 240, 360, 480, 720 ]) { for (const resolution of [ 240, 360, 480, 720 ]) {
await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist })
@ -427,8 +416,8 @@ describe('Test videos redundancy', function () {
it('Should view 2 times the first video to have > min_views config', async function () { it('Should view 2 times the first video to have > min_views config', async function () {
this.timeout(80000) this.timeout(80000)
await viewVideo(servers[0].url, video1Server2UUID) await servers[0].videosCommand.view({ id: video1Server2UUID })
await viewVideo(servers[2].url, video1Server2UUID) await servers[2].videosCommand.view({ id: video1Server2UUID })
await wait(10000) await wait(10000)
await waitJobs(servers) await waitJobs(servers)
@ -449,7 +438,7 @@ describe('Test videos redundancy', function () {
it('Should remove the video and the redundancy files', async function () { it('Should remove the video and the redundancy files', async function () {
this.timeout(20000) this.timeout(20000)
await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) await servers[1].videosCommand.remove({ id: video1Server2UUID })
await waitJobs(servers) await waitJobs(servers)
@ -495,8 +484,8 @@ describe('Test videos redundancy', function () {
it('Should have 1 redundancy on the first video', async function () { it('Should have 1 redundancy on the first video', async function () {
this.timeout(160000) this.timeout(160000)
await viewVideo(servers[0].url, video1Server2UUID) await servers[0].videosCommand.view({ id: video1Server2UUID })
await viewVideo(servers[2].url, video1Server2UUID) await servers[2].videosCommand.view({ id: video1Server2UUID })
await wait(10000) await wait(10000)
await waitJobs(servers) await waitJobs(servers)
@ -512,7 +501,7 @@ describe('Test videos redundancy', function () {
it('Should remove the video and the redundancy files', async function () { it('Should remove the video and the redundancy files', async function () {
this.timeout(20000) this.timeout(20000)
await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) await servers[1].videosCommand.remove({ id: video1Server2UUID })
await waitJobs(servers) await waitJobs(servers)
@ -588,8 +577,7 @@ describe('Test videos redundancy', function () {
async function checkContains (servers: ServerInfo[], str: string) { async function checkContains (servers: ServerInfo[], str: string) {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, video1Server2UUID) const video = await server.videosCommand.get({ id: video1Server2UUID })
const video: VideoDetails = res.body
for (const f of video.files) { for (const f of video.files) {
expect(f.magnetUri).to.contain(str) expect(f.magnetUri).to.contain(str)
@ -599,8 +587,7 @@ describe('Test videos redundancy', function () {
async function checkNotContains (servers: ServerInfo[], str: string) { async function checkNotContains (servers: ServerInfo[], str: string) {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, video1Server2UUID) const video = await server.videosCommand.get({ id: video1Server2UUID })
const video: VideoDetails = res.body
for (const f of video.files) { for (const f of video.files) {
expect(f.magnetUri).to.not.contain(str) expect(f.magnetUri).to.not.contain(str)
@ -665,13 +652,13 @@ describe('Test videos redundancy', function () {
await check1PlaylistRedundancies(video1Server2UUID) await check1PlaylistRedundancies(video1Server2UUID)
await checkStatsWith1Redundancy(strategy) await checkStatsWith1Redundancy(strategy)
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE }) const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } })
video2Server2UUID = res.body.video.uuid video2Server2UUID = uuid
// Wait transcoding before federation // Wait transcoding before federation
await waitJobs(servers) await waitJobs(servers)
await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC }) await servers[1].videosCommand.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } })
}) })
it('Should cache video 2 webseeds on the first video', async function () { it('Should cache video 2 webseeds on the first video', async function () {

View File

@ -5,12 +5,9 @@ import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideoChannelVideos,
SearchCommand, SearchCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo,
uploadVideo,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -53,8 +50,9 @@ describe('Test ActivityPub video channels search', function () {
const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel }) const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel })
channelIdServer2 = created.id channelIdServer2 = created.id
const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 }) const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 }
videoServer2UUID = res.body.video.uuid const { uuid } = await servers[1].videosCommand.upload({ token: userServer2Token, attributes })
videoServer2UUID = uuid
} }
await waitJobs(servers) await waitJobs(servers)
@ -149,16 +147,21 @@ describe('Test ActivityPub video channels search', function () {
await waitJobs(servers) await waitJobs(servers)
const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({
expect(res.body.total).to.equal(0) token: null,
expect(res.body.data).to.have.lengthOf(0) videoChannelName: 'channel1_server2@localhost:' + servers[1].port
})
expect(total).to.equal(0)
expect(data).to.have.lengthOf(0)
}) })
it('Should list video channel videos of server 2 with token', async function () { it('Should list video channel videos of server 2 with token', async function () {
const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({
videoChannelName: 'channel1_server2@localhost:' + servers[1].port
})
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data[0].name).to.equal('video 1 server 2') expect(data[0].name).to.equal('video 1 server 2')
}) })
it('Should update video channel of server 2, and refresh it on server 1', async function () { it('Should update video channel of server 2, and refresh it on server 1', async function () {
@ -190,8 +193,8 @@ describe('Test ActivityPub video channels search', function () {
it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
this.timeout(60000) this.timeout(60000)
await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' }) await servers[1].videosCommand.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } })
await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 }) await servers[1].videosCommand.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } })
await waitJobs(servers) await waitJobs(servers)
@ -204,11 +207,11 @@ describe('Test ActivityPub video channels search', function () {
await waitJobs(servers) await waitJobs(servers)
const videoChannelName = 'channel1_server2@localhost:' + servers[1].port const videoChannelName = 'channel1_server2@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt') const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName, sort: '-createdAt' })
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
expect(res.body.data[0].name).to.equal('video 2 server 2') expect(data[0].name).to.equal('video 2 server 2')
expect(res.body.data[1].name).to.equal('video 1 updated') expect(data[1].name).to.equal('video 1 updated')
}) })
it('Should delete video channel of server 2, and delete it on server 1', async function () { it('Should delete video channel of server 2, and delete it on server 1', async function () {

View File

@ -9,7 +9,6 @@ import {
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
uploadVideoAndGetId,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -34,8 +33,8 @@ describe('Test ActivityPub playlists search', function () {
await setDefaultVideoChannel(servers) await setDefaultVideoChannel(servers)
{ {
const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid const video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid
const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid const video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid
const attributes = { const attributes = {
displayName: 'playlist 1 on server 1', displayName: 'playlist 1 on server 1',
@ -51,8 +50,8 @@ describe('Test ActivityPub playlists search', function () {
} }
{ {
const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid const videoId = (await servers[1].videosCommand.quickUpload({ name: 'video 1' })).uuid
video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid video2Server2 = (await servers[1].videosCommand.quickUpload({ name: 'video 2' })).uuid
const attributes = { const attributes = {
displayName: 'playlist 1 on server 2', displayName: 'playlist 1 on server 2',

View File

@ -5,17 +5,13 @@ import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList,
removeVideo,
SearchCommand, SearchCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo, wait,
uploadVideo, waitJobs
wait } from '@shared/extra-utils'
} from '../../../../shared/extra-utils' import { VideoPrivacy } from '@shared/models'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { VideoPrivacy } from '../../../../shared/models/videos'
const expect = chai.expect const expect = chai.expect
@ -34,13 +30,13 @@ describe('Test ActivityPub videos search', function () {
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
{ {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 on server 1' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1 on server 1' } })
videoServer1UUID = res.body.video.uuid videoServer1UUID = uuid
} }
{ {
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 on server 2' }) const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 on server 2' } })
videoServer2UUID = res.body.video.uuid videoServer2UUID = uuid
} }
await waitJobs(servers) await waitJobs(servers)
@ -109,10 +105,10 @@ describe('Test ActivityPub videos search', function () {
}) })
it('Should not list this remote video', async function () { it('Should not list this remote video', async function () {
const res = await getVideosList(servers[0].url) const { total, data } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
expect(res.body.data[0].name).to.equal('video 1 on server 1') expect(data[0].name).to.equal('video 1 on server 1')
}) })
it('Should update video of server 2, and refresh it on server 1', async function () { it('Should update video of server 2, and refresh it on server 1', async function () {
@ -131,7 +127,7 @@ describe('Test ActivityPub videos search', function () {
privacy: VideoPrivacy.UNLISTED, privacy: VideoPrivacy.UNLISTED,
channelId: videoChannelId channelId: videoChannelId
} }
await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes) await servers[1].videosCommand.update({ id: videoServer2UUID, attributes })
await waitJobs(servers) await waitJobs(servers)
// Expire video // Expire video
@ -157,7 +153,7 @@ describe('Test ActivityPub videos search', function () {
it('Should delete video of server 2, and delete it on server 1', async function () { it('Should delete video of server 2, and delete it on server 1', async function () {
this.timeout(120000) this.timeout(120000)
await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID) await servers[1].videosCommand.remove({ id: videoServer2UUID })
await waitJobs(servers) await waitJobs(servers)
// Expire video // Expire video

View File

@ -2,7 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -20,7 +20,7 @@ describe('Test videos search', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
await uploadVideo(server.url, server.accessToken, { name: localVideoName }) await server.videosCommand.upload({ attributes: { name: localVideoName } })
command = server.searchCommand command = server.searchCommand
}) })

View File

@ -2,16 +2,15 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { VideoPlaylistPrivacy } from '@shared/models'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
SearchCommand, SearchCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel
uploadVideoAndGetId } from '@shared/extra-utils'
} from '../../../../shared/extra-utils' import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -27,7 +26,7 @@ describe('Test playlists search', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ]) await setDefaultVideoChannel([ server ])
const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid const videoId = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
{ {
const attributes = { const attributes = {

View File

@ -10,7 +10,6 @@ import {
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
stopFfmpeg, stopFfmpeg,
uploadVideo,
wait wait
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
@ -41,50 +40,49 @@ describe('Test videos search', function () {
nsfw: false, nsfw: false,
language: 'fr' language: 'fr'
} }
await uploadVideo(server.url, server.accessToken, attributes1) await server.videosCommand.upload({ attributes: attributes1 })
const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
await uploadVideo(server.url, server.accessToken, attributes2) await server.videosCommand.upload({ attributes: attributes2 })
{ {
const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
const res = await uploadVideo(server.url, server.accessToken, attributes3) const { id, uuid } = await server.videosCommand.upload({ attributes: attributes3 })
const videoId = res.body.video.id videoUUID = uuid
videoUUID = res.body.video.uuid
await server.captionsCommand.createVideoCaption({ await server.captionsCommand.createVideoCaption({
language: 'en', language: 'en',
videoId, videoId: id,
fixture: 'subtitle-good2.vtt', fixture: 'subtitle-good2.vtt',
mimeType: 'application/octet-stream' mimeType: 'application/octet-stream'
}) })
await server.captionsCommand.createVideoCaption({ await server.captionsCommand.createVideoCaption({
language: 'aa', language: 'aa',
videoId, videoId: id,
fixture: 'subtitle-good2.vtt', fixture: 'subtitle-good2.vtt',
mimeType: 'application/octet-stream' mimeType: 'application/octet-stream'
}) })
} }
const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
await uploadVideo(server.url, server.accessToken, attributes4) await server.videosCommand.upload({ attributes: attributes4 })
await wait(1000) await wait(1000)
startDate = new Date().toISOString() startDate = new Date().toISOString()
const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
await uploadVideo(server.url, server.accessToken, attributes5) await server.videosCommand.upload({ attributes: attributes5 })
const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
await uploadVideo(server.url, server.accessToken, attributes6) await server.videosCommand.upload({ attributes: attributes6 })
const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
await uploadVideo(server.url, server.accessToken, attributes7) await server.videosCommand.upload({ attributes: attributes7 })
const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
await uploadVideo(server.url, server.accessToken, attributes8) await server.videosCommand.upload({ attributes: attributes8 })
} }
{ {
@ -95,9 +93,9 @@ describe('Test videos search', function () {
licence: 2, licence: 2,
language: 'en' language: 'en'
} }
await uploadVideo(server.url, server.accessToken, attributes) await server.videosCommand.upload({ attributes: attributes })
await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' }) await server.videosCommand.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } })
} }
{ {
@ -108,7 +106,7 @@ describe('Test videos search', function () {
licence: 3, licence: 3,
language: 'pl' language: 'pl'
} }
await uploadVideo(server.url, server.accessToken, attributes) await server.videosCommand.upload({ attributes: attributes })
} }
{ {
@ -117,11 +115,11 @@ describe('Test videos search', function () {
tags: [ 'aaaa', 'bbbb', 'cccc' ], tags: [ 'aaaa', 'bbbb', 'cccc' ],
category: 1 category: 1
} }
await uploadVideo(server.url, server.accessToken, attributes1) await server.videosCommand.upload({ attributes: attributes1 })
await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } })
await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] }) await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } })
await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] }) await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } })
} }
{ {
@ -129,8 +127,8 @@ describe('Test videos search', function () {
name: 'aaaa 2', name: 'aaaa 2',
category: 1 category: 1
} }
await uploadVideo(server.url, server.accessToken, attributes1) await server.videosCommand.upload({ attributes: attributes1 })
await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } })
} }
command = server.searchCommand command = server.searchCommand

View File

@ -7,13 +7,10 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { Video } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -64,11 +61,10 @@ describe('Test bulk actions', function () {
describe('Bulk remove comments', function () { describe('Bulk remove comments', function () {
async function checkInstanceCommentsRemoved () { async function checkInstanceCommentsRemoved () {
{ {
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const videos = res.body.data as Video[]
// Server 1 should not have these comments anymore // Server 1 should not have these comments anymore
for (const video of videos) { for (const video of data) {
const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id }) const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id })
const comment = data.find(c => c.text === 'comment by user 3') const comment = data.find(c => c.text === 'comment by user 3')
@ -77,11 +73,10 @@ describe('Test bulk actions', function () {
} }
{ {
const res = await getVideosList(servers[1].url) const { data } = await servers[1].videosCommand.list()
const videos = res.body.data as Video[]
// Server 1 should not have these comments on videos of server 1 // Server 1 should not have these comments on videos of server 1
for (const video of videos) { for (const video of data) {
const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id }) const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id })
const comment = data.find(c => c.text === 'comment by user 3') const comment = data.find(c => c.text === 'comment by user 3')
@ -97,17 +92,17 @@ describe('Test bulk actions', function () {
before(async function () { before(async function () {
this.timeout(120000) this.timeout(120000)
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' }) await servers[0].videosCommand.upload({ attributes: { name: 'video 1 server 1' } })
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } })
await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' }) await servers[0].videosCommand.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } })
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
await waitJobs(servers) await waitJobs(servers)
{ {
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
for (const video of res.body.data) { for (const video of data) {
await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' }) await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' })
await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' }) await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' })
await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' }) await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' })
@ -115,9 +110,9 @@ describe('Test bulk actions', function () {
} }
{ {
const res = await getVideosList(servers[1].url) const { data } = await servers[1].videosCommand.list()
for (const video of res.body.data) { for (const video of data) {
await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' }) await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' })
const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' }) const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' })
@ -142,9 +137,9 @@ describe('Test bulk actions', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
for (const video of res.body.data) { for (const video of data) {
const { data } = await server.commentsCommand.listThreads({ videoId: video.id }) const { data } = await server.commentsCommand.listThreads({ videoId: video.id })
const comment = data.find(c => c.text === 'comment by user 2') const comment = data.find(c => c.text === 'comment by user 2')

View File

@ -11,8 +11,7 @@ import {
parallelTests, parallelTests,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers
uploadVideo
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { CustomConfig } from '@shared/models' import { CustomConfig } from '@shared/models'
@ -242,8 +241,8 @@ describe('Test config', function () {
expect(data.video.file.extensions).to.contain('.webm') expect(data.video.file.extensions).to.contain('.webm')
expect(data.video.file.extensions).to.contain('.ogv') expect(data.video.file.extensions).to.contain('.ogv')
await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
expect(data.contactForm.enabled).to.be.true expect(data.contactForm.enabled).to.be.true
}) })
@ -448,8 +447,8 @@ describe('Test config', function () {
expect(data.video.file.extensions).to.contain('.ogg') expect(data.video.file.extensions).to.contain('.ogg')
expect(data.video.file.extensions).to.contain('.flac') expect(data.video.file.extensions).to.contain('.flac')
await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200) await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200) await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
}) })
it('Should have the configuration updated after a restart', async function () { it('Should have the configuration updated after a restart', async function () {

View File

@ -3,15 +3,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
cleanupTests,
flushAndRunServer,
MockSmtpServer,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
waitJobs
} from '@shared/extra-utils'
const expect = chai.expect const expect = chai.expect
@ -58,20 +50,18 @@ describe('Test emails', function () {
} }
{ {
const attributes = { const attributes = { name: 'my super user video' }
name: 'my super user video' const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes })
} videoUserUUID = uuid
const res = await uploadVideo(server.url, userAccessToken, attributes)
videoUserUUID = res.body.video.uuid
} }
{ {
const attributes = { const attributes = {
name: 'my super name' name: 'my super name'
} }
const res = await uploadVideo(server.url, server.accessToken, attributes) const { uuid, id } = await server.videosCommand.upload({ attributes })
videoUUID = res.body.video.uuid videoUUID = uuid
videoId = res.body.video.id videoId = id
} }
}) })

View File

@ -3,19 +3,8 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getAccountVideos,
getVideo,
getVideoChannelVideos,
getVideoWithToken,
ServerInfo,
setAccessTokensToServers,
uploadVideo
} from '../../../../shared/extra-utils'
const expect = chai.expect const expect = chai.expect
@ -23,7 +12,7 @@ describe('Test follow constraints', function () {
let servers: ServerInfo[] = [] let servers: ServerInfo[] = []
let video1UUID: string let video1UUID: string
let video2UUID: string let video2UUID: string
let userAccessToken: string let userToken: string
before(async function () { before(async function () {
this.timeout(90000) this.timeout(90000)
@ -34,12 +23,12 @@ describe('Test follow constraints', function () {
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
{ {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } })
video1UUID = res.body.video.uuid video1UUID = uuid
} }
{ {
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } })
video2UUID = res.body.video.uuid video2UUID = uuid
} }
const user = { const user = {
@ -47,7 +36,7 @@ describe('Test follow constraints', function () {
password: 'super_password' password: 'super_password'
} }
await servers[0].usersCommand.create({ username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(user) userToken = await servers[0].loginCommand.getAccessToken(user)
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
}) })
@ -57,81 +46,81 @@ describe('Test follow constraints', function () {
describe('With an unlogged user', function () { describe('With an unlogged user', function () {
it('Should get the local video', async function () { it('Should get the local video', async function () {
await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) await servers[0].videosCommand.get({ id: video1UUID })
}) })
it('Should get the remote video', async function () { it('Should get the remote video', async function () {
await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200) await servers[0].videosCommand.get({ id: video2UUID })
}) })
it('Should list local account videos', async function () { it('Should list local account videos', async function () {
const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[0].port })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list remote account videos', async function () { it('Should list remote account videos', async function () {
const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[1].port })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list local channel videos', async function () { it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port const videoChannelName = 'root_channel@localhost:' + servers[0].port
const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list remote channel videos', async function () { it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port const videoChannelName = 'root_channel@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
}) })
describe('With a logged user', function () { describe('With a logged user', function () {
it('Should get the local video', async function () { it('Should get the local video', async function () {
await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
}) })
it('Should get the remote video', async function () { it('Should get the remote video', async function () {
await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
}) })
it('Should list local account videos', async function () { it('Should list local account videos', async function () {
const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list remote account videos', async function () { it('Should list remote account videos', async function () {
const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list local channel videos', async function () { it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port const videoChannelName = 'root_channel@localhost:' + servers[0].port
const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list remote channel videos', async function () { it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port const videoChannelName = 'root_channel@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
}) })
}) })
@ -147,13 +136,12 @@ describe('Test follow constraints', function () {
describe('With an unlogged user', function () { describe('With an unlogged user', function () {
it('Should get the local video', async function () { it('Should get the local video', async function () {
await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) await servers[0].videosCommand.get({ id: video1UUID })
}) })
it('Should not get the remote video', async function () { it('Should not get the remote video', async function () {
const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403) const body = await servers[0].videosCommand.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
const error = body as unknown as PeerTubeProblemDocument
const error = res.body as PeerTubeProblemDocument
const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints' const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
expect(error.type).to.equal(doc) expect(error.type).to.equal(doc)
@ -168,73 +156,79 @@ describe('Test follow constraints', function () {
}) })
it('Should list local account videos', async function () { it('Should list local account videos', async function () {
const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByAccount({
token: undefined,
accountName: 'root@localhost:' + servers[0].port
})
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should not list remote account videos', async function () { it('Should not list remote account videos', async function () {
const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByAccount({
token: undefined,
accountName: 'root@localhost:' + servers[1].port
})
expect(res.body.total).to.equal(0) expect(total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0) expect(data).to.have.lengthOf(0)
}) })
it('Should list local channel videos', async function () { it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port const videoChannelName = 'root_channel@localhost:' + servers[0].port
const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should not list remote channel videos', async function () { it('Should not list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port const videoChannelName = 'root_channel@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
expect(res.body.total).to.equal(0) expect(total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0) expect(data).to.have.lengthOf(0)
}) })
}) })
describe('With a logged user', function () { describe('With a logged user', function () {
it('Should get the local video', async function () { it('Should get the local video', async function () {
await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
}) })
it('Should get the remote video', async function () { it('Should get the remote video', async function () {
await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
}) })
it('Should list local account videos', async function () { it('Should list local account videos', async function () {
const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list remote account videos', async function () { it('Should list remote account videos', async function () {
const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list local channel videos', async function () { it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port const videoChannelName = 'root_channel@localhost:' + servers[0].port
const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
it('Should list remote channel videos', async function () { it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port const videoChannelName = 'root_channel@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
}) })
}) })
}) })

View File

@ -9,12 +9,9 @@ import {
expectAccountFollows, expectAccountFollows,
flushAndRunMultipleServers, flushAndRunMultipleServers,
FollowsCommand, FollowsCommand,
getVideosList,
rateVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testCaptionFile, testCaptionFile,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models' import { Video, VideoPrivacy } from '@shared/models'
@ -287,22 +284,28 @@ describe('Test follows', function () {
it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () {
this.timeout(60000) this.timeout(60000)
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) await servers[1].videosCommand.upload({ attributes: { name: 'server2' } })
await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) await servers[2].videosCommand.upload({ attributes: { name: 'server3' } })
await waitJobs(servers) await waitJobs(servers)
let res = await getVideosList(servers[0].url) {
expect(res.body.total).to.equal(1) const { total, data } = await servers[0].videosCommand.list()
expect(res.body.data[0].name).to.equal('server2') expect(total).to.equal(1)
expect(data[0].name).to.equal('server2')
}
res = await getVideosList(servers[1].url) {
expect(res.body.total).to.equal(1) const { total, data } = await servers[1].videosCommand.list()
expect(res.body.data[0].name).to.equal('server2') expect(total).to.equal(1)
expect(data[0].name).to.equal('server2')
}
res = await getVideosList(servers[2].url) {
expect(res.body.total).to.equal(1) const { total, data } = await servers[2].videosCommand.list()
expect(res.body.data[0].name).to.equal('server3') expect(total).to.equal(1)
expect(data[0].name).to.equal('server3')
}
}) })
describe('Should propagate data on a new following', function () { describe('Should propagate data on a new following', function () {
@ -319,21 +322,21 @@ describe('Test follows', function () {
tags: [ 'tag1', 'tag2', 'tag3' ] tags: [ 'tag1', 'tag2', 'tag3' ]
} }
await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' }) await servers[2].videosCommand.upload({ attributes: { name: 'server3-2' } })
await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' }) await servers[2].videosCommand.upload({ attributes: { name: 'server3-3' } })
await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes) await servers[2].videosCommand.upload({ attributes: video4Attributes })
await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' }) await servers[2].videosCommand.upload({ attributes: { name: 'server3-5' } })
await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) await servers[2].videosCommand.upload({ attributes: { name: 'server3-6' } })
{ {
const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain') const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain')
const resVideos = await getVideosList(servers[2].url) const { data } = await servers[2].videosCommand.list()
video4 = resVideos.body.data.find(v => v.name === 'server3-4') video4 = data.find(v => v.name === 'server3-4')
{ {
await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like') await servers[2].videosCommand.rate({ id: video4.id, rating: 'like' })
await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike') await servers[2].videosCommand.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' })
} }
{ {
@ -401,12 +404,12 @@ describe('Test follows', function () {
}) })
it('Should have propagated videos', async function () { it('Should have propagated videos', async function () {
const res = await getVideosList(servers[0].url) const { total, data } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(7) expect(total).to.equal(7)
const video2 = res.body.data.find(v => v.name === 'server3-2') const video2 = data.find(v => v.name === 'server3-2')
video4 = res.body.data.find(v => v.name === 'server3-4') video4 = data.find(v => v.name === 'server3-4')
const video6 = res.body.data.find(v => v.name === 'server3-6') const video6 = data.find(v => v.name === 'server3-6')
expect(video2).to.not.be.undefined expect(video2).to.not.be.undefined
expect(video4).to.not.be.undefined expect(video4).to.not.be.undefined
@ -447,7 +450,7 @@ describe('Test follows', function () {
} }
] ]
} }
await completeVideoCheck(servers[0].url, video4, checkAttributes) await completeVideoCheck(servers[0], video4, checkAttributes)
}) })
it('Should have propagated comments', async function () { it('Should have propagated comments', async function () {
@ -542,8 +545,8 @@ describe('Test follows', function () {
await waitJobs(servers) await waitJobs(servers)
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
}) })
}) })

View File

@ -8,19 +8,14 @@ import {
CommentsCommand, CommentsCommand,
completeVideoCheck, completeVideoCheck,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
getVideosList,
killallServers, killallServers,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo,
uploadVideo,
uploadVideoAndGetId,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { JobState, Video, VideoPrivacy } from '@shared/models' import { JobState, VideoCreateResult, VideoPrivacy } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -30,9 +25,9 @@ describe('Test handle downs', function () {
let threadIdServer2: number let threadIdServer2: number
let commentIdServer1: number let commentIdServer1: number
let commentIdServer2: number let commentIdServer2: number
let missedVideo1: Video let missedVideo1: VideoCreateResult
let missedVideo2: Video let missedVideo2: VideoCreateResult
let unlistedVideo: Video let unlistedVideo: VideoCreateResult
const videoIdsServer1: string[] = [] const videoIdsServer1: string[] = []
@ -110,15 +105,15 @@ describe('Test handle downs', function () {
await waitJobs(servers) await waitJobs(servers)
// Upload a video to server 1 // Upload a video to server 1
await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) await servers[0].videosCommand.upload({ attributes: videoAttributes })
await waitJobs(servers) await waitJobs(servers)
// And check all servers have this video // And check all servers have this video
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
} }
// Kill server 2 // Kill server 2
@ -126,7 +121,7 @@ describe('Test handle downs', function () {
// Remove server 2 follower // Remove server 2 follower
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) await servers[0].videosCommand.upload({ attributes: videoAttributes })
} }
await waitJobs([ servers[0], servers[2] ]) await waitJobs([ servers[0], servers[2] ])
@ -134,15 +129,12 @@ describe('Test handle downs', function () {
// Kill server 3 // Kill server 3
await killallServers([ servers[2] ]) await killallServers([ servers[2] ])
const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) missedVideo1 = await servers[0].videosCommand.upload({ attributes: videoAttributes })
missedVideo1 = resLastVideo1.body.video
const resLastVideo2 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) missedVideo2 = await servers[0].videosCommand.upload({ attributes: videoAttributes })
missedVideo2 = resLastVideo2.body.video
// Unlisted video // Unlisted video
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, unlistedVideoAttributes) unlistedVideo = await servers[0].videosCommand.upload({ attributes: unlistedVideoAttributes })
unlistedVideo = resVideo.body.video
// Add comments to video 2 // Add comments to video 2
{ {
@ -202,25 +194,27 @@ describe('Test handle downs', function () {
it('Should send an update to server 3, and automatically fetch the video', async function () { it('Should send an update to server 3, and automatically fetch the video', async function () {
this.timeout(15000) this.timeout(15000)
const res1 = await getVideosList(servers[2].url) {
expect(res1.body.data).to.be.an('array') const { data } = await servers[2].videosCommand.list()
expect(res1.body.data).to.have.lengthOf(11) expect(data).to.be.an('array')
expect(data).to.have.lengthOf(11)
}
await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, {}) await servers[0].videosCommand.update({ id: missedVideo1.uuid })
await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, {}) await servers[0].videosCommand.update({ id: unlistedVideo.uuid })
await waitJobs(servers) await waitJobs(servers)
const res = await getVideosList(servers[2].url) {
expect(res.body.data).to.be.an('array') const { data } = await servers[2].videosCommand.list()
// 1 video is unlisted expect(data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(12) // 1 video is unlisted
expect(data).to.have.lengthOf(12)
}
// Check unlisted video // Check unlisted video
const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid) const video = await servers[2].videosCommand.get({ id: unlistedVideo.uuid })
expect(resVideo.body).not.to.be.undefined await completeVideoCheck(servers[2], video, unlistedCheckAttributes)
await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes)
}) })
it('Should send comments on a video to server 3, and automatically fetch the video', async function () { it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
@ -230,8 +224,7 @@ describe('Test handle downs', function () {
await waitJobs(servers) await waitJobs(servers)
const resVideo = await getVideo(servers[2].url, missedVideo2.uuid) await servers[2].videosCommand.get({ id: missedVideo2.uuid })
expect(resVideo.body).not.to.be.undefined
{ {
const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid }) const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid })
@ -293,14 +286,14 @@ describe('Test handle downs', function () {
this.timeout(120000) this.timeout(120000)
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video ' + i })).uuid const uuid = (await servers[0].videosCommand.quickUpload({ name: 'video ' + i })).uuid
videoIdsServer1.push(uuid) videoIdsServer1.push(uuid)
} }
await waitJobs(servers) await waitJobs(servers)
for (const id of videoIdsServer1) { for (const id of videoIdsServer1) {
await getVideo(servers[1].url, id) await servers[1].videosCommand.get({ id })
} }
await waitJobs(servers) await waitJobs(servers)
@ -310,7 +303,7 @@ describe('Test handle downs', function () {
await wait(11000) await wait(11000)
// Refresh video -> score + 10 = 30 // Refresh video -> score + 10 = 30
await getVideo(servers[1].url, videoIdsServer1[0]) await servers[1].videosCommand.get({ id: videoIdsServer1[0] })
await waitJobs(servers) await waitJobs(servers)
}) })
@ -325,14 +318,14 @@ describe('Test handle downs', function () {
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
try { try {
await getVideo(servers[1].url, videoIdsServer1[i]) await servers[1].videosCommand.get({ id: videoIdsServer1[i] })
await waitJobs([ servers[1] ]) await waitJobs([ servers[1] ])
await wait(1500) await wait(1500)
} catch {} } catch {}
} }
for (const id of videoIdsServer1) { for (const id of videoIdsServer1) {
await getVideo(servers[1].url, id, HttpStatusCode.FORBIDDEN_403) await servers[1].videosCommand.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
} }
}) })

View File

@ -9,7 +9,6 @@ import {
flushAndRunMultipleServers, flushAndRunMultipleServers,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -32,8 +31,8 @@ describe('Test jobs', function () {
it('Should create some jobs', async function () { it('Should create some jobs', async function () {
this.timeout(120000) this.timeout(120000)
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) await servers[1].videosCommand.upload({ attributes: { name: 'video1' } })
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) await servers[1].videosCommand.upload({ attributes: { name: 'video2' } })
await waitJobs(servers) await waitJobs(servers)
}) })

View File

@ -10,7 +10,6 @@ import {
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -34,12 +33,12 @@ describe('Test logs', function () {
it('Should get logs with a start date', async function () { it('Should get logs with a start date', async function () {
this.timeout(20000) this.timeout(20000)
await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) await server.videosCommand.upload({ attributes: { name: 'video 1' } })
await waitJobs([ server ]) await waitJobs([ server ])
const now = new Date() const now = new Date()
await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) await server.videosCommand.upload({ attributes: { name: 'video 2' } })
await waitJobs([ server ]) await waitJobs([ server ])
const body = await logsCommand.getLogs({ startDate: now }) const body = await logsCommand.getLogs({ startDate: now })
@ -52,17 +51,17 @@ describe('Test logs', function () {
it('Should get logs with an end date', async function () { it('Should get logs with an end date', async function () {
this.timeout(30000) this.timeout(30000)
await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) await server.videosCommand.upload({ attributes: { name: 'video 3' } })
await waitJobs([ server ]) await waitJobs([ server ])
const now1 = new Date() const now1 = new Date()
await uploadVideo(server.url, server.accessToken, { name: 'video 4' }) await server.videosCommand.upload({ attributes: { name: 'video 4' } })
await waitJobs([ server ]) await waitJobs([ server ])
const now2 = new Date() const now2 = new Date()
await uploadVideo(server.url, server.accessToken, { name: 'video 5' }) await server.videosCommand.upload({ attributes: { name: 'video 5' } })
await waitJobs([ server ]) await waitJobs([ server ])
const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 }) const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 })
@ -78,7 +77,7 @@ describe('Test logs', function () {
const now = new Date() const now = new Date()
await uploadVideo(server.url, server.accessToken, { name: 'video 6' }) await server.videosCommand.upload({ attributes: { name: 'video 6' } })
await waitJobs([ server ]) await waitJobs([ server ])
{ {
@ -131,12 +130,12 @@ describe('Test logs', function () {
it('Should get logs with a start date', async function () { it('Should get logs with a start date', async function () {
this.timeout(20000) this.timeout(20000)
await uploadVideo(server.url, server.accessToken, { name: 'video 7' }) await server.videosCommand.upload({ attributes: { name: 'video 7' } })
await waitJobs([ server ]) await waitJobs([ server ])
const now = new Date() const now = new Date()
await uploadVideo(server.url, server.accessToken, { name: 'video 8' }) await server.videosCommand.upload({ attributes: { name: 'video 8' } })
await waitJobs([ server ]) await waitJobs([ server ])
const body = await logsCommand.getAuditLogs({ startDate: now }) const body = await logsCommand.getAuditLogs({ startDate: now })
@ -157,17 +156,17 @@ describe('Test logs', function () {
it('Should get logs with an end date', async function () { it('Should get logs with an end date', async function () {
this.timeout(30000) this.timeout(30000)
await uploadVideo(server.url, server.accessToken, { name: 'video 9' }) await server.videosCommand.upload({ attributes: { name: 'video 9' } })
await waitJobs([ server ]) await waitJobs([ server ])
const now1 = new Date() const now1 = new Date()
await uploadVideo(server.url, server.accessToken, { name: 'video 10' }) await server.videosCommand.upload({ attributes: { name: 'video 10' } })
await waitJobs([ server ]) await waitJobs([ server ])
const now2 = new Date() const now2 = new Date()
await uploadVideo(server.url, server.accessToken, { name: 'video 11' }) await server.videosCommand.upload({ attributes: { name: 'video 11' } })
await waitJobs([ server ]) await waitJobs([ server ])
const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 }) const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 })

View File

@ -2,20 +2,11 @@
import { expect } from 'chai' import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils'
cleanupTests,
flushAndRunServer,
getVideo,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
viewVideo,
wait
} from '@shared/extra-utils'
describe('Test application behind a reverse proxy', function () { describe('Test application behind a reverse proxy', function () {
let server: ServerInfo let server: ServerInfo
let videoId: number let videoId: string
before(async function () { before(async function () {
this.timeout(30000) this.timeout(30000)
@ -42,60 +33,60 @@ describe('Test application behind a reverse proxy', function () {
server = await flushAndRunServer(1, config) server = await flushAndRunServer(1, config)
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const { body } = await uploadVideo(server.url, server.accessToken, {}) const { uuid } = await server.videosCommand.upload()
videoId = body.video.uuid videoId = uuid
}) })
it('Should view a video only once with the same IP by default', async function () { it('Should view a video only once with the same IP by default', async function () {
this.timeout(20000) this.timeout(20000)
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
// Wait the repeatable job // Wait the repeatable job
await wait(8000) await wait(8000)
const { body } = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
expect(body.views).to.equal(1) expect(video.views).to.equal(1)
}) })
it('Should view a video 2 times with the X-Forwarded-For header set', async function () { it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
this.timeout(20000) this.timeout(20000)
await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.1,127.0.0.1') await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.1,127.0.0.1' })
await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.2,127.0.0.1') await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.2,127.0.0.1' })
// Wait the repeatable job // Wait the repeatable job
await wait(8000) await wait(8000)
const { body } = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
expect(body.views).to.equal(3) expect(video.views).to.equal(3)
}) })
it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () { it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
this.timeout(20000) this.timeout(20000)
await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1') await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.4,0.0.0.3,::ffff:127.0.0.1' })
await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.5,0.0.0.3,127.0.0.1') await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.5,0.0.0.3,127.0.0.1' })
// Wait the repeatable job // Wait the repeatable job
await wait(8000) await wait(8000)
const { body } = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
expect(body.views).to.equal(4) expect(video.views).to.equal(4)
}) })
it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () { it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
this.timeout(20000) this.timeout(20000)
await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.6,127.0.0.1') await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.6,127.0.0.1' })
await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.7,127.0.0.1') await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.7,127.0.0.1' })
// Wait the repeatable job // Wait the repeatable job
await wait(8000) await wait(8000)
const { body } = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
expect(body.views).to.equal(6) expect(video.views).to.equal(6)
}) })
it('Should rate limit logins', async function () { it('Should rate limit logins', async function () {
@ -140,13 +131,13 @@ describe('Test application behind a reverse proxy', function () {
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
try { try {
await getVideo(server.url, videoId) await server.videosCommand.get({ id: videoId })
} catch { } catch {
// don't care if it fails // don't care if it fails
} }
} }
await getVideo(server.url, videoId, HttpStatusCode.TOO_MANY_REQUESTS_429) await server.videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
}) })
after(async function () { after(async function () {

View File

@ -2,15 +2,8 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils'
import { Video, VideoPlaylistPrivacy } from '@shared/models' import { Video, VideoPlaylistPrivacy } from '@shared/models'
import {
getVideosList,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
uploadVideo
} from '../../../../shared/extra-utils'
import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
const expect = chai.expect const expect = chai.expect
@ -29,13 +22,11 @@ describe('Test services', function () {
await setDefaultVideoChannel([ server ]) await setDefaultVideoChannel([ server ])
{ {
const videoAttributes = { const attributes = { name: 'my super name' }
name: 'my super name' await server.videosCommand.upload({ attributes })
}
await uploadVideo(server.url, server.accessToken, videoAttributes)
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
video = res.body.data[0] video = data[0]
} }
{ {

View File

@ -8,8 +8,6 @@ import {
flushAndRunMultipleServers, flushAndRunMultipleServers,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
viewVideo,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -36,12 +34,11 @@ describe('Test stats (excluding redundancy)', function () {
await servers[0].usersCommand.create({ username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { fixture: 'video_short.webm' } })
const videoUUID = resVideo.body.video.uuid
await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'comment' }) await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
await viewVideo(servers[0].url, videoUUID) await servers[0].videosCommand.view({ id: uuid })
// Wait the video views repeatable job // Wait the video views repeatable job
await wait(8000) await wait(8000)
@ -154,7 +151,7 @@ describe('Test stats (excluding redundancy)', function () {
} }
{ {
await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId }) await server.videosCommand.upload({ attributes: { fixture: 'video_short.webm', channelId } })
const data = await server.statsCommand.get() const data = await server.statsCommand.get()
@ -213,7 +210,7 @@ describe('Test stats (excluding redundancy)', function () {
} }
}) })
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' }) await servers[0].videosCommand.upload({ attributes: { name: 'video', fixture: 'video_short.webm' } })
await waitJobs(servers) await waitJobs(servers)
@ -243,7 +240,7 @@ describe('Test stats (excluding redundancy)', function () {
const first = await servers[1].statsCommand.get() const first = await servers[1].statsCommand.get()
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
} }
await waitJobs(servers) await waitJobs(servers)

View File

@ -1,19 +1,9 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */
import * as magnetUtil from 'magnet-uri'
import 'mocha' import 'mocha'
import { import * as magnetUtil from 'magnet-uri'
cleanupTests,
flushAndRunServer,
getVideo,
killallServers,
reRunServer,
ServerInfo,
uploadVideo
} from '../../../../shared/extra-utils'
import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
import { VideoDetails } from '../../../../shared/models/videos'
import * as WebTorrent from 'webtorrent' import * as WebTorrent from 'webtorrent'
import { cleanupTests, flushAndRunServer, killallServers, reRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
describe('Test tracker', function () { describe('Test tracker', function () {
let server: ServerInfo let server: ServerInfo
@ -26,11 +16,8 @@ describe('Test tracker', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
{ {
const res = await uploadVideo(server.url, server.accessToken, {}) const { uuid } = await server.videosCommand.upload()
const videoUUID = res.body.video.uuid const video = await server.videosCommand.get({ id: uuid })
const resGet = await getVideo(server.url, videoUUID)
const video: VideoDetails = resGet.body
goodMagnet = video.files[0].magnetUri goodMagnet = video.files[0].magnetUri
const parsed = magnetUtil.decode(goodMagnet) const parsed = magnetUtil.decode(goodMagnet)

View File

@ -6,12 +6,9 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
SubscriptionsCommand, SubscriptionsCommand,
updateVideo,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -44,10 +41,10 @@ describe('Test users subscriptions', function () {
users.push({ accessToken }) users.push({ accessToken })
const videoName1 = 'video 1-' + server.serverNumber const videoName1 = 'video 1-' + server.serverNumber
await uploadVideo(server.url, accessToken, { name: videoName1 }) await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } })
const videoName2 = 'video 2-' + server.serverNumber const videoName2 = 'video 2-' + server.serverNumber
await uploadVideo(server.url, accessToken, { name: videoName2 }) await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } })
} }
} }
@ -57,9 +54,9 @@ describe('Test users subscriptions', function () {
}) })
it('Should display videos of server 2 on server 1', async function () { it('Should display videos of server 2 on server 1', async function () {
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(4) expect(total).to.equal(4)
}) })
it('User of server 1 should follow user of server 3 and root of server 1', async function () { it('User of server 1 should follow user of server 3 and root of server 1', async function () {
@ -70,17 +67,17 @@ describe('Test users subscriptions', function () {
await waitJobs(servers) await waitJobs(servers)
const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } })
video3UUID = res.body.video.uuid video3UUID = uuid
await waitJobs(servers) await waitJobs(servers)
}) })
it('Should not display videos of server 3 on server 1', async function () { it('Should not display videos of server 3 on server 1', async function () {
const res = await getVideosList(servers[0].url) const { total, data } = await servers[0].videosCommand.list()
expect(total).to.equal(4)
expect(res.body.total).to.equal(4) for (const video of data) {
for (const video of res.body.data) {
expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow') expect(video.name).to.not.contain('video server 3 added after follow')
@ -186,7 +183,7 @@ describe('Test users subscriptions', function () {
this.timeout(60000) this.timeout(60000)
const videoName = 'video server 1 added after follow' const videoName = 'video server 1 added after follow'
await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) await servers[0].videosCommand.upload({ attributes: { name: videoName } })
await waitJobs(servers) await waitJobs(servers)
@ -212,10 +209,10 @@ describe('Test users subscriptions', function () {
} }
{ {
const res = await getVideosList(servers[0].url) const { data, total } = await servers[0].videosCommand.list()
expect(total).to.equal(5)
expect(res.body.total).to.equal(5) for (const video of data) {
for (const video of res.body.data) {
expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow') expect(video.name).to.not.contain('video server 3 added after follow')
@ -230,13 +227,12 @@ describe('Test users subscriptions', function () {
await waitJobs(servers) await waitJobs(servers)
const res = await getVideosList(servers[0].url) const { data, total } = await servers[0].videosCommand.list()
expect(total).to.equal(8)
expect(res.body.total).to.equal(8)
const names = [ '1-3', '2-3', 'video server 3 added after follow' ] const names = [ '1-3', '2-3', 'video server 3 added after follow' ]
for (const name of names) { for (const name of names) {
const video = res.body.data.find(v => v.name.indexOf(name) === -1) const video = data.find(v => v.name.includes(name))
expect(video).to.not.be.undefined expect(video).to.not.be.undefined
} }
}) })
@ -248,10 +244,10 @@ describe('Test users subscriptions', function () {
await waitJobs(servers) await waitJobs(servers)
const res = await getVideosList(servers[0].url) const { total, data } = await servers[0].videosCommand.list()
expect(total).to.equal(5)
expect(res.body.total).to.equal(5) for (const video of data) {
for (const video of res.body.data) {
expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow') expect(video.name).to.not.contain('video server 3 added after follow')
@ -284,7 +280,7 @@ describe('Test users subscriptions', function () {
it('Should update a video of server 3 and see the updated video on server 1', async function () { it('Should update a video of server 3 and see the updated video on server 1', async function () {
this.timeout(30000) this.timeout(30000)
await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } })
await waitJobs(servers) await waitJobs(servers)
@ -329,10 +325,10 @@ describe('Test users subscriptions', function () {
}) })
it('Should correctly display public videos on server 1', async function () { it('Should correctly display public videos on server 1', async function () {
const res = await getVideosList(servers[0].url) const { total, data } = await servers[0].videosCommand.list()
expect(total).to.equal(5)
expect(res.body.total).to.equal(5) for (const video of data) {
for (const video of res.body.data) {
expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow updated') expect(video.name).to.not.contain('video server 3 added after follow updated')
@ -360,10 +356,10 @@ describe('Test users subscriptions', function () {
} }
{ {
const res = await getVideosList(servers[0].url) const { total, data } = await servers[0].videosCommand.list()
expect(total).to.equal(5)
expect(res.body.total).to.equal(5) for (const video of data) {
for (const video of res.body.data) {
expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow updated') expect(video.name).to.not.contain('video server 3 added after follow updated')

View File

@ -9,11 +9,9 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getAccountVideos,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testImage, testImage,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { User } from '@shared/models' import { User } from '@shared/models'
@ -44,7 +42,7 @@ describe('Test users with multiple servers', function () {
await doubleFollow(servers[1], servers[2]) await doubleFollow(servers[1], servers[2])
// The root user of server 1 is propagated to servers 2 and 3 // The root user of server 1 is propagated to servers 2 and 3
await uploadVideo(servers[0].url, servers[0].accessToken, {}) await servers[0].videosCommand.upload()
{ {
const user = { const user = {
@ -57,8 +55,8 @@ describe('Test users with multiple servers', function () {
} }
{ {
const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken })
videoUUID = resVideo.body.video.uuid videoUUID = uuid
} }
await waitJobs(servers) await waitJobs(servers)
@ -133,31 +131,29 @@ describe('Test users with multiple servers', function () {
it('Should list account videos', async function () { it('Should list account videos', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5) const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
expect(res.body.data[0].uuid).to.equal(videoUUID) expect(data[0].uuid).to.equal(videoUUID)
} }
}) })
it('Should search through account videos', async function () { it('Should search through account videos', async function () {
this.timeout(10_000) this.timeout(10_000)
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' })
search: 'Kami'
})
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid) expect(data[0].uuid).to.equal(created.uuid)
} }
}) })

View File

@ -6,17 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getMyVideos,
getVideosList,
killallServers, killallServers,
makePutBodyRequest, makePutBodyRequest,
rateVideo,
removeVideo,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testImage, testImage,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
@ -25,8 +20,8 @@ const expect = chai.expect
describe('Test users', function () { describe('Test users', function () {
let server: ServerInfo let server: ServerInfo
let accessToken: string let token: string
let accessTokenUser: string let userToken: string
let videoId: number let videoId: number
let userId: number let userId: number
const user = { const user = {
@ -101,18 +96,17 @@ describe('Test users', function () {
}) })
it('Should not be able to upload a video', async function () { it('Should not be able to upload a video', async function () {
accessToken = 'my_super_token' token = 'my_super_token'
const videoAttributes = {} await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
}) })
it('Should not be able to follow', async function () { it('Should not be able to follow', async function () {
accessToken = 'my_super_token' token = 'my_super_token'
await server.followsCommand.follow({ await server.followsCommand.follow({
targets: [ 'http://example.com' ], targets: [ 'http://example.com' ],
token: accessToken, token,
expectedStatus: HttpStatusCode.UNAUTHORIZED_401 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
}) })
}) })
@ -122,7 +116,7 @@ describe('Test users', function () {
it('Should be able to login', async function () { it('Should be able to login', async function () {
const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 })
accessToken = body.access_token token = body.access_token
}) })
it('Should be able to login with an insensitive username', async function () { it('Should be able to login with an insensitive username', async function () {
@ -140,33 +134,31 @@ describe('Test users', function () {
describe('Upload', function () { describe('Upload', function () {
it('Should upload the video with the correct token', async function () { it('Should upload the video with the correct token', async function () {
const videoAttributes = {} await server.videosCommand.upload({ token })
await uploadVideo(server.url, accessToken, videoAttributes) const { data } = await server.videosCommand.list()
const res = await getVideosList(server.url) const video = data[0]
const video = res.body.data[0]
expect(video.account.name).to.equal('root') expect(video.account.name).to.equal('root')
videoId = video.id videoId = video.id
}) })
it('Should upload the video again with the correct token', async function () { it('Should upload the video again with the correct token', async function () {
const videoAttributes = {} await server.videosCommand.upload({ token })
await uploadVideo(server.url, accessToken, videoAttributes)
}) })
}) })
describe('Ratings', function () { describe('Ratings', function () {
it('Should retrieve a video rating', async function () { it('Should retrieve a video rating', async function () {
await rateVideo(server.url, accessToken, videoId, 'like') await server.videosCommand.rate({ id: videoId, rating: 'like' })
const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) const rating = await server.usersCommand.getMyRating({ token, videoId })
expect(rating.videoId).to.equal(videoId) expect(rating.videoId).to.equal(videoId)
expect(rating.rating).to.equal('like') expect(rating.rating).to.equal('like')
}) })
it('Should retrieve ratings list', async function () { it('Should retrieve ratings list', async function () {
await rateVideo(server.url, accessToken, videoId, 'like') await server.videosCommand.rate({ id: videoId, rating: 'like' })
const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
@ -190,13 +182,13 @@ describe('Test users', function () {
describe('Remove video', function () { describe('Remove video', function () {
it('Should not be able to remove the video with an incorrect token', async function () { it('Should not be able to remove the video with an incorrect token', async function () {
await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should not be able to remove the video with the token of another account') it('Should not be able to remove the video with the token of another account')
it('Should be able to remove the video with the correct token', async function () { it('Should be able to remove the video with the correct token', async function () {
await removeVideo(server.url, accessToken, videoId) await server.videosCommand.remove({ token, id: videoId })
}) })
}) })
@ -210,7 +202,7 @@ describe('Test users', function () {
}) })
it('Should not be able to upload a video', async function () { it('Should not be able to upload a video', async function () {
await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should not be able to rate a video', async function () { it('Should not be able to rate a video', async function () {
@ -281,11 +273,11 @@ describe('Test users', function () {
}) })
it('Should be able to login with this user', async function () { it('Should be able to login with this user', async function () {
accessTokenUser = await server.loginCommand.getAccessToken(user) userToken = await server.loginCommand.getAccessToken(user)
}) })
it('Should be able to get user information', async function () { it('Should be able to get user information', async function () {
const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const userMe = await server.usersCommand.getMyInfo({ token: userToken })
const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true })
@ -323,15 +315,15 @@ describe('Test users', function () {
it('Should be able to upload a video with this user', async function () { it('Should be able to upload a video with this user', async function () {
this.timeout(10000) this.timeout(10000)
const videoAttributes = { const attributes = {
name: 'super user video', name: 'super user video',
fixture: 'video_short.webm' fixture: 'video_short.webm'
} }
await uploadVideo(server.url, accessTokenUser, videoAttributes) await server.videosCommand.upload({ token: userToken, attributes })
}) })
it('Should have video quota updated', async function () { it('Should have video quota updated', async function () {
const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken })
expect(quota.videoQuotaUsed).to.equal(218910) expect(quota.videoQuotaUsed).to.equal(218910)
const { data } = await server.usersCommand.list() const { data } = await server.usersCommand.list()
@ -340,13 +332,11 @@ describe('Test users', function () {
}) })
it('Should be able to list my videos', async function () { it('Should be able to list my videos', async function () {
const res = await getMyVideos(server.url, accessTokenUser, 0, 5) const { total, data } = await server.videosCommand.listMyVideos({ token: userToken })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
const videos = res.body.data const video: Video = data[0]
expect(videos).to.have.lengthOf(1)
const video: Video = videos[0]
expect(video.name).to.equal('super user video') expect(video.name).to.equal('super user video')
expect(video.thumbnailPath).to.not.be.null expect(video.thumbnailPath).to.not.be.null
expect(video.previewPath).to.not.be.null expect(video.previewPath).to.not.be.null
@ -354,19 +344,15 @@ describe('Test users', function () {
it('Should be able to search in my videos', async function () { it('Should be able to search in my videos', async function () {
{ {
const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' })
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
const videos = res.body.data
expect(videos).to.have.lengthOf(1)
} }
{ {
const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' })
expect(res.body.total).to.equal(0) expect(total).to.equal(0)
expect(data).to.have.lengthOf(0)
const videos = res.body.data
expect(videos).to.have.lengthOf(0)
} }
}) })
@ -382,17 +368,17 @@ describe('Test users', function () {
} }
{ {
const videoAttributes = { const attributes = {
name: 'super user video 2', name: 'super user video 2',
fixture: 'video_short.webm' fixture: 'video_short.webm'
} }
await uploadVideo(server.url, accessTokenUser, videoAttributes) await server.videosCommand.upload({ token: userToken, attributes })
await waitJobs([ server ]) await waitJobs([ server ])
} }
{ {
const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) const data = await server.usersCommand.getMyQuotaUsed({ token: userToken })
expect(data.videoQuotaUsed).to.be.greaterThan(220000) expect(data.videoQuotaUsed).to.be.greaterThan(220000)
} }
}) })
@ -505,7 +491,7 @@ describe('Test users', function () {
it('Should update my password', async function () { it('Should update my password', async function () {
await server.usersCommand.updateMe({ await server.usersCommand.updateMe({
token: accessTokenUser, token: userToken,
currentPassword: 'super password', currentPassword: 'super password',
password: 'new password' password: 'new password'
}) })
@ -516,11 +502,11 @@ describe('Test users', function () {
it('Should be able to change the NSFW display attribute', async function () { it('Should be able to change the NSFW display attribute', async function () {
await server.usersCommand.updateMe({ await server.usersCommand.updateMe({
token: accessTokenUser, token: userToken,
nsfwPolicy: 'do_not_list' nsfwPolicy: 'do_not_list'
}) })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com') expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.nsfwPolicy).to.equal('do_not_list')
@ -532,32 +518,32 @@ describe('Test users', function () {
it('Should be able to change the autoPlayVideo attribute', async function () { it('Should be able to change the autoPlayVideo attribute', async function () {
await server.usersCommand.updateMe({ await server.usersCommand.updateMe({
token: accessTokenUser, token: userToken,
autoPlayVideo: false autoPlayVideo: false
}) })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.autoPlayVideo).to.be.false expect(user.autoPlayVideo).to.be.false
}) })
it('Should be able to change the autoPlayNextVideo attribute', async function () { it('Should be able to change the autoPlayNextVideo attribute', async function () {
await server.usersCommand.updateMe({ await server.usersCommand.updateMe({
token: accessTokenUser, token: userToken,
autoPlayNextVideo: true autoPlayNextVideo: true
}) })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.autoPlayNextVideo).to.be.true expect(user.autoPlayNextVideo).to.be.true
}) })
it('Should be able to change the email attribute', async function () { it('Should be able to change the email attribute', async function () {
await server.usersCommand.updateMe({ await server.usersCommand.updateMe({
token: accessTokenUser, token: userToken,
currentPassword: 'new password', currentPassword: 'new password',
email: 'updated@example.com' email: 'updated@example.com'
}) })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com') expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.nsfwPolicy).to.equal('do_not_list')
@ -570,9 +556,9 @@ describe('Test users', function () {
it('Should be able to update my avatar with a gif', async function () { it('Should be able to update my avatar with a gif', async function () {
const fixture = 'avatar.gif' const fixture = 'avatar.gif'
await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) await server.usersCommand.updateMyAvatar({ token: userToken, fixture })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
}) })
@ -580,17 +566,17 @@ describe('Test users', function () {
for (const extension of [ '.png', '.gif' ]) { for (const extension of [ '.png', '.gif' ]) {
const fixture = 'avatar' + extension const fixture = 'avatar' + extension
await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) await server.usersCommand.updateMyAvatar({ token: userToken, fixture })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
} }
}) })
it('Should be able to update my display name', async function () { it('Should be able to update my display name', async function () {
await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com') expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.nsfwPolicy).to.equal('do_not_list')
@ -601,9 +587,9 @@ describe('Test users', function () {
}) })
it('Should be able to update my description', async function () { it('Should be able to update my description', async function () {
await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com') expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.nsfwPolicy).to.equal('do_not_list')
@ -617,21 +603,21 @@ describe('Test users', function () {
it('Should be able to update my theme', async function () { it('Should be able to update my theme', async function () {
for (const theme of [ 'background-red', 'default', 'instance-default' ]) { for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
await server.usersCommand.updateMe({ token: accessTokenUser, theme }) await server.usersCommand.updateMe({ token: userToken, theme })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.theme).to.equal(theme) expect(user.theme).to.equal(theme)
} }
}) })
it('Should be able to update my modal preferences', async function () { it('Should be able to update my modal preferences', async function () {
await server.usersCommand.updateMe({ await server.usersCommand.updateMe({
token: accessTokenUser, token: userToken,
noInstanceConfigWarningModal: true, noInstanceConfigWarningModal: true,
noWelcomeModal: true noWelcomeModal: true
}) })
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.noWelcomeModal).to.be.true expect(user.noWelcomeModal).to.be.true
expect(user.noInstanceConfigWarningModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true
}) })
@ -641,7 +627,7 @@ describe('Test users', function () {
it('Should be able to update another user', async function () { it('Should be able to update another user', async function () {
await server.usersCommand.update({ await server.usersCommand.update({
userId, userId,
token: accessToken, token,
email: 'updated2@example.com', email: 'updated2@example.com',
emailVerified: true, emailVerified: true,
videoQuota: 42, videoQuota: 42,
@ -650,7 +636,7 @@ describe('Test users', function () {
pluginAuth: 'toto' pluginAuth: 'toto'
}) })
const user = await server.usersCommand.get({ token: accessToken, userId }) const user = await server.usersCommand.get({ token, userId })
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated2@example.com') expect(user.email).to.equal('updated2@example.com')
@ -664,39 +650,39 @@ describe('Test users', function () {
}) })
it('Should reset the auth plugin', async function () { it('Should reset the auth plugin', async function () {
await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) await server.usersCommand.update({ userId, token, pluginAuth: null })
const user = await server.usersCommand.get({ token: accessToken, userId }) const user = await server.usersCommand.get({ token, userId })
expect(user.pluginAuth).to.be.null expect(user.pluginAuth).to.be.null
}) })
it('Should have removed the user token', async function () { it('Should have removed the user token', async function () {
await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
accessTokenUser = await server.loginCommand.getAccessToken(user) userToken = await server.loginCommand.getAccessToken(user)
}) })
it('Should be able to update another user password', async function () { it('Should be able to update another user password', async function () {
await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) await server.usersCommand.update({ userId, token, password: 'password updated' })
await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
user.password = 'password updated' user.password = 'password updated'
accessTokenUser = await server.loginCommand.getAccessToken(user) userToken = await server.loginCommand.getAccessToken(user)
}) })
}) })
describe('Video blacklists', function () { describe('Video blacklists', function () {
it('Should be able to list video blacklist by a moderator', async function () { it('Should be able to list video blacklist by a moderator', async function () {
await server.blacklistCommand.list({ token: accessTokenUser }) await server.blacklistCommand.list({ token: userToken })
}) })
}) })
describe('Remove a user', function () { describe('Remove a user', function () {
it('Should be able to remove this user', async function () { it('Should be able to remove this user', async function () {
await server.usersCommand.remove({ userId, token: accessToken }) await server.usersCommand.remove({ userId, token })
}) })
it('Should not be able to login with this user', async function () { it('Should not be able to login with this user', async function () {
@ -704,11 +690,10 @@ describe('Test users', function () {
}) })
it('Should not have videos of this user', async function () { it('Should not have videos of this user', async function () {
const res = await getVideosList(server.url) const { data, total } = await server.videosCommand.list()
expect(total).to.equal(1)
expect(res.body.total).to.equal(1) const video = data[0]
const video = res.body.data[0]
expect(video.account.name).to.equal('root') expect(video.account.name).to.equal('root')
}) })
}) })
@ -832,12 +817,11 @@ describe('Test users', function () {
}) })
it('Should report correct videos count', async function () { it('Should report correct videos count', async function () {
const videoAttributes = { const attributes = { name: 'video to test user stats' }
name: 'video to test user stats' await server.videosCommand.upload({ token: user17AccessToken, attributes })
}
await uploadVideo(server.url, user17AccessToken, videoAttributes) const { data } = await server.videosCommand.list()
const res1 = await getVideosList(server.url) videoId = data.find(video => video.name === attributes.name).id
videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
expect(user.videosCount).to.equal(1) expect(user.videosCount).to.equal(1)

View File

@ -4,17 +4,7 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { join } from 'path' import { join } from 'path'
import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils'
import { import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
waitJobs
} from '../../../../shared/extra-utils'
import { VideoDetails } from '../../../../shared/models/videos'
const expect = chai.expect 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 () { it('Should upload a video and transcode it', async function () {
this.timeout(120000) this.timeout(120000)
const resUpload = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'audio only' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'audio only' } })
videoUUID = resUpload.body.video.uuid videoUUID = uuid
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video: VideoDetails = res.body
expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists).to.have.lengthOf(1)
for (const files of [ video.files, video.streamingPlaylists[0].files ]) { for (const files of [ video.files, video.streamingPlaylists[0].files ]) {

View File

@ -13,17 +13,9 @@ import {
dateIsValid, dateIsValid,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getLocalVideos,
getVideo,
getVideosList,
rateVideo,
removeVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testImage, testImage,
updateVideo,
uploadVideo,
viewVideo,
wait, wait,
waitJobs, waitJobs,
webtorrentAdd webtorrentAdd
@ -67,10 +59,9 @@ describe('Test multiple servers', function () {
it('Should not have videos for all servers', async function () { it('Should not have videos for all servers', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data).to.be.an('array')
expect(videos).to.be.an('array') expect(data.length).to.equal(0)
expect(videos.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 () { it('Should upload the video on server 1 and propagate on each server', async function () {
this.timeout(25000) this.timeout(25000)
const videoAttributes = { const attributes = {
name: 'my super name for server 1', name: 'my super name for server 1',
category: 5, category: 5,
licence: 4, licence: 4,
@ -91,7 +82,7 @@ describe('Test multiple servers', function () {
channelId: videoChannelId, channelId: videoChannelId,
fixture: 'video_short1.webm' fixture: 'video_short1.webm'
} }
await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
@ -134,14 +125,13 @@ describe('Test multiple servers', function () {
] ]
} }
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data).to.be.an('array')
expect(videos).to.be.an('array') expect(data.length).to.equal(1)
expect(videos.length).to.equal(1) const video = data[0]
const video = videos[0]
await completeVideoCheck(server.url, video, checkAttributes) await completeVideoCheck(server, video, checkAttributes)
publishedAt = video.publishedAt 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 }) await servers[1].usersCommand.create({ username: user.username, password: user.password })
const userAccessToken = await servers[1].loginCommand.getAccessToken(user) const userAccessToken = await servers[1].loginCommand.getAccessToken(user)
const videoAttributes = { const attributes = {
name: 'my super name for server 2', name: 'my super name for server 2',
category: 4, category: 4,
licence: 3, licence: 3,
@ -168,7 +158,7 @@ describe('Test multiple servers', function () {
thumbnailfile: 'thumbnail.jpg', thumbnailfile: 'thumbnail.jpg',
previewfile: 'preview.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 // Transcoding
await waitJobs(servers) await waitJobs(servers)
@ -223,65 +213,67 @@ describe('Test multiple servers', function () {
previewfile: 'preview' previewfile: 'preview'
} }
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data).to.be.an('array')
expect(videos).to.be.an('array') expect(data.length).to.equal(2)
expect(videos.length).to.equal(2) const video = data[1]
const video = videos[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 () { it('Should upload two videos on server 3 and propagate on each server', async function () {
this.timeout(45000) this.timeout(45000)
const videoAttributes1 = { {
name: 'my super name for server 3', const attributes = {
category: 6, name: 'my super name for server 3',
licence: 5, category: 6,
language: 'de', licence: 5,
nsfw: true, language: 'de',
description: 'my super description for server 3', nsfw: true,
support: 'my super support text for server 3', description: 'my super description for server 3',
tags: [ 'tag1p3' ], support: 'my super support text for server 3',
fixture: 'video_short3.webm' 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', const attributes = {
category: 7, name: 'my super name for server 3-2',
licence: 6, category: 7,
language: 'ko', licence: 6,
nsfw: false, language: 'ko',
description: 'my super description for server 3-2', nsfw: false,
support: 'my super support text for server 3-2', description: 'my super description for server 3-2',
tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], support: 'my super support text for server 3-2',
fixture: 'video_short.webm' 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) await waitJobs(servers)
// All servers should have this video // All servers should have this video
for (const server of servers) { for (const server of servers) {
const isLocal = server.url === 'http://localhost:' + servers[2].port 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(data).to.be.an('array')
expect(videos).to.be.an('array') expect(data.length).to.equal(4)
expect(videos.length).to.equal(4)
// We not sure about the order of the two last uploads // We not sure about the order of the two last uploads
let video1 = null let video1 = null
let video2 = null let video2 = null
if (videos[2].name === 'my super name for server 3') { if (data[2].name === 'my super name for server 3') {
video1 = videos[2] video1 = data[2]
video2 = videos[3] video2 = data[3]
} else { } else {
video1 = videos[3] video1 = data[3]
video2 = videos[2] video2 = data[2]
} }
const checkAttributesVideo1 = { const checkAttributesVideo1 = {
@ -316,7 +308,7 @@ describe('Test multiple servers', function () {
} }
] ]
} }
await completeVideoCheck(server.url, video1, checkAttributesVideo1) await completeVideoCheck(server, video1, checkAttributesVideo1)
const checkAttributesVideo2 = { const checkAttributesVideo2 = {
name: 'my super name for server 3-2', 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 () { describe('It should list local videos', function () {
it('Should list only local videos on server 1', async 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(total).to.equal(1)
expect(body.data).to.be.an('array') expect(data).to.be.an('array')
expect(body.data.length).to.equal(1) expect(data.length).to.equal(1)
expect(body.data[0].name).to.equal('my super name for server 1') expect(data[0].name).to.equal('my super name for server 1')
}) })
it('Should list only local videos on server 2', async function () { 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(total).to.equal(1)
expect(body.data).to.be.an('array') expect(data).to.be.an('array')
expect(body.data.length).to.equal(1) expect(data.length).to.equal(1)
expect(body.data[0].name).to.equal('my super name for server 2') expect(data[0].name).to.equal('my super name for server 2')
}) })
it('Should list only local videos on server 3', async function () { 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(total).to.equal(2)
expect(body.data).to.be.an('array') expect(data).to.be.an('array')
expect(body.data.length).to.equal(2) expect(data.length).to.equal(2)
expect(body.data[0].name).to.equal('my super name for server 3') expect(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(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 () { it('Should add the file 1 by asking server 3', async function () {
this.timeout(10000) this.timeout(10000)
const res = await getVideosList(servers[2].url) const { data } = await servers[2].videosCommand.list()
const video = res.body.data[0] const video = data[0]
toRemove.push(res.body.data[2]) toRemove.push(data[2])
toRemove.push(res.body.data[3]) toRemove.push(data[3])
const res2 = await getVideo(servers[2].url, video.id)
const videoDetails = res2.body
const videoDetails = await servers[2].videosCommand.get({ id: video.id })
const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
expect(torrent.files).to.be.an('array') expect(torrent.files).to.be.an('array')
expect(torrent.files.length).to.equal(1) 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 () { it('Should add the file 2 by asking server 1', async function () {
this.timeout(10000) this.timeout(10000)
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const video = res.body.data[1] const video = data[1]
const res2 = await getVideo(servers[0].url, video.id) const videoDetails = await servers[0].videosCommand.get({ id: video.id })
const videoDetails = res2.body
const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
expect(torrent.files).to.be.an('array') 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 () { it('Should add the file 3 by asking server 2', async function () {
this.timeout(10000) this.timeout(10000)
const res = await getVideosList(servers[1].url) const { data } = await servers[1].videosCommand.list()
const video = res.body.data[2] const video = data[2]
const res2 = await getVideo(servers[1].url, video.id) const videoDetails = await servers[1].videosCommand.get({ id: video.id })
const videoDetails = res2.body
const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
expect(torrent.files).to.be.an('array') 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 () { it('Should add the file 3-2 by asking server 1', async function () {
this.timeout(10000) this.timeout(10000)
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const video = res.body.data[3] const video = data[3]
const res2 = await getVideo(servers[0].url, video.id) const videoDetails = await servers[0].videosCommand.get({ id: video.id })
const videoDetails = res2.body
const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
expect(torrent.files).to.be.an('array') 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 () { it('Should add the file 2 in 360p by asking server 1', async function () {
this.timeout(10000) 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 video = data.find(v => v.name === 'my super name for server 2')
const res2 = await getVideo(servers[0].url, video.id) const videoDetails = await servers[0].videosCommand.get({ id: video.id })
const videoDetails = res2.body
const file = videoDetails.files.find(f => f.resolution.id === 360) const file = videoDetails.files.find(f => f.resolution.id === 360)
expect(file).not.to.be.undefined expect(file).not.to.be.undefined
@ -475,30 +461,36 @@ describe('Test multiple servers', function () {
let remoteVideosServer3 = [] let remoteVideosServer3 = []
before(async function () { 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) const { data } = await servers[2].videosCommand.list()
remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 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 () { it('Should view multiple videos on owned servers', async function () {
this.timeout(30000) this.timeout(30000)
await viewVideo(servers[2].url, localVideosServer3[0]) await servers[2].videosCommand.view({ id: localVideosServer3[0] })
await wait(1000) await wait(1000)
await viewVideo(servers[2].url, localVideosServer3[0]) await servers[2].videosCommand.view({ id: localVideosServer3[0] })
await viewVideo(servers[2].url, localVideosServer3[1]) await servers[2].videosCommand.view({ id: localVideosServer3[1] })
await wait(1000) await wait(1000)
await viewVideo(servers[2].url, localVideosServer3[0]) await servers[2].videosCommand.view({ id: localVideosServer3[0] })
await viewVideo(servers[2].url, localVideosServer3[0]) await servers[2].videosCommand.view({ id: localVideosServer3[0] })
await waitJobs(servers) await waitJobs(servers)
@ -508,11 +500,10 @@ describe('Test multiple servers', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 = data.find(v => v.uuid === localVideosServer3[0])
const video0 = videos.find(v => v.uuid === localVideosServer3[0]) const video1 = data.find(v => v.uuid === localVideosServer3[1])
const video1 = videos.find(v => v.uuid === localVideosServer3[1])
expect(video0.views).to.equal(3) expect(video0.views).to.equal(3)
expect(video1.views).to.equal(1) expect(video1.views).to.equal(1)
@ -523,16 +514,16 @@ describe('Test multiple servers', function () {
this.timeout(45000) this.timeout(45000)
const tasks: Promise<any>[] = [] const tasks: Promise<any>[] = []
tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) tasks.push(servers[0].videosCommand.view({ id: remoteVideosServer1[0] }))
tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] }))
tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] }))
tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[0] }))
tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
await Promise.all(tasks) await Promise.all(tasks)
@ -546,18 +537,16 @@ describe('Test multiple servers', function () {
let baseVideos = null let baseVideos = null
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data
// Initialize base videos for future comparisons // Initialize base videos for future comparisons
if (baseVideos === null) { if (baseVideos === null) {
baseVideos = videos baseVideos = data
continue continue
} }
for (const baseVideo of baseVideos) { 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) 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 () { it('Should like and dislikes videos on different services', async function () {
this.timeout(50000) 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 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 wait(500)
await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' })
await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like') await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'like' })
await wait(500) await wait(500)
await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike') await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'dislike' })
await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike') await servers[2].videosCommand.rate({ id: remoteVideosServer3[1], rating: 'dislike' })
await wait(500) 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 waitJobs(servers)
await wait(5000) await wait(5000)
@ -584,18 +573,16 @@ describe('Test multiple servers', function () {
let baseVideos = null let baseVideos = null
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data
// Initialize base videos for future comparisons // Initialize base videos for future comparisons
if (baseVideos === null) { if (baseVideos === null) {
baseVideos = videos baseVideos = data
continue continue
} }
for (const baseVideo of baseVideos) { 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.likes).to.equal(sameVideo.likes)
expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
} }
@ -621,7 +608,7 @@ describe('Test multiple servers', function () {
previewfile: 'preview.jpg' 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) await waitJobs(servers)
}) })
@ -630,10 +617,9 @@ describe('Test multiple servers', function () {
this.timeout(10000) this.timeout(10000)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data const videoUpdated = data.find(video => video.name === 'my super video updated')
const videoUpdated = videos.find(video => video.name === 'my super video updated')
expect(!!videoUpdated).to.be.true expect(!!videoUpdated).to.be.true
const isLocal = server.url === 'http://localhost:' + servers[2].port const isLocal = server.url === 'http://localhost:' + servers[2].port
@ -672,15 +658,15 @@ describe('Test multiple servers', function () {
thumbnailfile: 'thumbnail', thumbnailfile: 'thumbnail',
previewfile: 'preview' 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 () { it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
this.timeout(10000) this.timeout(10000)
await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) await servers[2].videosCommand.remove({ id: toRemove[0].id })
await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) await servers[2].videosCommand.remove({ id: toRemove[1].id })
await waitJobs(servers) await waitJobs(servers)
}) })
@ -694,27 +680,24 @@ describe('Test multiple servers', function () {
it('Should have videos 1 and 3 on each server', async function () { it('Should have videos 1 and 3 on each server', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data).to.be.an('array')
expect(videos).to.be.an('array') expect(data.length).to.equal(2)
expect(videos.length).to.equal(2) expect(data[0].name).not.to.equal(data[1].name)
expect(videos[0].name).not.to.equal(videos[1].name) expect(data[0].name).not.to.equal(toRemove[0].name)
expect(videos[0].name).not.to.equal(toRemove[0].name) expect(data[1].name).not.to.equal(toRemove[0].name)
expect(videos[1].name).not.to.equal(toRemove[0].name) expect(data[0].name).not.to.equal(toRemove[1].name)
expect(videos[0].name).not.to.equal(toRemove[1].name) expect(data[1].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 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 () { it('Should get the same video by UUID on each server', async function () {
let baseVideo = null let baseVideo = null
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video = res.body
if (baseVideo === null) { if (baseVideo === null) {
baseVideo = video baseVideo = video
@ -737,8 +720,7 @@ describe('Test multiple servers', function () {
it('Should get the preview from each server', async function () { it('Should get the preview from each server', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video = res.body
await testImage(server.url, 'video_short1-preview.webm', video.previewPath) await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
} }
@ -975,14 +957,14 @@ describe('Test multiple servers', function () {
downloadEnabled: false downloadEnabled: false
} }
await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) await servers[0].videosCommand.update({ id: videoUUID, attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
expect(res.body.commentsEnabled).to.be.false expect(video.commentsEnabled).to.be.false
expect(res.body.downloadEnabled).to.be.false expect(video.downloadEnabled).to.be.false
const text = 'my super forbidden comment' const text = 'my super forbidden comment'
await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
@ -1010,8 +992,8 @@ describe('Test multiple servers', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 === 'minimum parameters') const video = data.find(v => v.name === 'minimum parameters')
const isLocal = server.url === 'http://localhost:' + servers[1].port const isLocal = server.url === 'http://localhost:' + servers[1].port
const checkAttributes = { const checkAttributes = {
@ -1058,7 +1040,7 @@ describe('Test multiple servers', function () {
} }
] ]
} }
await completeVideoCheck(server.url, video, checkAttributes) await completeVideoCheck(server, video, checkAttributes)
} }
}) })
}) })

View File

@ -9,8 +9,6 @@ import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
prepareResumableUpload,
sendResumableChunks,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel setDefaultVideoChannel
@ -45,7 +43,7 @@ describe('Test resumable upload', function () {
const mimetype = 'video/mp4' 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] return res.header['location'].split('?')[1]
} }
@ -63,15 +61,13 @@ describe('Test resumable upload', function () {
const size = await buildSize(defaultFixture, options.size) const size = await buildSize(defaultFixture, options.size)
const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture) const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture)
return sendResumableChunks({ return server.videosCommand.sendResumableChunks({
url: server.url,
token: server.accessToken,
pathUploadId, pathUploadId,
videoFilePath: absoluteFilePath, videoFilePath: absoluteFilePath,
size, size,
contentLength, contentLength,
contentRangeBuilder, contentRangeBuilder,
specialStatus: expectedStatus expectedStatus
}) })
} }

View File

@ -2,34 +2,17 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { keyBy } from 'lodash'
import { import {
checkVideoFilesWereRemoved, checkVideoFilesWereRemoved,
cleanupTests, cleanupTests,
completeVideoCheck, completeVideoCheck,
flushAndRunServer, flushAndRunServer,
getVideo,
getVideoCategories,
getVideoLanguages,
getVideoLicences,
getVideoPrivacies,
getVideosList,
getVideosListPagination,
getVideosListSort,
getVideosWithFilters,
rateVideo,
removeVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testImage, testImage,
updateVideo,
uploadVideo,
viewVideo,
wait wait
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { VideoPrivacy } from '../../../../shared/models/videos' import { Video, VideoPrivacy } from '@shared/models'
import { HttpStatusCode } from '@shared/core-utils'
const expect = chai.expect const expect = chai.expect
@ -37,8 +20,8 @@ describe('Test a single server', function () {
function runSuite (mode: 'legacy' | 'resumable') { function runSuite (mode: 'legacy' | 'resumable') {
let server: ServerInfo = null let server: ServerInfo = null
let videoId = -1 let videoId: number | string
let videoId2 = -1 let videoId2: string
let videoUUID = '' let videoUUID = ''
let videosListBase: any[] = null let videosListBase: any[] = null
@ -117,128 +100,116 @@ describe('Test a single server', function () {
}) })
it('Should list video categories', async function () { it('Should list video categories', async function () {
const res = await getVideoCategories(server.url) const categories = await server.videosCommand.getCategories()
const categories = res.body
expect(Object.keys(categories)).to.have.length.above(10) expect(Object.keys(categories)).to.have.length.above(10)
expect(categories[11]).to.equal('News & Politics') expect(categories[11]).to.equal('News & Politics')
}) })
it('Should list video licences', async function () { it('Should list video licences', async function () {
const res = await getVideoLicences(server.url) const licences = await server.videosCommand.getLicences()
const licences = res.body
expect(Object.keys(licences)).to.have.length.above(5) expect(Object.keys(licences)).to.have.length.above(5)
expect(licences[3]).to.equal('Attribution - No Derivatives') expect(licences[3]).to.equal('Attribution - No Derivatives')
}) })
it('Should list video languages', async function () { it('Should list video languages', async function () {
const res = await getVideoLanguages(server.url) const languages = await server.videosCommand.getLanguages()
const languages = res.body
expect(Object.keys(languages)).to.have.length.above(5) expect(Object.keys(languages)).to.have.length.above(5)
expect(languages['ru']).to.equal('Russian') expect(languages['ru']).to.equal('Russian')
}) })
it('Should list video privacies', async function () { it('Should list video privacies', async function () {
const res = await getVideoPrivacies(server.url) const privacies = await server.videosCommand.getPrivacies()
const privacies = res.body
expect(Object.keys(privacies)).to.have.length.at.least(3) expect(Object.keys(privacies)).to.have.length.at.least(3)
expect(privacies[3]).to.equal('Private') expect(privacies[3]).to.equal('Private')
}) })
it('Should not have videos', async function () { 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(total).to.equal(0)
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data.length).to.equal(0) expect(data.length).to.equal(0)
}) })
it('Should upload the video', async function () { it('Should upload the video', async function () {
this.timeout(10000) this.timeout(10000)
const videoAttributes = { const attributes = {
name: 'my super name', name: 'my super name',
category: 2, category: 2,
nsfw: true, nsfw: true,
licence: 6, licence: 6,
tags: [ 'tag1', 'tag2', 'tag3' ] tags: [ 'tag1', 'tag2', 'tag3' ]
} }
const res = await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) const video = await server.videosCommand.upload({ attributes, mode })
expect(res.body.video).to.not.be.undefined expect(video).to.not.be.undefined
expect(res.body.video.id).to.equal(1) expect(video.id).to.equal(1)
expect(res.body.video.uuid).to.have.length.above(5) expect(video.uuid).to.have.length.above(5)
videoId = res.body.video.id videoId = video.id
videoUUID = res.body.video.uuid videoUUID = video.uuid
}) })
it('Should get and seed the uploaded video', async function () { it('Should get and seed the uploaded video', async function () {
this.timeout(5000) this.timeout(5000)
const res = await getVideosList(server.url) const { data, total } = await server.videosCommand.list()
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data.length).to.equal(1) expect(data.length).to.equal(1)
const video = res.body.data[0] const video = data[0]
await completeVideoCheck(server.url, video, getCheckAttributes()) await completeVideoCheck(server, video, getCheckAttributes())
}) })
it('Should get the video by UUID', async function () { it('Should get the video by UUID', async function () {
this.timeout(5000) this.timeout(5000)
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
await completeVideoCheck(server, video, getCheckAttributes())
const video = res.body
await completeVideoCheck(server.url, video, getCheckAttributes())
}) })
it('Should have the views updated', async function () { it('Should have the views updated', async function () {
this.timeout(20000) this.timeout(20000)
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
await wait(1500) await wait(1500)
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
await wait(1500) await wait(1500)
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
await viewVideo(server.url, videoId) await server.videosCommand.view({ id: videoId })
// Wait the repeatable job // Wait the repeatable job
await wait(8000) await wait(8000)
const res = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
const video = res.body
expect(video.views).to.equal(3) expect(video.views).to.equal(3)
}) })
it('Should remove the video', async function () { it('Should remove the video', async function () {
await removeVideo(server.url, server.accessToken, videoId) await server.videosCommand.remove({ id: videoId })
await checkVideoFilesWereRemoved(videoUUID, server) await checkVideoFilesWereRemoved(videoUUID, server)
}) })
it('Should not have videos', async function () { 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(total).to.equal(0)
expect(res.body.data).to.be.an('array') expect(data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(0) expect(data).to.have.lengthOf(0)
}) })
it('Should upload 6 videos', async function () { it('Should upload 6 videos', async function () {
@ -250,7 +221,7 @@ describe('Test a single server', function () {
]) ])
for (const video of videos) { for (const video of videos) {
const videoAttributes = { const attributes = {
name: video + ' name', name: video + ' name',
description: video + ' description', description: video + ' description',
category: 2, category: 2,
@ -261,19 +232,20 @@ describe('Test a single server', function () {
fixture: video 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 () { it('Should have the correct durations', async function () {
const res = await getVideosList(server.url) const { total, data } = await server.videosCommand.list()
expect(res.body.total).to.equal(6) expect(total).to.equal(6)
const videos = res.body.data expect(data).to.be.an('array')
expect(videos).to.be.an('array') expect(data).to.have.lengthOf(6)
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.mp4 name'].duration).to.equal(5)
expect(videosByName['video_short.ogv 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) 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 () { 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 // For the next test
videosListBase = videos videosListBase = data
for (const video of videos) { for (const video of data) {
const videoName = video.name.replace(' name', '') const videoName = video.name.replace(' name', '')
await testImage(server.url, videoName, video.thumbnailPath) await testImage(server.url, videoName, video.thumbnailPath)
} }
}) })
it('Should list only the two first videos', async function () { 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(total).to.equal(6)
expect(res.body.total).to.equal(6) expect(data.length).to.equal(2)
expect(videos.length).to.equal(2) expect(data[0].name).to.equal(videosListBase[0].name)
expect(videos[0].name).to.equal(videosListBase[0].name) expect(data[1].name).to.equal(videosListBase[1].name)
expect(videos[1].name).to.equal(videosListBase[1].name)
}) })
it('Should list only the next three videos', async function () { 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(total).to.equal(6)
expect(res.body.total).to.equal(6) expect(data.length).to.equal(3)
expect(videos.length).to.equal(3) expect(data[0].name).to.equal(videosListBase[2].name)
expect(videos[0].name).to.equal(videosListBase[2].name) expect(data[1].name).to.equal(videosListBase[3].name)
expect(videos[1].name).to.equal(videosListBase[3].name) expect(data[2].name).to.equal(videosListBase[4].name)
expect(videos[2].name).to.equal(videosListBase[4].name)
}) })
it('Should list the last video', async function () { 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(total).to.equal(6)
expect(res.body.total).to.equal(6) expect(data.length).to.equal(1)
expect(videos.length).to.equal(1) expect(data[0].name).to.equal(videosListBase[5].name)
expect(videos[0].name).to.equal(videosListBase[5].name)
}) })
it('Should not have the total field', async function () { 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(total).to.not.exist
expect(res.body.total).to.not.exist expect(data.length).to.equal(1)
expect(videos.length).to.equal(1) expect(data[0].name).to.equal(videosListBase[5].name)
expect(videos[0].name).to.equal(videosListBase[5].name)
}) })
it('Should list and sort by name in descending order', async function () { 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(total).to.equal(6)
expect(res.body.total).to.equal(6) expect(data.length).to.equal(6)
expect(videos.length).to.equal(6) expect(data[0].name).to.equal('video_short.webm name')
expect(videos[0].name).to.equal('video_short.webm name') expect(data[1].name).to.equal('video_short.ogv name')
expect(videos[1].name).to.equal('video_short.ogv name') expect(data[2].name).to.equal('video_short.mp4 name')
expect(videos[2].name).to.equal('video_short.mp4 name') expect(data[3].name).to.equal('video_short3.webm name')
expect(videos[3].name).to.equal('video_short3.webm name') expect(data[4].name).to.equal('video_short2.webm name')
expect(videos[4].name).to.equal('video_short2.webm name') expect(data[5].name).to.equal('video_short1.webm name')
expect(videos[5].name).to.equal('video_short1.webm name')
videoId = videos[3].uuid videoId = data[3].uuid
videoId2 = videos[5].uuid videoId2 = data[5].uuid
}) })
it('Should list and sort by trending in descending order', async function () { 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(total).to.equal(6)
expect(res.body.total).to.equal(6) expect(data.length).to.equal(2)
expect(videos.length).to.equal(2)
}) })
it('Should list and sort by hotness in descending order', async function () { 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(total).to.equal(6)
expect(res.body.total).to.equal(6) expect(data.length).to.equal(2)
expect(videos.length).to.equal(2)
}) })
it('Should list and sort by best in descending order', async function () { 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(total).to.equal(6)
expect(res.body.total).to.equal(6) expect(data.length).to.equal(2)
expect(videos.length).to.equal(2)
}) })
it('Should update a video', async function () { it('Should update a video', async function () {
@ -387,67 +350,66 @@ describe('Test a single server', function () {
downloadEnabled: false, downloadEnabled: false,
tags: [ 'tagup1', 'tagup2' ] 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 () { 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) const { data, total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
expect(res1.body.data[0].name).to.equal('my super video updated') 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 () { it('Should have the video updated', async function () {
this.timeout(60000) this.timeout(60000)
const res = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
const video = res.body
await completeVideoCheck(server.url, video, updateCheckAttributes()) await completeVideoCheck(server, video, updateCheckAttributes())
}) })
it('Should update only the tags of a video', async function () { it('Should update only the tags of a video', async function () {
const attributes = { const attributes = {
tags: [ 'supertag', 'tag1', 'tag2' ] 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 = await server.videosCommand.get({ id: videoId })
const video = res.body
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 () { it('Should update only the description of a video', async function () {
const attributes = { const attributes = {
description: 'hello everybody' 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 = await server.videosCommand.get({ id: videoId })
const video = res.body
const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) 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 () { 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 = await server.videosCommand.get({ id: videoId })
const video = res.body
expect(video.likes).to.equal(1) expect(video.likes).to.equal(1)
expect(video.dislikes).to.equal(0) expect(video.dislikes).to.equal(0)
}) })
it('Should dislike the same video', async function () { 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 = await server.videosCommand.get({ id: videoId })
const video = res.body
expect(video.likes).to.equal(0) expect(video.likes).to.equal(0)
expect(video.dislikes).to.equal(1) expect(video.dislikes).to.equal(1)
@ -457,10 +419,10 @@ describe('Test a single server', function () {
{ {
const now = new Date() const now = new Date()
const attributes = { originallyPublishedAt: now.toISOString() } 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 { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' })
const names = res.body.data.map(v => v.name) const names = data.map(v => v.name)
expect(names[0]).to.equal('my super video updated') expect(names[0]).to.equal('my super video updated')
expect(names[1]).to.equal('video_short2.webm name') expect(names[1]).to.equal('video_short2.webm name')
@ -473,10 +435,10 @@ describe('Test a single server', function () {
{ {
const now = new Date() const now = new Date()
const attributes = { originallyPublishedAt: now.toISOString() } 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 { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' })
const names = res.body.data.map(v => v.name) const names = data.map(v => v.name)
expect(names[0]).to.equal('video_short1.webm name') expect(names[0]).to.equal('video_short1.webm name')
expect(names[1]).to.equal('my super video updated') expect(names[1]).to.equal('my super video updated')

View File

@ -7,11 +7,9 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
removeVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testCaptionFile, testCaptionFile,
uploadVideo,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -34,8 +32,8 @@ describe('Test video captions', function () {
await waitJobs(servers) await waitJobs(servers)
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'my video name' } })
videoUUID = res.body.video.uuid videoUUID = uuid
await waitJobs(servers) await waitJobs(servers)
}) })
@ -180,7 +178,7 @@ describe('Test video captions', function () {
}) })
it('Should remove the video, and thus all video captions', async 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]) await checkVideoFilesWereRemoved(videoUUID, servers[0])
}) })

View File

@ -2,22 +2,19 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '@shared/core-utils'
import { import {
ChangeOwnershipCommand, ChangeOwnershipCommand,
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
flushAndRunServer, flushAndRunServer,
getVideo,
getVideosList,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
uploadVideo waitJobs
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { VideoPrivacy } from '@shared/models'
import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
const expect = chai.expect const expect = chai.expect
@ -71,14 +68,13 @@ describe('Test video change ownership - nominal', function () {
} }
{ {
const videoAttributes = { const attributes = {
name: 'my super name', name: 'my super name',
description: 'my super description' 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 = await servers[0].videosCommand.get({ id })
servers[0].video = resVideo.body
} }
{ {
@ -212,9 +208,7 @@ describe('Test video change ownership - nominal', function () {
it('Should have the channel of the video updated', async function () { it('Should have the channel of the video updated', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, servers[0].video.uuid) const video = await server.videosCommand.get({ id: servers[0].video.uuid })
const video: VideoDetails = res.body
expect(video.name).to.equal('my super name') expect(video.name).to.equal('my super name')
expect(video.channel.displayName).to.equal('Main second channel') expect(video.channel.displayName).to.equal('Main second channel')
@ -243,9 +237,7 @@ describe('Test video change ownership - nominal', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, servers[0].video.uuid) const video = await server.videosCommand.get({ id: servers[0].video.uuid })
const video: VideoDetails = res.body
expect(video.name).to.equal('my super name') expect(video.name).to.equal('my super name')
expect(video.channel.displayName).to.equal('Main second channel') 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) secondUserToken = await server.loginCommand.getAccessToken(secondUser)
// Upload some videos on the server // Upload some videos on the server
const video1Attributes = { const attributes = {
name: 'my super name', name: 'my super name',
description: 'my super description' description: 'my super description'
} }
await uploadVideo(server.url, firstUserToken, video1Attributes) await server.videosCommand.upload({ token: firstUserToken, attributes })
await waitJobs(server) await waitJobs(server)
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data.length).to.equal(1)
expect(videos.length).to.equal(1) server.video = data.find(video => video.name === 'my super name')
server.video = videos.find(video => video.name === 'my super name')
}) })
it('Should send a request to change ownership of a video', async function () { it('Should send a request to change ownership of a video', async function () {

View File

@ -8,20 +8,15 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
getVideoChannelVideos,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
testFileExistsOrNot, testFileExistsOrNot,
testImage, testImage,
updateVideo,
uploadVideo,
viewVideo,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { User, Video, VideoChannel, VideoDetails } from '@shared/models' import { User, VideoChannel } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -77,9 +72,9 @@ describe('Test video channels', function () {
// The channel is 1 is propagated to servers 2 // The channel is 1 is propagated to servers 2
{ {
const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } const attributes = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg) const { uuid } = await servers[0].videosCommand.upload({ attributes })
videoUUID = res.body.video.uuid videoUUID = uuid
} }
await waitJobs(servers) await waitJobs(servers)
@ -219,9 +214,7 @@ describe('Test video channels', function () {
it('Should not have updated the video support field', async function () { it('Should not have updated the video support field', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video: VideoDetails = res.body
expect(video.support).to.equal('video support field') expect(video.support).to.equal('video support field')
} }
}) })
@ -239,9 +232,7 @@ describe('Test video channels', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video: VideoDetails = res.body
expect(video.support).to.equal(videoChannelAttributes.support) expect(video.support).to.equal(videoChannelAttributes.support)
} }
}) })
@ -333,18 +324,19 @@ describe('Test video channels', function () {
for (const server of servers) { for (const server of servers) {
const channelURI = 'second_video_channel@localhost:' + servers[0].port const channelURI = 'second_video_channel@localhost:' + servers[0].port
const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI })
expect(res1.body.total).to.equal(1)
expect(res1.body.data).to.be.an('array') expect(total).to.equal(1)
expect(res1.body.data).to.have.lengthOf(1) expect(data).to.be.an('array')
expect(res1.body.data[0].name).to.equal('my video name') 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 () { it('Should change the video channel of a video', async function () {
this.timeout(10000) 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) await waitJobs(servers)
}) })
@ -353,18 +345,21 @@ describe('Test video channels', function () {
this.timeout(10000) this.timeout(10000)
for (const server of servers) { 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) const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
expect(res1.body.total).to.equal(0) const { total } = await server.videosCommand.listByChannel({ videoChannelName: secondChannelURI })
expect(total).to.equal(0)
}
const channelURI = 'root_channel@localhost:' + servers[0].port {
const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) const channelURI = 'root_channel@localhost:' + servers[0].port
expect(res2.body.total).to.equal(1) const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI })
expect(total).to.equal(1)
const videos: Video[] = res2.body.data expect(data).to.be.an('array')
expect(videos).to.be.an('array') expect(data).to.have.lengthOf(1)
expect(videos).to.have.lengthOf(1) expect(data[0].name).to.equal('my video name')
expect(videos[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 // 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 servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '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.2,127.0.0.1' })
// Wait the repeatable job // Wait the repeatable job
await wait(8000) 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 () { it('Should list channels by updatedAt desc if a video has been uploaded', async function () {
this.timeout(30000) this.timeout(30000)
await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: totoChannel }) await servers[0].videosCommand.upload({ attributes: { channelId: totoChannel } })
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
@ -470,7 +465,7 @@ describe('Test video channels', function () {
expect(data[1].name).to.equal('root_channel') 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) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {

View File

@ -9,8 +9,7 @@ import {
flushAndRunServer, flushAndRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testImage, testImage
uploadVideo
} from '@shared/extra-utils' } from '@shared/extra-utils'
const expect = chai.expect const expect = chai.expect
@ -33,9 +32,9 @@ describe('Test video comments', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const res = await uploadVideo(server.url, server.accessToken, {}) const { id, uuid } = await server.videosCommand.upload()
videoUUID = res.body.video.uuid videoUUID = uuid
videoId = res.body.video.id videoId = id
await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })

View File

@ -2,19 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
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'
const expect = chai.expect const expect = chai.expect
@ -43,20 +31,19 @@ describe('Test video description', function () {
const attributes = { const attributes = {
description: longDescription description: longDescription
} }
await uploadVideo(servers[0].url, servers[0].accessToken, attributes) await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
videoId = res.body.data[0].id videoId = data[0].id
videoUUID = res.body.data[0].uuid videoUUID = data[0].uuid
}) })
it('Should have a truncated description on each server', async function () { it('Should have a truncated description on each server', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video = res.body
// 30 characters * 6 -> 240 characters // 30 characters * 6 -> 240 characters
const truncatedDescription = 'my super description for server 1'.repeat(7) + 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 () { it('Should fetch long description on each server', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video = res.body
const res2 = await getVideoDescription(server.url, video.descriptionPath) const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath })
expect(res2.body.description).to.equal(longDescription) expect(description).to.equal(longDescription)
} }
}) })
@ -82,20 +68,19 @@ describe('Test video description', function () {
const attributes = { const attributes = {
description: 'short description' description: 'short description'
} }
await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes) await servers[0].videosCommand.update({ id: videoId, attributes })
await waitJobs(servers) await waitJobs(servers)
}) })
it('Should have a small description on each server', async function () { it('Should have a small description on each server', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video = res.body
expect(video.description).to.equal('short description') expect(video.description).to.equal('short description')
const res2 = await getVideoDescription(server.url, video.descriptionPath) const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath })
expect(res2.body.description).to.equal('short description') expect(description).to.equal('short description')
} }
}) })

View File

@ -3,7 +3,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { join } from 'path' import { join } from 'path'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '@shared/core-utils'
import { import {
checkDirectoryIsEmpty, checkDirectoryIsEmpty,
checkResolutionsInMasterPlaylist, checkResolutionsInMasterPlaylist,
@ -12,26 +12,20 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
makeRawRequest, makeRawRequest,
removeVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo,
uploadVideo,
waitJobs, waitJobs,
webtorrentAdd webtorrentAdd
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { VideoDetails } from '../../../../shared/models/videos' import { VideoStreamingPlaylistType } from '@shared/models'
import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
const expect = chai.expect const expect = chai.expect
async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) {
for (const server of servers) { for (const server of servers) {
const resVideoDetails = await getVideo(server.url, videoUUID) const videoDetails = await server.videosCommand.get({ id: videoUUID })
const videoDetails: VideoDetails = resVideoDetails.body
const baseUrl = `http://${videoDetails.account.host}` const baseUrl = `http://${videoDetails.account.host}`
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) 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 () { it('Should upload a video and transcode it to HLS', async function () {
this.timeout(120000) this.timeout(120000)
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
videoUUID = res.body.video.uuid videoUUID = uuid
await waitJobs(servers) 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 () { it('Should upload an audio file and transcode it to HLS', async function () {
this.timeout(120000) this.timeout(120000)
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
videoAudioUUID = res.body.video.uuid videoAudioUUID = uuid
await waitJobs(servers) await waitJobs(servers)
@ -135,7 +129,7 @@ describe('Test HLS videos', function () {
it('Should update the video', async function () { it('Should update the video', async function () {
this.timeout(10000) 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) await waitJobs(servers)
@ -145,14 +139,14 @@ describe('Test HLS videos', function () {
it('Should delete videos', async function () { it('Should delete videos', async function () {
this.timeout(10000) this.timeout(10000)
await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) await servers[0].videosCommand.remove({ id: videoUUID })
await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) await servers[0].videosCommand.remove({ id: videoAudioUUID })
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) await server.videosCommand.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) await server.videosCommand.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
} }
}) })

View File

@ -7,9 +7,6 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getMyVideos,
getVideo,
getVideosList,
ImportsCommand, ImportsCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
@ -17,7 +14,7 @@ import {
testImage, testImage,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models' import { VideoPrivacy, VideoResolution } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -29,8 +26,7 @@ describe('Test video imports', function () {
if (areHttpImportTestsDisabled()) return if (areHttpImportTestsDisabled()) return
async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) {
const resHttp = await getVideo(server.url, idHttp) const videoHttp = await server.videosCommand.get({ id: idHttp })
const videoHttp: VideoDetails = resHttp.body
expect(videoHttp.name).to.equal('small video - youtube') expect(videoHttp.name).to.equal('small video - youtube')
// FIXME: youtube-dl seems broken // FIXME: youtube-dl seems broken
@ -47,10 +43,8 @@ describe('Test video imports', function () {
expect(originallyPublishedAt.getMonth()).to.equal(0) expect(originallyPublishedAt.getMonth()).to.equal(0)
expect(originallyPublishedAt.getFullYear()).to.equal(2019) expect(originallyPublishedAt.getFullYear()).to.equal(2019)
const resMagnet = await getVideo(server.url, idMagnet) const videoMagnet = await server.videosCommand.get({ id: idMagnet })
const videoMagnet: VideoDetails = resMagnet.body const videoTorrent = await server.videosCommand.get({ id: idTorrent })
const resTorrent = await getVideo(server.url, idTorrent)
const videoTorrent: VideoDetails = resTorrent.body
for (const video of [ videoMagnet, videoTorrent ]) { for (const video of [ videoMagnet, videoTorrent ]) {
expect(video.category.label).to.equal('Misc') expect(video.category.label).to.equal('Misc')
@ -70,8 +64,7 @@ describe('Test video imports', function () {
} }
async function checkVideoServer2 (server: ServerInfo, id: number | string) { async function checkVideoServer2 (server: ServerInfo, id: number | string) {
const res = await getVideo(server.url, id) const video = await server.videosCommand.get({ id })
const video: VideoDetails = res.body
expect(video.name).to.equal('my super name') expect(video.name).to.equal('my super name')
expect(video.category.label).to.equal('Entertainment') 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 () { 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(data).to.have.lengthOf(3)
expect(videos).to.have.lengthOf(3) expect(data[0].name).to.equal('small video - youtube')
expect(videos[0].name).to.equal('small video - youtube') expect(data[1].name).to.equal('super peertube2 video')
expect(videos[1].name).to.equal('super peertube2 video') expect(data[2].name).to.equal('你好 世界 720p.mp4')
expect(videos[2].name).to.equal('你好 世界 720p.mp4')
}) })
it('Should list the videos to import in my imports on server 1', async function () { 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) await waitJobs(servers)
for (const server of 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(3) expect(total).to.equal(3)
expect(res.body.data).to.have.lengthOf(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) await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
} }
}) })
@ -262,13 +254,13 @@ Ajouter un sous-titre est vraiment facile`)
await waitJobs(servers) await waitJobs(servers)
for (const server of 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(4) expect(total).to.equal(4)
expect(res.body.data).to.have.lengthOf(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) await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
} }
}) })
@ -288,8 +280,7 @@ Ajouter un sous-titre est vraiment facile`)
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video: VideoDetails = res.body
expect(video.name).to.equal('transcoded video') expect(video.name).to.equal('transcoded video')
expect(video.files).to.have.lengthOf(4) expect(video.files).to.have.lengthOf(4)
@ -339,8 +330,7 @@ Ajouter un sous-titre est vraiment facile`)
await waitJobs(servers) await waitJobs(servers)
// test resolution // test resolution
const res2 = await getVideo(servers[0].url, videoUUID) const video = await servers[0].videosCommand.get({ id: videoUUID })
const video: VideoDetails = res2.body
expect(video.name).to.equal('hdr video') expect(video.name).to.equal('hdr video')
const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) 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) expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P)

View File

@ -2,18 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
cleanupTests,
flushAndRunServer,
getAccountVideos,
getMyVideos,
getVideoChannelVideos,
getVideosList,
getVideosListWithToken,
ServerInfo,
setAccessTokensToServers,
uploadVideo
} from '@shared/extra-utils'
import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -37,10 +26,10 @@ describe('Test video NSFW policy', function () {
if (token) { if (token) {
promises = [ promises = [
getVideosListWithToken(server.url, token, query).then(res => res.body),
server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }),
getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body), server.videosCommand.listWithToken({ token, ...query }),
getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body) server.videosCommand.listByAccount({ token, accountName, ...query }),
server.videosCommand.listByChannel({ token, videoChannelName, ...query })
] ]
// Overviews do not support video filters // Overviews do not support video filters
@ -54,10 +43,10 @@ describe('Test video NSFW policy', function () {
} }
promises = [ promises = [
getVideosList(server.url).then(res => res.body),
server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }), server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }),
getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body), server.videosCommand.list(),
getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body) server.videosCommand.listByAccount({ accountName }),
server.videosCommand.listByChannel({ videoChannelName })
] ]
// Overviews do not support video filters // Overviews do not support video filters
@ -79,12 +68,12 @@ describe('Test video NSFW policy', function () {
{ {
const attributes = { name: 'nsfw', nsfw: true, category: 1 } 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 } 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() 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 () { 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) const { total, data } = await server.videosCommand.listMyVideos()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
const videos = res.body.data expect(data).to.have.lengthOf(2)
expect(videos).to.have.lengthOf(2) expect(data[0].name).to.equal('normal')
expect(videos[0].name).to.equal('normal') expect(data[1].name).to.equal('nsfw')
expect(videos[1].name).to.equal('nsfw')
}) })
it('Should display NSFW videos when the nsfw param === true', async function () { it('Should display NSFW videos when the nsfw param === true', async function () {

View File

@ -10,7 +10,6 @@ import {
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
testImage, testImage,
uploadVideoAndGetId,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 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 // Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).id
video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).id
await waitJobs(servers) await waitJobs(servers)
}) })

View File

@ -13,9 +13,6 @@ import {
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
testImage, testImage,
updateVideo,
uploadVideo,
uploadVideoAndGetId,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -99,14 +96,14 @@ describe('Test video playlists', function () {
for (const server of servers) { for (const server of servers) {
for (let i = 0; i < 7; i++) { for (let i = 0; i < 7; i++) {
const name = `video ${i} server ${server.serverNumber}` 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') 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 }) return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes })
} }
video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userTokenServer1 })).uuid video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid
video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid video2 = (await servers[1].videosCommand.quickUpload({ name: 'video 90' })).uuid
video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid video3 = (await servers[0].videosCommand.quickUpload({ name: 'video 91', nsfw: true })).uuid
await waitJobs(servers) await waitJobs(servers)
@ -640,7 +637,7 @@ describe('Test video playlists', function () {
const position = 1 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 waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 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 waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)

View File

@ -3,22 +3,8 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import { cleanupTests, doubleFollow, flushAndRunServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
cleanupTests, import { VideoCreateResult, VideoPrivacy } from '@shared/models'
doubleFollow,
flushAndRunServer,
getMyVideos,
getVideo,
getVideosList,
getVideosListWithToken,
getVideoWithToken,
ServerInfo,
setAccessTokensToServers,
updateVideo,
uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -66,55 +52,53 @@ describe('Test video privacy', function () {
for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) {
const attributes = { privacy } const attributes = { privacy }
await uploadVideo(servers[0].url, servers[0].accessToken, attributes) await servers[0].videosCommand.upload({ attributes })
} }
await waitJobs(servers) await waitJobs(servers)
}) })
it('Should not have these private and internal videos on server 2', async function () { 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(total).to.equal(0)
expect(res.body.data).to.have.lengthOf(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 () { 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(total).to.equal(0)
expect(res.body.data).to.have.lengthOf(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 () { 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(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(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 () { 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(total).to.equal(2)
expect(res.body.data).to.have.lengthOf(2) expect(data).to.have.lengthOf(2)
const videos: Video[] = res.body.data const privateVideo = data.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
privateVideoId = privateVideo.id privateVideoId = privateVideo.id
privateVideoUUID = privateVideo.uuid 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 internalVideoId = internalVideo.id
internalVideoUUID = internalVideo.uuid internalVideoUUID = internalVideo.uuid
}) })
it('Should not be able to watch the private/internal video with non authenticated user', async function () { 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 servers[0].videosCommand.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await getVideo(servers[0].url, internalVideoUUID, 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 () { 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 }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
anotherUserToken = await servers[0].loginCommand.getAccessToken(user) 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 () { 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 () { 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', name: 'unlisted video',
privacy: VideoPrivacy.UNLISTED privacy: VideoPrivacy.UNLISTED
} }
await uploadVideo(servers[1].url, servers[1].accessToken, attributes) await servers[1].videosCommand.upload({ attributes })
// Server 2 has transcoding enabled // Server 2 has transcoding enabled
await waitJobs(servers) 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 () { it('Should not have this unlisted video listed on server 1 and 2', async function () {
for (const server of 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(total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0) expect(data).to.have.lengthOf(0)
} }
}) })
it('Should list my (unlisted) videos', async function () { 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(total).to.equal(1)
expect(res.body.data).to.have.lengthOf(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 () { 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 () { it('Should be able to get this unlisted video using its uuid/shortUUID', async function () {
for (const server of servers) { for (const server of servers) {
for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) { 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', name: 'unlisted video',
privacy: VideoPrivacy.UNLISTED privacy: VideoPrivacy.UNLISTED
} }
await uploadVideo(servers[0].url, servers[0].accessToken, attributes) await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
}) })
it('Should list my new unlisted video', async function () { 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(total).to.equal(3)
expect(res.body.data).to.have.lengthOf(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 () { 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 () { 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() now = Date.now()
{ {
const attribute = { const attributes = {
name: 'private video becomes public', name: 'private video becomes public',
privacy: VideoPrivacy.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', name: 'internal video becomes public',
privacy: VideoPrivacy.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) 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 () { it('Should have this new public video listed on server 1 and 2', async function () {
for (const server of 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(2) expect(total).to.equal(2)
expect(res.body.data).to.have.lengthOf(2) expect(data).to.have.lengthOf(2)
const videos: Video[] = res.body.data const privateVideo = data.find(v => v.name === 'private video becomes public')
const privateVideo = videos.find(v => v.name === 'private video becomes public') const internalVideo = data.find(v => v.name === 'internal video becomes public')
const internalVideo = videos.find(v => v.name === 'internal video becomes public')
expect(privateVideo).to.not.be.undefined expect(privateVideo).to.not.be.undefined
expect(internalVideo).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 () { it('Should set these videos as private and internal', async function () {
this.timeout(10000) this.timeout(10000)
await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE }) await servers[0].videosCommand.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } })
await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL }) await servers[0].videosCommand.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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(total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0) expect(data).to.have.lengthOf(0)
} }
{ {
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) const { total, data } = await servers[0].videosCommand.listMyVideos()
const videos = res.body.data expect(total).to.equal(3)
expect(data).to.have.lengthOf(3)
expect(res.body.total).to.equal(3) const privateVideo = data.find(v => v.name === 'private video becomes public')
expect(videos).to.have.lengthOf(3) const internalVideo = data.find(v => v.name === 'internal video becomes public')
const privateVideo = videos.find(v => v.name === 'private video becomes public')
const internalVideo = videos.find(v => v.name === 'internal video becomes public')
expect(privateVideo).to.not.be.undefined expect(privateVideo).to.not.be.undefined
expect(internalVideo).to.not.be.undefined expect(internalVideo).to.not.be.undefined

View File

@ -1,22 +1,17 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha' import 'mocha'
import { VideoPrivacy } from '../../../../shared/models/videos' import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getMyVideos,
getVideosList,
getVideoWithToken,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo, wait,
uploadVideo, waitJobs
wait } from '@shared/extra-utils'
} from '../../../../shared/extra-utils' import { VideoPrivacy } from '@shared/models'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
const expect = chai.expect 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 () { it('Should upload a video and schedule an update in 10 seconds', async function () {
this.timeout(10000) this.timeout(10000)
const videoAttributes = { const attributes = {
name: 'video 1', name: 'video 1',
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: { scheduleUpdate: {
updateAt: in10Seconds().toISOString(), 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) await waitJobs(servers)
}) })
it('Should not list the video (in privacy mode)', async function () { it('Should not list the video (in privacy mode)', async function () {
for (const server of servers) { 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 () { it('Should have my scheduled video in my account videos', async function () {
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) const { total, data } = await servers[0].videosCommand.listMyVideos()
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
const videoFromList = res.body.data[0] const videoFromList = data[0]
const res2 = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoFromList.uuid) const videoFromGet = await servers[0].videosCommand.getWithToken({ id: videoFromList.uuid })
const videoFromGet = res2.body
for (const video of [ videoFromList, videoFromGet ]) { for (const video of [ videoFromList, videoFromGet ]) {
expect(video.name).to.equal('video 1') expect(video.name).to.equal('video 1')
@ -90,23 +84,23 @@ describe('Test video update scheduler', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of 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(total).to.equal(1)
expect(res.body.data[0].name).to.equal('video 1') expect(data[0].name).to.equal('video 1')
} }
}) })
it('Should upload a video without scheduling an update', async function () { it('Should upload a video without scheduling an update', async function () {
this.timeout(10000) this.timeout(10000)
const videoAttributes = { const attributes = {
name: 'video 2', name: 'video 2',
privacy: VideoPrivacy.PRIVATE privacy: VideoPrivacy.PRIVATE
} }
const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) const { uuid } = await servers[0].videosCommand.upload({ attributes })
video2UUID = res.body.video.uuid video2UUID = uuid
await waitJobs(servers) await waitJobs(servers)
}) })
@ -114,31 +108,31 @@ describe('Test video update scheduler', function () {
it('Should update a video by scheduling an update', async function () { it('Should update a video by scheduling an update', async function () {
this.timeout(10000) this.timeout(10000)
const videoAttributes = { const attributes = {
name: 'video 2 updated', name: 'video 2 updated',
scheduleUpdate: { scheduleUpdate: {
updateAt: in10Seconds().toISOString(), 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) await waitJobs(servers)
}) })
it('Should not display the updated video', async function () { it('Should not display the updated video', async function () {
for (const server of servers) { 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 () { 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) const { total, data } = await servers[0].videosCommand.listMyVideos()
expect(res.body.total).to.equal(2) 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).not.to.be.undefined
expect(video.name).to.equal('video 2 updated') expect(video.name).to.equal('video 2 updated')
@ -155,11 +149,10 @@ describe('Test video update scheduler', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { total, data } = await server.videosCommand.list()
expect(total).to.equal(2)
expect(res.body.total).to.equal(2) const video = data.find(v => v.uuid === video2UUID)
const video = res.body.data.find(v => v.uuid === video2UUID)
expect(video).not.to.be.undefined expect(video).not.to.be.undefined
expect(video.name).to.equal('video 2 updated') expect(video.name).to.equal('video 2 updated')
} }

View File

@ -2,11 +2,9 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { FfprobeData } from 'fluent-ffmpeg'
import { omit } from 'lodash' import { omit } from 'lodash'
import { join } from 'path' import { join } from 'path'
import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { HttpStatusCode } from '@shared/core-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
@ -14,19 +12,14 @@ import {
flushAndRunMultipleServers, flushAndRunMultipleServers,
generateHighBitrateVideo, generateHighBitrateVideo,
generateVideoWithFramerate, generateVideoWithFramerate,
getMyVideos,
getVideo,
getVideoFileMetadataUrl,
getVideosList,
makeGetRequest, makeGetRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
uploadVideoAndGetId,
waitJobs, waitJobs,
webtorrentAdd webtorrentAdd
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' import { getMaxBitrate, VideoResolution, VideoState } from '@shared/models'
import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
import { import {
canDoQuickTranscode, canDoQuickTranscode,
getAudioStream, getAudioStream,
@ -84,21 +77,20 @@ describe('Test video transcoding', function () {
it('Should not transcode video on server 1', async function () { it('Should not transcode video on server 1', async function () {
this.timeout(60_000) this.timeout(60_000)
const videoAttributes = { const attributes = {
name: 'my super name for server 1', name: 'my super name for server 1',
description: 'my super description for server 1', description: 'my super description for server 1',
fixture: 'video_short.webm' fixture: 'video_short.webm'
} }
await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const video = res.body.data[0] const video = data[0]
const res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(1) expect(videoDetails.files).to.have.lengthOf(1)
const magnetUri = videoDetails.files[0].magnetUri const magnetUri = videoDetails.files[0].magnetUri
@ -114,21 +106,20 @@ describe('Test video transcoding', function () {
it('Should transcode video on server 2', async function () { it('Should transcode video on server 2', async function () {
this.timeout(120_000) this.timeout(120_000)
const videoAttributes = { const attributes = {
name: 'my super name for server 2', name: 'my super name for server 2',
description: 'my super description for server 2', description: 'my super description for server 2',
fixture: 'video_short.webm' fixture: 'video_short.webm'
} }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files).to.have.lengthOf(4)
@ -147,47 +138,50 @@ describe('Test video transcoding', function () {
{ {
// Upload the video, but wait transcoding // Upload the video, but wait transcoding
const videoAttributes = { const attributes = {
name: 'waiting video', name: 'waiting video',
fixture: 'video_short1.webm', fixture: 'video_short1.webm',
waitTranscoding: true waitTranscoding: true
} }
const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) const { uuid } = await servers[1].videosCommand.upload({ attributes })
const videoId = resVideo.body.video.uuid const videoId = uuid
// Should be in transcode state // 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.name).to.equal('waiting video')
expect(body.state.id).to.equal(VideoState.TO_TRANSCODE) expect(body.state.id).to.equal(VideoState.TO_TRANSCODE)
expect(body.state.label).to.equal('To transcode') expect(body.state.label).to.equal('To transcode')
expect(body.waitTranscoding).to.be.true expect(body.waitTranscoding).to.be.true
// Should have my video {
const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10) // Should have my video
const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name) const { data } = await servers[1].videosCommand.listMyVideos()
expect(videoToFindInMine).not.to.be.undefined const videoToFindInMine = data.find(v => v.name === attributes.name)
expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) expect(videoToFindInMine).not.to.be.undefined
expect(videoToFindInMine.state.label).to.equal('To transcode') expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE)
expect(videoToFindInMine.waitTranscoding).to.be.true 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) // Should not list this video
const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name) const { data } = await servers[1].videosCommand.list()
expect(videoToFindInList).to.be.undefined const videoToFindInList = data.find(v => v.name === attributes.name)
expect(videoToFindInList).to.be.undefined
}
// Server 1 should not have the video yet // 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) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videoToFind = res.body.data.find(v => v.name === 'waiting video') const videoToFind = data.find(v => v.name === 'waiting video')
expect(videoToFind).not.to.be.undefined expect(videoToFind).not.to.be.undefined
const res2 = await getVideo(server.url, videoToFind.id) const videoDetails = await server.videosCommand.get({ id: videoToFind.id })
const videoDetails: VideoDetails = res2.body
expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED)
expect(videoDetails.state.label).to.equal('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' ]) { for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) {
const videoAttributes = { const attributes = {
name: fixture, name: fixture,
fixture fixture
} }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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) expect(videoDetails.files).to.have.lengthOf(4)
const magnetUri = videoDetails.files[0].magnetUri const magnetUri = videoDetails.files[0].magnetUri
@ -235,22 +227,20 @@ describe('Test video transcoding', function () {
it('Should transcode a 4k video', async function () { it('Should transcode a 4k video', async function () {
this.timeout(200_000) this.timeout(200_000)
const videoAttributes = { const attributes = {
name: '4k video', name: '4k video',
fixture: 'video_short_4k.mp4' fixture: 'video_short_4k.mp4'
} }
const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) const { uuid } = await servers[1].videosCommand.upload({ attributes })
video4k = resUpload.body.video.uuid video4k = uuid
await waitJobs(servers) await waitJobs(servers)
const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ]
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, video4k) const videoDetails = await server.videosCommand.get({ id: video4k })
const videoDetails: VideoDetails = res.body
expect(videoDetails.files).to.have.lengthOf(resolutions.length) expect(videoDetails.files).to.have.lengthOf(resolutions.length)
for (const r of resolutions) { 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 () { it('Should transcode high bit rate mp3 to proper bit rate', async function () {
this.timeout(60_000) this.timeout(60_000)
const videoAttributes = { const attributes = {
name: 'mp3_256k', name: 'mp3_256k',
fixture: 'video_short_mp3_256k.mp4' fixture: 'video_short_mp3_256k.mp4'
} }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails: VideoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(4) 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 () { it('Should transcode video with no audio and have no audio itself', async function () {
this.timeout(60_000) this.timeout(60_000)
const videoAttributes = { const attributes = {
name: 'no_audio', name: 'no_audio',
fixture: 'video_short_no_audio.mp4' fixture: 'video_short_no_audio.mp4'
} }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails: VideoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files).to.have.lengthOf(4)
const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) 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 () { it('Should leave the audio untouched, but properly transcode the video', async function () {
this.timeout(60_000) this.timeout(60_000)
const videoAttributes = { const attributes = {
name: 'untouched_audio', name: 'untouched_audio',
fixture: 'video_short.mp4' fixture: 'video_short.mp4'
} }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails: VideoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files).to.have.lengthOf(4)
const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
const fixtureVideoProbe = await getAudioStream(fixturePath) const fixtureVideoProbe = await getAudioStream(fixturePath)
const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) 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 () { it('Should merge an audio file with the preview file', async function () {
this.timeout(60_000) this.timeout(60_000)
const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) await servers[1].videosCommand.upload({ attributes, mode })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 video = data.find(v => v.name === 'audio_with_preview')
const res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails: VideoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(1) 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 () { it('Should upload an audio file and choose a default background image', async function () {
this.timeout(60_000) this.timeout(60_000)
const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) await servers[1].videosCommand.upload({ attributes, mode })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 video = data.find(v => v.name === 'audio_without_preview')
const res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(1) 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 attributes = { 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 { id } = await servers[1].videosCommand.upload({ attributes, mode })
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res2 = await getVideo(server.url, resVideo.body.video.id) const videoDetails = await server.videosCommand.get({ id })
const videoDetails: VideoDetails = res2.body
for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
expect(files).to.have.lengthOf(2) expect(files).to.have.lengthOf(2)
@ -481,21 +465,20 @@ describe('Test video transcoding', function () {
it('Should transcode a 60 FPS video', async function () { it('Should transcode a 60 FPS video', async function () {
this.timeout(60_000) this.timeout(60_000)
const videoAttributes = { const attributes = {
name: 'my super 30fps name for server 2', name: 'my super 30fps name for server 2',
description: 'my super 30fps description for server 2', description: 'my super 30fps description for server 2',
fixture: '60fps_720p_small.mp4' fixture: '60fps_720p_small.mp4'
} }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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 res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails: VideoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) 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) expect(fps).to.be.equal(59)
} }
const videoAttributes = { const attributes = {
name: '59fps video', name: '59fps video',
description: '59fps video', description: '59fps video',
fixture: tempFixturePath fixture: tempFixturePath
} }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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')) 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)) expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
} }
const videoAttributes = { const attributes = {
name: 'high bitrate video', name: 'high bitrate video',
description: 'high bitrate video', description: 'high bitrate video',
fixture: tempFixturePath fixture: tempFixturePath
} }
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers) await waitJobs(servers)
for (const server of 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' ]) { for (const resolution of [ '240', '360', '480', '720', '1080' ]) {
const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
@ -621,19 +604,18 @@ describe('Test video transcoding', function () {
} }
await servers[1].configCommand.updateCustomSubConfig({ newConfig }) await servers[1].configCommand.updateCustomSubConfig({ newConfig })
const videoAttributes = { const attributes = {
name: 'low bitrate', name: 'low bitrate',
fixture: 'low-bitrate.mp4' fixture: 'low-bitrate.mp4'
} }
const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) const { uuid } = await servers[1].videosCommand.upload({ attributes })
const videoUUID = resUpload.body.video.uuid
await waitJobs(servers) await waitJobs(servers)
const resolutions = [ 240, 360, 480, 720, 1080 ] const resolutions = [ 240, 360, 480, 720, 1080 ]
for (const r of resolutions) { 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) const size = await servers[1].serversCommand.getServerFileSize(path)
expect(size, `${path} not below ${60_000}`).to.be.below(60_000) 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 () { it('Should provide valid ffprobe data', async function () {
this.timeout(160_000) 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) await waitJobs(servers)
{ {
@ -679,8 +661,7 @@ describe('Test video transcoding', function () {
} }
for (const server of servers) { for (const server of servers) {
const res2 = await getVideo(server.url, videoUUID) const videoDetails = await server.videosCommand.get({ id: videoUUID })
const videoDetails: VideoDetails = res2.body
const videoFiles = videoDetails.files const videoFiles = videoDetails.files
.concat(videoDetails.streamingPlaylists[0].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(servers[1].url)
expect(file.metadataUrl).to.contain(videoUUID) expect(file.metadataUrl).to.contain(videoUUID)
const res3 = await getVideoFileMetadataUrl(file.metadataUrl) const metadata = await server.videosCommand.getFileMetadata({ url: file.metadataUrl })
const metadata: FfprobeData = res3.body
expect(metadata).to.have.nested.property('format.size') expect(metadata).to.have.nested.property('format.size')
} }
} }

View File

@ -1,21 +1,17 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import * as chai from 'chai' import { expect } from 'chai'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
makeGetRequest, makeGetRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers
uploadVideo } from '@shared/extra-utils'
} from '../../../../shared/extra-utils' import { UserRole, Video, VideoPrivacy } from '@shared/models'
import { UserRole } from '../../../../shared/models/users'
import { Video, VideoPrivacy } from '../../../../shared/models/videos'
const expect = chai.expect
async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
const paths = [ const paths = [
@ -62,16 +58,16 @@ describe('Test videos filter', function () {
await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(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 } 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 } const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
await uploadVideo(server.url, server.accessToken, attributes) await server.videosCommand.upload({ attributes })
} }
} }

View File

@ -6,17 +6,14 @@ import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getVideosListWithToken,
getVideoWithToken,
HistoryCommand, HistoryCommand,
killallServers, killallServers,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
wait wait
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { Video, VideoDetails } from '@shared/models' import { Video } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -39,18 +36,18 @@ describe('Test videos history', function () {
command = server.historyCommand command = server.historyCommand
{ {
const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 1' } })
video1UUID = res.body.video.uuid video1UUID = uuid
} }
{ {
const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 2' } })
video2UUID = res.body.video.uuid video2UUID = uuid
} }
{ {
const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 3' } })
video3UUID = res.body.video.uuid video3UUID = uuid
} }
const user = { const user = {
@ -62,12 +59,10 @@ describe('Test videos history', function () {
}) })
it('Should get videos, without watching history', async function () { it('Should get videos, without watching history', async function () {
const res = await getVideosListWithToken(server.url, server.accessToken) const { data } = await server.videosCommand.listWithToken()
const videos: Video[] = res.body.data
for (const video of videos) { for (const video of data) {
const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id) const videoDetails = await server.videosCommand.getWithToken({ id: video.id })
const videoDetails: VideoDetails = resDetail.body
expect(video.userHistory).to.be.undefined expect(video.userHistory).to.be.undefined
expect(videoDetails.userHistory).to.be.undefined expect(videoDetails.userHistory).to.be.undefined
@ -83,8 +78,8 @@ describe('Test videos history', function () {
const videosOfVideos: Video[][] = [] const videosOfVideos: Video[][] = []
{ {
const res = await getVideosListWithToken(server.url, server.accessToken) const { data } = await server.videosCommand.listWithToken()
videosOfVideos.push(res.body.data) videosOfVideos.push(data)
} }
{ {
@ -107,24 +102,21 @@ describe('Test videos history', function () {
} }
{ {
const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID) const videoDetails = await server.videosCommand.getWithToken({ id: video1UUID })
const videoDetails: VideoDetails = resDetail.body
expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory).to.not.be.undefined
expect(videoDetails.userHistory.currentTime).to.equal(3) expect(videoDetails.userHistory.currentTime).to.equal(3)
} }
{ {
const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID) const videoDetails = await server.videosCommand.getWithToken({ id: video2UUID })
const videoDetails: VideoDetails = resDetail.body
expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory).to.not.be.undefined
expect(videoDetails.userHistory.currentTime).to.equal(8) expect(videoDetails.userHistory.currentTime).to.equal(8)
} }
{ {
const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID) const videoDetails = await server.videosCommand.getWithToken({ id: video3UUID })
const videoDetails: VideoDetails = resDetail.body
expect(videoDetails.userHistory).to.be.undefined expect(videoDetails.userHistory).to.be.undefined
} }

View File

@ -2,7 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' 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' import { VideosOverview } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -35,10 +35,12 @@ describe('Test a videos overview', function () {
await wait(3000) await wait(3000)
await uploadVideo(server.url, server.accessToken, { await server.videosCommand.upload({
name: 'video 0', attributes: {
category: 3, name: 'video 0',
tags: [ 'coucou1', 'coucou2' ] category: 3,
tags: [ 'coucou1', 'coucou2' ]
}
}) })
const body = await server.overviewsCommand.getVideos({ page: 1 }) 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++) { for (let i = 1; i < 6; i++) {
await uploadVideo(server.url, server.accessToken, { await server.videosCommand.upload({
name: 'video ' + i, attributes: {
category: 3, name: 'video ' + i,
tags: [ 'coucou1', 'coucou2' ] category: 3,
tags: [ 'coucou1', 'coucou2' ]
}
}) })
} }

View File

@ -10,8 +10,6 @@ import {
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideoAndGetId,
viewVideo,
wait, wait,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
@ -32,15 +30,15 @@ describe('Test video views cleaner', function () {
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid videoIdServer1 = (await servers[0].videosCommand.quickUpload({ name: 'video server 1' })).uuid
videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid videoIdServer2 = (await servers[1].videosCommand.quickUpload({ name: 'video server 2' })).uuid
await waitJobs(servers) await waitJobs(servers)
await viewVideo(servers[0].url, videoIdServer1) await servers[0].videosCommand.view({ id: videoIdServer1 })
await viewVideo(servers[1].url, videoIdServer1) await servers[1].videosCommand.view({ id: videoIdServer1 })
await viewVideo(servers[0].url, videoIdServer2) await servers[0].videosCommand.view({ id: videoIdServer2 })
await viewVideo(servers[1].url, videoIdServer2) await servers[1].videosCommand.view({ id: videoIdServer2 })
await waitJobs(servers) await waitJobs(servers)
}) })

View File

@ -2,19 +2,8 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { VideoFile } from '@shared/models/videos/video-file.model' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
import { import { VideoFile } from '@shared/models'
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
getVideosList,
ServerInfo,
setAccessTokensToServers,
uploadVideo
} from '../../../shared/extra-utils'
import { waitJobs } from '../../../shared/extra-utils/server/jobs'
import { VideoDetails } from '../../../shared/models/videos'
const expect = chai.expect const expect = chai.expect
@ -45,10 +34,15 @@ describe('Test create import video jobs', function () {
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
// Upload two videos for our needs // Upload two videos for our needs
const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' }) {
video1UUID = res1.body.video.uuid const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video1' } })
const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) video1UUID = uuid
video2UUID = res2.body.video.uuid }
{
const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video2' } })
video2UUID = uuid
}
// Transcoding // Transcoding
await waitJobs(servers) await waitJobs(servers)
@ -61,14 +55,14 @@ describe('Test create import video jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const { data: videos } = (await getVideosList(server.url)).body const { data: videos } = await server.videosCommand.list()
expect(videos).to.have.lengthOf(2) expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video1UUID) const video = videos.find(({ uuid }) => uuid === video1UUID)
const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body const videoDetails = await server.videosCommand.get({ id: video.uuid })
expect(videoDetail.files).to.have.lengthOf(2) expect(videoDetails.files).to.have.lengthOf(2)
const [ originalVideo, transcodedVideo ] = videoDetail.files const [ originalVideo, transcodedVideo ] = videoDetails.files
assertVideoProperties(originalVideo, 720, 'webm', 218910) assertVideoProperties(originalVideo, 720, 'webm', 218910)
assertVideoProperties(transcodedVideo, 480, 'webm', 69217) assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
} }
@ -81,14 +75,14 @@ describe('Test create import video jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const { data: videos } = (await getVideosList(server.url)).body const { data: videos } = await server.videosCommand.list()
expect(videos).to.have.lengthOf(2) expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video2UUID) const video = videos.find(({ uuid }) => uuid === video2UUID)
const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body const videoDetails = await server.videosCommand.get({ id: video.uuid })
expect(videoDetail.files).to.have.lengthOf(4) expect(videoDetails.files).to.have.lengthOf(4)
const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
assertVideoProperties(originalVideo, 720, 'ogv', 140849) assertVideoProperties(originalVideo, 720, 'ogv', 140849)
assertVideoProperties(transcodedVideo420, 480, 'mp4') assertVideoProperties(transcodedVideo420, 480, 'mp4')
assertVideoProperties(transcodedVideo320, 360, 'mp4') assertVideoProperties(transcodedVideo320, 360, 'mp4')
@ -103,14 +97,14 @@ describe('Test create import video jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const { data: videos } = (await getVideosList(server.url)).body const { data: videos } = await server.videosCommand.list()
expect(videos).to.have.lengthOf(2) expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video1UUID) const video = videos.find(({ uuid }) => uuid === video1UUID)
const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body const videoDetails = await server.videosCommand.get({ id: video.uuid })
expect(videoDetail.files).to.have.lengthOf(2) expect(videoDetails.files).to.have.lengthOf(2)
const [ video720, video480 ] = videoDetail.files const [ video720, video480 ] = videoDetails.files
assertVideoProperties(video720, 720, 'webm', 942961) assertVideoProperties(video720, 720, 'webm', 942961)
assertVideoProperties(video480, 480, 'webm', 69217) assertVideoProperties(video480, 480, 'webm', 69217)
} }

View File

@ -6,14 +6,10 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
getVideosList,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo waitJobs
} from '../../../shared/extra-utils' } from '../../../shared/extra-utils'
import { waitJobs } from '../../../shared/extra-utils/server/jobs'
import { VideoDetails } from '../../../shared/models/videos'
const expect = chai.expect const expect = chai.expect
@ -51,8 +47,8 @@ describe('Test create transcoding jobs', function () {
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
for (let i = 1; i <= 5; i++) { for (let i = 1; i <= 5; i++) {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' + i }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' + i } })
videosUUID.push(res.body.video.uuid) videosUUID.push(uuid)
} }
await waitJobs(servers) await waitJobs(servers)
@ -62,13 +58,11 @@ describe('Test create transcoding jobs', function () {
this.timeout(30000) this.timeout(30000)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data).to.have.lengthOf(videosUUID.length)
expect(videos).to.have.lengthOf(videosUUID.length)
for (const video of videos) { for (const video of data) {
const res2 = await getVideo(server.url, video.uuid) const videoDetail = await server.videosCommand.get({ id: video.uuid })
const videoDetail: VideoDetails = res2.body
expect(videoDetail.files).to.have.lengthOf(1) expect(videoDetail.files).to.have.lengthOf(1)
expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
} }
@ -82,14 +76,12 @@ describe('Test create transcoding jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data
let infoHashes: { [id: number]: string } let infoHashes: { [id: number]: string }
for (const video of videos) { for (const video of data) {
const res2 = await getVideo(server.url, video.uuid) const videoDetail = await server.videosCommand.get({ id: video.uuid })
const videoDetail: VideoDetails = res2.body
if (video.uuid === videosUUID[1]) { if (video.uuid === videosUUID[1]) {
expect(videoDetail.files).to.have.lengthOf(4) expect(videoDetail.files).to.have.lengthOf(4)
@ -123,18 +115,16 @@ describe('Test create transcoding jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data).to.have.lengthOf(videosUUID.length)
expect(videos).to.have.lengthOf(videosUUID.length)
const res2 = await getVideo(server.url, videosUUID[0]) const videoDetails = await server.videosCommand.get({ id: videosUUID[0] })
const videoDetail: VideoDetails = res2.body
expect(videoDetail.files).to.have.lengthOf(2) expect(videoDetails.files).to.have.lengthOf(2)
expect(videoDetail.files[0].resolution.id).to.equal(720) expect(videoDetails.files[0].resolution.id).to.equal(720)
expect(videoDetail.files[1].resolution.id).to.equal(480) expect(videoDetails.files[1].resolution.id).to.equal(480)
expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
} }
}) })
@ -146,13 +136,12 @@ describe('Test create transcoding jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videosUUID[2]) const videoDetails = await server.videosCommand.get({ id: videosUUID[2] })
const videoDetail: VideoDetails = res.body
expect(videoDetail.files).to.have.lengthOf(1) expect(videoDetails.files).to.have.lengthOf(1)
expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
const files = videoDetail.streamingPlaylists[0].files const files = videoDetails.streamingPlaylists[0].files
expect(files).to.have.lengthOf(1) expect(files).to.have.lengthOf(1)
expect(files[0].resolution.id).to.equal(480) expect(files[0].resolution.id).to.equal(480)
} }
@ -166,10 +155,9 @@ describe('Test create transcoding jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videosUUID[2]) const videoDetails = await server.videosCommand.get({ id: videosUUID[2] })
const videoDetail: VideoDetails = res.body
const files = videoDetail.streamingPlaylists[0].files const files = videoDetails.streamingPlaylists[0].files
expect(files).to.have.lengthOf(1) expect(files).to.have.lengthOf(1)
expect(files[0].resolution.id).to.equal(480) expect(files[0].resolution.id).to.equal(480)
} }
@ -183,13 +171,12 @@ describe('Test create transcoding jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videosUUID[3]) const videoDetails = await server.videosCommand.get({ id: videosUUID[3] })
const videoDetail: VideoDetails = res.body
expect(videoDetail.files).to.have.lengthOf(1) expect(videoDetails.files).to.have.lengthOf(1)
expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
const files = videoDetail.streamingPlaylists[0].files const files = videoDetails.streamingPlaylists[0].files
expect(files).to.have.lengthOf(4) expect(files).to.have.lengthOf(4)
} }
}) })
@ -205,12 +192,11 @@ describe('Test create transcoding jobs', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideo(server.url, videosUUID[4]) const videoDetails = await server.videosCommand.get({ id: videosUUID[4] })
const videoDetail: VideoDetails = res.body
expect(videoDetail.files).to.have.lengthOf(4) expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
expect(videoDetail.streamingPlaylists[0].files).to.have.lengthOf(4) expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(4)
} }
}) })

View File

@ -8,16 +8,12 @@ import {
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
generateHighBitrateVideo, generateHighBitrateVideo,
getVideo,
getVideosList,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo, wait,
viewVideo, waitJobs
wait } from '@shared/extra-utils'
} from '../../../shared/extra-utils' import { getMaxBitrate, VideoResolution } from '@shared/models'
import { waitJobs } from '../../../shared/extra-utils/server/jobs'
import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos'
import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils' import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils'
import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
@ -45,8 +41,8 @@ describe('Test optimize old videos', function () {
} }
// Upload two videos for our needs // Upload two videos for our needs
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1', fixture: tempFixturePath }) await servers[0].videosCommand.upload({ attributes: { name: 'video1', fixture: tempFixturePath } })
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2', fixture: tempFixturePath }) await servers[0].videosCommand.upload({ attributes: { name: 'video2', fixture: tempFixturePath } })
await waitJobs(servers) await waitJobs(servers)
}) })
@ -55,14 +51,12 @@ describe('Test optimize old videos', function () {
this.timeout(30000) this.timeout(30000)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data).to.have.lengthOf(2)
expect(videos).to.have.lengthOf(2)
for (const video of videos) { for (const video of data) {
const res2 = await getVideo(server.url, video.uuid) const videoDetails = await server.videosCommand.get({ id: video.uuid })
const videoDetail: VideoDetails = res2.body expect(videoDetails.files).to.have.lengthOf(1)
expect(videoDetail.files).to.have.lengthOf(1)
} }
} }
}) })
@ -74,24 +68,21 @@ describe('Test optimize old videos', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos: Video[] = res.body.data expect(data).to.have.lengthOf(2)
expect(videos).to.have.lengthOf(2) for (const video of data) {
await server.videosCommand.view({ id: video.uuid })
for (const video of videos) {
await viewVideo(server.url, video.uuid)
// Refresh video // Refresh video
await waitJobs(servers) await waitJobs(servers)
await wait(5000) await wait(5000)
await waitJobs(servers) await waitJobs(servers)
const res2 = await getVideo(server.url, video.uuid) const videoDetails = await server.videosCommand.get({ id: video.uuid })
const videosDetails: VideoDetails = res2.body
expect(videosDetails.files).to.have.lengthOf(1) expect(videoDetails.files).to.have.lengthOf(1)
const file = videosDetails.files[0] const file = videoDetails.files[0]
expect(file.size).to.be.below(8000000) expect(file.size).to.be.below(8000000)

View File

@ -2,7 +2,6 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { Video, VideoDetails } from '../../../shared'
import { import {
areHttpImportTestsDisabled, areHttpImportTestsDisabled,
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
@ -10,15 +9,10 @@ import {
CLICommand, CLICommand,
doubleFollow, doubleFollow,
flushAndRunServer, flushAndRunServer,
getLocalIdByUUID,
getVideo,
getVideosList,
ImportsCommand, ImportsCommand,
removeVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testHelloWorldRegisteredSettings, testHelloWorldRegisteredSettings,
uploadVideoAndGetId,
waitJobs waitJobs
} from '../../../shared/extra-utils' } from '../../../shared/extra-utils'
@ -109,14 +103,10 @@ describe('Test CLI wrapper', function () {
}) })
it('Should have the video uploaded', async function () { it('Should have the video uploaded', async function () {
const res = await getVideosList(server.url) const { total, data } = await server.videosCommand.list()
expect(total).to.equal(1)
expect(res.body.total).to.equal(1)
const videos: Video[] = res.body.data
const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
const video = await server.videosCommand.get({ id: data[0].uuid })
expect(video.name).to.equal('test upload') expect(video.name).to.equal('test upload')
expect(video.support).to.equal('support_text') expect(video.support).to.equal('support_text')
expect(video.channel.name).to.equal('user_channel') expect(video.channel.name).to.equal('user_channel')
@ -138,21 +128,19 @@ describe('Test CLI wrapper', function () {
await waitJobs([ server ]) await waitJobs([ server ])
const res = await getVideosList(server.url) const { total, data } = await server.videosCommand.list()
expect(total).to.equal(2)
expect(res.body.total).to.equal(2) const video = data.find(v => v.name === 'small video - youtube')
const videos: Video[] = res.body.data
const video = videos.find(v => v.name === 'small video - youtube')
expect(video).to.not.be.undefined expect(video).to.not.be.undefined
const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.channel.name).to.equal('user_channel') expect(videoDetails.channel.name).to.equal('user_channel')
expect(videoDetails.support).to.equal('super support text') expect(videoDetails.support).to.equal('super support text')
expect(videoDetails.nsfw).to.be.false expect(videoDetails.nsfw).to.be.false
// So we can reimport it // So we can reimport it
await removeVideo(server.url, userAccessToken, video.id) await server.videosCommand.remove({ token: userAccessToken, id: video.id })
}) })
it('Should import and override some imported attributes', async function () { it('Should import and override some imported attributes', async function () {
@ -167,14 +155,13 @@ describe('Test CLI wrapper', function () {
await waitJobs([ server ]) await waitJobs([ server ])
{ {
const res = await getVideosList(server.url) const { total, data } = await server.videosCommand.list()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
const videos: Video[] = res.body.data const video = data.find(v => v.name === 'toto')
const video = videos.find(v => v.name === 'toto')
expect(video).to.not.be.undefined expect(video).to.not.be.undefined
const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.channel.name).to.equal('user_channel') expect(videoDetails.channel.name).to.equal('user_channel')
expect(videoDetails.support).to.equal('support') expect(videoDetails.support).to.equal('support')
expect(videoDetails.nsfw).to.be.true expect(videoDetails.nsfw).to.be.true
@ -238,10 +225,10 @@ describe('Test CLI wrapper', function () {
servers = [ server, anotherServer ] servers = [ server, anotherServer ]
await waitJobs(servers) await waitJobs(servers)
const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid const { uuid } = await anotherServer.videosCommand.quickUpload({ name: 'super video' })
await waitJobs(servers) await waitJobs(servers)
video1Server2 = await getLocalIdByUUID(server.url, uuid) video1Server2 = await server.videosCommand.getId({ uuid })
}) })
it('Should add a redundancy', async function () { it('Should add a redundancy', async function () {

View File

@ -16,7 +16,6 @@ import {
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
uploadVideo,
wait, wait,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -69,8 +68,8 @@ describe('Test prune storage scripts', function () {
await setDefaultVideoChannel(servers) await setDefaultVideoChannel(servers)
for (const server of servers) { for (const server of servers) {
await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) await server.videosCommand.upload({ attributes: { name: 'video 1' } })
await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) await server.videosCommand.upload({ attributes: { name: 'video 2' } })
await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })

View File

@ -2,29 +2,30 @@ import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { writeFile } from 'fs-extra' import { writeFile } from 'fs-extra'
import { basename, join } from 'path' import { basename, join } from 'path'
import { Video, VideoDetails } from '@shared/models' import { HttpStatusCode } from '@shared/core-utils'
import { Video } from '@shared/models'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
makeRawRequest, makeRawRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideoAndGetId,
waitJobs waitJobs
} from '../../../shared/extra-utils' } from '../../../shared/extra-utils'
import { HttpStatusCode } from '@shared/core-utils'
async function testThumbnail (server: ServerInfo, videoId: number | string) { async function testThumbnail (server: ServerInfo, videoId: number | string) {
const res = await getVideo(server.url, videoId) const video = await server.videosCommand.get({ id: videoId })
const video: VideoDetails = res.body
const res1 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) const requests = [
expect(res1.body).to.not.have.lengthOf(0) makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200),
makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
]
const res2 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) for (const req of requests) {
expect(res2.body).to.not.have.lengthOf(0) const res = await req
expect(res.body).to.not.have.lengthOf(0)
}
} }
describe('Test regenerate thumbnails script', function () { describe('Test regenerate thumbnails script', function () {
@ -46,20 +47,20 @@ describe('Test regenerate thumbnails script', function () {
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
{ {
const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid const videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid
video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body)) video1 = await servers[0].videosCommand.get({ id: videoUUID1 })
thumbnail1Path = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(video1.thumbnailPath)) thumbnail1Path = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(video1.thumbnailPath))
const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid const videoUUID2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid
video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body)) video2 = await servers[0].videosCommand.get({ id: videoUUID2 })
} }
{ {
const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'video 3' })).uuid
await waitJobs(servers) await waitJobs(servers)
remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body)) remoteVideo = await servers[0].videosCommand.get({ id: videoUUID })
thumbnailRemotePath = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath)) thumbnailRemotePath = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath))
} }

View File

@ -5,18 +5,14 @@ import { expect } from 'chai'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getVideo,
getVideosList,
killallServers, killallServers,
makeActivityPubGetRequest, makeActivityPubGetRequest,
parseTorrentVideo, parseTorrentVideo,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoDetails } from '@shared/models'
describe('Test update host scripts', function () { describe('Test update host scripts', function () {
let server: ServerInfo let server: ServerInfo
@ -34,10 +30,8 @@ describe('Test update host scripts', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
// Upload two videos for our needs // Upload two videos for our needs
const videoAttributes = {} const { uuid: video1UUID } = await server.videosCommand.upload()
const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes) await server.videosCommand.upload()
const video1UUID = resVideo1.body.video.uuid
await uploadVideo(server.url, server.accessToken, videoAttributes)
// Create a user // Create a user
await server.usersCommand.create({ username: 'toto', password: 'coucou' }) await server.usersCommand.create({ username: 'toto', password: 'coucou' })
@ -68,16 +62,15 @@ describe('Test update host scripts', function () {
}) })
it('Should have updated videos url', async function () { it('Should have updated videos url', async function () {
const res = await getVideosList(server.url) const { total, data } = await server.videosCommand.list()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
for (const video of res.body.data) { for (const video of data) {
const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid) expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
const res = await getVideo(server.url, video.uuid) const videoDetails = await server.videosCommand.get({ id: video.uuid })
const videoDetails: VideoDetails = res.body
expect(videoDetails.trackerUrls[0]).to.include(server.host) expect(videoDetails.trackerUrls[0]).to.include(server.host)
expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host) expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
@ -111,13 +104,11 @@ describe('Test update host scripts', function () {
it('Should have updated torrent hosts', async function () { it('Should have updated torrent hosts', async function () {
this.timeout(30000) this.timeout(30000)
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data expect(data).to.have.lengthOf(2)
expect(videos).to.have.lengthOf(2)
for (const video of videos) { for (const video of data) {
const res2 = await getVideo(server.url, video.id) const videoDetails = await server.videosCommand.get({ id: video.id })
const videoDetails: VideoDetails = res2.body
expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files).to.have.lengthOf(4)

View File

@ -9,13 +9,11 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList,
makeGetRequest, makeGetRequest,
makeHTMLRequest, makeHTMLRequest,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
uploadVideo,
waitJobs waitJobs
} from '../../shared/extra-utils' } from '../../shared/extra-utils'
@ -68,36 +66,41 @@ describe('Test a client controllers', function () {
// Video // Video
const videoAttributes = { name: videoName, description: videoDescription } {
await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) const attributes = { name: videoName, description: videoDescription }
await servers[0].videosCommand.upload({ attributes })
const resVideosRequest = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const videos = resVideosRequest.body.data expect(data.length).to.equal(1)
expect(videos.length).to.equal(1)
const video = videos[0] const video = data[0]
servers[0].video = video servers[0].video = video
videoIds = [ video.id, video.uuid, video.shortUUID ] videoIds = [ video.id, video.uuid, video.shortUUID ]
}
// Playlist // Playlist
const attributes = { {
displayName: playlistName, const attributes = {
description: playlistDescription, displayName: playlistName,
privacy: VideoPlaylistPrivacy.PUBLIC, description: playlistDescription,
videoChannelId: servers[0].videoChannel.id privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: servers[0].videoChannel.id
}
playlist = await servers[0].playlistsCommand.create({ attributes })
playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ]
await servers[0].playlistsCommand.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: servers[0].video.id } })
} }
playlist = await servers[0].playlistsCommand.create({ attributes })
playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ]
await servers[0].playlistsCommand.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: video.id } })
// Account // Account
await servers[0].usersCommand.updateMe({ description: 'my account description' }) {
await servers[0].usersCommand.updateMe({ description: 'my account description' })
account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` }) account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` })
}
await waitJobs(servers) await waitJobs(servers)
}) })

View File

@ -3,7 +3,7 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
describe('Official plugin auth-ldap', function () { describe('Official plugin auth-ldap', function () {
let server: ServerInfo let server: ServerInfo
@ -77,7 +77,7 @@ describe('Official plugin auth-ldap', function () {
}) })
it('Should upload a video', async function () { it('Should upload a video', async function () {
await uploadVideo(server.url, accessToken, { name: 'my super video' }) await server.videosCommand.upload({ token: accessToken, attributes: { name: 'my super video' } })
}) })
it('Should not be able to login if the user is banned', async function () { it('Should not be able to login if the user is banned', async function () {

View File

@ -2,27 +2,23 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { Video } from '@shared/models'
import {
doubleFollow,
getVideosList,
MockBlocklist,
setAccessTokensToServers,
uploadVideoAndGetId,
wait
} from '../../../shared/extra-utils'
import { import {
cleanupTests, cleanupTests,
doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
killallServers, killallServers,
MockBlocklist,
reRunServer, reRunServer,
ServerInfo ServerInfo,
} from '../../../shared/extra-utils/server/servers' setAccessTokensToServers,
wait
} from '@shared/extra-utils'
import { Video } from '@shared/models'
async function check (server: ServerInfo, videoUUID: string, exists = true) { async function check (server: ServerInfo, videoUUID: string, exists = true) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const video = res.body.data.find(v => v.uuid === videoUUID) const video = data.find(v => v.uuid === videoUUID)
if (exists) expect(video).to.not.be.undefined if (exists) expect(video).to.not.be.undefined
else expect(video).to.be.undefined else expect(video).to.be.undefined
@ -48,19 +44,19 @@ describe('Official plugin auto-block videos', function () {
blocklistServer = new MockBlocklist() blocklistServer = new MockBlocklist()
port = await blocklistServer.initialize() port = await blocklistServer.initialize()
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2 server 2' }) await await servers[1].videosCommand.quickUpload({ name: 'video 2 server 2' })
await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2' }) await await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2' })
{ {
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
server1Videos = res.body.data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid })) server1Videos = data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid }))
} }
{ {
const res = await getVideosList(servers[1].url) const { data } = await servers[1].videosCommand.list()
server2Videos = res.body.data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid })) server2Videos = data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid }))
} }
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])

View File

@ -7,14 +7,12 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList,
killallServers, killallServers,
makeGetRequest, makeGetRequest,
MockBlocklist, MockBlocklist,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideoAndGetId,
wait wait
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -37,8 +35,8 @@ describe('Official plugin auto-mute', function () {
blocklistServer = new MockBlocklist() blocklistServer = new MockBlocklist()
port = await blocklistServer.initialize() port = await blocklistServer.initialize()
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
}) })
@ -66,8 +64,8 @@ describe('Official plugin auto-mute', function () {
await wait(2000) await wait(2000)
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
}) })
it('Should remove a server blocklist', async function () { it('Should remove a server blocklist', async function () {
@ -84,8 +82,8 @@ describe('Official plugin auto-mute', function () {
await wait(2000) await wait(2000)
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
}) })
it('Should add an account blocklist', async function () { it('Should add an account blocklist', async function () {
@ -101,8 +99,8 @@ describe('Official plugin auto-mute', function () {
await wait(2000) await wait(2000)
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
}) })
it('Should remove an account blocklist', async function () { it('Should remove an account blocklist', async function () {
@ -119,8 +117,8 @@ describe('Official plugin auto-mute', function () {
await wait(2000) await wait(2000)
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
}) })
it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () { it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
@ -140,15 +138,15 @@ describe('Official plugin auto-mute', function () {
await wait(2000) await wait(2000)
{ {
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(1) expect(total).to.equal(1)
} }
await servers[0].blocklistCommand.removeFromServerBlocklist({ account }) await servers[0].blocklistCommand.removeFromServerBlocklist({ account })
{ {
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
} }
await killallServers([ servers[0] ]) await killallServers([ servers[0] ])
@ -156,8 +154,8 @@ describe('Official plugin auto-mute', function () {
await wait(2000) await wait(2000)
{ {
const res = await getVideosList(servers[0].url) const { total } = await servers[0].videosCommand.list()
expect(res.body.total).to.equal(2) expect(total).to.equal(2)
} }
}) })
@ -215,8 +213,8 @@ describe('Official plugin auto-mute', function () {
await wait(2000) await wait(2000)
for (const server of servers) { 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)
} }
}) })

View File

@ -11,8 +11,6 @@ import {
flushAndRunServer, flushAndRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo,
uploadVideoAndGetId,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
@ -68,28 +66,26 @@ describe('Test syndication feeds', () => {
} }
{ {
await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' }) await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'user video' } })
} }
{ {
const videoAttributes = { const attributes = {
name: 'my super name for server 1', name: 'my super name for server 1',
description: 'my super description for server 1', description: 'my super description for server 1',
fixture: 'video_short.webm' fixture: 'video_short.webm'
} }
const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) const { id } = await servers[0].videosCommand.upload({ attributes })
const videoId = res.body.video.id
await servers[0].commentsCommand.createThread({ videoId, text: 'super comment 1' }) await servers[0].commentsCommand.createThread({ videoId: id, text: 'super comment 1' })
await servers[0].commentsCommand.createThread({ videoId, text: 'super comment 2' }) await servers[0].commentsCommand.createThread({ videoId: id, text: 'super comment 2' })
} }
{ {
const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } const attributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) const { id } = await servers[0].videosCommand.upload({ attributes })
const videoId = res.body.video.id
await servers[0].commentsCommand.createThread({ videoId, text: 'comment on unlisted video' }) await servers[0].commentsCommand.createThread({ videoId: id, text: 'comment on unlisted video' })
} }
await waitJobs(servers) await waitJobs(servers)
@ -218,7 +214,7 @@ describe('Test syndication feeds', () => {
it('Should correctly have videos feed with HLS only', async function () { it('Should correctly have videos feed with HLS only', async function () {
this.timeout(120000) this.timeout(120000)
await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' }) await serverHLSOnly.videosCommand.upload({ attributes: { name: 'hls only video' } })
await waitJobs([ serverHLSOnly ]) await waitJobs([ serverHLSOnly ])
@ -265,7 +261,7 @@ describe('Test syndication feeds', () => {
await servers[1].blocklistCommand.removeFromServerBlocklist({ account: remoteHandle }) await servers[1].blocklistCommand.removeFromServerBlocklist({ account: remoteHandle })
{ {
const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid
await waitJobs(servers) await waitJobs(servers)
await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'super comment' }) await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'super comment' })
await waitJobs(servers) await waitJobs(servers)

View File

@ -3,15 +3,8 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import { cleanupTests, flushAndRunServer, makeGetRequest, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
cleanupTests, import { VideoPrivacy } from '@shared/models'
flushAndRunServer,
makeGetRequest,
ServerInfo,
setAccessTokensToServers,
uploadVideo
} from '../../shared/extra-utils'
import { VideoPrivacy } from '../../shared/models/videos'
const expect = chai.expect const expect = chai.expect
@ -165,9 +158,9 @@ describe('Test misc endpoints', function () {
it('Should add videos, channel and accounts and get sitemap', async function () { it('Should add videos, channel and accounts and get sitemap', async function () {
this.timeout(35000) this.timeout(35000)
await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false }) await server.videosCommand.upload({ attributes: { name: 'video 1', nsfw: false } })
await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false }) await server.videosCommand.upload({ attributes: { name: 'video 2', nsfw: false } })
await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE }) await server.videosCommand.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } }) await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } }) await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })

View File

@ -9,10 +9,7 @@ import {
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel
updateVideo,
uploadVideo,
viewVideo
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
@ -52,20 +49,20 @@ describe('Test plugin action hooks', function () {
describe('Videos hooks', function () { describe('Videos hooks', function () {
it('Should run action:api.video.uploaded', async function () { it('Should run action:api.video.uploaded', async function () {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
videoUUID = res.body.video.uuid videoUUID = uuid
await checkHook('action:api.video.uploaded') await checkHook('action:api.video.uploaded')
}) })
it('Should run action:api.video.updated', async function () { it('Should run action:api.video.updated', async function () {
await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video updated' } })
await checkHook('action:api.video.updated') await checkHook('action:api.video.updated')
}) })
it('Should run action:api.video.viewed', async function () { it('Should run action:api.video.viewed', async function () {
await viewVideo(servers[0].url, videoUUID) await servers[0].videosCommand.view({ id: videoUUID })
await checkHook('action:api.video.viewed') await checkHook('action:api.video.viewed')
}) })
@ -170,8 +167,8 @@ describe('Test plugin action hooks', function () {
} }
{ {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' }) const { id } = await servers[0].videosCommand.upload({ attributes: { name: 'my super name' } })
videoId = res.body.video.id videoId = id
} }
}) })

View File

@ -7,22 +7,12 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getAccountVideos,
getMyVideos,
getVideo,
getVideoChannelVideos,
getVideosList,
getVideosListPagination,
getVideoWithToken,
ImportsCommand, ImportsCommand,
makeRawRequest, makeRawRequest,
PluginsCommand, PluginsCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
updateVideo,
uploadVideo,
uploadVideoAndGetId,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
@ -46,11 +36,11 @@ describe('Test plugin filter hooks', function () {
await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) await servers[0].videosCommand.upload({ attributes: { name: 'default video ' + i } })
} }
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
videoUUID = res.body.data[0].uuid videoUUID = data[0].uuid
await servers[0].configCommand.updateCustomSubConfig({ await servers[0].configCommand.updateCustomSubConfig({
newConfig: { newConfig: {
@ -67,69 +57,68 @@ describe('Test plugin filter hooks', function () {
}) })
it('Should run filter:api.videos.list.params', async function () { it('Should run filter:api.videos.list.params', async function () {
const res = await getVideosListPagination(servers[0].url, 0, 2) const { data } = await servers[0].videosCommand.list({ start: 0, count: 2 })
// 2 plugins do +1 to the count parameter // 2 plugins do +1 to the count parameter
expect(res.body.data).to.have.lengthOf(4) expect(data).to.have.lengthOf(4)
}) })
it('Should run filter:api.videos.list.result', async function () { it('Should run filter:api.videos.list.result', async function () {
const res = await getVideosListPagination(servers[0].url, 0, 0) const { total } = await servers[0].videosCommand.list({ start: 0, count: 0 })
// Plugin do +1 to the total result // Plugin do +1 to the total result
expect(res.body.total).to.equal(11) expect(total).to.equal(11)
}) })
it('Should run filter:api.accounts.videos.list.params', async function () { it('Should run filter:api.accounts.videos.list.params', async function () {
const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) const { data } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 })
// 1 plugin do +1 to the count parameter // 1 plugin do +1 to the count parameter
expect(res.body.data).to.have.lengthOf(3) expect(data).to.have.lengthOf(3)
}) })
it('Should run filter:api.accounts.videos.list.result', async function () { it('Should run filter:api.accounts.videos.list.result', async function () {
const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) const { total } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 })
// Plugin do +2 to the total result // Plugin do +2 to the total result
expect(res.body.total).to.equal(12) expect(total).to.equal(12)
}) })
it('Should run filter:api.video-channels.videos.list.params', async function () { it('Should run filter:api.video-channels.videos.list.params', async function () {
const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) const { data } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 })
// 1 plugin do +3 to the count parameter // 1 plugin do +3 to the count parameter
expect(res.body.data).to.have.lengthOf(5) expect(data).to.have.lengthOf(5)
}) })
it('Should run filter:api.video-channels.videos.list.result', async function () { it('Should run filter:api.video-channels.videos.list.result', async function () {
const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) const { total } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 })
// Plugin do +3 to the total result // Plugin do +3 to the total result
expect(res.body.total).to.equal(13) expect(total).to.equal(13)
}) })
it('Should run filter:api.user.me.videos.list.params', async function () { it('Should run filter:api.user.me.videos.list.params', async function () {
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) const { data } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 })
// 1 plugin do +4 to the count parameter // 1 plugin do +4 to the count parameter
expect(res.body.data).to.have.lengthOf(6) expect(data).to.have.lengthOf(6)
}) })
it('Should run filter:api.user.me.videos.list.result', async function () { it('Should run filter:api.user.me.videos.list.result', async function () {
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) const { total } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 })
// Plugin do +4 to the total result // Plugin do +4 to the total result
expect(res.body.total).to.equal(14) expect(total).to.equal(14)
}) })
it('Should run filter:api.video.get.result', async function () { it('Should run filter:api.video.get.result', async function () {
const res = await getVideo(servers[0].url, videoUUID) const video = await servers[0].videosCommand.get({ id: videoUUID })
expect(video.name).to.contain('<3')
expect(res.body.name).to.contain('<3')
}) })
it('Should run filter:api.video.upload.accept.result', async function () { it('Should run filter:api.video.upload.accept.result', async function () {
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) await servers[0].videosCommand.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}) })
it('Should run filter:api.live-video.create.accept.result', async function () { it('Should run filter:api.live-video.create.accept.result', async function () {
@ -270,14 +259,13 @@ describe('Test plugin filter hooks', function () {
describe('Should run filter:video.auto-blacklist.result', function () { describe('Should run filter:video.auto-blacklist.result', function () {
async function checkIsBlacklisted (id: number | string, value: boolean) { async function checkIsBlacklisted (id: number | string, value: boolean) {
const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id) const video = await servers[0].videosCommand.getWithToken({ id })
const video: VideoDetails = res.body
expect(video.blacklisted).to.equal(value) expect(video.blacklisted).to.equal(value)
} }
it('Should blacklist on upload', async function () { it('Should blacklist on upload', async function () {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video please blacklist me' } })
await checkIsBlacklisted(res.body.video.uuid, true) await checkIsBlacklisted(uuid, true)
}) })
it('Should blacklist on import', async function () { it('Should blacklist on import', async function () {
@ -293,36 +281,34 @@ describe('Test plugin filter hooks', function () {
}) })
it('Should blacklist on update', async function () { it('Should blacklist on update', async function () {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
const videoId = res.body.video.uuid await checkIsBlacklisted(uuid, false)
await checkIsBlacklisted(videoId, false)
await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) await servers[0].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } })
await checkIsBlacklisted(videoId, true) await checkIsBlacklisted(uuid, true)
}) })
it('Should blacklist on remote upload', async function () { it('Should blacklist on remote upload', async function () {
this.timeout(120000) this.timeout(120000)
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'remote please blacklist me' } })
await waitJobs(servers) await waitJobs(servers)
await checkIsBlacklisted(res.body.video.uuid, true) await checkIsBlacklisted(uuid, true)
}) })
it('Should blacklist on remote update', async function () { it('Should blacklist on remote update', async function () {
this.timeout(120000) this.timeout(120000)
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video' } })
await waitJobs(servers) await waitJobs(servers)
const videoId = res.body.video.uuid await checkIsBlacklisted(uuid, false)
await checkIsBlacklisted(videoId, false)
await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) await servers[1].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } })
await waitJobs(servers) await waitJobs(servers)
await checkIsBlacklisted(videoId, true) await checkIsBlacklisted(uuid, true)
}) })
}) })
@ -370,15 +356,14 @@ describe('Test plugin filter hooks', function () {
const uuids: string[] = [] const uuids: string[] = []
for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid
uuids.push(uuid) uuids.push(uuid)
} }
await waitJobs(servers) await waitJobs(servers)
for (const uuid of uuids) { for (const uuid of uuids) {
const res = await getVideo(servers[0].url, uuid) downloadVideos.push(await servers[0].videosCommand.get({ id: uuid }))
downloadVideos.push(res.body)
} }
}) })
@ -428,9 +413,8 @@ describe('Test plugin filter hooks', function () {
for (const name of [ 'bad embed', 'good embed' ]) { for (const name of [ 'bad embed', 'good embed' ]) {
{ {
const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid
const res = await getVideo(servers[0].url, uuid) embedVideos.push(await servers[0].videosCommand.get({ id: uuid }))
embedVideos.push(res.body)
} }
{ {

View File

@ -8,15 +8,11 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo,
getVideosList,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
PluginsCommand, PluginsCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideoAndGetId,
viewVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -144,59 +140,54 @@ describe('Test plugin helpers', function () {
this.timeout(60000) this.timeout(60000)
{ {
const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) const res = await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
videoUUIDServer1 = res.uuid videoUUIDServer1 = res.uuid
} }
{ {
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
} }
await waitJobs(servers) await waitJobs(servers)
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const videos = res.body.data
expect(videos).to.have.lengthOf(2) expect(data).to.have.lengthOf(2)
}) })
it('Should mute server 2', async function () { it('Should mute server 2', async function () {
this.timeout(10000) this.timeout(10000)
await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const videos = res.body.data
expect(videos).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
expect(videos[0].name).to.equal('video server 1') expect(data[0].name).to.equal('video server 1')
}) })
it('Should unmute server 2', async function () { it('Should unmute server 2', async function () {
await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const videos = res.body.data
expect(videos).to.have.lengthOf(2) expect(data).to.have.lengthOf(2)
}) })
it('Should mute account of server 2', async function () { it('Should mute account of server 2', async function () {
await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const videos = res.body.data
expect(videos).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
expect(videos[0].name).to.equal('video server 1') expect(data[0].name).to.equal('video server 1')
}) })
it('Should unmute account of server 2', async function () { it('Should unmute account of server 2', async function () {
await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
const res = await getVideosList(servers[0].url) const { data } = await servers[0].videosCommand.list()
const videos = res.body.data
expect(videos).to.have.lengthOf(2) expect(data).to.have.lengthOf(2)
}) })
it('Should blacklist video', async function () { it('Should blacklist video', async function () {
@ -207,11 +198,10 @@ describe('Test plugin helpers', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data
expect(videos).to.have.lengthOf(1) expect(data).to.have.lengthOf(1)
expect(videos[0].name).to.equal('video server 2') expect(data[0].name).to.equal('video server 2')
} }
}) })
@ -223,10 +213,9 @@ describe('Test plugin helpers', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const { data } = await server.videosCommand.list()
const videos = res.body.data
expect(videos).to.have.lengthOf(2) expect(data).to.have.lengthOf(2)
} }
}) })
}) })
@ -235,7 +224,7 @@ describe('Test plugin helpers', function () {
let videoUUID: string let videoUUID: string
before(async () => { before(async () => {
const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' }) const res = await await servers[0].videosCommand.quickUpload({ name: 'video1' })
videoUUID = res.uuid videoUUID = res.uuid
}) })
@ -243,15 +232,15 @@ describe('Test plugin helpers', function () {
this.timeout(40000) this.timeout(40000)
// Should not throw -> video exists // Should not throw -> video exists
await getVideo(servers[0].url, videoUUID) await servers[0].videosCommand.get({ id: videoUUID })
// Should delete the video // Should delete the video
await viewVideo(servers[0].url, videoUUID) await servers[0].videosCommand.view({ id: videoUUID })
await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.') await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.')
try { try {
// Should throw because the video should have been deleted // Should throw because the video should have been deleted
await getVideo(servers[0].url, videoUUID) await servers[0].videosCommand.get({ id: videoUUID })
throw new Error('Video exists') throw new Error('Video exists')
} catch (err) { } catch (err) {
if (err.message.includes('exists')) throw err if (err.message.includes('exists')) throw err

View File

@ -7,16 +7,14 @@ import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getVideo,
PluginsCommand, PluginsCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
testFfmpegStreamError, testFfmpegStreamError,
uploadVideoAndGetId,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoDetails, VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
async function createLiveWrapper (server: ServerInfo) { async function createLiveWrapper (server: ServerInfo) {
const liveAttributes = { const liveAttributes = {
@ -81,8 +79,7 @@ describe('Test transcoding plugins', function () {
describe('When using a plugin adding profiles to existing encoders', function () { describe('When using a plugin adding profiles to existing encoders', function () {
async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) { async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) {
const res = await getVideo(server.url, uuid) const video = await server.videosCommand.get({ id: uuid })
const video = res.body as VideoDetails
const files = video.files.concat(...video.streamingPlaylists.map(p => p.files)) const files = video.files.concat(...video.streamingPlaylists.map(p => p.files))
for (const file of files) { for (const file of files) {
@ -119,7 +116,7 @@ describe('Test transcoding plugins', function () {
it('Should not use the plugin profile if not chosen by the admin', async function () { it('Should not use the plugin profile if not chosen by the admin', async function () {
this.timeout(240000) this.timeout(240000)
const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ]) await waitJobs([ server ])
await checkVideoFPS(videoUUID, 'above', 20) await checkVideoFPS(videoUUID, 'above', 20)
@ -130,7 +127,7 @@ describe('Test transcoding plugins', function () {
await updateConf(server, 'low-vod', 'default') await updateConf(server, 'low-vod', 'default')
const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ]) await waitJobs([ server ])
await checkVideoFPS(videoUUID, 'below', 12) await checkVideoFPS(videoUUID, 'below', 12)
@ -141,7 +138,7 @@ describe('Test transcoding plugins', function () {
await updateConf(server, 'input-options-vod', 'default') await updateConf(server, 'input-options-vod', 'default')
const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ]) await waitJobs([ server ])
await checkVideoFPS(videoUUID, 'below', 6) await checkVideoFPS(videoUUID, 'below', 6)
@ -152,13 +149,11 @@ describe('Test transcoding plugins', function () {
await updateConf(server, 'bad-scale-vod', 'default') await updateConf(server, 'bad-scale-vod', 'default')
const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ]) await waitJobs([ server ])
// Transcoding failed // Transcoding failed
const res = await getVideo(server.url, videoUUID) const video = await server.videosCommand.get({ id: videoUUID })
const video: VideoDetails = res.body
expect(video.files).to.have.lengthOf(1) expect(video.files).to.have.lengthOf(1)
expect(video.streamingPlaylists).to.have.lengthOf(0) expect(video.streamingPlaylists).to.have.lengthOf(0)
}) })
@ -224,7 +219,7 @@ describe('Test transcoding plugins', function () {
expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ])
expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ])
const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ]) await waitJobs([ server ])
await checkVideoFPS(videoUUID, 'above', 20) await checkVideoFPS(videoUUID, 'above', 20)
@ -243,7 +238,7 @@ describe('Test transcoding plugins', function () {
it('Should use the new vod encoders', async function () { it('Should use the new vod encoders', async function () {
this.timeout(240000) this.timeout(240000)
const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid const videoUUID = (await server.videosCommand.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid
await waitJobs([ server ]) await waitJobs([ server ])
const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4'))

View File

@ -3,20 +3,8 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
cleanupTests, import { VideoPlaylistPrivacy } from '@shared/models'
flushAndRunServer,
getVideo,
getVideoCategories,
getVideoLanguages,
getVideoLicences,
getVideoPrivacies,
PluginsCommand,
ServerInfo,
setAccessTokensToServers,
uploadVideo
} from '@shared/extra-utils'
import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -33,8 +21,7 @@ describe('Test plugin altering video constants', function () {
}) })
it('Should have updated languages', async function () { it('Should have updated languages', async function () {
const res = await getVideoLanguages(server.url) const languages = await server.videosCommand.getLanguages()
const languages = res.body
expect(languages['en']).to.not.exist expect(languages['en']).to.not.exist
expect(languages['fr']).to.not.exist expect(languages['fr']).to.not.exist
@ -45,8 +32,7 @@ describe('Test plugin altering video constants', function () {
}) })
it('Should have updated categories', async function () { it('Should have updated categories', async function () {
const res = await getVideoCategories(server.url) const categories = await server.videosCommand.getCategories()
const categories = res.body
expect(categories[1]).to.not.exist expect(categories[1]).to.not.exist
expect(categories[2]).to.not.exist expect(categories[2]).to.not.exist
@ -56,8 +42,7 @@ describe('Test plugin altering video constants', function () {
}) })
it('Should have updated licences', async function () { it('Should have updated licences', async function () {
const res = await getVideoLicences(server.url) const licences = await server.videosCommand.getLicences()
const licences = res.body
expect(licences[1]).to.not.exist expect(licences[1]).to.not.exist
expect(licences[7]).to.not.exist expect(licences[7]).to.not.exist
@ -67,8 +52,7 @@ describe('Test plugin altering video constants', function () {
}) })
it('Should have updated video privacies', async function () { it('Should have updated video privacies', async function () {
const res = await getVideoPrivacies(server.url) const privacies = await server.videosCommand.getPrivacies()
const privacies = res.body
expect(privacies[1]).to.exist expect(privacies[1]).to.exist
expect(privacies[2]).to.not.exist expect(privacies[2]).to.not.exist
@ -85,8 +69,8 @@ describe('Test plugin altering video constants', function () {
}) })
it('Should not be able to create a video with this privacy', async function () { it('Should not be able to create a video with this privacy', async function () {
const attrs = { name: 'video', privacy: 2 } const attributes = { name: 'video', privacy: 2 }
await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) await server.videosCommand.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}) })
it('Should not be able to create a video with this privacy', async function () { it('Should not be able to create a video with this privacy', async function () {
@ -95,12 +79,10 @@ describe('Test plugin altering video constants', function () {
}) })
it('Should be able to upload a video with these values', async function () { it('Should be able to upload a video with these values', async function () {
const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
const resUpload = await uploadVideo(server.url, server.accessToken, attrs) const { uuid } = await server.videosCommand.upload({ attributes })
const res = await getVideo(server.url, resUpload.body.video.uuid) const video = await server.videosCommand.get({ id: uuid })
const video: VideoDetails = res.body
expect(video.language.label).to.equal('Al Bhed 2') expect(video.language.label).to.equal('Al Bhed 2')
expect(video.licence.label).to.equal('Best licence') expect(video.licence.label).to.equal('Best licence')
expect(video.category.label).to.equal('Best category') expect(video.category.label).to.equal('Best category')
@ -110,8 +92,7 @@ describe('Test plugin altering video constants', function () {
await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
{ {
const res = await getVideoLanguages(server.url) const languages = await server.videosCommand.getLanguages()
const languages = res.body
expect(languages['en']).to.equal('English') expect(languages['en']).to.equal('English')
expect(languages['fr']).to.equal('French') expect(languages['fr']).to.equal('French')
@ -122,8 +103,7 @@ describe('Test plugin altering video constants', function () {
} }
{ {
const res = await getVideoCategories(server.url) const categories = await server.videosCommand.getCategories()
const categories = res.body
expect(categories[1]).to.equal('Music') expect(categories[1]).to.equal('Music')
expect(categories[2]).to.equal('Films') expect(categories[2]).to.equal('Films')
@ -133,8 +113,7 @@ describe('Test plugin altering video constants', function () {
} }
{ {
const res = await getVideoLicences(server.url) const licences = await server.videosCommand.getLicences()
const licences = res.body
expect(licences[1]).to.equal('Attribution') expect(licences[1]).to.equal('Attribution')
expect(licences[7]).to.equal('Public Domain Dedication') expect(licences[7]).to.equal('Public Domain Dedication')
@ -144,8 +123,7 @@ describe('Test plugin altering video constants', function () {
} }
{ {
const res = await getVideoPrivacies(server.url) const privacies = await server.videosCommand.getPrivacies()
const privacies = res.body
expect(privacies[1]).to.exist expect(privacies[1]).to.exist
expect(privacies[2]).to.exist expect(privacies[2]).to.exist

View File

@ -16,7 +16,7 @@ const version = require('../../../package.json').version
async function getAdminTokenOrDie (server: ServerInfo, username: string, password: string) { async function getAdminTokenOrDie (server: ServerInfo, username: string, password: string) {
const token = await server.loginCommand.getAccessToken(username, password) const token = await server.loginCommand.getAccessToken(username, password)
const me = await server.usersCommand.getMyUserInformation({ token }) const me = await server.usersCommand.getMyInfo({ token })
if (me.role !== UserRole.ADMINISTRATOR) { if (me.role !== UserRole.ADMINISTRATOR) {
console.error('You must be an administrator.') console.error('You must be an administrator.')

View File

@ -9,7 +9,6 @@ import { join } from 'path'
import * as prompt from 'prompt' import * as prompt from 'prompt'
import { promisify } from 'util' import { promisify } from 'util'
import { YoutubeDL } from '@server/helpers/youtube-dl' import { YoutubeDL } from '@server/helpers/youtube-dl'
import { getVideoCategories, uploadVideo } from '../../shared/extra-utils/index'
import { sha256 } from '../helpers/core-utils' import { sha256 } from '../helpers/core-utils'
import { doRequestAndSaveToFile } from '../helpers/requests' import { doRequestAndSaveToFile } from '../helpers/requests'
import { CONSTRAINTS_FIELDS } from '../initializers/constants' import { CONSTRAINTS_FIELDS } from '../initializers/constants'
@ -21,6 +20,7 @@ import {
getLogger, getLogger,
getServerCredentials getServerCredentials
} from './cli' } from './cli'
import { ServerInfo } from '@shared/extra-utils'
const processOptions = { const processOptions = {
maxBuffer: Infinity maxBuffer: Infinity
@ -200,7 +200,10 @@ async function uploadVideoOnPeerTube (parameters: {
}) { }) {
const { youtubeDL, videoInfo, videoPath, cwd, url, username, password } = parameters const { youtubeDL, videoInfo, videoPath, cwd, url, username, password } = parameters
const category = await getCategory(videoInfo.categories, url) const server = buildServer(url)
await assignToken(server, username, password)
const category = await getCategory(server, videoInfo.categories)
const licence = getLicence(videoInfo.license) const licence = getLicence(videoInfo.license)
let tags = [] let tags = []
if (Array.isArray(videoInfo.tags)) { if (Array.isArray(videoInfo.tags)) {
@ -232,29 +235,28 @@ async function uploadVideoOnPeerTube (parameters: {
tags tags
} }
const server = buildServer(url) const baseAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes)
await assignToken(server, username, password)
const videoAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes) const attributes = {
...baseAttributes,
Object.assign(videoAttributes, {
originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null, originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null,
thumbnailfile, thumbnailfile,
previewfile: thumbnailfile, previewfile: thumbnailfile,
fixture: videoPath fixture: videoPath
}) }
log.info('\nUploading on PeerTube video "%s".', videoAttributes.name) log.info('\nUploading on PeerTube video "%s".', attributes.name)
try { try {
await uploadVideo(url, server.accessToken, videoAttributes) await server.videosCommand.upload({ attributes })
} catch (err) { } catch (err) {
if (err.message.indexOf('401') !== -1) { if (err.message.indexOf('401') !== -1) {
log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.') log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.')
server.accessToken = await server.loginCommand.getAccessToken(username, password) server.accessToken = await server.loginCommand.getAccessToken(username, password)
await uploadVideo(url, server.accessToken, videoAttributes) await server.videosCommand.upload({ attributes })
} else { } else {
exitError(err.message) exitError(err.message)
} }
@ -263,20 +265,19 @@ async function uploadVideoOnPeerTube (parameters: {
await remove(videoPath) await remove(videoPath)
if (thumbnailfile) await remove(thumbnailfile) if (thumbnailfile) await remove(thumbnailfile)
log.warn('Uploaded video "%s"!\n', videoAttributes.name) log.warn('Uploaded video "%s"!\n', attributes.name)
} }
/* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */
async function getCategory (categories: string[], url: string) { async function getCategory (server: ServerInfo, categories: string[]) {
if (!categories) return undefined if (!categories) return undefined
const categoryString = categories[0] const categoryString = categories[0]
if (categoryString === 'News & Politics') return 11 if (categoryString === 'News & Politics') return 11
const res = await getVideoCategories(url) const categoriesServer = await server.videosCommand.getCategories()
const categoriesServer = res.body
for (const key of Object.keys(categoriesServer)) { for (const key of Object.keys(categoriesServer)) {
const categoryServer = categoriesServer[key] const categoryServer = categoriesServer[key]

View File

@ -4,7 +4,6 @@ registerTSPaths()
import { program } from 'commander' import { program } from 'commander'
import { access, constants } from 'fs-extra' import { access, constants } from 'fs-extra'
import { isAbsolute } from 'path' import { isAbsolute } from 'path'
import { uploadVideo } from '../../shared/extra-utils/'
import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli' import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
let command = program let command = program
@ -52,16 +51,18 @@ async function run (url: string, username: string, password: string) {
console.log('Uploading %s video...', options.videoName) console.log('Uploading %s video...', options.videoName)
const videoAttributes = await buildVideoAttributesFromCommander(server, program) const baseAttributes = await buildVideoAttributesFromCommander(server, program)
const attributes = {
...baseAttributes,
Object.assign(videoAttributes, {
fixture: options.file, fixture: options.file,
thumbnailfile: options.thumbnail, thumbnailfile: options.thumbnail,
previewfile: options.preview previewfile: options.preview
}) }
try { try {
await uploadVideo(url, server.accessToken, videoAttributes) await server.videosCommand.upload({ attributes })
console.log(`Video ${options.videoName} uploaded.`) console.log(`Video ${options.videoName} uploaded.`)
process.exit(0) process.exit(0)
} catch (err) { } catch (err) {

View File

@ -1,4 +1,8 @@
import { readFile } from 'fs-extra'
import * as parseTorrent from 'parse-torrent'
import { join } from 'path'
import * as WebTorrent from 'webtorrent' import * as WebTorrent from 'webtorrent'
import { ServerInfo } from '../server'
let webtorrent: WebTorrent.Instance let webtorrent: WebTorrent.Instance
@ -11,6 +15,16 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
} }
export { async function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
webtorrentAdd const torrentName = videoUUID + '-' + resolution + '.torrent'
const torrentPath = server.serversCommand.buildDirectory(join('torrents', torrentName))
const data = await readFile(torrentPath)
return parseTorrent(data)
}
export {
webtorrentAdd,
parseTorrentVideo
} }

View File

@ -67,11 +67,17 @@ function makeUploadRequest (options: {
method?: 'POST' | 'PUT' method?: 'POST' | 'PUT'
path: string path: string
token?: string token?: string
fields: { [ fieldName: string ]: any } fields: { [ fieldName: string ]: any }
attaches?: { [ attachName: string ]: any | any[] } attaches?: { [ attachName: string ]: any | any[] }
headers?: { [ name: string ]: string }
statusCodeExpected?: HttpStatusCode statusCodeExpected?: HttpStatusCode
}) { }) {
if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 if (options.statusCodeExpected === undefined) {
options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400
}
let req: request.Test let req: request.Test
if (options.method === 'PUT') { if (options.method === 'PUT') {
@ -84,6 +90,10 @@ function makeUploadRequest (options: {
if (options.token) req.set('Authorization', 'Bearer ' + options.token) if (options.token) req.set('Authorization', 'Bearer ' + options.token)
Object.keys(options.headers || {}).forEach(name => {
req.set(name, options.headers[name])
})
Object.keys(options.fields).forEach(field => { Object.keys(options.fields).forEach(field => {
const value = options.fields[field] const value = options.fields[field]
@ -107,7 +117,11 @@ function makeUploadRequest (options: {
} }
}) })
return req.expect(options.statusCodeExpected) if (options.statusCodeExpected) {
req.expect(options.statusCodeExpected)
}
return req
} }
function makePostBodyRequest (options: { function makePostBodyRequest (options: {
@ -115,7 +129,9 @@ function makePostBodyRequest (options: {
path: string path: string
token?: string token?: string
fields?: { [ fieldName: string ]: any } fields?: { [ fieldName: string ]: any }
headers?: { [ name: string ]: string }
type?: string type?: string
xForwardedFor?: string
statusCodeExpected?: HttpStatusCode statusCodeExpected?: HttpStatusCode
}) { }) {
if (!options.fields) options.fields = {} if (!options.fields) options.fields = {}
@ -126,8 +142,13 @@ function makePostBodyRequest (options: {
.set('Accept', 'application/json') .set('Accept', 'application/json')
if (options.token) req.set('Authorization', 'Bearer ' + options.token) if (options.token) req.set('Authorization', 'Bearer ' + options.token)
if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor)
if (options.type) req.type(options.type) if (options.type) req.type(options.type)
Object.keys(options.headers || {}).forEach(name => {
req.set(name, options.headers[name])
})
return req.send(options.fields) return req.send(options.fields)
.expect(options.statusCodeExpected) .expect(options.statusCodeExpected)
} }

View File

@ -27,7 +27,8 @@ import {
LiveCommand, LiveCommand,
PlaylistsCommand, PlaylistsCommand,
ServicesCommand, ServicesCommand,
StreamingPlaylistsCommand StreamingPlaylistsCommand,
VideosCommand
} from '../videos' } from '../videos'
import { CommentsCommand } from '../videos/comments-command' import { CommentsCommand } from '../videos/comments-command'
import { ConfigCommand } from './config-command' import { ConfigCommand } from './config-command'
@ -128,6 +129,7 @@ interface ServerInfo {
serversCommand?: ServersCommand serversCommand?: ServersCommand
loginCommand?: LoginCommand loginCommand?: LoginCommand
usersCommand?: UsersCommand usersCommand?: UsersCommand
videosCommand?: VideosCommand
} }
function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) {
@ -361,6 +363,7 @@ function assignCommands (server: ServerInfo) {
server.serversCommand = new ServersCommand(server) server.serversCommand = new ServersCommand(server)
server.loginCommand = new LoginCommand(server) server.loginCommand = new LoginCommand(server)
server.usersCommand = new UsersCommand(server) server.usersCommand = new UsersCommand(server)
server.videosCommand = new VideosCommand(server)
} }
async function reRunServer (server: ServerInfo, configOverride?: any) { async function reRunServer (server: ServerInfo, configOverride?: any) {

Some files were not shown because too many files have changed in this diff Show More