import * as autocannon from 'autocannon'
import { writeJson } from 'fs-extra'
-import { flushAndRunServer, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils'
+import { flushAndRunServer, killallServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models'
import { registerTSPaths } from '../server/helpers/register-ts-paths'
})
await setAccessTokensToServers([ server ])
- const videoAttributes = {
+ const attributes = {
name: 'my super video',
category: 2,
nsfw: true,
}
for (let i = 0; i < 10; i++) {
- Object.assign(videoAttributes, { name: 'my super video ' + i })
- await uploadVideo(server.url, server.accessToken, videoAttributes)
+ await server.videosCommand.upload({ attributes: { ...attributes, name: 'my super video ' + i } })
}
- const resVideos = await getVideosList(server.url)
- video = resVideos.body.data.find(v => v.name === 'my super video 1')
+ const { data } = await server.videosCommand.list()
+ video = data.find(v => v.name === 'my super video 1')
for (let i = 0; i < 10; i++) {
const text = 'my super first comment'
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
- rateVideo,
ServerInfo,
setAccessTokensToServers,
- uploadVideoAndGetId,
wait,
waitJobs
} from '@shared/extra-utils'
// Create 1 comment per video
// Update 1 remote URL and 1 local URL on
- videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid
- videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
- videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid
+ videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid
+ videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid
+ videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid
videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ]
for (const server of servers) {
for (const uuid of videoUUIDs) {
- await rateVideo(server.url, server.accessToken, uuid, 'like')
+ await server.videosCommand.rate({ id: uuid, rating: 'like' })
await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' })
}
}
it('Should have the correct likes', async function () {
for (const server of servers) {
for (const uuid of videoUUIDs) {
- const res = await getVideo(server.url, uuid)
- expect(res.body.likes).to.equal(3)
- expect(res.body.dislikes).to.equal(0)
+ const video = await server.videosCommand.get({ id: uuid })
+
+ expect(video.likes).to.equal(3)
+ expect(video.dislikes).to.equal(0)
}
}
})
// Updated rates of my video
{
- const res = await getVideo(servers[0].url, videoUUID1)
- expect(res.body.likes).to.equal(2)
- expect(res.body.dislikes).to.equal(0)
+ const video = await servers[0].videosCommand.get({ id: videoUUID1 })
+ expect(video.likes).to.equal(2)
+ expect(video.dislikes).to.equal(0)
}
// Did not update rates of a remote video
{
- const res = await getVideo(servers[0].url, videoUUID2)
- expect(res.body.likes).to.equal(3)
- expect(res.body.dislikes).to.equal(0)
+ const video = await servers[0].videosCommand.get({ id: videoUUID2 })
+ expect(video.likes).to.equal(3)
+ expect(video.dislikes).to.equal(0)
}
})
for (const server of servers) {
for (const uuid of videoUUIDs) {
- await rateVideo(server.url, server.accessToken, uuid, 'dislike')
+ await server.videosCommand.rate({ id: uuid, rating: 'dislike' })
}
}
for (const server of servers) {
for (const uuid of videoUUIDs) {
- const res = await getVideo(server.url, uuid)
- expect(res.body.likes).to.equal(0)
- expect(res.body.dislikes).to.equal(3)
+ const video = await server.videosCommand.get({ id: uuid })
+ expect(video.likes).to.equal(0)
+ expect(video.dislikes).to.equal(3)
}
}
})
// Updated rates of my video
{
- const res = await getVideo(servers[0].url, videoUUID1)
- expect(res.body.likes).to.equal(0)
- expect(res.body.dislikes).to.equal(2)
+ const video = await servers[0].videosCommand.get({ id: videoUUID1 })
+ expect(video.likes).to.equal(0)
+ expect(video.dislikes).to.equal(2)
}
// Did not update rates of a remote video
{
- const res = await getVideo(servers[0].url, videoUUID2)
- expect(res.body.likes).to.equal(0)
- expect(res.body.dislikes).to.equal(3)
+ const video = await servers[0].videosCommand.get({ id: videoUUID2 })
+ expect(video.likes).to.equal(0)
+ expect(video.dislikes).to.equal(3)
}
})
import 'mocha'
import * as chai from 'chai'
-import { VideoPlaylistPrivacy } from '@shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
doubleFollow,
makeActivityPubGetRequest,
ServerInfo,
setAccessTokensToServers,
- setDefaultVideoChannel,
- uploadVideoAndGetId
-} from '../../../../shared/extra-utils'
+ setDefaultVideoChannel
+} from '@shared/extra-utils'
+import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect
await setDefaultVideoChannel(servers)
{
- video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })
+ video = await await servers[0].videosCommand.quickUpload({ name: 'video' })
}
{
import 'mocha'
import * as chai from 'chai'
-import {
- cleanupTests,
- doubleFollow,
- flushAndRunMultipleServers,
- getVideosListSort,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo,
- waitJobs
-} from '../../../../shared/extra-utils'
-import { Video } from '../../../../shared/models/videos'
+import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
const expect = chai.expect
const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' })
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' })
- const badVideoUUID = res.body.video.uuid
- await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
+ await servers[0].videosCommand.upload({ attributes: { name: 'video root' } })
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'bad video root' } })
+ await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'video user' } })
{
const to = 'http://localhost:' + servers[0].port + '/accounts/user1'
}
{
- const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID
- await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value)
+ const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid
+ await servers[0].sqlCommand.setVideoField(uuid, 'url', value)
}
})
await waitJobs(servers)
{
- const res = await getVideosListSort(servers[0].url, 'createdAt')
- expect(res.body.total).to.equal(3)
+ const { total, data } = await servers[0].videosCommand.list({ sort: 'createdAt' })
- const data: Video[] = res.body.data
+ expect(total).to.equal(3)
expect(data[0].name).to.equal('video root')
expect(data[1].name).to.equal('bad video root')
expect(data[2].name).to.equal('video user')
}
{
- const res = await getVideosListSort(servers[1].url, 'createdAt')
- expect(res.body.total).to.equal(1)
+ const { total, data } = await servers[1].videosCommand.list({ sort: 'createdAt' })
- const data: Video[] = res.body.data
+ expect(total).to.equal(1)
expect(data[0].name).to.equal('video root')
}
})
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
killallServers,
reRunServer,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- uploadVideo,
- uploadVideoAndGetId,
wait,
waitJobs
} from '@shared/extra-utils'
await setDefaultVideoChannel(servers)
{
- videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid
- videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid
- videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid
+ videoUUID1 = (await servers[1].videosCommand.quickUpload({ name: 'video1' })).uuid
+ videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'video2' })).uuid
+ videoUUID3 = (await servers[1].videosCommand.quickUpload({ name: 'video3' })).uuid
}
{
- const a1 = await servers[1].usersCommand.generateUserAndToken('user1')
- await uploadVideo(servers[1].url, a1, { name: 'video4' })
+ const token1 = await servers[1].usersCommand.generateUserAndToken('user1')
+ await servers[1].videosCommand.upload({ token: token1, attributes: { name: 'video4' } })
- const a2 = await servers[1].usersCommand.generateUserAndToken('user2')
- await uploadVideo(servers[1].url, a2, { name: 'video5' })
+ const token2 = await servers[1].usersCommand.generateUserAndToken('user2')
+ await servers[1].videosCommand.upload({ token: token2, attributes: { name: 'video5' } })
}
{
// Change UUID so the remote server returns a 404
await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
- await getVideo(servers[0].url, videoUUID1)
- await getVideo(servers[0].url, videoUUID2)
+ await servers[0].videosCommand.get({ id: videoUUID1 })
+ await servers[0].videosCommand.get({ id: videoUUID2 })
await waitJobs(servers)
- await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
- await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
+ await servers[0].videosCommand.get({ id: videoUUID2 })
})
it('Should not update a remote video if the remote instance is down', async function () {
// Video will need a refresh
await wait(10000)
- await getVideo(servers[0].url, videoUUID3)
+ await servers[0].videosCommand.get({ id: videoUUID3 })
// The refresh should fail
await waitJobs([ servers[0] ])
await reRunServer(servers[1])
- await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.get({ id: videoUUID3 })
})
})
cleanupTests,
doubleFollow,
flushAndRunServer,
- getVideoIdFromUUID,
makeGetRequest,
makePostBodyRequest,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { AbuseCreate, AbuseState } from '@shared/models'
await setAccessTokensToServers([ server ])
- const username = 'user1'
- const password = 'my super password'
- await server.usersCommand.create({ username: username, password: password })
- userToken = await server.loginCommand.getAccessToken({ username, password })
-
+ userToken = await server.usersCommand.generateUserAndToken('user_1')
userToken2 = await server.usersCommand.generateUserAndToken('user_2')
- const res = await uploadVideo(server.url, server.accessToken, {})
- server.video = res.body.video
+ server.video = await server.videosCommand.upload()
command = server.abusesCommand
})
await doubleFollow(anotherServer, server)
- const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid)
+ const server2VideoId = await anotherServer.videosCommand.getId({ uuid: server.video.uuid })
await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId })
await waitJobs([ server, anotherServer ])
sendRTMPStream,
ServerInfo,
setAccessTokensToServers,
- stopFfmpeg,
- uploadVideoAndGetId
+ stopFfmpeg
} from '@shared/extra-utils'
import { VideoCreateResult, VideoPrivacy } from '@shared/models'
}
{
- videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
+ videoIdNotLive = (await server.videosCommand.quickUpload({ name: 'not live' })).id
}
command = server.liveCommand
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
makeDeleteRequest,
makeGetRequest,
makePostBodyRequest,
makePutBodyRequest,
ServerInfo,
setAccessTokensToServers,
- uploadVideoAndGetId,
waitJobs
} from '../../../../shared/extra-utils'
await servers[0].usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(user)
- videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
+ videoIdLocal = (await servers[0].videosCommand.quickUpload({ name: 'video' })).id
- const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid
+ const remoteUUID = (await servers[1].videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs(servers)
- const resVideo = await getVideo(servers[0].url, remoteUUID)
- videoRemote = resVideo.body
+ videoRemote = await servers[0].videosCommand.get({ id: remoteUUID })
})
describe('When listing redundancies', function () {
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
-import { VideoPlaylistPrivacy } from '@shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
flushAndRunServer,
makeGetRequest,
ServerInfo,
setAccessTokensToServers,
- setDefaultVideoChannel,
- uploadVideo
-} from '../../../../shared/extra-utils'
+ setDefaultVideoChannel
+} from '@shared/extra-utils'
+import { VideoPlaylistPrivacy } from '@shared/models'
describe('Test services API validators', function () {
let server: ServerInfo
await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ])
- {
- const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
- server.video = res.body.video
- }
+ server.video = await server.videosCommand.upload({ attributes: { name: 'my super name' } })
{
const created = await server.playlistsCommand.create({
import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode, randomInt } from '@shared/core-utils'
-import { VideoImportState, VideoPrivacy } from '@shared/models'
import {
cleanupTests,
flushAndRunServer,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- uploadVideo,
+ VideosCommand,
waitJobs
-} from '../../../../shared/extra-utils'
+} from '@shared/extra-utils'
+import { VideoImportState, VideoPrivacy } from '@shared/models'
describe('Test upload quota', function () {
let server: ServerInfo
let rootId: number
+ let command: VideosCommand
// ---------------------------------------------------------------
rootId = user.id
await server.usersCommand.update({ userId: rootId, videoQuota: 42 })
+
+ command = server.videosCommand
})
describe('When having a video quota', function () {
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
await server.usersCommand.register(user)
- const userAccessToken = await server.loginCommand.getAccessToken(user)
+ const userToken = await server.loginCommand.getAccessToken(user)
- const videoAttributes = { fixture: 'video_short2.webm' }
+ const attributes = { fixture: 'video_short2.webm' }
for (let i = 0; i < 5; i++) {
- await uploadVideo(server.url, userAccessToken, videoAttributes)
+ await command.upload({ token: userToken, attributes })
}
- await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
+ await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
})
it('Should fail with a registered user having too many videos with resumable upload', async function () {
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
await server.usersCommand.register(user)
- const userAccessToken = await server.loginCommand.getAccessToken(user)
+ const userToken = await server.loginCommand.getAccessToken(user)
- const videoAttributes = { fixture: 'video_short2.webm' }
+ const attributes = { fixture: 'video_short2.webm' }
for (let i = 0; i < 5; i++) {
- await uploadVideo(server.url, userAccessToken, videoAttributes)
+ await command.upload({ token: userToken, attributes })
}
- await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
+ await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
})
it('Should fail to import with HTTP/Torrent/magnet', async function () {
it('Should fail with a user having too many videos daily', async function () {
await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 })
- await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
- await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
+ await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
+ await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
})
})
videoQuotaDaily: 1024 * 1024 * 1024
})
- await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
- await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
+ await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
+ await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
})
it('Should fail if exceeding daily quota', async function () {
videoQuotaDaily: 42
})
- await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
- await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
+ await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
+ await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
})
})
import 'mocha'
import { omit } from 'lodash'
-import { UserRole, VideoCreateResult } from '../../../../shared'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
buildAbsoluteFixturePath,
+ checkBadCountPagination,
+ checkBadSortPagination,
+ checkBadStartPagination,
cleanupTests,
flushAndRunServer,
killallServers,
makePostBodyRequest,
makePutBodyRequest,
makeUploadRequest,
+ MockSmtpServer,
reRunServer,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
UsersCommand
-} from '../../../../shared/extra-utils'
-import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
-import {
- checkBadCountPagination,
- checkBadSortPagination,
- checkBadStartPagination
-} from '../../../../shared/extra-utils/requests/check-api-params'
-import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
+} from '@shared/extra-utils'
+import { UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models'
describe('Test users API validators', function () {
const path = '/api/v1/users/'
}
{
- const res = await uploadVideo(server.url, server.accessToken, {})
- video = res.body.video
+ video = await server.videosCommand.upload()
}
{
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
- getVideoWithToken,
makePostBodyRequest,
makePutBodyRequest,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
-import { VideoBlacklistType, VideoDetails } from '@shared/models'
+import { VideoBlacklistType } from '@shared/models'
describe('Test video blacklist API validators', function () {
let servers: ServerInfo[]
- let notBlacklistedVideoId: number
+ let notBlacklistedVideoId: string
let remoteVideoUUID: string
let userAccessToken1 = ''
let userAccessToken2 = ''
}
{
- const res = await uploadVideo(servers[0].url, userAccessToken1, {})
- servers[0].video = res.body.video
+ servers[0].video = await servers[0].videosCommand.upload({ token: userAccessToken1 })
}
{
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
- notBlacklistedVideoId = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload()
+ notBlacklistedVideoId = uuid
}
{
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
- remoteVideoUUID = res.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload()
+ remoteVideoUUID = uuid
}
await waitJobs(servers)
describe('When getting blacklisted video', function () {
it('Should fail with a non authenticated user', async function () {
- await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
+ await servers[0].videosCommand.get({ id: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail with another user', async function () {
- await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
+ await servers[0].videosCommand.getWithToken({
+ token: userAccessToken2,
+ id: servers[0].video.uuid,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
})
it('Should succeed with the owner authenticated user', async function () {
- const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200)
- const video: VideoDetails = res.body
-
+ const video = await servers[0].videosCommand.getWithToken({ token: userAccessToken1, id: servers[0].video.uuid })
expect(video.blacklisted).to.be.true
})
const video = servers[0].video
for (const id of [ video.id, video.uuid, video.shortUUID ]) {
- const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id, HttpStatusCode.OK_200)
- const video: VideoDetails = res.body
-
+ const video = await servers[0].videosCommand.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 })
expect(video.blacklisted).to.be.true
}
})
makeGetRequest,
makeUploadRequest,
ServerInfo,
- setAccessTokensToServers,
- uploadVideo
+ setAccessTokensToServers
} from '@shared/extra-utils'
import { VideoCreateResult } from '@shared/models'
await setAccessTokensToServers([ server ])
- {
- const res = await uploadVideo(server.url, server.accessToken, {})
- video = res.body.video
- }
+ video = await server.videosCommand.upload()
{
const user = {
makeGetRequest,
makePostBodyRequest,
ServerInfo,
- setAccessTokensToServers,
- uploadVideo
+ setAccessTokensToServers
} from '@shared/extra-utils'
import { VideoCreateResult } from '@shared/models'
await setAccessTokensToServers([ server ])
{
- const res = await uploadVideo(server.url, server.accessToken, {})
- video = res.body.video
+ const video = await server.videosCommand.upload({ attributes: {} })
pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
}
let anotherVideoUUID: string
{
- const res = await uploadVideo(server.url, userAccessToken, { name: 'video' })
- anotherVideoUUID = res.body.video.uuid
+ const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes: { name: 'video' } })
+ anotherVideoUUID = uuid
}
{
describe('When a video has comments disabled', function () {
before(async function () {
- const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
- video = res.body.video
+ video = await server.videosCommand.upload({ attributes: { commentsEnabled: false } })
pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
})
import 'mocha'
import { HttpStatusCode } from '@shared/core-utils'
-import {
- VideoPlaylistCreate,
- VideoPlaylistCreateResult,
- VideoPlaylistElementCreate,
- VideoPlaylistElementUpdate,
- VideoPlaylistPrivacy,
- VideoPlaylistReorder,
- VideoPlaylistType
-} from '@shared/models'
import {
checkBadCountPagination,
checkBadSortPagination,
PlaylistsCommand,
ServerInfo,
setAccessTokensToServers,
- setDefaultVideoChannel,
- uploadVideoAndGetId
-} from '../../../../shared/extra-utils'
+ setDefaultVideoChannel
+} from '@shared/extra-utils'
+import {
+ VideoPlaylistCreate,
+ VideoPlaylistCreateResult,
+ VideoPlaylistElementCreate,
+ VideoPlaylistElementUpdate,
+ VideoPlaylistPrivacy,
+ VideoPlaylistReorder,
+ VideoPlaylistType
+} from '@shared/models'
describe('Test video playlists API validator', function () {
let server: ServerInfo
await setDefaultVideoChannel([ server ])
userAccessToken = await server.usersCommand.generateUserAndToken('user1')
- videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id
+ videoId = (await server.videosCommand.quickUpload({ name: 'video 1' })).id
command = server.playlistsCommand
}
before(async function () {
- videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id
- videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id
+ videoId3 = (await server.videosCommand.quickUpload({ name: 'video 3' })).id
+ videoId4 = (await server.videosCommand.quickUpload({ name: 'video 4' })).id
for (const id of [ videoId3, videoId4 ]) {
await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } })
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
+import { HttpStatusCode } from '@shared/core-utils'
import {
checkBadCountPagination,
checkBadStartPagination,
makePostBodyRequest,
makePutBodyRequest,
ServerInfo,
- setAccessTokensToServers,
- uploadVideo
-} from '../../../../shared/extra-utils'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+ setAccessTokensToServers
+} from '@shared/extra-utils'
describe('Test videos history API validator', function () {
const myHistoryPath = '/api/v1/users/me/history/videos'
await setAccessTokensToServers([ server ])
- const res = await uploadVideo(server.url, server.accessToken, {})
- const videoUUID = res.body.video.uuid
-
- watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
+ const { uuid } = await server.videosCommand.upload()
+ watchingPath = '/api/v1/videos/' + uuid + '/watching'
})
describe('When notifying a user is watching a video', function () {
import * as chai from 'chai'
import { omit } from 'lodash'
import { join } from 'path'
-import { randomInt } from '@shared/core-utils'
-import { PeerTubeProblemDocument, VideoCreateResult } from '@shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode, randomInt } from '@shared/core-utils'
import {
+ checkBadCountPagination,
+ checkBadSortPagination,
+ checkBadStartPagination,
checkUploadVideoParam,
cleanupTests,
flushAndRunServer,
- getVideo,
- getVideosList,
makeDeleteRequest,
makeGetRequest,
makePutBodyRequest,
makeUploadRequest,
- removeVideo,
root,
ServerInfo,
setAccessTokensToServers
-} from '../../../../shared/extra-utils'
-import {
- checkBadCountPagination,
- checkBadSortPagination,
- checkBadStartPagination
-} from '../../../../shared/extra-utils/requests/check-api-params'
-import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
+} from '@shared/extra-utils'
+import { PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models'
const expect = chai.expect
it('Should fail with nothing', async function () {
const fields = {}
const attaches = {}
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail without name', async function () {
const fields = omit(baseCorrectParams, 'name')
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a long name', async function () {
const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a bad category', async function () {
const fields = { ...baseCorrectParams, category: 125 }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a bad licence', async function () {
const fields = { ...baseCorrectParams, licence: 125 }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a bad language', async function () {
const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a long description', async function () {
const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a long support text', async function () {
const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail without a channel', async function () {
const fields = omit(baseCorrectParams, 'channelId')
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a bad channel', async function () {
const fields = { ...baseCorrectParams, channelId: 545454 }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with another user channel', async function () {
const fields = { ...baseCorrectParams, channelId: customChannelId }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with too many tags', async function () {
const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a tag length too low', async function () {
const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a tag length too big', async function () {
const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a bad schedule update (miss updateAt)', async function () {
const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a bad schedule update (wrong updateAt)', async function () {
}
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with a bad originally published at attribute', async function () {
const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
const attaches = baseCorrectAttaches
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail without an input file', async function () {
const fields = baseCorrectParams
const attaches = {}
- await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
+ await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
})
it('Should fail with an incorrect input file', async function () {
let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
await checkUploadVideoParam(
- server.url,
+ server,
server.accessToken,
{ ...fields, ...attaches },
HttpStatusCode.UNPROCESSABLE_ENTITY_422,
attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
await checkUploadVideoParam(
- server.url,
+ server,
server.accessToken,
{ ...fields, ...attaches },
HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
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 () {
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 () {
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 () {
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 () {
const attaches = baseCorrectAttaches
const attributes = { ...fields, ...attaches }
- const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
+ const body = await checkUploadVideoParam(server, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
- const error = res.body as PeerTubeProblemDocument
+ const error = body as unknown as PeerTubeProblemDocument
if (mode === 'legacy') {
expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy')
{
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)
}
{
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)
}
{
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)
}
})
}
}
before(async function () {
- const res = await getVideosList(server.url)
- video = res.body.data[0]
+ const { data } = await server.videosCommand.list()
+ video = data[0]
})
it('Should fail with nothing', async function () {
})
it('Should fail without a correct uuid', async function () {
- await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
+ await server.videosCommand.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should return 404 with an incorrect video', async function () {
- await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
+ await server.videosCommand.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Shoud report the appropriate error', async function () {
- const res = await getVideo(server.url, 'hi', HttpStatusCode.BAD_REQUEST_400)
- const error = res.body as PeerTubeProblemDocument
+ const body = await server.videosCommand.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+ const error = body as unknown as PeerTubeProblemDocument
expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo')
})
it('Should succeed with the correct parameters', async function () {
- await getVideo(server.url, video.shortUUID)
+ await server.videosCommand.get({ id: video.shortUUID })
})
})
describe('When rating a video', function () {
- let videoId
+ let videoId: number
before(async function () {
- const res = await getVideosList(server.url)
- videoId = res.body.data[0].id
+ const { data } = await server.videosCommand.list()
+ videoId = data[0].id
})
it('Should fail without a valid uuid', async function () {
})
it('Should fail without a correct uuid', async function () {
- await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
+ await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should fail with a video which does not exist', async function () {
- await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
+ await server.videosCommand.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should fail with a video of another user without the appropriate right', async function () {
- await removeVideo(server.url, userAccessToken, video.uuid, HttpStatusCode.FORBIDDEN_403)
+ await server.videosCommand.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should fail with a video of another server')
it('Shoud report the appropriate error', async function () {
- const res = await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
- const error = res.body as PeerTubeProblemDocument
+ const body = await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+ const error = body as unknown as PeerTubeProblemDocument
expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo')
})
it('Should succeed with the correct parameters', async function () {
- await removeVideo(server.url, server.accessToken, video.uuid)
+ await server.videosCommand.remove({ id: video.uuid })
})
})
import 'mocha'
import * as chai from 'chai'
-import { VideoDetails, VideoPrivacy } from '@shared/models'
+import { VideoPrivacy } from '@shared/models'
import {
checkLiveCleanup,
cleanupTests,
ConfigCommand,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
for (const server of servers) {
- const res = await getVideo(server.url, videoId)
-
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: videoId })
expect(video.isLive).to.be.false
expect(video.duration).to.be.greaterThan(0)
}
import 'mocha'
import * as chai from 'chai'
-import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
+import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
import {
cleanupTests,
ConfigCommand,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
async function checkVideoState (videoId: string, state: VideoState) {
for (const server of servers) {
- const res = await getVideo(server.url, videoId)
- expect((res.body as VideoDetails).state.id).to.equal(state)
+ const video = await server.videosCommand.get({ id: videoId })
+ expect(video.state.id).to.equal(state)
}
}
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
-
- const videoDetails = res.body as VideoDetails
+ const videoDetails = await server.videosCommand.get({ id: videoUUID })
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
}
})
import 'mocha'
import * as chai from 'chai'
import { FfmpegCommand } from 'fluent-ffmpeg'
-import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
checkLiveCleanup,
cleanupTests,
ConfigCommand,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
- getVideosList,
- removeVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
stopFfmpeg,
testFfmpegStreamError,
- updateVideo,
wait,
waitJobs
-} from '../../../../shared/extra-utils'
+} from '@shared/extra-utils'
+import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
const expect = chai.expect
async function createLiveWrapper (saveReplay: boolean) {
if (liveVideoUUID) {
try {
- await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
+ await servers[0].videosCommand.remove({ id: liveVideoUUID })
await waitJobs(servers)
} catch {}
}
return uuid
}
- async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) {
+ async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) {
for (const server of servers) {
const length = existsInList ? 1 : 0
- const resVideos = await getVideosList(server.url)
- expect(resVideos.body.data).to.have.lengthOf(length)
- expect(resVideos.body.total).to.equal(length)
+ const { data, total } = await server.videosCommand.list()
+ expect(data).to.have.lengthOf(length)
+ expect(total).to.equal(length)
- if (getStatus) {
- await getVideo(server.url, videoId, getStatus)
+ if (expectedStatus) {
+ await server.videosCommand.get({ id: videoId, expectedStatus })
}
}
}
async function checkVideoState (videoId: string, state: VideoState) {
for (const server of servers) {
- const res = await getVideo(server.url, videoId)
- expect((res.body as VideoDetails).state.id).to.equal(state)
+ const video = await server.videosCommand.get({ id: videoId })
+ expect(video.state.id).to.equal(state)
}
}
await checkVideosExist(liveVideoUUID, false)
- await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
- await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
+ await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await wait(5000)
await waitJobs(servers)
await Promise.all([
testFfmpegStreamError(ffmpegCommand, true),
- removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
+ servers[0].videosCommand.remove({ id: liveVideoUUID })
])
await wait(5000)
it('Should update the saved live and correctly federate the updated attributes', async function () {
this.timeout(30000)
- await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' })
+ await servers[0].videosCommand.update({ id: liveVideoUUID, attributes: { name: 'video updated' } })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, liveVideoUUID)
- expect(res.body.name).to.equal('video updated')
- expect(res.body.isLive).to.be.false
+ const video = await server.videosCommand.get({ id: liveVideoUUID })
+ expect(video.name).to.equal('video updated')
+ expect(video.isLive).to.be.false
}
})
await checkVideosExist(liveVideoUUID, false)
- await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
- await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
+ await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await wait(5000)
await waitJobs(servers)
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([
- removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID),
+ servers[0].videosCommand.remove({ id: liveVideoUUID }),
testFfmpegStreamError(ffmpegCommand, true)
])
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideoIdFromUUID,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
stopFfmpeg,
- viewVideo,
wait,
waitJobs,
waitUntilLivePublishedOnAllServers
await waitJobs(servers)
{
- const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
+ const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
localSocket.on('state-change', data => localStateChanges.push(data.state))
}
{
- const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
+ const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID })
const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
remoteSocket.on('state-change', data => remoteStateChanges.push(data.state))
await waitJobs(servers)
{
- const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
+ const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
localSocket.on('views-change', data => { localLastVideoViews = data.views })
}
{
- const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
+ const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID })
const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views })
expect(localLastVideoViews).to.equal(0)
expect(remoteLastVideoViews).to.equal(0)
- await viewVideo(servers[0].url, liveVideoUUID)
- await viewVideo(servers[1].url, liveVideoUUID)
+ await servers[0].videosCommand.view({ id: liveVideoUUID })
+ await servers[1].videosCommand.view({ id: liveVideoUUID })
await waitJobs(servers)
await wait(5000)
const liveVideoUUID = await createLiveWrapper()
await waitJobs(servers)
- const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
+ const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
const socket = servers[0].socketIOCommand.getLiveNotificationSocket()
socket.on('state-change', data => stateChanges.push(data.state))
import 'mocha'
import * as chai from 'chai'
import { FfmpegCommand } from 'fluent-ffmpeg'
-import { VideoDetails, VideoPrivacy } from '@shared/models'
+import { VideoPrivacy } from '@shared/models'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
stopFfmpeg,
- viewVideo,
wait,
waitJobs,
waitUntilLivePublishedOnAllServers
async function countViews (expected: number) {
for (const server of servers) {
- const res = await getVideo(server.url, liveVideoId)
- const video: VideoDetails = res.body
-
+ const video = await server.videosCommand.get({ id: liveVideoId })
expect(video.views).to.equal(expected)
}
}
it('Should view a live twice and display 1 view', async function () {
this.timeout(30000)
- await viewVideo(servers[0].url, liveVideoId)
- await viewVideo(servers[0].url, liveVideoId)
+ await servers[0].videosCommand.view({ id: liveVideoId })
+ await servers[0].videosCommand.view({ id: liveVideoId })
await wait(7000)
it('Should view a live on a remote and on local and display 2 views', async function () {
this.timeout(30000)
- await viewVideo(servers[0].url, liveVideoId)
- await viewVideo(servers[1].url, liveVideoId)
- await viewVideo(servers[1].url, liveVideoId)
+ await servers[0].videosCommand.view({ id: liveVideoId })
+ await servers[1].videosCommand.view({ id: liveVideoId })
+ await servers[1].videosCommand.view({ id: liveVideoId })
await wait(7000)
await waitJobs(servers)
import * as chai from 'chai'
import { join } from 'path'
import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
-import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
checkLiveCleanup,
checkLiveSegmentHash,
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getMyVideosWithFilter,
- getVideo,
- getVideosList,
- getVideosWithFilters,
killallServers,
LiveCommand,
makeRawRequest,
- removeVideo,
reRunServer,
sendRTMPStream,
ServerInfo,
stopFfmpeg,
testFfmpegStreamError,
testImage,
- uploadVideoAndGetId,
wait,
waitJobs,
waitUntilLivePublishedOnAllServers
-} from '../../../../shared/extra-utils'
+} from '@shared/extra-utils'
+import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
const expect = chai.expect
await waitJobs(servers)
for (const server of servers) {
- const resVideo = await getVideo(server.url, liveVideoUUID)
- const video: VideoDetails = resVideo.body
+ const video = await server.videosCommand.get({ id: liveVideoUUID })
expect(video.category.id).to.equal(1)
expect(video.licence.id).to.equal(2)
await waitJobs(servers)
for (const server of servers) {
- const resVideo = await getVideo(server.url, videoId)
- const video: VideoDetails = resVideo.body
-
+ const video = await server.videosCommand.get({ id: videoId })
expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
expect(video.nsfw).to.be.true
it('Should not have the live listed since nobody streams into', async function () {
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { total, data } = await server.videosCommand.list()
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
}
})
it('Delete the live', async function () {
this.timeout(10000)
- await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
+ await servers[0].videosCommand.remove({ id: liveVideoUUID })
await waitJobs(servers)
})
it('Should have the live deleted', async function () {
for (const server of servers) {
- await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
+ await server.videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}
})
before(async function () {
this.timeout(120000)
- vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid
+ vodVideoId = (await servers[0].videosCommand.quickUpload({ name: 'vod video' })).uuid
const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id }
const live = await commands[0].create({ fields: liveOptions })
})
it('Should only display lives', async function () {
- const res = await getVideosWithFilters(servers[0].url, { isLive: true })
+ const { data, total } = await servers[0].videosCommand.list({ isLive: true })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
- expect(res.body.data[0].name).to.equal('live')
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].name).to.equal('live')
})
it('Should not display lives', async function () {
- const res = await getVideosWithFilters(servers[0].url, { isLive: false })
+ const { data, total } = await servers[0].videosCommand.list({ isLive: false })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
- expect(res.body.data[0].name).to.equal('vod video')
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].name).to.equal('vod video')
})
it('Should display my lives', async function () {
await stopFfmpeg(ffmpegCommand)
await waitJobs(servers)
- const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true })
- const videos = res.body.data as Video[]
+ const { data } = await servers[0].videosCommand.listMyVideos({ isLive: true })
- const result = videos.every(v => v.isLive)
+ const result = data.every(v => v.isLive)
expect(result).to.be.true
})
it('Should not display my lives', async function () {
- const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: false })
- const videos = res.body.data as Video[]
+ const { data } = await servers[0].videosCommand.listMyVideos({ isLive: false })
- const result = videos.every(v => !v.isLive)
+ const result = data.every(v => !v.isLive)
expect(result).to.be.true
})
after(async function () {
- await removeVideo(servers[0].url, servers[0].accessToken, vodVideoId)
- await removeVideo(servers[0].url, servers[0].accessToken, liveVideoId)
+ await servers[0].videosCommand.remove({ id: vodVideoId })
+ await servers[0].videosCommand.remove({ id: liveVideoId })
})
})
const { uuid } = await commands[0].create({ fields: liveAttributes })
const live = await commands[0].get({ videoId: uuid })
- const resVideo = await getVideo(servers[0].url, uuid)
+ const video = await servers[0].videosCommand.get({ id: uuid })
- return Object.assign(resVideo.body as VideoDetails, live)
+ return Object.assign(video, live)
}
it('Should not allow a stream without the appropriate path', async function () {
it('Should list this live now someone stream into it', async function () {
for (const server of servers) {
- const res = await getVideosList(server.url)
-
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ const { total, data } = await server.videosCommand.list()
- const video: Video = res.body.data[0]
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
+ const video = data[0]
expect(video.name).to.equal('user live')
expect(video.isLive).to.be.true
}
liveVideo = await createLiveWrapper()
- await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid)
+ await servers[0].videosCommand.remove({ id: liveVideo.uuid })
const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
await testFfmpegStreamError(command, true)
async function testVideoResolutions (liveVideoId: string, resolutions: number[]) {
for (const server of servers) {
- const resList = await getVideosList(server.url)
- const videos: Video[] = resList.body.data
-
- expect(videos.find(v => v.uuid === liveVideoId)).to.exist
+ const { data } = await server.videosCommand.list()
+ expect(data.find(v => v.uuid === liveVideoId)).to.exist
- const resVideo = await getVideo(server.url, liveVideoId)
- const video: VideoDetails = resVideo.body
+ const video = await server.videosCommand.get({ id: liveVideoId })
expect(video.streamingPlaylists).to.have.lengthOf(1)
}
for (const server of servers) {
- const resVideo = await getVideo(server.url, liveVideoId)
- const video: VideoDetails = resVideo.body
+ const video = await server.videosCommand.get({ id: liveVideoId })
expect(video.state.id).to.equal(VideoState.PUBLISHED)
expect(video.duration).to.be.greaterThan(1)
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideoIdFromUUID,
- getVideosList,
- removeVideo,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
- uploadVideoAndGetId,
waitJobs
} from '@shared/extra-utils'
import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
this.timeout(50000)
// Upload some videos on each servers
- const video1Attributes = {
- name: 'my super name for server 1',
- description: 'my super description for server 1'
+ {
+ const attributes = {
+ name: 'my super name for server 1',
+ description: 'my super description for server 1'
+ }
+ await servers[0].videosCommand.upload({ attributes })
}
- await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
- const video2Attributes = {
- name: 'my super name for server 2',
- description: 'my super description for server 2'
+ {
+ const attributes = {
+ name: 'my super name for server 2',
+ description: 'my super description for server 2'
+ }
+ await servers[1].videosCommand.upload({ attributes })
}
- await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
// Wait videos propagation, server 2 has transcoding enabled
await waitJobs(servers)
- const res = await getVideosList(servers[0].url)
- const videos = res.body.data
-
- expect(videos.length).to.equal(2)
+ const { data } = await servers[0].videosCommand.list()
+ expect(data.length).to.equal(2)
- servers[0].video = videos.find(video => video.name === 'my super name for server 1')
- servers[1].video = videos.find(video => video.name === 'my super name for server 2')
+ servers[0].video = data.find(video => video.name === 'my super name for server 1')
+ servers[1].video = data.find(video => video.name === 'my super name for server 2')
})
it('Should not have abuses', async function () {
this.timeout(10000)
const reason = 'my super bad reason 2'
- const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
+ const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid })
await commands[0].report({ videoId, reason })
// We wait requests propagation
this.timeout(10000)
{
- const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
+ const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid })
await commands[1].report({ videoId, reason: 'will mute this' })
await waitJobs(servers)
it('Should keep the video abuse when deleting the video', async function () {
this.timeout(10000)
- await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
+ await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid })
await waitJobs(servers)
const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
// upload a third video via this user
- const video3Attributes = {
+ const attributes = {
name: 'my second super name for server 1',
description: 'my second super description for server 1'
}
- const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
- const video3Id = resUpload.body.video.id
+ const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
+ const video3Id = id
// resume with the test
const reason3 = 'my super bad reason 3'
async function getComment (server: ServerInfo, videoIdArg: number | string) {
const videoId = typeof videoIdArg === 'string'
- ? await getVideoIdFromUUID(server.url, videoIdArg)
+ ? await server.videosCommand.getId({ uuid: videoIdArg })
: videoIdArg
const { data } = await server.commentsCommand.listThreads({ videoId })
before(async function () {
this.timeout(50000)
- servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
- servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
+ servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' })
+ servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' })
await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' })
const token = await servers[1].usersCommand.generateUserAndToken('user_2')
- await uploadVideo(servers[1].url, token, { name: 'super video' })
+ await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } })
await waitJobs(servers)
})
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' })
})
import 'mocha'
import * as chai from 'chai'
-import {
- cleanupTests,
- doubleFollow,
- flushAndRunMultipleServers,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo,
- waitJobs
-} from '@shared/extra-utils'
+import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
import { UserNotificationType } from '@shared/models'
const expect = chai.expect
await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
{
- const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
- videoUUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } })
+ videoUUID = uuid
await waitJobs(servers)
}
})
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' } })
}
{
CommentsCommand,
doubleFollow,
flushAndRunMultipleServers,
- getVideosList,
- getVideosListWithToken,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
-import { UserNotificationType, Video } from '@shared/models'
+import { UserNotificationType } from '@shared/models'
const expect = chai.expect
async function checkAllVideos (server: ServerInfo, token: string) {
{
- const res = await getVideosListWithToken(server.url, token)
-
- expect(res.body.data).to.have.lengthOf(5)
+ const { data } = await server.videosCommand.listWithToken({ token })
+ expect(data).to.have.lengthOf(5)
}
{
- const res = await getVideosList(server.url)
-
- expect(res.body.data).to.have.lengthOf(5)
+ const { data } = await server.videosCommand.list()
+ expect(data).to.have.lengthOf(5)
}
}
await servers[0].usersCommand.create({ username: user.username, password: user.password })
userToken1 = await servers[0].loginCommand.getAccessToken(user)
- await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
+ await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } })
}
{
await servers[1].usersCommand.create({ username: user.username, password: user.password })
userToken2 = await servers[1].loginCommand.getAccessToken(user)
- await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
+ await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } })
}
{
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
- videoUUID1 = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } })
+ videoUUID1 = uuid
}
{
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
- videoUUID2 = res.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } })
+ videoUUID2 = uuid
}
{
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
- videoUUID3 = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } })
+ videoUUID3 = uuid
}
await doubleFollow(servers[0], servers[1])
})
it('Should hide its videos', async function () {
- const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+ const { data } = await servers[0].videosCommand.listWithToken()
- const videos: Video[] = res.body.data
- expect(videos).to.have.lengthOf(4)
+ expect(data).to.have.lengthOf(4)
- const v = videos.find(v => v.name === 'video user 2')
+ const v = data.find(v => v.name === 'video user 2')
expect(v).to.be.undefined
})
})
it('Should hide its videos', async function () {
- const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+ const { data } = await servers[0].videosCommand.listWithToken()
- const videos: Video[] = res.body.data
- expect(videos).to.have.lengthOf(3)
+ expect(data).to.have.lengthOf(3)
- const v = videos.find(v => v.name === 'video user 1')
+ const v = data.find(v => v.name === 'video user 1')
expect(v).to.be.undefined
})
})
it('Should display its videos', async function () {
- const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+ const { data } = await servers[0].videosCommand.listWithToken()
+ expect(data).to.have.lengthOf(4)
- const videos: Video[] = res.body.data
- expect(videos).to.have.lengthOf(4)
-
- const v = videos.find(v => v.name === 'video user 2')
+ const v = data.find(v => v.name === 'video user 2')
expect(v).not.to.be.undefined
})
})
it('Should hide its videos', async function () {
- const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+ const { data } = await servers[0].videosCommand.listWithToken()
- const videos: Video[] = res.body.data
- expect(videos).to.have.lengthOf(3)
+ expect(data).to.have.lengthOf(3)
- const v1 = videos.find(v => v.name === 'video user 2')
- const v2 = videos.find(v => v.name === 'video server 2')
+ const v1 = data.find(v => v.name === 'video user 2')
+ const v2 = data.find(v => v.name === 'video server 2')
expect(v1).to.be.undefined
expect(v2).to.be.undefined
it('Should hide its videos', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
- const res = await getVideosListWithToken(servers[0].url, token)
+ const { data } = await servers[0].videosCommand.listWithToken({ token })
- const videos: Video[] = res.body.data
- expect(videos).to.have.lengthOf(4)
+ expect(data).to.have.lengthOf(4)
- const v = videos.find(v => v.name === 'video user 2')
+ const v = data.find(v => v.name === 'video user 2')
expect(v).to.be.undefined
}
})
it('Should hide its videos', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
- const res = await getVideosListWithToken(servers[0].url, token)
+ const { data } = await servers[0].videosCommand.listWithToken({ token })
- const videos: Video[] = res.body.data
- expect(videos).to.have.lengthOf(3)
+ expect(data).to.have.lengthOf(3)
- const v = videos.find(v => v.name === 'video user 1')
+ const v = data.find(v => v.name === 'video user 1')
expect(v).to.be.undefined
}
})
it('Should display its videos', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
- const res = await getVideosListWithToken(servers[0].url, token)
-
- const videos: Video[] = res.body.data
- expect(videos).to.have.lengthOf(4)
+ const { data } = await servers[0].videosCommand.listWithToken({ token })
+ expect(data).to.have.lengthOf(4)
- const v = videos.find(v => v.name === 'video user 2')
+ const v = data.find(v => v.name === 'video user 2')
expect(v).not.to.be.undefined
}
})
it('Should hide its videos', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
- const res1 = await getVideosList(servers[0].url)
- const res2 = await getVideosListWithToken(servers[0].url, token)
+ const requests = [
+ servers[0].videosCommand.list(),
+ servers[0].videosCommand.listWithToken({ token })
+ ]
- for (const res of [ res1, res2 ]) {
- const videos: Video[] = res.body.data
- expect(videos).to.have.lengthOf(3)
+ for (const req of requests) {
+ const { data } = await req
+ expect(data).to.have.lengthOf(3)
- const v1 = videos.find(v => v.name === 'video user 2')
- const v2 = videos.find(v => v.name === 'video server 2')
+ const v1 = data.find(v => v.name === 'video user 2')
+ const v2 = data.find(v => v.name === 'video server 2')
expect(v1).to.be.undefined
expect(v2).to.be.undefined
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getMyVideos,
- getVideosList,
ImportsCommand,
killallServers,
reRunServer,
ServerInfo,
setAccessTokensToServers,
- updateVideo,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
let command: BlacklistCommand
async function blacklistVideosOnServer (server: ServerInfo) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const videos = res.body.data
- for (const video of videos) {
+ for (const video of data) {
await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' })
}
}
await doubleFollow(servers[0], servers[1])
// Upload 2 videos on server 2
- await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
- await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
+ await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } })
+ await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } })
// Wait videos propagation, server 2 has transcoding enabled
await waitJobs(servers)
it('Should not have the video blacklisted in videos list/search on server 1', async function () {
{
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videosCommand.list()
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data.length).to.equal(0)
+ expect(total).to.equal(0)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(0)
}
{
it('Should have the blacklisted video in videos list/search on server 2', async function () {
{
- const res = await getVideosList(servers[1].url)
+ const { total, data } = await servers[1].videosCommand.list()
- expect(res.body.total).to.equal(2)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data.length).to.equal(2)
+ expect(total).to.equal(2)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(2)
}
{
it('Should display blacklisted videos', async function () {
await blacklistVideosOnServer(servers[1])
- const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
+ const { total, data } = await servers[1].videosCommand.listMyVideos()
- expect(res.body.total).to.equal(2)
- expect(res.body.data).to.have.lengthOf(2)
+ expect(total).to.equal(2)
+ expect(data).to.have.lengthOf(2)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.blacklisted).to.be.true
expect(video.blacklistedReason).to.equal('super reason')
}
let blacklist = []
it('Should not have any video in videos list on server 1', async function () {
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data.length).to.equal(0)
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(0)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(0)
})
it('Should remove a video from the blacklist on server 1', async function () {
})
it('Should have the ex-blacklisted video in videos list on server 1', async function () {
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(1)
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(1)
- const videos = res.body.data
- expect(videos).to.be.an('array')
- expect(videos.length).to.equal(1)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(1)
- expect(videos[0].name).to.equal(videoToRemove.video.name)
- expect(videos[0].id).to.equal(videoToRemove.video.id)
+ expect(data[0].name).to.equal(videoToRemove.video.name)
+ expect(data[0].id).to.equal(videoToRemove.video.id)
})
it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
this.timeout(10000)
{
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' })
- video3UUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } })
+ video3UUID = uuid
}
{
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' })
- video4UUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } })
+ video4UUID = uuid
}
await waitJobs(servers)
await waitJobs(servers)
{
- const res = await getVideosList(servers[0].url)
- expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined
+ const { data } = await servers[0].videosCommand.list()
+ expect(data.find(v => v.uuid === video3UUID)).to.be.undefined
}
{
- const res = await getVideosList(servers[1].url)
- expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined
+ const { data } = await servers[1].videosCommand.list()
+ expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
+ const { data } = await server.videosCommand.list()
+ expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
}
})
it('Should have the video unfederated even after an Update AP message', async function () {
this.timeout(10000)
- await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' })
+ await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
+ const { data } = await server.videosCommand.list()
+ expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined
+ const { data } = await server.videosCommand.list()
+ expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined
}
})
})
it('Should auto blacklist a video on upload', async function () {
- await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
+ await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } })
const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
expect(body.total).to.equal(1)
})
it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
- await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
+ await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } })
const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
expect(body.total).to.equal(3)
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { UserNotification } from '@shared/models'
it('Should not send a new comment notification after a comment on another video', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
it('Should not send a new comment notification if I comment my own video', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
const commentId = created.id
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
- const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
it('Should send a new comment notification after a local comment on my video', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
it('Should send a new comment notification after a remote comment on my video', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
await waitJobs(servers)
it('Should send a new comment notification after a local reply on my video', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
it('Should send a new comment notification after a remote reply on my video', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
await waitJobs(servers)
{
it('Should convert markdown in comment to html', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'cool video' } })
await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText })
it('Should not send a new mention comment notification if I mention the video owner', async function () {
this.timeout(10000)
- const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
it('Should not send a new mention comment notification if I mention myself', async function () {
this.timeout(10000)
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
it('Should not send a new mention notification if the remote account mention a local account', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
await waitJobs(servers)
const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
it('Should send a new mention notification after local comments', async function () {
this.timeout(10000)
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
it('Should send a new mention notification after remote comments', async function () {
this.timeout(20000)
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
await waitJobs(servers)
it('Should convert markdown in comment to html', async function () {
this.timeout(10000)
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' })
checkVideoAutoBlacklistForModerators,
checkVideoIsPublished,
cleanupTests,
- getVideoIdFromUUID,
MockInstancesIndex,
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
- uploadVideo,
wait,
waitJobs
} from '@shared/extra-utils'
this.timeout(20000)
const name = 'video for abuse ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
- const video = resVideo.body.video
+ const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' })
this.timeout(20000)
const name = 'video for abuse ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
- const video = resVideo.body.video
+ const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
await waitJobs(servers)
- const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid)
+ const videoId = await servers[1].videosCommand.getId({ uuid: video.uuid })
await servers[1].abusesCommand.report({ videoId, reason: 'super reason' })
await waitJobs(servers)
this.timeout(20000)
const name = 'video for abuse ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
- const video = resVideo.body.video
+ const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const comment = await servers[0].commentsCommand.createThread({
token: userAccessToken,
videoId: video.id,
this.timeout(20000)
const name = 'video for abuse ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
- const video = resVideo.body.video
+ const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
await servers[0].commentsCommand.createThread({
token: userAccessToken,
const username = 'user' + new Date().getTime()
const tmpToken = await servers[0].usersCommand.generateUserAndToken(username)
- await uploadVideo(servers[0].url, tmpToken, { name: 'super video' })
+ await servers[0].videosCommand.upload({ token: tmpToken, attributes: { name: 'super video' } })
await waitJobs(servers)
}
const name = 'abuse ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
- const video = resVideo.body.video
+ const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
abuseId = body.abuse.id
}
const name = 'abuse ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
- const video = resVideo.body.video
+ const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
{
const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
this.timeout(10000)
const name = 'video for abuse ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
await servers[0].blacklistCommand.add({ videoId: uuid })
this.timeout(10000)
const name = 'video for abuse ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
await servers[0].blacklistCommand.add({ videoId: uuid })
this.timeout(40000)
videoName = 'video with auto-blacklist ' + buildUUID()
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
- videoUUID = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: videoName } })
+ videoUUID = uuid
await waitJobs(servers)
await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
const name = 'video with auto-blacklist and future schedule ' + buildUUID()
- const data = {
+ const attributes = {
name,
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
updateAt: updateAt.toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
await servers[0].blacklistCommand.remove({ videoId: uuid })
const name = 'video with schedule done and still auto-blacklisted ' + buildUUID()
- const data = {
+ const attributes = {
name,
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
updateAt: updateAt.toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
await wait(6000)
await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
const name = 'video without auto-blacklist ' + buildUUID()
// admin with blacklist right will not be auto-blacklisted
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
- const uuid = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name } })
await waitJobs(servers)
await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
- uploadRandomVideo,
waitJobs
} from '@shared/extra-utils'
import { UserNotification, UserNotificationSettingValue } from '@shared/models'
await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
for (let i = 0; i < 10; i++) {
- await uploadRandomVideo(server, false)
+ await server.videosCommand.randomUpload({ wait: false })
}
await waitJobs([ server ])
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
}
- const { name, uuid } = await uploadRandomVideo(server)
+ const { name, uuid } = await server.videosCommand.randomUpload()
const check = { web: true, mail: true }
await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
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 }
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 { name, uuid } = await uploadRandomVideo(server)
+ const { name, uuid } = await server.videosCommand.randomUpload()
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
})
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
- updateVideo,
uploadRandomVideoOnServers,
wait,
waitJobs
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
updateAt: updateAt.toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
updateAt: updateAt.toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
updateAt: updateAt.toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
- await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
+ await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
- await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
+ await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
const data = { privacy: VideoPrivacy.PRIVATE }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
- await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
+ await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
})
const data = { privacy: VideoPrivacy.PRIVATE }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
- await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
+ await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
updateAt: updateAt.toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
updateAt: updateAt.toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getLocalIdByUUID,
RedundancyCommand,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
- uploadVideoAndGetId,
waitJobs
} from '@shared/extra-utils'
import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
commands = servers.map(s => s.redundancyCommand)
{
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
- video1Server2UUID = res.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
+ video1Server2UUID = uuid
}
{
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' })
- video2Server2UUID = res.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2' } })
+ video2Server2UUID = uuid
}
await waitJobs(servers)
it('Should manually add a redundancy and list it', async function () {
this.timeout(120000)
- const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
+ const uuid = (await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
await waitJobs(servers)
- const videoId = await getLocalIdByUUID(servers[0].url, uuid)
+ const videoId = await servers[0].videosCommand.getId({ uuid })
await commands[0].addVideo({ videoId })
reRunServer,
ServerInfo,
setAccessTokensToServers,
- updateVideo,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models'
async function uploadWrapper (videoName: string) {
// Wait for transcoding
- const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
+ const { id } = await localServer.videosCommand.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
await waitJobs([ localServer ])
// Update video to schedule a federation
- await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
+ await localServer.videosCommand.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
}
async function getTotalRedundanciesLocalServer () {
// Get the access tokens
await setAccessTokensToServers(servers)
- await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' })
+ await localServer.videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
await waitJobs(servers)
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
- getVideoWithToken,
killallServers,
makeGetRequest,
- removeVideo,
reRunServer,
root,
ServerInfo,
setAccessTokensToServers,
- updateVideo,
- uploadVideo,
- viewVideo,
wait,
waitJobs
} from '@shared/extra-utils'
-import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models'
+import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models'
const expect = chai.expect
await setAccessTokensToServers(servers)
{
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
- video1Server2UUID = res.body.video.uuid
- video1Server2Id = res.body.video.id
+ const { uuid, id } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
+ video1Server2UUID = uuid
+ video1Server2Id = id
- await viewVideo(servers[1].url, video1Server2UUID)
+ await servers[1].videosCommand.view({ id: video1Server2UUID })
}
await waitJobs(servers)
for (const server of servers) {
// With token to avoid issues with video follow constraints
- const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
+ const video = await server.videosCommand.getWithToken({ id: videoUUID })
- const video: VideoDetails = res.body
for (const f of video.files) {
checkMagnetWebseeds(f, webseeds, server)
}
]
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
-
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: videoUUID })
for (const file of video.files) {
checkMagnetWebseeds(file, webseeds, server)
for (const server of servers) {
// With token to avoid issues with video follow constraints
- const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.getWithToken({ id: videoUUID })
expect(video.streamingPlaylists).to.be.an('array')
expect(video.streamingPlaylists).to.have.lengthOf(1)
if (!videoUUID) videoUUID = video1Server2UUID
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: videoUUID })
expect(video.streamingPlaylists).to.have.lengthOf(1)
expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1)
const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls'
const baseUrlSegment = servers[0].url + '/static/redundancy/hls'
- const res = await getVideo(servers[0].url, videoUUID)
- const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0]
+ const video = await servers[0].videosCommand.get({ id: videoUUID })
+ const hlsPlaylist = video.streamingPlaylists[0]
for (const resolution of [ 240, 360, 480, 720 ]) {
await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist })
it('Should view 2 times the first video to have > min_views config', async function () {
this.timeout(80000)
- await viewVideo(servers[0].url, video1Server2UUID)
- await viewVideo(servers[2].url, video1Server2UUID)
+ await servers[0].videosCommand.view({ id: video1Server2UUID })
+ await servers[2].videosCommand.view({ id: video1Server2UUID })
await wait(10000)
await waitJobs(servers)
it('Should remove the video and the redundancy files', async function () {
this.timeout(20000)
- await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID)
+ await servers[1].videosCommand.remove({ id: video1Server2UUID })
await waitJobs(servers)
it('Should have 1 redundancy on the first video', async function () {
this.timeout(160000)
- await viewVideo(servers[0].url, video1Server2UUID)
- await viewVideo(servers[2].url, video1Server2UUID)
+ await servers[0].videosCommand.view({ id: video1Server2UUID })
+ await servers[2].videosCommand.view({ id: video1Server2UUID })
await wait(10000)
await waitJobs(servers)
it('Should remove the video and the redundancy files', async function () {
this.timeout(20000)
- await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID)
+ await servers[1].videosCommand.remove({ id: video1Server2UUID })
await waitJobs(servers)
async function checkContains (servers: ServerInfo[], str: string) {
for (const server of servers) {
- const res = await getVideo(server.url, video1Server2UUID)
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: video1Server2UUID })
for (const f of video.files) {
expect(f.magnetUri).to.contain(str)
async function checkNotContains (servers: ServerInfo[], str: string) {
for (const server of servers) {
- const res = await getVideo(server.url, video1Server2UUID)
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: video1Server2UUID })
for (const f of video.files) {
expect(f.magnetUri).to.not.contain(str)
await check1PlaylistRedundancies(video1Server2UUID)
await checkStatsWith1Redundancy(strategy)
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE })
- video2Server2UUID = res.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } })
+ video2Server2UUID = uuid
// Wait transcoding before federation
await waitJobs(servers)
- await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC })
+ await servers[1].videosCommand.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } })
})
it('Should cache video 2 webseeds on the first video', async function () {
import {
cleanupTests,
flushAndRunMultipleServers,
- getVideoChannelVideos,
SearchCommand,
ServerInfo,
setAccessTokensToServers,
- updateVideo,
- uploadVideo,
wait,
waitJobs
} from '@shared/extra-utils'
const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel })
channelIdServer2 = created.id
- const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
- videoServer2UUID = res.body.video.uuid
+ const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 }
+ const { uuid } = await servers[1].videosCommand.upload({ token: userServer2Token, attributes })
+ videoServer2UUID = uuid
}
await waitJobs(servers)
await waitJobs(servers)
- const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.have.lengthOf(0)
+ const { total, data } = await servers[0].videosCommand.listByChannel({
+ token: null,
+ videoChannelName: 'channel1_server2@localhost:' + servers[1].port
+ })
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
})
it('Should list video channel videos of server 2 with token', async function () {
- const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({
+ videoChannelName: 'channel1_server2@localhost:' + servers[1].port
+ })
- expect(res.body.total).to.equal(1)
- expect(res.body.data[0].name).to.equal('video 1 server 2')
+ expect(total).to.equal(1)
+ expect(data[0].name).to.equal('video 1 server 2')
})
it('Should update video channel of server 2, and refresh it on server 1', async function () {
it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
this.timeout(60000)
- await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' })
- await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 })
+ await servers[1].videosCommand.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } })
+ await servers[1].videosCommand.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } })
await waitJobs(servers)
await waitJobs(servers)
const videoChannelName = 'channel1_server2@localhost:' + servers[1].port
- const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt')
+ const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName, sort: '-createdAt' })
- expect(res.body.total).to.equal(2)
- expect(res.body.data[0].name).to.equal('video 2 server 2')
- expect(res.body.data[1].name).to.equal('video 1 updated')
+ expect(total).to.equal(2)
+ expect(data[0].name).to.equal('video 2 server 2')
+ expect(data[1].name).to.equal('video 1 updated')
})
it('Should delete video channel of server 2, and delete it on server 1', async function () {
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- uploadVideoAndGetId,
wait,
waitJobs
} from '@shared/extra-utils'
await setDefaultVideoChannel(servers)
{
- const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid
- const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid
+ const video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid
+ const video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid
const attributes = {
displayName: 'playlist 1 on server 1',
}
{
- const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid
- video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid
+ const videoId = (await servers[1].videosCommand.quickUpload({ name: 'video 1' })).uuid
+ video2Server2 = (await servers[1].videosCommand.quickUpload({ name: 'video 2' })).uuid
const attributes = {
displayName: 'playlist 1 on server 2',
import {
cleanupTests,
flushAndRunMultipleServers,
- getVideosList,
- removeVideo,
SearchCommand,
ServerInfo,
setAccessTokensToServers,
- updateVideo,
- uploadVideo,
- wait
-} from '../../../../shared/extra-utils'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { VideoPrivacy } from '../../../../shared/models/videos'
+ wait,
+ waitJobs
+} from '@shared/extra-utils'
+import { VideoPrivacy } from '@shared/models'
const expect = chai.expect
await setAccessTokensToServers(servers)
{
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 on server 1' })
- videoServer1UUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1 on server 1' } })
+ videoServer1UUID = uuid
}
{
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 on server 2' })
- videoServer2UUID = res.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 on server 2' } })
+ videoServer2UUID = uuid
}
await waitJobs(servers)
})
it('Should not list this remote video', async function () {
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
- expect(res.body.data[0].name).to.equal('video 1 on server 1')
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].name).to.equal('video 1 on server 1')
})
it('Should update video of server 2, and refresh it on server 1', async function () {
privacy: VideoPrivacy.UNLISTED,
channelId: videoChannelId
}
- await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
+ await servers[1].videosCommand.update({ id: videoServer2UUID, attributes })
await waitJobs(servers)
// Expire video
it('Should delete video of server 2, and delete it on server 1', async function () {
this.timeout(120000)
- await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
+ await servers[1].videosCommand.remove({ id: videoServer2UUID })
await waitJobs(servers)
// Expire video
import 'mocha'
import * as chai from 'chai'
-import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils'
+import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
const expect = chai.expect
await setAccessTokensToServers([ server ])
- await uploadVideo(server.url, server.accessToken, { name: localVideoName })
+ await server.videosCommand.upload({ attributes: { name: localVideoName } })
command = server.searchCommand
})
import 'mocha'
import * as chai from 'chai'
-import { VideoPlaylistPrivacy } from '@shared/models'
import {
cleanupTests,
flushAndRunServer,
SearchCommand,
ServerInfo,
setAccessTokensToServers,
- setDefaultVideoChannel,
- uploadVideoAndGetId
-} from '../../../../shared/extra-utils'
+ setDefaultVideoChannel
+} from '@shared/extra-utils'
+import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect
await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ])
- const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid
+ const videoId = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
{
const attributes = {
setAccessTokensToServers,
setDefaultVideoChannel,
stopFfmpeg,
- uploadVideo,
wait
} from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models'
nsfw: false,
language: 'fr'
}
- await uploadVideo(server.url, server.accessToken, attributes1)
+ await server.videosCommand.upload({ attributes: attributes1 })
const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
- await uploadVideo(server.url, server.accessToken, attributes2)
+ await server.videosCommand.upload({ attributes: attributes2 })
{
const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
- const res = await uploadVideo(server.url, server.accessToken, attributes3)
- const videoId = res.body.video.id
- videoUUID = res.body.video.uuid
+ const { id, uuid } = await server.videosCommand.upload({ attributes: attributes3 })
+ videoUUID = uuid
await server.captionsCommand.createVideoCaption({
language: 'en',
- videoId,
+ videoId: id,
fixture: 'subtitle-good2.vtt',
mimeType: 'application/octet-stream'
})
await server.captionsCommand.createVideoCaption({
language: 'aa',
- videoId,
+ videoId: id,
fixture: 'subtitle-good2.vtt',
mimeType: 'application/octet-stream'
})
}
const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
- await uploadVideo(server.url, server.accessToken, attributes4)
+ await server.videosCommand.upload({ attributes: attributes4 })
await wait(1000)
startDate = new Date().toISOString()
const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
- await uploadVideo(server.url, server.accessToken, attributes5)
+ await server.videosCommand.upload({ attributes: attributes5 })
const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
- await uploadVideo(server.url, server.accessToken, attributes6)
+ await server.videosCommand.upload({ attributes: attributes6 })
const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
- await uploadVideo(server.url, server.accessToken, attributes7)
+ await server.videosCommand.upload({ attributes: attributes7 })
const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
- await uploadVideo(server.url, server.accessToken, attributes8)
+ await server.videosCommand.upload({ attributes: attributes8 })
}
{
licence: 2,
language: 'en'
}
- await uploadVideo(server.url, server.accessToken, attributes)
+ await server.videosCommand.upload({ attributes: attributes })
- await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' })
+ await server.videosCommand.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } })
}
{
licence: 3,
language: 'pl'
}
- await uploadVideo(server.url, server.accessToken, attributes)
+ await server.videosCommand.upload({ attributes: attributes })
}
{
tags: [ 'aaaa', 'bbbb', 'cccc' ],
category: 1
}
- await uploadVideo(server.url, server.accessToken, attributes1)
- await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 })
+ await server.videosCommand.upload({ attributes: attributes1 })
+ await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } })
- await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] })
- await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] })
+ await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } })
+ await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } })
}
{
name: 'aaaa 2',
category: 1
}
- await uploadVideo(server.url, server.accessToken, attributes1)
- await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 })
+ await server.videosCommand.upload({ attributes: attributes1 })
+ await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } })
}
command = server.searchCommand
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideosList,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
-import { Video } from '@shared/models'
const expect = chai.expect
describe('Bulk remove comments', function () {
async function checkInstanceCommentsRemoved () {
{
- const res = await getVideosList(servers[0].url)
- const videos = res.body.data as Video[]
+ const { data } = await servers[0].videosCommand.list()
// Server 1 should not have these comments anymore
- for (const video of videos) {
+ for (const video of data) {
const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id })
const comment = data.find(c => c.text === 'comment by user 3')
}
{
- const res = await getVideosList(servers[1].url)
- const videos = res.body.data as Video[]
+ const { data } = await servers[1].videosCommand.list()
// Server 1 should not have these comments on videos of server 1
- for (const video of videos) {
+ for (const video of data) {
const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id })
const comment = data.find(c => c.text === 'comment by user 3')
before(async function () {
this.timeout(120000)
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' })
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
- await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' })
+ await servers[0].videosCommand.upload({ attributes: { name: 'video 1 server 1' } })
+ await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } })
+ await servers[0].videosCommand.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } })
- await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
+ await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
await waitJobs(servers)
{
- const res = await getVideosList(servers[0].url)
- for (const video of res.body.data) {
+ const { data } = await servers[0].videosCommand.list()
+ for (const video of data) {
await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' })
await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' })
await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' })
}
{
- const res = await getVideosList(servers[1].url)
+ const { data } = await servers[1].videosCommand.list()
- for (const video of res.body.data) {
+ for (const video of data) {
await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' })
const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- for (const video of res.body.data) {
+ for (const video of data) {
const { data } = await server.commentsCommand.listThreads({ videoId: video.id })
const comment = data.find(c => c.text === 'comment by user 2')
parallelTests,
reRunServer,
ServerInfo,
- setAccessTokensToServers,
- uploadVideo
+ setAccessTokensToServers
} from '@shared/extra-utils'
import { CustomConfig } from '@shared/models'
expect(data.video.file.extensions).to.contain('.webm')
expect(data.video.file.extensions).to.contain('.ogv')
- await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
- await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
+ await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
+ await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
expect(data.contactForm.enabled).to.be.true
})
expect(data.video.file.extensions).to.contain('.ogg')
expect(data.video.file.extensions).to.contain('.flac')
- await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
- await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
+ await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
+ await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
})
it('Should have the configuration updated after a restart', async function () {
import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import {
- cleanupTests,
- flushAndRunServer,
- MockSmtpServer,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo,
- waitJobs
-} from '@shared/extra-utils'
+import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
const expect = chai.expect
}
{
- const attributes = {
- name: 'my super user video'
- }
- const res = await uploadVideo(server.url, userAccessToken, attributes)
- videoUserUUID = res.body.video.uuid
+ const attributes = { name: 'my super user video' }
+ const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes })
+ videoUserUUID = uuid
}
{
const attributes = {
name: 'my super name'
}
- const res = await uploadVideo(server.url, server.accessToken, attributes)
- videoUUID = res.body.video.uuid
- videoId = res.body.video.id
+ const { uuid, id } = await server.videosCommand.upload({ attributes })
+ videoUUID = uuid
+ videoId = id
}
})
import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
+import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
-import {
- cleanupTests,
- doubleFollow,
- flushAndRunMultipleServers,
- getAccountVideos,
- getVideo,
- getVideoChannelVideos,
- getVideoWithToken,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo
-} from '../../../../shared/extra-utils'
const expect = chai.expect
let servers: ServerInfo[] = []
let video1UUID: string
let video2UUID: string
- let userAccessToken: string
+ let userToken: string
before(async function () {
this.timeout(90000)
await setAccessTokensToServers(servers)
{
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
- video1UUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } })
+ video1UUID = uuid
}
{
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
- video2UUID = res.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } })
+ video2UUID = uuid
}
const user = {
password: 'super_password'
}
await servers[0].usersCommand.create({ username: user.username, password: user.password })
- userAccessToken = await servers[0].loginCommand.getAccessToken(user)
+ userToken = await servers[0].loginCommand.getAccessToken(user)
await doubleFollow(servers[0], servers[1])
})
describe('With an unlogged user', function () {
it('Should get the local video', async function () {
- await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.get({ id: video1UUID })
})
it('Should get the remote video', async function () {
- await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.get({ id: video2UUID })
})
it('Should list local account videos', async function () {
- const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[0].port })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
- const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[1].port })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port
- const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port
- const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
})
describe('With a logged user', function () {
it('Should get the local video', async function () {
- await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
})
it('Should get the remote video', async function () {
- await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
})
it('Should list local account videos', async function () {
- const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
- const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port
- const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port
- const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
})
})
describe('With an unlogged user', function () {
it('Should get the local video', async function () {
- await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.get({ id: video1UUID })
})
it('Should not get the remote video', async function () {
- const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403)
-
- const error = res.body as PeerTubeProblemDocument
+ const body = await servers[0].videosCommand.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ const error = body as unknown as PeerTubeProblemDocument
const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
expect(error.type).to.equal(doc)
})
it('Should list local account videos', async function () {
- const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByAccount({
+ token: undefined,
+ accountName: 'root@localhost:' + servers[0].port
+ })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should not list remote account videos', async function () {
- const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByAccount({
+ token: undefined,
+ accountName: 'root@localhost:' + servers[1].port
+ })
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
})
it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port
- const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should not list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port
- const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
})
})
describe('With a logged user', function () {
it('Should get the local video', async function () {
- await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
})
it('Should get the remote video', async function () {
- await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
})
it('Should list local account videos', async function () {
- const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
- const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port
- const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port
- const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
+ const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
})
})
})
expectAccountFollows,
flushAndRunMultipleServers,
FollowsCommand,
- getVideosList,
- rateVideo,
ServerInfo,
setAccessTokensToServers,
testCaptionFile,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models'
it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () {
this.timeout(60000)
- await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' })
- await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' })
+ await servers[1].videosCommand.upload({ attributes: { name: 'server2' } })
+ await servers[2].videosCommand.upload({ attributes: { name: 'server3' } })
await waitJobs(servers)
- let res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(1)
- expect(res.body.data[0].name).to.equal('server2')
+ {
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(1)
+ expect(data[0].name).to.equal('server2')
+ }
- res = await getVideosList(servers[1].url)
- expect(res.body.total).to.equal(1)
- expect(res.body.data[0].name).to.equal('server2')
+ {
+ const { total, data } = await servers[1].videosCommand.list()
+ expect(total).to.equal(1)
+ expect(data[0].name).to.equal('server2')
+ }
- res = await getVideosList(servers[2].url)
- expect(res.body.total).to.equal(1)
- expect(res.body.data[0].name).to.equal('server3')
+ {
+ const { total, data } = await servers[2].videosCommand.list()
+ expect(total).to.equal(1)
+ expect(data[0].name).to.equal('server3')
+ }
})
describe('Should propagate data on a new following', function () {
tags: [ 'tag1', 'tag2', 'tag3' ]
}
- await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' })
- await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' })
- await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes)
- await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' })
- await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' })
+ await servers[2].videosCommand.upload({ attributes: { name: 'server3-2' } })
+ await servers[2].videosCommand.upload({ attributes: { name: 'server3-3' } })
+ await servers[2].videosCommand.upload({ attributes: video4Attributes })
+ await servers[2].videosCommand.upload({ attributes: { name: 'server3-5' } })
+ await servers[2].videosCommand.upload({ attributes: { name: 'server3-6' } })
{
const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain')
- const resVideos = await getVideosList(servers[2].url)
- video4 = resVideos.body.data.find(v => v.name === 'server3-4')
+ const { data } = await servers[2].videosCommand.list()
+ video4 = data.find(v => v.name === 'server3-4')
{
- await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like')
- await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike')
+ await servers[2].videosCommand.rate({ id: video4.id, rating: 'like' })
+ await servers[2].videosCommand.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' })
}
{
})
it('Should have propagated videos', async function () {
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(7)
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(7)
- const video2 = res.body.data.find(v => v.name === 'server3-2')
- video4 = res.body.data.find(v => v.name === 'server3-4')
- const video6 = res.body.data.find(v => v.name === 'server3-6')
+ const video2 = data.find(v => v.name === 'server3-2')
+ video4 = data.find(v => v.name === 'server3-4')
+ const video6 = data.find(v => v.name === 'server3-6')
expect(video2).to.not.be.undefined
expect(video4).to.not.be.undefined
}
]
}
- await completeVideoCheck(servers[0].url, video4, checkAttributes)
+ await completeVideoCheck(servers[0], video4, checkAttributes)
})
it('Should have propagated comments', async function () {
await waitJobs(servers)
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(1)
+ const { total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(1)
})
})
CommentsCommand,
completeVideoCheck,
flushAndRunMultipleServers,
- getVideo,
- getVideosList,
killallServers,
reRunServer,
ServerInfo,
setAccessTokensToServers,
- updateVideo,
- uploadVideo,
- uploadVideoAndGetId,
wait,
waitJobs
} from '@shared/extra-utils'
-import { JobState, Video, VideoPrivacy } from '@shared/models'
+import { JobState, VideoCreateResult, VideoPrivacy } from '@shared/models'
const expect = chai.expect
let threadIdServer2: number
let commentIdServer1: number
let commentIdServer2: number
- let missedVideo1: Video
- let missedVideo2: Video
- let unlistedVideo: Video
+ let missedVideo1: VideoCreateResult
+ let missedVideo2: VideoCreateResult
+ let unlistedVideo: VideoCreateResult
const videoIdsServer1: string[] = []
await waitJobs(servers)
// Upload a video to server 1
- await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
+ await servers[0].videosCommand.upload({ attributes: videoAttributes })
await waitJobs(servers)
// And check all servers have this video
for (const server of servers) {
- const res = await getVideosList(server.url)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data).to.have.lengthOf(1)
+ const { data } = await server.videosCommand.list()
+ expect(data).to.be.an('array')
+ expect(data).to.have.lengthOf(1)
}
// Kill server 2
// Remove server 2 follower
for (let i = 0; i < 10; i++) {
- await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
+ await servers[0].videosCommand.upload({ attributes: videoAttributes })
}
await waitJobs([ servers[0], servers[2] ])
// Kill server 3
await killallServers([ servers[2] ])
- const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
- missedVideo1 = resLastVideo1.body.video
+ missedVideo1 = await servers[0].videosCommand.upload({ attributes: videoAttributes })
- const resLastVideo2 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
- missedVideo2 = resLastVideo2.body.video
+ missedVideo2 = await servers[0].videosCommand.upload({ attributes: videoAttributes })
// Unlisted video
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, unlistedVideoAttributes)
- unlistedVideo = resVideo.body.video
+ unlistedVideo = await servers[0].videosCommand.upload({ attributes: unlistedVideoAttributes })
// Add comments to video 2
{
it('Should send an update to server 3, and automatically fetch the video', async function () {
this.timeout(15000)
- const res1 = await getVideosList(servers[2].url)
- expect(res1.body.data).to.be.an('array')
- expect(res1.body.data).to.have.lengthOf(11)
+ {
+ const { data } = await servers[2].videosCommand.list()
+ expect(data).to.be.an('array')
+ expect(data).to.have.lengthOf(11)
+ }
- await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, {})
- await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, {})
+ await servers[0].videosCommand.update({ id: missedVideo1.uuid })
+ await servers[0].videosCommand.update({ id: unlistedVideo.uuid })
await waitJobs(servers)
- const res = await getVideosList(servers[2].url)
- expect(res.body.data).to.be.an('array')
- // 1 video is unlisted
- expect(res.body.data).to.have.lengthOf(12)
+ {
+ const { data } = await servers[2].videosCommand.list()
+ expect(data).to.be.an('array')
+ // 1 video is unlisted
+ expect(data).to.have.lengthOf(12)
+ }
// Check unlisted video
- const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid)
- expect(resVideo.body).not.to.be.undefined
-
- await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes)
+ const video = await servers[2].videosCommand.get({ id: unlistedVideo.uuid })
+ await completeVideoCheck(servers[2], video, unlistedCheckAttributes)
})
it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
await waitJobs(servers)
- const resVideo = await getVideo(servers[2].url, missedVideo2.uuid)
- expect(resVideo.body).not.to.be.undefined
+ await servers[2].videosCommand.get({ id: missedVideo2.uuid })
{
const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid })
this.timeout(120000)
for (let i = 0; i < 10; i++) {
- const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video ' + i })).uuid
+ const uuid = (await servers[0].videosCommand.quickUpload({ name: 'video ' + i })).uuid
videoIdsServer1.push(uuid)
}
await waitJobs(servers)
for (const id of videoIdsServer1) {
- await getVideo(servers[1].url, id)
+ await servers[1].videosCommand.get({ id })
}
await waitJobs(servers)
await wait(11000)
// Refresh video -> score + 10 = 30
- await getVideo(servers[1].url, videoIdsServer1[0])
+ await servers[1].videosCommand.get({ id: videoIdsServer1[0] })
await waitJobs(servers)
})
for (let i = 0; i < 5; i++) {
try {
- await getVideo(servers[1].url, videoIdsServer1[i])
+ await servers[1].videosCommand.get({ id: videoIdsServer1[i] })
await waitJobs([ servers[1] ])
await wait(1500)
} catch {}
}
for (const id of videoIdsServer1) {
- await getVideo(servers[1].url, id, HttpStatusCode.FORBIDDEN_403)
+ await servers[1].videosCommand.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}
})
flushAndRunMultipleServers,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
it('Should create some jobs', async function () {
this.timeout(120000)
- await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
- await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
+ await servers[1].videosCommand.upload({ attributes: { name: 'video1' } })
+ await servers[1].videosCommand.upload({ attributes: { name: 'video2' } })
await waitJobs(servers)
})
reRunServer,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
it('Should get logs with a start date', async function () {
this.timeout(20000)
- await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
+ await server.videosCommand.upload({ attributes: { name: 'video 1' } })
await waitJobs([ server ])
const now = new Date()
- await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
+ await server.videosCommand.upload({ attributes: { name: 'video 2' } })
await waitJobs([ server ])
const body = await logsCommand.getLogs({ startDate: now })
it('Should get logs with an end date', async function () {
this.timeout(30000)
- await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
+ await server.videosCommand.upload({ attributes: { name: 'video 3' } })
await waitJobs([ server ])
const now1 = new Date()
- await uploadVideo(server.url, server.accessToken, { name: 'video 4' })
+ await server.videosCommand.upload({ attributes: { name: 'video 4' } })
await waitJobs([ server ])
const now2 = new Date()
- await uploadVideo(server.url, server.accessToken, { name: 'video 5' })
+ await server.videosCommand.upload({ attributes: { name: 'video 5' } })
await waitJobs([ server ])
const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 })
const now = new Date()
- await uploadVideo(server.url, server.accessToken, { name: 'video 6' })
+ await server.videosCommand.upload({ attributes: { name: 'video 6' } })
await waitJobs([ server ])
{
it('Should get logs with a start date', async function () {
this.timeout(20000)
- await uploadVideo(server.url, server.accessToken, { name: 'video 7' })
+ await server.videosCommand.upload({ attributes: { name: 'video 7' } })
await waitJobs([ server ])
const now = new Date()
- await uploadVideo(server.url, server.accessToken, { name: 'video 8' })
+ await server.videosCommand.upload({ attributes: { name: 'video 8' } })
await waitJobs([ server ])
const body = await logsCommand.getAuditLogs({ startDate: now })
it('Should get logs with an end date', async function () {
this.timeout(30000)
- await uploadVideo(server.url, server.accessToken, { name: 'video 9' })
+ await server.videosCommand.upload({ attributes: { name: 'video 9' } })
await waitJobs([ server ])
const now1 = new Date()
- await uploadVideo(server.url, server.accessToken, { name: 'video 10' })
+ await server.videosCommand.upload({ attributes: { name: 'video 10' } })
await waitJobs([ server ])
const now2 = new Date()
- await uploadVideo(server.url, server.accessToken, { name: 'video 11' })
+ await server.videosCommand.upload({ attributes: { name: 'video 11' } })
await waitJobs([ server ])
const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 })
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import {
- cleanupTests,
- flushAndRunServer,
- getVideo,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo,
- viewVideo,
- wait
-} from '@shared/extra-utils'
+import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils'
describe('Test application behind a reverse proxy', function () {
let server: ServerInfo
- let videoId: number
+ let videoId: string
before(async function () {
this.timeout(30000)
server = await flushAndRunServer(1, config)
await setAccessTokensToServers([ server ])
- const { body } = await uploadVideo(server.url, server.accessToken, {})
- videoId = body.video.uuid
+ const { uuid } = await server.videosCommand.upload()
+ videoId = uuid
})
it('Should view a video only once with the same IP by default', async function () {
this.timeout(20000)
- await viewVideo(server.url, videoId)
- await viewVideo(server.url, videoId)
+ await server.videosCommand.view({ id: videoId })
+ await server.videosCommand.view({ id: videoId })
// Wait the repeatable job
await wait(8000)
- const { body } = await getVideo(server.url, videoId)
- expect(body.views).to.equal(1)
+ const video = await server.videosCommand.get({ id: videoId })
+ expect(video.views).to.equal(1)
})
it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
this.timeout(20000)
- await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.1,127.0.0.1')
- await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.2,127.0.0.1')
+ await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.1,127.0.0.1' })
+ await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.2,127.0.0.1' })
// Wait the repeatable job
await wait(8000)
- const { body } = await getVideo(server.url, videoId)
- expect(body.views).to.equal(3)
+ const video = await server.videosCommand.get({ id: videoId })
+ expect(video.views).to.equal(3)
})
it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
this.timeout(20000)
- await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1')
- await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.5,0.0.0.3,127.0.0.1')
+ await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.4,0.0.0.3,::ffff:127.0.0.1' })
+ await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.5,0.0.0.3,127.0.0.1' })
// Wait the repeatable job
await wait(8000)
- const { body } = await getVideo(server.url, videoId)
- expect(body.views).to.equal(4)
+ const video = await server.videosCommand.get({ id: videoId })
+ expect(video.views).to.equal(4)
})
it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
this.timeout(20000)
- await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.6,127.0.0.1')
- await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.7,127.0.0.1')
+ await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.6,127.0.0.1' })
+ await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.7,127.0.0.1' })
// Wait the repeatable job
await wait(8000)
- const { body } = await getVideo(server.url, videoId)
- expect(body.views).to.equal(6)
+ const video = await server.videosCommand.get({ id: videoId })
+ expect(video.views).to.equal(6)
})
it('Should rate limit logins', async function () {
for (let i = 0; i < 100; i++) {
try {
- await getVideo(server.url, videoId)
+ await server.videosCommand.get({ id: videoId })
} catch {
// don't care if it fails
}
}
- await getVideo(server.url, videoId, HttpStatusCode.TOO_MANY_REQUESTS_429)
+ await server.videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
})
after(async function () {
import 'mocha'
import * as chai from 'chai'
+import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils'
import { Video, VideoPlaylistPrivacy } from '@shared/models'
-import {
- getVideosList,
- ServerInfo,
- setAccessTokensToServers,
- setDefaultVideoChannel,
- uploadVideo
-} from '../../../../shared/extra-utils'
-import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
const expect = chai.expect
await setDefaultVideoChannel([ server ])
{
- const videoAttributes = {
- name: 'my super name'
- }
- await uploadVideo(server.url, server.accessToken, videoAttributes)
+ const attributes = { name: 'my super name' }
+ await server.videosCommand.upload({ attributes })
- const res = await getVideosList(server.url)
- video = res.body.data[0]
+ const { data } = await server.videosCommand.list()
+ video = data[0]
}
{
flushAndRunMultipleServers,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
- viewVideo,
wait,
waitJobs
} from '@shared/extra-utils'
await servers[0].usersCommand.create({ username: user.username, password: user.password })
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
- const videoUUID = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { fixture: 'video_short.webm' } })
- await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'comment' })
+ await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
- await viewVideo(servers[0].url, videoUUID)
+ await servers[0].videosCommand.view({ id: uuid })
// Wait the video views repeatable job
await wait(8000)
}
{
- 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()
}
})
- 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)
const first = await servers[1].statsCommand.get()
for (let i = 0; i < 10; i++) {
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
+ await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
}
await waitJobs(servers)
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */
-import * as magnetUtil from 'magnet-uri'
import 'mocha'
-import {
- cleanupTests,
- flushAndRunServer,
- getVideo,
- killallServers,
- reRunServer,
- ServerInfo,
- uploadVideo
-} from '../../../../shared/extra-utils'
-import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
-import { VideoDetails } from '../../../../shared/models/videos'
+import * as magnetUtil from 'magnet-uri'
import * as WebTorrent from 'webtorrent'
+import { cleanupTests, flushAndRunServer, killallServers, reRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
describe('Test tracker', function () {
let server: ServerInfo
await setAccessTokensToServers([ server ])
{
- const res = await uploadVideo(server.url, server.accessToken, {})
- const videoUUID = res.body.video.uuid
-
- const resGet = await getVideo(server.url, videoUUID)
- const video: VideoDetails = resGet.body
+ const { uuid } = await server.videosCommand.upload()
+ const video = await server.videosCommand.get({ id: uuid })
goodMagnet = video.files[0].magnetUri
const parsed = magnetUtil.decode(goodMagnet)
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideosList,
ServerInfo,
setAccessTokensToServers,
SubscriptionsCommand,
- updateVideo,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
users.push({ accessToken })
const videoName1 = 'video 1-' + server.serverNumber
- await uploadVideo(server.url, accessToken, { name: videoName1 })
+ await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } })
const videoName2 = 'video 2-' + server.serverNumber
- await uploadVideo(server.url, accessToken, { name: videoName2 })
+ await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } })
}
}
})
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 () {
await waitJobs(servers)
- const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' })
- video3UUID = res.body.video.uuid
+ const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } })
+ video3UUID = uuid
await waitJobs(servers)
})
it('Should not display videos of server 3 on server 1', async function () {
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(4)
- expect(res.body.total).to.equal(4)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow')
this.timeout(60000)
const videoName = 'video server 1 added after follow'
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName })
+ await servers[0].videosCommand.upload({ attributes: { name: videoName } })
await waitJobs(servers)
}
{
- const res = await getVideosList(servers[0].url)
+ const { data, total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(5)
- expect(res.body.total).to.equal(5)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow')
await waitJobs(servers)
- const res = await getVideosList(servers[0].url)
-
- expect(res.body.total).to.equal(8)
+ const { data, total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(8)
const names = [ '1-3', '2-3', 'video server 3 added after follow' ]
for (const name of names) {
- const video = res.body.data.find(v => v.name.indexOf(name) === -1)
+ const video = data.find(v => v.name.includes(name))
expect(video).to.not.be.undefined
}
})
await waitJobs(servers)
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(5)
- expect(res.body.total).to.equal(5)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow')
it('Should update a video of server 3 and see the updated video on server 1', async function () {
this.timeout(30000)
- await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' })
+ await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } })
await waitJobs(servers)
})
it('Should correctly display public videos on server 1', async function () {
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(5)
- expect(res.body.total).to.equal(5)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow updated')
}
{
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videosCommand.list()
+ expect(total).to.equal(5)
- expect(res.body.total).to.equal(5)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow updated')
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getAccountVideos,
ServerInfo,
setAccessTokensToServers,
testImage,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { User } from '@shared/models'
await doubleFollow(servers[1], servers[2])
// The root user of server 1 is propagated to servers 2 and 3
- await uploadVideo(servers[0].url, servers[0].accessToken, {})
+ await servers[0].videosCommand.upload()
{
const user = {
}
{
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, {})
- videoUUID = resVideo.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken })
+ videoUUID = uuid
}
await waitJobs(servers)
it('Should list account videos', async function () {
for (const server of servers) {
- const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5)
+ const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port })
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data).to.have.lengthOf(1)
- expect(res.body.data[0].uuid).to.equal(videoUUID)
+ expect(total).to.equal(1)
+ expect(data).to.be.an('array')
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].uuid).to.equal(videoUUID)
}
})
it('Should search through account videos', async function () {
this.timeout(10_000)
- const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' })
+ const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
await waitJobs(servers)
for (const server of servers) {
- const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, {
- search: 'Kami'
- })
-
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data).to.have.lengthOf(1)
- expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid)
+ const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' })
+
+ expect(total).to.equal(1)
+ expect(data).to.be.an('array')
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].uuid).to.equal(created.uuid)
}
})
import {
cleanupTests,
flushAndRunServer,
- getMyVideos,
- getVideosList,
killallServers,
makePutBodyRequest,
- rateVideo,
- removeVideo,
reRunServer,
ServerInfo,
setAccessTokensToServers,
testImage,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
describe('Test users', function () {
let server: ServerInfo
- let accessToken: string
- let accessTokenUser: string
+ let token: string
+ let userToken: string
let videoId: number
let userId: number
const user = {
})
it('Should not be able to upload a video', async function () {
- accessToken = 'my_super_token'
+ token = 'my_super_token'
- const videoAttributes = {}
- await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
+ await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should not be able to follow', async function () {
- accessToken = 'my_super_token'
+ token = 'my_super_token'
await server.followsCommand.follow({
targets: [ 'http://example.com' ],
- token: accessToken,
+ token,
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
it('Should be able to login', async function () {
const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 })
- accessToken = body.access_token
+ token = body.access_token
})
it('Should be able to login with an insensitive username', async function () {
describe('Upload', function () {
it('Should upload the video with the correct token', async function () {
- const videoAttributes = {}
- await uploadVideo(server.url, accessToken, videoAttributes)
- const res = await getVideosList(server.url)
- const video = res.body.data[0]
+ await server.videosCommand.upload({ token })
+ const { data } = await server.videosCommand.list()
+ const video = data[0]
expect(video.account.name).to.equal('root')
videoId = video.id
})
it('Should upload the video again with the correct token', async function () {
- const videoAttributes = {}
- await uploadVideo(server.url, accessToken, videoAttributes)
+ await server.videosCommand.upload({ token })
})
})
describe('Ratings', function () {
it('Should retrieve a video rating', async function () {
- await rateVideo(server.url, accessToken, videoId, 'like')
- const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId })
+ await server.videosCommand.rate({ id: videoId, rating: 'like' })
+ const rating = await server.usersCommand.getMyRating({ token, videoId })
expect(rating.videoId).to.equal(videoId)
expect(rating.rating).to.equal('like')
})
it('Should retrieve ratings list', async function () {
- await rateVideo(server.url, accessToken, videoId, 'like')
+ await server.videosCommand.rate({ id: videoId, rating: 'like' })
const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
describe('Remove video', function () {
it('Should not be able to remove the video with an incorrect token', async function () {
- await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
+ await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should not be able to remove the video with the token of another account')
it('Should be able to remove the video with the correct token', async function () {
- await removeVideo(server.url, accessToken, videoId)
+ await server.videosCommand.remove({ token, id: videoId })
})
})
})
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 be able to login with this user', async function () {
- accessTokenUser = await server.loginCommand.getAccessToken(user)
+ userToken = await server.loginCommand.getAccessToken(user)
})
it('Should be able to get user information', async function () {
- const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const userMe = await server.usersCommand.getMyInfo({ token: userToken })
const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true })
it('Should be able to upload a video with this user', async function () {
this.timeout(10000)
- const videoAttributes = {
+ const attributes = {
name: 'super user video',
fixture: 'video_short.webm'
}
- await uploadVideo(server.url, accessTokenUser, videoAttributes)
+ await server.videosCommand.upload({ token: userToken, attributes })
})
it('Should have video quota updated', async function () {
- const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
+ const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken })
expect(quota.videoQuotaUsed).to.equal(218910)
const { data } = await server.usersCommand.list()
})
it('Should be able to list my videos', async function () {
- const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
- expect(res.body.total).to.equal(1)
-
- const videos = res.body.data
- expect(videos).to.have.lengthOf(1)
+ const { total, data } = await server.videosCommand.listMyVideos({ token: userToken })
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
- const video: Video = videos[0]
+ const video: Video = data[0]
expect(video.name).to.equal('super user video')
expect(video.thumbnailPath).to.not.be.null
expect(video.previewPath).to.not.be.null
it('Should be able to search in my videos', async function () {
{
- const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
- expect(res.body.total).to.equal(1)
-
- const videos = res.body.data
- expect(videos).to.have.lengthOf(1)
+ const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' })
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
}
{
- const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
- expect(res.body.total).to.equal(0)
-
- const videos = res.body.data
- expect(videos).to.have.lengthOf(0)
+ const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' })
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
}
})
}
{
- const videoAttributes = {
+ const attributes = {
name: 'super user video 2',
fixture: 'video_short.webm'
}
- await uploadVideo(server.url, accessTokenUser, videoAttributes)
+ await server.videosCommand.upload({ token: userToken, attributes })
await waitJobs([ server ])
}
{
- const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
+ const data = await server.usersCommand.getMyQuotaUsed({ token: userToken })
expect(data.videoQuotaUsed).to.be.greaterThan(220000)
}
})
it('Should update my password', async function () {
await server.usersCommand.updateMe({
- token: accessTokenUser,
+ token: userToken,
currentPassword: 'super password',
password: 'new password'
})
it('Should be able to change the NSFW display attribute', async function () {
await server.usersCommand.updateMe({
- token: accessTokenUser,
+ token: userToken,
nsfwPolicy: 'do_not_list'
})
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list')
it('Should be able to change the autoPlayVideo attribute', async function () {
await server.usersCommand.updateMe({
- token: accessTokenUser,
+ token: userToken,
autoPlayVideo: false
})
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.autoPlayVideo).to.be.false
})
it('Should be able to change the autoPlayNextVideo attribute', async function () {
await server.usersCommand.updateMe({
- token: accessTokenUser,
+ token: userToken,
autoPlayNextVideo: true
})
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.autoPlayNextVideo).to.be.true
})
it('Should be able to change the email attribute', async function () {
await server.usersCommand.updateMe({
- token: accessTokenUser,
+ token: userToken,
currentPassword: 'new password',
email: 'updated@example.com'
})
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list')
it('Should be able to update my avatar with a gif', async function () {
const fixture = 'avatar.gif'
- await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
+ await server.usersCommand.updateMyAvatar({ token: userToken, fixture })
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
})
for (const extension of [ '.png', '.gif' ]) {
const fixture = 'avatar' + extension
- await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
+ await server.usersCommand.updateMyAvatar({ token: userToken, fixture })
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
}
})
it('Should be able to update my display name', async function () {
- await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' })
+ await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' })
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list')
})
it('Should be able to update my description', async function () {
- await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' })
+ await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' })
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list')
it('Should be able to update my theme', async function () {
for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
- await server.usersCommand.updateMe({ token: accessTokenUser, theme })
+ await server.usersCommand.updateMe({ token: userToken, theme })
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.theme).to.equal(theme)
}
})
it('Should be able to update my modal preferences', async function () {
await server.usersCommand.updateMe({
- token: accessTokenUser,
+ token: userToken,
noInstanceConfigWarningModal: true,
noWelcomeModal: true
})
- const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const user = await server.usersCommand.getMyInfo({ token: userToken })
expect(user.noWelcomeModal).to.be.true
expect(user.noInstanceConfigWarningModal).to.be.true
})
it('Should be able to update another user', async function () {
await server.usersCommand.update({
userId,
- token: accessToken,
+ token,
email: 'updated2@example.com',
emailVerified: true,
videoQuota: 42,
pluginAuth: 'toto'
})
- const user = await server.usersCommand.get({ token: accessToken, userId })
+ const user = await server.usersCommand.get({ token, userId })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated2@example.com')
})
it('Should reset the auth plugin', async function () {
- await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null })
+ await server.usersCommand.update({ userId, token, pluginAuth: null })
- const user = await server.usersCommand.get({ token: accessToken, userId })
+ const user = await server.usersCommand.get({ token, userId })
expect(user.pluginAuth).to.be.null
})
it('Should have removed the user token', async function () {
- await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
- accessTokenUser = await server.loginCommand.getAccessToken(user)
+ userToken = await server.loginCommand.getAccessToken(user)
})
it('Should be able to update another user password', async function () {
- await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' })
+ await server.usersCommand.update({ userId, token, password: 'password updated' })
- await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
user.password = 'password updated'
- accessTokenUser = await server.loginCommand.getAccessToken(user)
+ userToken = await server.loginCommand.getAccessToken(user)
})
})
describe('Video blacklists', function () {
it('Should be able to list video blacklist by a moderator', async function () {
- await server.blacklistCommand.list({ token: accessTokenUser })
+ await server.blacklistCommand.list({ token: userToken })
})
})
describe('Remove a user', function () {
it('Should be able to remove this user', async function () {
- await server.usersCommand.remove({ userId, token: accessToken })
+ await server.usersCommand.remove({ userId, token })
})
it('Should not be able to login with this user', async function () {
})
it('Should not have videos of this user', async function () {
- const res = await getVideosList(server.url)
-
- expect(res.body.total).to.equal(1)
+ const { data, total } = await server.videosCommand.list()
+ expect(total).to.equal(1)
- const video = res.body.data[0]
+ const video = data[0]
expect(video.account.name).to.equal('root')
})
})
})
it('Should report correct videos count', async function () {
- const videoAttributes = {
- name: 'video to test user stats'
- }
- await uploadVideo(server.url, user17AccessToken, videoAttributes)
- const res1 = await getVideosList(server.url)
- videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
+ const attributes = { name: 'video to test user stats' }
+ await server.videosCommand.upload({ token: user17AccessToken, attributes })
+
+ const { data } = await server.videosCommand.list()
+ videoId = data.find(video => video.name === attributes.name).id
const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
expect(user.videosCount).to.equal(1)
import * as chai from 'chai'
import { join } from 'path'
import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils'
-import {
- cleanupTests,
- doubleFollow,
- flushAndRunMultipleServers,
- getVideo,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo,
- waitJobs
-} from '../../../../shared/extra-utils'
-import { VideoDetails } from '../../../../shared/models/videos'
+import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
const expect = chai.expect
it('Should upload a video and transcode it', async function () {
this.timeout(120000)
- const resUpload = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'audio only' })
- videoUUID = resUpload.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'audio only' } })
+ videoUUID = uuid
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video: VideoDetails = res.body
-
+ const video = await server.videosCommand.get({ id: videoUUID })
expect(video.streamingPlaylists).to.have.lengthOf(1)
for (const files of [ video.files, video.streamingPlaylists[0].files ]) {
dateIsValid,
doubleFollow,
flushAndRunMultipleServers,
- getLocalVideos,
- getVideo,
- getVideosList,
- rateVideo,
- removeVideo,
ServerInfo,
setAccessTokensToServers,
testImage,
- updateVideo,
- uploadVideo,
- viewVideo,
wait,
waitJobs,
webtorrentAdd
it('Should not have videos for all servers', async function () {
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videos = res.body.data
- expect(videos).to.be.an('array')
- expect(videos.length).to.equal(0)
+ const { data } = await server.videosCommand.list()
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(0)
}
})
it('Should upload the video on server 1 and propagate on each server', async function () {
this.timeout(25000)
- const videoAttributes = {
+ const attributes = {
name: 'my super name for server 1',
category: 5,
licence: 4,
channelId: videoChannelId,
fixture: 'video_short1.webm'
}
- await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
+ await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers)
]
}
- const res = await getVideosList(server.url)
- const videos = res.body.data
- expect(videos).to.be.an('array')
- expect(videos.length).to.equal(1)
- const video = videos[0]
+ const { data } = await server.videosCommand.list()
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(1)
+ const video = data[0]
- await completeVideoCheck(server.url, video, checkAttributes)
- publishedAt = video.publishedAt
+ await completeVideoCheck(server, video, checkAttributes)
+ publishedAt = video.publishedAt as string
}
})
await servers[1].usersCommand.create({ username: user.username, password: user.password })
const userAccessToken = await servers[1].loginCommand.getAccessToken(user)
- const videoAttributes = {
+ const attributes = {
name: 'my super name for server 2',
category: 4,
licence: 3,
thumbnailfile: 'thumbnail.jpg',
previewfile: 'preview.jpg'
}
- await uploadVideo(servers[1].url, userAccessToken, videoAttributes, HttpStatusCode.OK_200, 'resumable')
+ await servers[1].videosCommand.upload({ token: userAccessToken, attributes, mode: 'resumable' })
// Transcoding
await waitJobs(servers)
previewfile: 'preview'
}
- const res = await getVideosList(server.url)
- const videos = res.body.data
- expect(videos).to.be.an('array')
- expect(videos.length).to.equal(2)
- const video = videos[1]
+ const { data } = await server.videosCommand.list()
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(2)
+ const video = data[1]
- await completeVideoCheck(server.url, video, checkAttributes)
+ await completeVideoCheck(server, video, checkAttributes)
}
})
it('Should upload two videos on server 3 and propagate on each server', async function () {
this.timeout(45000)
- const videoAttributes1 = {
- name: 'my super name for server 3',
- category: 6,
- licence: 5,
- language: 'de',
- nsfw: true,
- description: 'my super description for server 3',
- support: 'my super support text for server 3',
- tags: [ 'tag1p3' ],
- fixture: 'video_short3.webm'
+ {
+ const attributes = {
+ name: 'my super name for server 3',
+ category: 6,
+ licence: 5,
+ language: 'de',
+ nsfw: true,
+ description: 'my super description for server 3',
+ support: 'my super support text for server 3',
+ tags: [ 'tag1p3' ],
+ fixture: 'video_short3.webm'
+ }
+ await servers[2].videosCommand.upload({ attributes })
}
- await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
-
- const videoAttributes2 = {
- name: 'my super name for server 3-2',
- category: 7,
- licence: 6,
- language: 'ko',
- nsfw: false,
- description: 'my super description for server 3-2',
- support: 'my super support text for server 3-2',
- tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
- fixture: 'video_short.webm'
+
+ {
+ const attributes = {
+ name: 'my super name for server 3-2',
+ category: 7,
+ licence: 6,
+ language: 'ko',
+ nsfw: false,
+ description: 'my super description for server 3-2',
+ support: 'my super support text for server 3-2',
+ tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
+ fixture: 'video_short.webm'
+ }
+ await servers[2].videosCommand.upload({ attributes })
}
- await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
await waitJobs(servers)
// All servers should have this video
for (const server of servers) {
const isLocal = server.url === 'http://localhost:' + servers[2].port
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const videos = res.body.data
- expect(videos).to.be.an('array')
- expect(videos.length).to.equal(4)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(4)
// We not sure about the order of the two last uploads
let video1 = null
let video2 = null
- if (videos[2].name === 'my super name for server 3') {
- video1 = videos[2]
- video2 = videos[3]
+ if (data[2].name === 'my super name for server 3') {
+ video1 = data[2]
+ video2 = data[3]
} else {
- video1 = videos[3]
- video2 = videos[2]
+ video1 = data[3]
+ video2 = data[2]
}
const checkAttributesVideo1 = {
}
]
}
- await completeVideoCheck(server.url, video1, checkAttributesVideo1)
+ await completeVideoCheck(server, video1, checkAttributesVideo1)
const checkAttributesVideo2 = {
name: 'my super name for server 3-2',
}
]
}
- await completeVideoCheck(server.url, video2, checkAttributesVideo2)
+ await completeVideoCheck(server, video2, checkAttributesVideo2)
}
})
})
describe('It should list local videos', function () {
it('Should list only local videos on server 1', async function () {
- const { body } = await getLocalVideos(servers[0].url)
+ const { data, total } = await servers[0].videosCommand.list({ filter: 'local' })
- expect(body.total).to.equal(1)
- expect(body.data).to.be.an('array')
- expect(body.data.length).to.equal(1)
- expect(body.data[0].name).to.equal('my super name for server 1')
+ expect(total).to.equal(1)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(1)
+ expect(data[0].name).to.equal('my super name for server 1')
})
it('Should list only local videos on server 2', async function () {
- const { body } = await getLocalVideos(servers[1].url)
+ const { data, total } = await servers[1].videosCommand.list({ filter: 'local' })
- expect(body.total).to.equal(1)
- expect(body.data).to.be.an('array')
- expect(body.data.length).to.equal(1)
- expect(body.data[0].name).to.equal('my super name for server 2')
+ expect(total).to.equal(1)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(1)
+ expect(data[0].name).to.equal('my super name for server 2')
})
it('Should list only local videos on server 3', async function () {
- const { body } = await getLocalVideos(servers[2].url)
+ const { data, total } = await servers[2].videosCommand.list({ filter: 'local' })
- expect(body.total).to.equal(2)
- expect(body.data).to.be.an('array')
- expect(body.data.length).to.equal(2)
- expect(body.data[0].name).to.equal('my super name for server 3')
- expect(body.data[1].name).to.equal('my super name for server 3-2')
+ expect(total).to.equal(2)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(2)
+ expect(data[0].name).to.equal('my super name for server 3')
+ expect(data[1].name).to.equal('my super name for server 3-2')
})
})
it('Should add the file 1 by asking server 3', async function () {
this.timeout(10000)
- const res = await getVideosList(servers[2].url)
-
- const video = res.body.data[0]
- toRemove.push(res.body.data[2])
- toRemove.push(res.body.data[3])
+ const { data } = await servers[2].videosCommand.list()
- const res2 = await getVideo(servers[2].url, video.id)
- const videoDetails = res2.body
+ const video = data[0]
+ toRemove.push(data[2])
+ toRemove.push(data[3])
+ const videoDetails = await servers[2].videosCommand.get({ id: video.id })
const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
expect(torrent.files).to.be.an('array')
expect(torrent.files.length).to.equal(1)
it('Should add the file 2 by asking server 1', async function () {
this.timeout(10000)
- const res = await getVideosList(servers[0].url)
+ const { data } = await servers[0].videosCommand.list()
- const video = res.body.data[1]
- const res2 = await getVideo(servers[0].url, video.id)
- const videoDetails = res2.body
+ const video = data[1]
+ const videoDetails = await servers[0].videosCommand.get({ id: video.id })
const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
expect(torrent.files).to.be.an('array')
it('Should add the file 3 by asking server 2', async function () {
this.timeout(10000)
- const res = await getVideosList(servers[1].url)
+ const { data } = await servers[1].videosCommand.list()
- const video = res.body.data[2]
- const res2 = await getVideo(servers[1].url, video.id)
- const videoDetails = res2.body
+ const video = data[2]
+ const videoDetails = await servers[1].videosCommand.get({ id: video.id })
const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
expect(torrent.files).to.be.an('array')
it('Should add the file 3-2 by asking server 1', async function () {
this.timeout(10000)
- const res = await getVideosList(servers[0].url)
+ const { data } = await servers[0].videosCommand.list()
- const video = res.body.data[3]
- const res2 = await getVideo(servers[0].url, video.id)
- const videoDetails = res2.body
+ const video = data[3]
+ const videoDetails = await servers[0].videosCommand.get({ id: video.id })
const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
expect(torrent.files).to.be.an('array')
it('Should add the file 2 in 360p by asking server 1', async function () {
this.timeout(10000)
- const res = await getVideosList(servers[0].url)
+ const { data } = await servers[0].videosCommand.list()
- const video = res.body.data.find(v => v.name === 'my super name for server 2')
- const res2 = await getVideo(servers[0].url, video.id)
- const videoDetails = res2.body
+ const video = data.find(v => v.name === 'my super name for server 2')
+ const videoDetails = await servers[0].videosCommand.get({ id: video.id })
const file = videoDetails.files.find(f => f.resolution.id === 360)
expect(file).not.to.be.undefined
let remoteVideosServer3 = []
before(async function () {
- const res1 = await getVideosList(servers[0].url)
- remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
+ {
+ const { data } = await servers[0].videosCommand.list()
+ remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid)
+ }
- const res2 = await getVideosList(servers[1].url)
- remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
+ {
+ const { data } = await servers[1].videosCommand.list()
+ remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid)
+ }
- const res3 = await getVideosList(servers[2].url)
- localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
- remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
+ {
+ const { data } = await servers[2].videosCommand.list()
+ localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid)
+ remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid)
+ }
})
it('Should view multiple videos on owned servers', async function () {
this.timeout(30000)
- await viewVideo(servers[2].url, localVideosServer3[0])
+ await servers[2].videosCommand.view({ id: localVideosServer3[0] })
await wait(1000)
- await viewVideo(servers[2].url, localVideosServer3[0])
- await viewVideo(servers[2].url, localVideosServer3[1])
+ await servers[2].videosCommand.view({ id: localVideosServer3[0] })
+ await servers[2].videosCommand.view({ id: localVideosServer3[1] })
await wait(1000)
- await viewVideo(servers[2].url, localVideosServer3[0])
- await viewVideo(servers[2].url, localVideosServer3[0])
+ await servers[2].videosCommand.view({ id: localVideosServer3[0] })
+ await servers[2].videosCommand.view({ id: localVideosServer3[0] })
await waitJobs(servers)
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const videos = res.body.data
- const video0 = videos.find(v => v.uuid === localVideosServer3[0])
- const video1 = videos.find(v => v.uuid === localVideosServer3[1])
+ const video0 = data.find(v => v.uuid === localVideosServer3[0])
+ const video1 = data.find(v => v.uuid === localVideosServer3[1])
expect(video0.views).to.equal(3)
expect(video1.views).to.equal(1)
this.timeout(45000)
const tasks: Promise<any>[] = []
- tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0]))
- tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
- tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
- tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0]))
- tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
- tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
- tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
- tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
- tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
- tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
+ tasks.push(servers[0].videosCommand.view({ id: remoteVideosServer1[0] }))
+ tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] }))
+ tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] }))
+ tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[0] }))
+ tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
+ tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
+ tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
+ tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
+ tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
+ tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
await Promise.all(tasks)
let baseVideos = null
for (const server of servers) {
- const res = await getVideosList(server.url)
-
- const videos = res.body.data
+ const { data } = await server.videosCommand.list()
// Initialize base videos for future comparisons
if (baseVideos === null) {
- baseVideos = videos
+ baseVideos = data
continue
}
for (const baseVideo of baseVideos) {
- const sameVideo = videos.find(video => video.name === baseVideo.name)
+ const sameVideo = data.find(video => video.name === baseVideo.name)
expect(baseVideo.views).to.equal(sameVideo.views)
}
}
it('Should like and dislikes videos on different services', async function () {
this.timeout(50000)
- await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
+ await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' })
await wait(500)
- await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')
+ await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'dislike' })
await wait(500)
- await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
- await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')
+ await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' })
+ await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'like' })
await wait(500)
- await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')
- await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')
+ await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'dislike' })
+ await servers[2].videosCommand.rate({ id: remoteVideosServer3[1], rating: 'dislike' })
await wait(500)
- await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')
+ await servers[2].videosCommand.rate({ id: remoteVideosServer3[0], rating: 'like' })
await waitJobs(servers)
await wait(5000)
let baseVideos = null
for (const server of servers) {
- const res = await getVideosList(server.url)
-
- const videos = res.body.data
+ const { data } = await server.videosCommand.list()
// Initialize base videos for future comparisons
if (baseVideos === null) {
- baseVideos = videos
+ baseVideos = data
continue
}
for (const baseVideo of baseVideos) {
- const sameVideo = videos.find(video => video.name === baseVideo.name)
+ const sameVideo = data.find(video => video.name === baseVideo.name)
expect(baseVideo.likes).to.equal(sameVideo.likes)
expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
}
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)
})
this.timeout(10000)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const videos = res.body.data
- const videoUpdated = videos.find(video => video.name === 'my super video updated')
+ const videoUpdated = data.find(video => video.name === 'my super video updated')
expect(!!videoUpdated).to.be.true
const isLocal = server.url === 'http://localhost:' + servers[2].port
thumbnailfile: 'thumbnail',
previewfile: 'preview'
}
- await completeVideoCheck(server.url, videoUpdated, checkAttributes)
+ await completeVideoCheck(server, videoUpdated, checkAttributes)
}
})
it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
this.timeout(10000)
- await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
- await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
+ await servers[2].videosCommand.remove({ id: toRemove[0].id })
+ await servers[2].videosCommand.remove({ id: toRemove[1].id })
await waitJobs(servers)
})
it('Should have videos 1 and 3 on each server', async function () {
for (const server of servers) {
- const res = await getVideosList(server.url)
-
- const videos = res.body.data
- expect(videos).to.be.an('array')
- expect(videos.length).to.equal(2)
- expect(videos[0].name).not.to.equal(videos[1].name)
- expect(videos[0].name).not.to.equal(toRemove[0].name)
- expect(videos[1].name).not.to.equal(toRemove[0].name)
- expect(videos[0].name).not.to.equal(toRemove[1].name)
- expect(videos[1].name).not.to.equal(toRemove[1].name)
-
- videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
+ const { data } = await server.videosCommand.list()
+
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(2)
+ expect(data[0].name).not.to.equal(data[1].name)
+ expect(data[0].name).not.to.equal(toRemove[0].name)
+ expect(data[1].name).not.to.equal(toRemove[0].name)
+ expect(data[0].name).not.to.equal(toRemove[1].name)
+ expect(data[1].name).not.to.equal(toRemove[1].name)
+
+ videoUUID = data.find(video => video.name === 'my super name for server 1').uuid
}
})
it('Should get the same video by UUID on each server', async function () {
let baseVideo = null
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
-
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoUUID })
if (baseVideo === null) {
baseVideo = video
it('Should get the preview from each server', async function () {
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoUUID })
await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
}
downloadEnabled: false
}
- await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes)
+ await servers[0].videosCommand.update({ id: videoUUID, attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- expect(res.body.commentsEnabled).to.be.false
- expect(res.body.downloadEnabled).to.be.false
+ const video = await server.videosCommand.get({ id: videoUUID })
+ expect(video.commentsEnabled).to.be.false
+ expect(video.downloadEnabled).to.be.false
const text = 'my super forbidden comment'
await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const video = res.body.data.find(v => v.name === 'minimum parameters')
+ const { data } = await server.videosCommand.list()
+ const video = data.find(v => v.name === 'minimum parameters')
const isLocal = server.url === 'http://localhost:' + servers[1].port
const checkAttributes = {
}
]
}
- await completeVideoCheck(server.url, video, checkAttributes)
+ await completeVideoCheck(server, video, checkAttributes)
}
})
})
buildAbsoluteFixturePath,
cleanupTests,
flushAndRunServer,
- prepareResumableUpload,
- sendResumableChunks,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel
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]
}
const size = await buildSize(defaultFixture, options.size)
const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture)
- return sendResumableChunks({
- url: server.url,
- token: server.accessToken,
+ return server.videosCommand.sendResumableChunks({
pathUploadId,
videoFilePath: absoluteFilePath,
size,
contentLength,
contentRangeBuilder,
- specialStatus: expectedStatus
+ expectedStatus
})
}
import 'mocha'
import * as chai from 'chai'
-import { keyBy } from 'lodash'
-
import {
checkVideoFilesWereRemoved,
cleanupTests,
completeVideoCheck,
flushAndRunServer,
- getVideo,
- getVideoCategories,
- getVideoLanguages,
- getVideoLicences,
- getVideoPrivacies,
- getVideosList,
- getVideosListPagination,
- getVideosListSort,
- getVideosWithFilters,
- rateVideo,
- removeVideo,
ServerInfo,
setAccessTokensToServers,
testImage,
- updateVideo,
- uploadVideo,
- viewVideo,
wait
-} from '../../../../shared/extra-utils'
-import { VideoPrivacy } from '../../../../shared/models/videos'
-import { HttpStatusCode } from '@shared/core-utils'
+} from '@shared/extra-utils'
+import { Video, VideoPrivacy } from '@shared/models'
const expect = chai.expect
function runSuite (mode: 'legacy' | 'resumable') {
let server: ServerInfo = null
- let videoId = -1
- let videoId2 = -1
+ let videoId: number | string
+ let videoId2: string
let videoUUID = ''
let videosListBase: any[] = null
})
it('Should list video categories', async function () {
- const res = await getVideoCategories(server.url)
-
- const categories = res.body
+ const categories = await server.videosCommand.getCategories()
expect(Object.keys(categories)).to.have.length.above(10)
expect(categories[11]).to.equal('News & Politics')
})
it('Should list video licences', async function () {
- const res = await getVideoLicences(server.url)
-
- const licences = res.body
+ const licences = await server.videosCommand.getLicences()
expect(Object.keys(licences)).to.have.length.above(5)
expect(licences[3]).to.equal('Attribution - No Derivatives')
})
it('Should list video languages', async function () {
- const res = await getVideoLanguages(server.url)
-
- const languages = res.body
+ const languages = await server.videosCommand.getLanguages()
expect(Object.keys(languages)).to.have.length.above(5)
expect(languages['ru']).to.equal('Russian')
})
it('Should list video privacies', async function () {
- const res = await getVideoPrivacies(server.url)
-
- const privacies = res.body
+ const privacies = await server.videosCommand.getPrivacies()
expect(Object.keys(privacies)).to.have.length.at.least(3)
expect(privacies[3]).to.equal('Private')
})
it('Should not have videos', async function () {
- const res = await getVideosList(server.url)
+ const { data, total } = await server.videosCommand.list()
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data.length).to.equal(0)
+ expect(total).to.equal(0)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(0)
})
it('Should upload the video', async function () {
this.timeout(10000)
- const videoAttributes = {
+ const attributes = {
name: 'my super name',
category: 2,
nsfw: true,
licence: 6,
tags: [ 'tag1', 'tag2', 'tag3' ]
}
- const res = await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode)
- expect(res.body.video).to.not.be.undefined
- expect(res.body.video.id).to.equal(1)
- expect(res.body.video.uuid).to.have.length.above(5)
+ const video = await server.videosCommand.upload({ attributes, mode })
+ expect(video).to.not.be.undefined
+ expect(video.id).to.equal(1)
+ expect(video.uuid).to.have.length.above(5)
- videoId = res.body.video.id
- videoUUID = res.body.video.uuid
+ videoId = video.id
+ videoUUID = video.uuid
})
it('Should get and seed the uploaded video', async function () {
this.timeout(5000)
- const res = await getVideosList(server.url)
+ const { data, total } = await server.videosCommand.list()
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data.length).to.equal(1)
+ expect(total).to.equal(1)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(1)
- const video = res.body.data[0]
- await completeVideoCheck(server.url, video, getCheckAttributes())
+ const video = data[0]
+ await completeVideoCheck(server, video, getCheckAttributes())
})
it('Should get the video by UUID', async function () {
this.timeout(5000)
- const res = await getVideo(server.url, videoUUID)
-
- const video = res.body
- await completeVideoCheck(server.url, video, getCheckAttributes())
+ const video = await server.videosCommand.get({ id: videoUUID })
+ await completeVideoCheck(server, video, getCheckAttributes())
})
it('Should have the views updated', async function () {
this.timeout(20000)
- await viewVideo(server.url, videoId)
- await viewVideo(server.url, videoId)
- await viewVideo(server.url, videoId)
+ await server.videosCommand.view({ id: videoId })
+ await server.videosCommand.view({ id: videoId })
+ await server.videosCommand.view({ id: videoId })
await wait(1500)
- await viewVideo(server.url, videoId)
- await viewVideo(server.url, videoId)
+ await server.videosCommand.view({ id: videoId })
+ await server.videosCommand.view({ id: videoId })
await wait(1500)
- await viewVideo(server.url, videoId)
- await viewVideo(server.url, videoId)
+ await server.videosCommand.view({ id: videoId })
+ await server.videosCommand.view({ id: videoId })
// Wait the repeatable job
await wait(8000)
- const res = await getVideo(server.url, videoId)
-
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoId })
expect(video.views).to.equal(3)
})
it('Should remove the video', async function () {
- await removeVideo(server.url, server.accessToken, videoId)
+ await server.videosCommand.remove({ id: videoId })
await checkVideoFilesWereRemoved(videoUUID, server)
})
it('Should not have videos', async function () {
- const res = await getVideosList(server.url)
+ const { total, data } = await server.videosCommand.list()
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.be.an('array')
- expect(res.body.data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
+ expect(data).to.be.an('array')
+ expect(data).to.have.lengthOf(0)
})
it('Should upload 6 videos', async function () {
])
for (const video of videos) {
- const videoAttributes = {
+ const attributes = {
name: video + ' name',
description: video + ' description',
category: 2,
fixture: video
}
- await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode)
+ await server.videosCommand.upload({ attributes, mode })
}
})
it('Should have the correct durations', async function () {
- const res = await getVideosList(server.url)
+ const { total, data } = await server.videosCommand.list()
+
+ expect(total).to.equal(6)
+ expect(data).to.be.an('array')
+ expect(data).to.have.lengthOf(6)
- expect(res.body.total).to.equal(6)
- const videos = res.body.data
- expect(videos).to.be.an('array')
- expect(videos).to.have.lengthOf(6)
+ const videosByName: { [ name: string ]: Video } = {}
+ data.forEach(v => { videosByName[v.name] = v })
- const videosByName = keyBy<{ duration: number }>(videos, 'name')
expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
expect(videosByName['video_short.ogv name'].duration).to.equal(5)
expect(videosByName['video_short.webm name'].duration).to.equal(5)
})
it('Should have the correct thumbnails', async function () {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const videos = res.body.data
// For the next test
- videosListBase = videos
+ videosListBase = data
- for (const video of videos) {
+ for (const video of data) {
const videoName = video.name.replace(' name', '')
await testImage(server.url, videoName, video.thumbnailPath)
}
})
it('Should list only the two first videos', async function () {
- const res = await getVideosListPagination(server.url, 0, 2, 'name')
+ const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: 'name' })
- const videos = res.body.data
- expect(res.body.total).to.equal(6)
- expect(videos.length).to.equal(2)
- expect(videos[0].name).to.equal(videosListBase[0].name)
- expect(videos[1].name).to.equal(videosListBase[1].name)
+ expect(total).to.equal(6)
+ expect(data.length).to.equal(2)
+ expect(data[0].name).to.equal(videosListBase[0].name)
+ expect(data[1].name).to.equal(videosListBase[1].name)
})
it('Should list only the next three videos', async function () {
- const res = await getVideosListPagination(server.url, 2, 3, 'name')
+ const { total, data } = await server.videosCommand.list({ start: 2, count: 3, sort: 'name' })
- const videos = res.body.data
- expect(res.body.total).to.equal(6)
- expect(videos.length).to.equal(3)
- expect(videos[0].name).to.equal(videosListBase[2].name)
- expect(videos[1].name).to.equal(videosListBase[3].name)
- expect(videos[2].name).to.equal(videosListBase[4].name)
+ expect(total).to.equal(6)
+ expect(data.length).to.equal(3)
+ expect(data[0].name).to.equal(videosListBase[2].name)
+ expect(data[1].name).to.equal(videosListBase[3].name)
+ expect(data[2].name).to.equal(videosListBase[4].name)
})
it('Should list the last video', async function () {
- const res = await getVideosListPagination(server.url, 5, 6, 'name')
+ const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name' })
- const videos = res.body.data
- expect(res.body.total).to.equal(6)
- expect(videos.length).to.equal(1)
- expect(videos[0].name).to.equal(videosListBase[5].name)
+ expect(total).to.equal(6)
+ expect(data.length).to.equal(1)
+ expect(data[0].name).to.equal(videosListBase[5].name)
})
it('Should not have the total field', async function () {
- const res = await getVideosListPagination(server.url, 5, 6, 'name', true)
+ const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name', skipCount: true })
- const videos = res.body.data
- expect(res.body.total).to.not.exist
- expect(videos.length).to.equal(1)
- expect(videos[0].name).to.equal(videosListBase[5].name)
+ expect(total).to.not.exist
+ expect(data.length).to.equal(1)
+ expect(data[0].name).to.equal(videosListBase[5].name)
})
it('Should list and sort by name in descending order', async function () {
- const res = await getVideosListSort(server.url, '-name')
+ const { total, data } = await server.videosCommand.list({ sort: '-name' })
- const videos = res.body.data
- expect(res.body.total).to.equal(6)
- expect(videos.length).to.equal(6)
- expect(videos[0].name).to.equal('video_short.webm name')
- expect(videos[1].name).to.equal('video_short.ogv name')
- expect(videos[2].name).to.equal('video_short.mp4 name')
- expect(videos[3].name).to.equal('video_short3.webm name')
- expect(videos[4].name).to.equal('video_short2.webm name')
- expect(videos[5].name).to.equal('video_short1.webm name')
+ expect(total).to.equal(6)
+ expect(data.length).to.equal(6)
+ expect(data[0].name).to.equal('video_short.webm name')
+ expect(data[1].name).to.equal('video_short.ogv name')
+ expect(data[2].name).to.equal('video_short.mp4 name')
+ expect(data[3].name).to.equal('video_short3.webm name')
+ expect(data[4].name).to.equal('video_short2.webm name')
+ expect(data[5].name).to.equal('video_short1.webm name')
- videoId = videos[3].uuid
- videoId2 = videos[5].uuid
+ videoId = data[3].uuid
+ videoId2 = data[5].uuid
})
it('Should list and sort by trending in descending order', async function () {
- const res = await getVideosListPagination(server.url, 0, 2, '-trending')
+ const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-trending' })
- const videos = res.body.data
- expect(res.body.total).to.equal(6)
- expect(videos.length).to.equal(2)
+ expect(total).to.equal(6)
+ expect(data.length).to.equal(2)
})
it('Should list and sort by hotness in descending order', async function () {
- const res = await getVideosListPagination(server.url, 0, 2, '-hot')
+ const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-hot' })
- const videos = res.body.data
- expect(res.body.total).to.equal(6)
- expect(videos.length).to.equal(2)
+ expect(total).to.equal(6)
+ expect(data.length).to.equal(2)
})
it('Should list and sort by best in descending order', async function () {
- const res = await getVideosListPagination(server.url, 0, 2, '-best')
+ const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-best' })
- const videos = res.body.data
- expect(res.body.total).to.equal(6)
- expect(videos.length).to.equal(2)
+ expect(total).to.equal(6)
+ expect(data.length).to.equal(2)
})
it('Should update a video', async function () {
downloadEnabled: false,
tags: [ 'tagup1', 'tagup2' ]
}
- await updateVideo(server.url, server.accessToken, videoId, attributes)
+ await server.videosCommand.update({ id: videoId, attributes })
})
it('Should filter by tags and category', async function () {
- const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
- expect(res1.body.total).to.equal(1)
- expect(res1.body.data[0].name).to.equal('my super video updated')
+ {
+ const { data, total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
+ expect(total).to.equal(1)
+ expect(data[0].name).to.equal('my super video updated')
+ }
- const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
- expect(res2.body.total).to.equal(0)
+ {
+ const { total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
+ expect(total).to.equal(0)
+ }
})
it('Should have the video updated', async function () {
this.timeout(60000)
- const res = await getVideo(server.url, videoId)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoId })
- await completeVideoCheck(server.url, video, updateCheckAttributes())
+ await completeVideoCheck(server, video, updateCheckAttributes())
})
it('Should update only the tags of a video', async function () {
const attributes = {
tags: [ 'supertag', 'tag1', 'tag2' ]
}
- await updateVideo(server.url, server.accessToken, videoId, attributes)
+ await server.videosCommand.update({ id: videoId, attributes })
- const res = await getVideo(server.url, videoId)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoId })
- await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes))
+ await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes))
})
it('Should update only the description of a video', async function () {
const attributes = {
description: 'hello everybody'
}
- await updateVideo(server.url, server.accessToken, videoId, attributes)
+ await server.videosCommand.update({ id: videoId, attributes })
- const res = await getVideo(server.url, videoId)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoId })
const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
- await completeVideoCheck(server.url, video, expectedAttributes)
+ await completeVideoCheck(server, video, expectedAttributes)
})
it('Should like a video', async function () {
- await rateVideo(server.url, server.accessToken, videoId, 'like')
+ await server.videosCommand.rate({ id: videoId, rating: 'like' })
- const res = await getVideo(server.url, videoId)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoId })
expect(video.likes).to.equal(1)
expect(video.dislikes).to.equal(0)
})
it('Should dislike the same video', async function () {
- await rateVideo(server.url, server.accessToken, videoId, 'dislike')
+ await server.videosCommand.rate({ id: videoId, rating: 'dislike' })
- const res = await getVideo(server.url, videoId)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoId })
expect(video.likes).to.equal(0)
expect(video.dislikes).to.equal(1)
{
const now = new Date()
const attributes = { originallyPublishedAt: now.toISOString() }
- await updateVideo(server.url, server.accessToken, videoId, attributes)
+ await server.videosCommand.update({ id: videoId, attributes })
- const res = await getVideosListSort(server.url, '-originallyPublishedAt')
- const names = res.body.data.map(v => v.name)
+ const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' })
+ const names = data.map(v => v.name)
expect(names[0]).to.equal('my super video updated')
expect(names[1]).to.equal('video_short2.webm name')
{
const now = new Date()
const attributes = { originallyPublishedAt: now.toISOString() }
- await updateVideo(server.url, server.accessToken, videoId2, attributes)
+ await server.videosCommand.update({ id: videoId2, attributes })
- const res = await getVideosListSort(server.url, '-originallyPublishedAt')
- const names = res.body.data.map(v => v.name)
+ const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' })
+ const names = data.map(v => v.name)
expect(names[0]).to.equal('video_short1.webm name')
expect(names[1]).to.equal('my super video updated')
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- removeVideo,
ServerInfo,
setAccessTokensToServers,
testCaptionFile,
- uploadVideo,
wait,
waitJobs
} from '@shared/extra-utils'
await waitJobs(servers)
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' })
- videoUUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'my video name' } })
+ videoUUID = uuid
await waitJobs(servers)
})
})
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])
})
import 'mocha'
import * as chai from 'chai'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
ChangeOwnershipCommand,
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
flushAndRunServer,
- getVideo,
- getVideosList,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- uploadVideo
-} from '../../../../shared/extra-utils'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
+ waitJobs
+} from '@shared/extra-utils'
+import { VideoPrivacy } from '@shared/models'
const expect = chai.expect
}
{
- const videoAttributes = {
+ const attributes = {
name: 'my super name',
description: 'my super description'
}
- const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes)
+ const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes })
- const resVideo = await getVideo(servers[0].url, res.body.video.id)
- servers[0].video = resVideo.body
+ servers[0].video = await servers[0].videosCommand.get({ id })
}
{
it('Should have the channel of the video updated', async function () {
for (const server of servers) {
- const res = await getVideo(server.url, servers[0].video.uuid)
-
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: servers[0].video.uuid })
expect(video.name).to.equal('my super name')
expect(video.channel.displayName).to.equal('Main second channel')
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, servers[0].video.uuid)
-
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: servers[0].video.uuid })
expect(video.name).to.equal('my super name')
expect(video.channel.displayName).to.equal('Main second channel')
secondUserToken = await server.loginCommand.getAccessToken(secondUser)
// Upload some videos on the server
- const video1Attributes = {
+ const attributes = {
name: 'my super name',
description: 'my super description'
}
- await uploadVideo(server.url, firstUserToken, video1Attributes)
+ await server.videosCommand.upload({ token: firstUserToken, attributes })
await waitJobs(server)
- const res = await getVideosList(server.url)
- const videos = res.body.data
-
- expect(videos.length).to.equal(1)
+ const { data } = await server.videosCommand.list()
+ expect(data.length).to.equal(1)
- server.video = videos.find(video => video.name === 'my super name')
+ server.video = data.find(video => video.name === 'my super name')
})
it('Should send a request to change ownership of a video', async function () {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
- getVideoChannelVideos,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
testFileExistsOrNot,
testImage,
- updateVideo,
- uploadVideo,
- viewVideo,
wait,
waitJobs
} from '@shared/extra-utils'
-import { User, Video, VideoChannel, VideoDetails } from '@shared/models'
+import { User, VideoChannel } from '@shared/models'
const expect = chai.expect
// The channel is 1 is propagated to servers 2
{
- const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
- videoUUID = res.body.video.uuid
+ const attributes = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
+ const { uuid } = await servers[0].videosCommand.upload({ attributes })
+ videoUUID = uuid
}
await waitJobs(servers)
it('Should not have updated the video support field', async function () {
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video: VideoDetails = res.body
-
+ const video = await server.videosCommand.get({ id: videoUUID })
expect(video.support).to.equal('video support field')
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video: VideoDetails = res.body
-
+ const video = await server.videosCommand.get({ id: videoUUID })
expect(video.support).to.equal(videoChannelAttributes.support)
}
})
for (const server of servers) {
const channelURI = 'second_video_channel@localhost:' + servers[0].port
- const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
- expect(res1.body.total).to.equal(1)
- expect(res1.body.data).to.be.an('array')
- expect(res1.body.data).to.have.lengthOf(1)
- expect(res1.body.data[0].name).to.equal('my video name')
+ const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI })
+
+ expect(total).to.equal(1)
+ expect(data).to.be.an('array')
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].name).to.equal('my video name')
}
})
it('Should change the video channel of a video', async function () {
this.timeout(10000)
- await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: servers[0].videoChannel.id })
+ await servers[0].videosCommand.update({ id: videoUUID, attributes: { channelId: servers[0].videoChannel.id } })
await waitJobs(servers)
})
this.timeout(10000)
for (const server of servers) {
- const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
- const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
- expect(res1.body.total).to.equal(0)
-
- const channelURI = 'root_channel@localhost:' + servers[0].port
- const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
- expect(res2.body.total).to.equal(1)
-
- const videos: Video[] = res2.body.data
- expect(videos).to.be.an('array')
- expect(videos).to.have.lengthOf(1)
- expect(videos[0].name).to.equal('my video name')
+ {
+ const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
+ const { total } = await server.videosCommand.listByChannel({ videoChannelName: secondChannelURI })
+ expect(total).to.equal(0)
+ }
+
+ {
+ const channelURI = 'root_channel@localhost:' + servers[0].port
+ const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI })
+ expect(total).to.equal(1)
+
+ expect(data).to.be.an('array')
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].name).to.equal('my video name')
+ }
}
})
{
// video has been posted on channel servers[0].videoChannel.id since last update
- await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1')
- await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1')
+ await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' })
+ await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' })
// Wait the repeatable job
await wait(8000)
it('Should list channels by updatedAt desc if a video has been uploaded', async function () {
this.timeout(30000)
- await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: totoChannel })
+ await servers[0].videosCommand.upload({ attributes: { channelId: totoChannel } })
await waitJobs(servers)
for (const server of servers) {
expect(data[1].name).to.equal('root_channel')
}
- await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: servers[0].videoChannel.id })
+ await servers[0].videosCommand.upload({ attributes: { channelId: servers[0].videoChannel.id } })
await waitJobs(servers)
for (const server of servers) {
flushAndRunServer,
ServerInfo,
setAccessTokensToServers,
- testImage,
- uploadVideo
+ testImage
} from '@shared/extra-utils'
const expect = chai.expect
await setAccessTokensToServers([ server ])
- const res = await uploadVideo(server.url, server.accessToken, {})
- videoUUID = res.body.video.uuid
- videoId = res.body.video.id
+ const { id, uuid } = await server.videosCommand.upload()
+ videoUUID = uuid
+ videoId = id
await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
import 'mocha'
import * as chai from 'chai'
-import {
- cleanupTests,
- flushAndRunMultipleServers,
- getVideo,
- getVideoDescription,
- getVideosList,
- ServerInfo,
- setAccessTokensToServers,
- updateVideo,
- uploadVideo
-} from '../../../../shared/extra-utils/index'
-import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
+import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
const expect = chai.expect
const attributes = {
description: longDescription
}
- await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
+ await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers)
- const res = await getVideosList(servers[0].url)
+ const { data } = await servers[0].videosCommand.list()
- videoId = res.body.data[0].id
- videoUUID = res.body.data[0].uuid
+ videoId = data[0].id
+ videoUUID = data[0].uuid
})
it('Should have a truncated description on each server', async function () {
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoUUID })
// 30 characters * 6 -> 240 characters
const truncatedDescription = 'my super description for server 1'.repeat(7) +
it('Should fetch long description on each server', async function () {
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoUUID })
- const res2 = await getVideoDescription(server.url, video.descriptionPath)
- expect(res2.body.description).to.equal(longDescription)
+ const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath })
+ expect(description).to.equal(longDescription)
}
})
const attributes = {
description: 'short description'
}
- await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes)
+ await servers[0].videosCommand.update({ id: videoId, attributes })
await waitJobs(servers)
})
it('Should have a small description on each server', async function () {
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video = res.body
+ const video = await server.videosCommand.get({ id: videoUUID })
expect(video.description).to.equal('short description')
- const res2 = await getVideoDescription(server.url, video.descriptionPath)
- expect(res2.body.description).to.equal('short description')
+ const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath })
+ expect(description).to.equal('short description')
}
})
import 'mocha'
import * as chai from 'chai'
import { join } from 'path'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
checkDirectoryIsEmpty,
checkResolutionsInMasterPlaylist,
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
makeRawRequest,
- removeVideo,
ServerInfo,
setAccessTokensToServers,
- updateVideo,
- uploadVideo,
waitJobs,
webtorrentAdd
-} from '../../../../shared/extra-utils'
-import { VideoDetails } from '../../../../shared/models/videos'
-import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
+} from '@shared/extra-utils'
+import { VideoStreamingPlaylistType } from '@shared/models'
import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
const expect = chai.expect
async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) {
for (const server of servers) {
- const resVideoDetails = await getVideo(server.url, videoUUID)
- const videoDetails: VideoDetails = resVideoDetails.body
+ const videoDetails = await server.videosCommand.get({ id: videoUUID })
const baseUrl = `http://${videoDetails.account.host}`
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
it('Should upload a video and transcode it to HLS', async function () {
this.timeout(120000)
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' })
- videoUUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
+ videoUUID = uuid
await waitJobs(servers)
it('Should upload an audio file and transcode it to HLS', async function () {
this.timeout(120000)
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' })
- videoAudioUUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
+ videoAudioUUID = uuid
await waitJobs(servers)
it('Should update the video', async function () {
this.timeout(10000)
- await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' })
+ await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video 1 updated' } })
await waitJobs(servers)
it('Should delete videos', async function () {
this.timeout(10000)
- await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
- await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID)
+ await servers[0].videosCommand.remove({ id: videoUUID })
+ await servers[0].videosCommand.remove({ id: videoAudioUUID })
await waitJobs(servers)
for (const server of servers) {
- await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404)
- await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404)
+ await server.videosCommand.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
+ await server.videosCommand.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}
})
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getMyVideos,
- getVideo,
- getVideosList,
ImportsCommand,
ServerInfo,
setAccessTokensToServers,
testImage,
waitJobs
} from '@shared/extra-utils'
-import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models'
+import { VideoPrivacy, VideoResolution } from '@shared/models'
const expect = chai.expect
if (areHttpImportTestsDisabled()) return
async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) {
- const resHttp = await getVideo(server.url, idHttp)
- const videoHttp: VideoDetails = resHttp.body
+ const videoHttp = await server.videosCommand.get({ id: idHttp })
expect(videoHttp.name).to.equal('small video - youtube')
// FIXME: youtube-dl seems broken
expect(originallyPublishedAt.getMonth()).to.equal(0)
expect(originallyPublishedAt.getFullYear()).to.equal(2019)
- const resMagnet = await getVideo(server.url, idMagnet)
- const videoMagnet: VideoDetails = resMagnet.body
- const resTorrent = await getVideo(server.url, idTorrent)
- const videoTorrent: VideoDetails = resTorrent.body
+ const videoMagnet = await server.videosCommand.get({ id: idMagnet })
+ const videoTorrent = await server.videosCommand.get({ id: idTorrent })
for (const video of [ videoMagnet, videoTorrent ]) {
expect(video.category.label).to.equal('Misc')
}
async function checkVideoServer2 (server: ServerInfo, id: number | string) {
- const res = await getVideo(server.url, id)
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id })
expect(video.name).to.equal('my super name')
expect(video.category.label).to.equal('Entertainment')
})
it('Should list the videos to import in my videos on server 1', async function () {
- const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
+ const { total, data } = await servers[0].videosCommand.listMyVideos({ sort: 'createdAt' })
- expect(res.body.total).to.equal(3)
+ expect(total).to.equal(3)
- const videos = res.body.data
- expect(videos).to.have.lengthOf(3)
- expect(videos[0].name).to.equal('small video - youtube')
- expect(videos[1].name).to.equal('super peertube2 video')
- expect(videos[2].name).to.equal('ä½ å¥½ 世界 720p.mp4')
+ expect(data).to.have.lengthOf(3)
+ expect(data[0].name).to.equal('small video - youtube')
+ expect(data[1].name).to.equal('super peertube2 video')
+ expect(data[2].name).to.equal('ä½ å¥½ 世界 720p.mp4')
})
it('Should list the videos to import in my imports on server 1', async function () {
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- expect(res.body.total).to.equal(3)
- expect(res.body.data).to.have.lengthOf(3)
+ const { total, data } = await server.videosCommand.list()
+ expect(total).to.equal(3)
+ expect(data).to.have.lengthOf(3)
- const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
+ const [ videoHttp, videoMagnet, videoTorrent ] = data
await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- expect(res.body.total).to.equal(4)
- expect(res.body.data).to.have.lengthOf(4)
+ const { total, data } = await server.videosCommand.list()
+ expect(total).to.equal(4)
+ expect(data).to.have.lengthOf(4)
- await checkVideoServer2(server, res.body.data[0].uuid)
+ await checkVideoServer2(server, data[0].uuid)
- const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
+ const [ , videoHttp, videoMagnet, videoTorrent ] = data
await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videoUUID)
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: videoUUID })
expect(video.name).to.equal('transcoded video')
expect(video.files).to.have.lengthOf(4)
await waitJobs(servers)
// test resolution
- const res2 = await getVideo(servers[0].url, videoUUID)
- const video: VideoDetails = res2.body
+ const video = await servers[0].videosCommand.get({ id: videoUUID })
expect(video.name).to.equal('hdr video')
const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id }))
expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P)
import 'mocha'
import * as chai from 'chai'
-import {
- cleanupTests,
- flushAndRunServer,
- getAccountVideos,
- getMyVideos,
- getVideoChannelVideos,
- getVideosList,
- getVideosListWithToken,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo
-} from '@shared/extra-utils'
+import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models'
const expect = chai.expect
if (token) {
promises = [
- getVideosListWithToken(server.url, token, query).then(res => res.body),
server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }),
- getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body),
- getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body)
+ server.videosCommand.listWithToken({ token, ...query }),
+ server.videosCommand.listByAccount({ token, accountName, ...query }),
+ server.videosCommand.listByChannel({ token, videoChannelName, ...query })
]
// Overviews do not support video filters
}
promises = [
- getVideosList(server.url).then(res => res.body),
server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }),
- getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body),
- getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body)
+ server.videosCommand.list(),
+ server.videosCommand.listByAccount({ accountName }),
+ server.videosCommand.listByChannel({ videoChannelName })
]
// Overviews do not support video filters
{
const attributes = { name: 'nsfw', nsfw: true, category: 1 }
- await uploadVideo(server.url, server.accessToken, attributes)
+ await server.videosCommand.upload({ attributes })
}
{
const attributes = { name: 'normal', nsfw: false, category: 1 }
- await uploadVideo(server.url, server.accessToken, attributes)
+ await server.videosCommand.upload({ attributes })
}
customConfig = await server.configCommand.getCustomConfig()
})
it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
- const res = await getMyVideos(server.url, server.accessToken, 0, 5)
- expect(res.body.total).to.equal(2)
+ const { total, data } = await server.videosCommand.listMyVideos()
+ expect(total).to.equal(2)
- const videos = res.body.data
- expect(videos).to.have.lengthOf(2)
- expect(videos[0].name).to.equal('normal')
- expect(videos[1].name).to.equal('nsfw')
+ expect(data).to.have.lengthOf(2)
+ expect(data[0].name).to.equal('normal')
+ expect(data[1].name).to.equal('nsfw')
})
it('Should display NSFW videos when the nsfw param === true', async function () {
setAccessTokensToServers,
setDefaultVideoChannel,
testImage,
- uploadVideoAndGetId,
waitJobs
} from '../../../../shared/extra-utils'
import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
// Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1])
- video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id
- video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id
+ video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).id
+ video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).id
await waitJobs(servers)
})
setAccessTokensToServers,
setDefaultVideoChannel,
testImage,
- updateVideo,
- uploadVideo,
- uploadVideoAndGetId,
wait,
waitJobs
} from '@shared/extra-utils'
for (const server of servers) {
for (let i = 0; i < 7; i++) {
const name = `video ${i} server ${server.serverNumber}`
- const resVideo = await uploadVideo(server.url, server.accessToken, { name, nsfw: false })
+ const video = await server.videosCommand.upload({ attributes: { name, nsfw: false } })
- server.videos.push(resVideo.body.video)
+ server.videos.push(video)
}
}
}
- nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id
+ nsfwVideoServer1 = (await servers[0].videosCommand.quickUpload({ name: 'NSFW video', nsfw: true })).id
userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1')
return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes })
}
- video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userTokenServer1 })).uuid
- video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid
- video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid
+ video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid
+ video2 = (await servers[1].videosCommand.quickUpload({ name: 'video 90' })).uuid
+ video3 = (await servers[0].videosCommand.quickUpload({ name: 'video 91', nsfw: true })).uuid
await waitJobs(servers)
const position = 1
{
- await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE })
+ await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } })
await waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
}
{
- await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC })
+ await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } })
await waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import {
- cleanupTests,
- doubleFollow,
- flushAndRunServer,
- getMyVideos,
- getVideo,
- getVideosList,
- getVideosListWithToken,
- getVideoWithToken,
- ServerInfo,
- setAccessTokensToServers,
- updateVideo,
- uploadVideo,
- waitJobs
-} from '@shared/extra-utils'
-import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models'
+import { cleanupTests, doubleFollow, flushAndRunServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
+import { VideoCreateResult, VideoPrivacy } from '@shared/models'
const expect = chai.expect
for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) {
const attributes = { privacy }
- await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
+ await servers[0].videosCommand.upload({ attributes })
}
await waitJobs(servers)
})
it('Should not have these private and internal videos on server 2', async function () {
- const res = await getVideosList(servers[1].url)
+ const { total, data } = await servers[1].videosCommand.list()
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
})
it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () {
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videosCommand.list()
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
})
it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () {
- const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+ const { total, data } = await servers[0].videosCommand.listWithToken()
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
- expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL)
+ expect(data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL)
})
it('Should list my (private and internal) videos', async function () {
- const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10)
+ const { total, data } = await servers[0].videosCommand.listMyVideos()
- expect(res.body.total).to.equal(2)
- expect(res.body.data).to.have.lengthOf(2)
+ expect(total).to.equal(2)
+ expect(data).to.have.lengthOf(2)
- const videos: Video[] = res.body.data
-
- const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
+ const privateVideo = data.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
privateVideoId = privateVideo.id
privateVideoUUID = privateVideo.uuid
- const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL)
+ const internalVideo = data.find(v => v.privacy.id === VideoPrivacy.INTERNAL)
internalVideoId = internalVideo.id
internalVideoUUID = internalVideo.uuid
})
it('Should not be able to watch the private/internal video with non authenticated user', async function () {
- await getVideo(servers[0].url, privateVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
- await getVideo(servers[0].url, internalVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
+ await servers[0].videosCommand.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ await servers[0].videosCommand.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should not be able to watch the private video with another user', async function () {
await servers[0].usersCommand.create({ username: user.username, password: user.password })
anotherUserToken = await servers[0].loginCommand.getAccessToken(user)
- await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403)
+
+ await servers[0].videosCommand.getWithToken({
+ token: anotherUserToken,
+ id: privateVideoUUID,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
})
it('Should be able to watch the internal video with another user', async function () {
- await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.getWithToken({ token: anotherUserToken, id: internalVideoUUID })
})
it('Should be able to watch the private video with the correct user', async function () {
- await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, HttpStatusCode.OK_200)
+ await servers[0].videosCommand.getWithToken({ id: privateVideoUUID })
})
})
name: 'unlisted video',
privacy: VideoPrivacy.UNLISTED
}
- await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
+ await servers[1].videosCommand.upload({ attributes })
// Server 2 has transcoding enabled
await waitJobs(servers)
it('Should not have this unlisted video listed on server 1 and 2', async function () {
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { total, data } = await server.videosCommand.list()
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
}
})
it('Should list my (unlisted) videos', async function () {
- const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
+ const { total, data } = await servers[1].videosCommand.listMyVideos()
- expect(res.body.total).to.equal(1)
- expect(res.body.data).to.have.lengthOf(1)
+ expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(1)
- unlistedVideo = res.body.data[0]
+ unlistedVideo = data[0]
})
it('Should not be able to get this unlisted video using its id', async function () {
- await getVideo(servers[1].url, unlistedVideo.id, 404)
+ await servers[1].videosCommand.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should be able to get this unlisted video using its uuid/shortUUID', async function () {
for (const server of servers) {
for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) {
- const res = await getVideo(server.url, id)
+ const video = await server.videosCommand.get({ id })
- expect(res.body.name).to.equal('unlisted video')
+ expect(video.name).to.equal('unlisted video')
}
}
})
name: 'unlisted video',
privacy: VideoPrivacy.UNLISTED
}
- await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
+ await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers)
})
it('Should list my new unlisted video', async function () {
- const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 3)
+ const { total, data } = await servers[0].videosCommand.listMyVideos()
- expect(res.body.total).to.equal(3)
- expect(res.body.data).to.have.lengthOf(3)
+ expect(total).to.equal(3)
+ expect(data).to.have.lengthOf(3)
- nonFederatedUnlistedVideoUUID = res.body.data[0].uuid
+ nonFederatedUnlistedVideoUUID = data[0].uuid
})
it('Should be able to get non-federated unlisted video from origin', async function () {
- const res = await getVideo(servers[0].url, nonFederatedUnlistedVideoUUID)
+ const video = await servers[0].videosCommand.get({ id: nonFederatedUnlistedVideoUUID })
- expect(res.body.name).to.equal('unlisted video')
+ expect(video.name).to.equal('unlisted video')
})
it('Should not be able to get non-federated unlisted video from federated server', async function () {
- await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, HttpStatusCode.NOT_FOUND_404)
+ await servers[1].videosCommand.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
})
now = Date.now()
{
- const attribute = {
+ const attributes = {
name: 'private video becomes public',
privacy: VideoPrivacy.PUBLIC
}
- await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
+ await servers[0].videosCommand.update({ id: privateVideoId, attributes })
}
{
- const attribute = {
+ const attributes = {
name: 'internal video becomes public',
privacy: VideoPrivacy.PUBLIC
}
- await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, attribute)
+ await servers[0].videosCommand.update({ id: internalVideoId, attributes })
}
await waitJobs(servers)
it('Should have this new public video listed on server 1 and 2', async function () {
for (const server of servers) {
- const res = await getVideosList(server.url)
- expect(res.body.total).to.equal(2)
- expect(res.body.data).to.have.lengthOf(2)
+ const { total, data } = await server.videosCommand.list()
+ expect(total).to.equal(2)
+ expect(data).to.have.lengthOf(2)
- const videos: Video[] = res.body.data
- const privateVideo = videos.find(v => v.name === 'private video becomes public')
- const internalVideo = videos.find(v => v.name === 'internal video becomes public')
+ const privateVideo = data.find(v => v.name === 'private video becomes public')
+ const internalVideo = data.find(v => v.name === 'internal video becomes public')
expect(privateVideo).to.not.be.undefined
expect(internalVideo).to.not.be.undefined
it('Should set these videos as private and internal', async function () {
this.timeout(10000)
- await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE })
- await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL })
+ await servers[0].videosCommand.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } })
+ await servers[0].videosCommand.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { total, data } = await server.videosCommand.list()
- expect(res.body.total).to.equal(0)
- expect(res.body.data).to.have.lengthOf(0)
+ expect(total).to.equal(0)
+ expect(data).to.have.lengthOf(0)
}
{
- const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
- const videos = res.body.data
-
- expect(res.body.total).to.equal(3)
- expect(videos).to.have.lengthOf(3)
+ const { total, data } = await servers[0].videosCommand.listMyVideos()
+ expect(total).to.equal(3)
+ expect(data).to.have.lengthOf(3)
- const privateVideo = videos.find(v => v.name === 'private video becomes public')
- const internalVideo = videos.find(v => v.name === 'internal video becomes public')
+ const privateVideo = data.find(v => v.name === 'private video becomes public')
+ const internalVideo = data.find(v => v.name === 'internal video becomes public')
expect(privateVideo).to.not.be.undefined
expect(internalVideo).to.not.be.undefined
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import * as chai from 'chai'
import 'mocha'
-import { VideoPrivacy } from '../../../../shared/models/videos'
+import * as chai from 'chai'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getMyVideos,
- getVideosList,
- getVideoWithToken,
ServerInfo,
setAccessTokensToServers,
- updateVideo,
- uploadVideo,
- wait
-} from '../../../../shared/extra-utils'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
+ wait,
+ waitJobs
+} from '@shared/extra-utils'
+import { VideoPrivacy } from '@shared/models'
const expect = chai.expect
it('Should upload a video and schedule an update in 10 seconds', async function () {
this.timeout(10000)
- const videoAttributes = {
+ const attributes = {
name: 'video 1',
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
updateAt: in10Seconds().toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
- await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
+ await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers)
})
it('Should not list the video (in privacy mode)', async function () {
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { total } = await server.videosCommand.list()
- expect(res.body.total).to.equal(0)
+ expect(total).to.equal(0)
}
})
it('Should have my scheduled video in my account videos', async function () {
- const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
- expect(res.body.total).to.equal(1)
+ const { total, data } = await servers[0].videosCommand.listMyVideos()
+ expect(total).to.equal(1)
- const videoFromList = res.body.data[0]
- const res2 = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoFromList.uuid)
- const videoFromGet = res2.body
+ const videoFromList = data[0]
+ const videoFromGet = await servers[0].videosCommand.getWithToken({ id: videoFromList.uuid })
for (const video of [ videoFromList, videoFromGet ]) {
expect(video.name).to.equal('video 1')
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { total, data } = await server.videosCommand.list()
- expect(res.body.total).to.equal(1)
- expect(res.body.data[0].name).to.equal('video 1')
+ expect(total).to.equal(1)
+ expect(data[0].name).to.equal('video 1')
}
})
it('Should upload a video without scheduling an update', async function () {
this.timeout(10000)
- const videoAttributes = {
+ const attributes = {
name: 'video 2',
privacy: VideoPrivacy.PRIVATE
}
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
- video2UUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes })
+ video2UUID = uuid
await waitJobs(servers)
})
it('Should update a video by scheduling an update', async function () {
this.timeout(10000)
- const videoAttributes = {
+ const attributes = {
name: 'video 2 updated',
scheduleUpdate: {
updateAt: in10Seconds().toISOString(),
- privacy: VideoPrivacy.PUBLIC
+ privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
- await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes)
+ await servers[0].videosCommand.update({ id: video2UUID, attributes })
await waitJobs(servers)
})
it('Should not display the updated video', async function () {
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { total } = await server.videosCommand.list()
- expect(res.body.total).to.equal(1)
+ expect(total).to.equal(1)
}
})
it('Should have my scheduled updated video in my account videos', async function () {
- const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
- expect(res.body.total).to.equal(2)
+ const { total, data } = await servers[0].videosCommand.listMyVideos()
+ expect(total).to.equal(2)
- const video = res.body.data.find(v => v.uuid === video2UUID)
+ const video = data.find(v => v.uuid === video2UUID)
expect(video).not.to.be.undefined
expect(video.name).to.equal('video 2 updated')
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
-
- expect(res.body.total).to.equal(2)
+ const { total, data } = await server.videosCommand.list()
+ expect(total).to.equal(2)
- const video = res.body.data.find(v => v.uuid === video2UUID)
+ const video = data.find(v => v.uuid === video2UUID)
expect(video).not.to.be.undefined
expect(video.name).to.equal('video 2 updated')
}
import 'mocha'
import * as chai from 'chai'
-import { FfprobeData } from 'fluent-ffmpeg'
import { omit } from 'lodash'
import { join } from 'path'
-import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
buildAbsoluteFixturePath,
cleanupTests,
flushAndRunMultipleServers,
generateHighBitrateVideo,
generateVideoWithFramerate,
- getMyVideos,
- getVideo,
- getVideoFileMetadataUrl,
- getVideosList,
makeGetRequest,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
- uploadVideoAndGetId,
waitJobs,
webtorrentAdd
-} from '../../../../shared/extra-utils'
-import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos'
+} from '@shared/extra-utils'
+import { getMaxBitrate, VideoResolution, VideoState } from '@shared/models'
+import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
import {
canDoQuickTranscode,
getAudioStream,
it('Should not transcode video on server 1', async function () {
this.timeout(60_000)
- const videoAttributes = {
+ const attributes = {
name: 'my super name for server 1',
description: 'my super description for server 1',
fixture: 'video_short.webm'
}
- await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
+ await servers[0].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const video = res.body.data[0]
+ const { data } = await server.videosCommand.list()
+ const video = data[0]
- const res2 = await getVideo(server.url, video.id)
- const videoDetails = res2.body
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(1)
const magnetUri = videoDetails.files[0].magnetUri
it('Should transcode video on server 2', async function () {
this.timeout(120_000)
- const videoAttributes = {
+ const attributes = {
name: 'my super name for server 2',
description: 'my super description for server 2',
fixture: 'video_short.webm'
}
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === videoAttributes.name)
- const res2 = await getVideo(server.url, video.id)
- const videoDetails = res2.body
+ const video = data.find(v => v.name === attributes.name)
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
{
// Upload the video, but wait transcoding
- const videoAttributes = {
+ const attributes = {
name: 'waiting video',
fixture: 'video_short1.webm',
waitTranscoding: true
}
- const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
- const videoId = resVideo.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes })
+ const videoId = uuid
// Should be in transcode state
- const { body } = await getVideo(servers[1].url, videoId)
+ const body = await servers[1].videosCommand.get({ id: videoId })
expect(body.name).to.equal('waiting video')
expect(body.state.id).to.equal(VideoState.TO_TRANSCODE)
expect(body.state.label).to.equal('To transcode')
expect(body.waitTranscoding).to.be.true
- // Should have my video
- const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10)
- const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name)
- expect(videoToFindInMine).not.to.be.undefined
- expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE)
- expect(videoToFindInMine.state.label).to.equal('To transcode')
- expect(videoToFindInMine.waitTranscoding).to.be.true
+ {
+ // Should have my video
+ const { data } = await servers[1].videosCommand.listMyVideos()
+ const videoToFindInMine = data.find(v => v.name === attributes.name)
+ expect(videoToFindInMine).not.to.be.undefined
+ expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE)
+ expect(videoToFindInMine.state.label).to.equal('To transcode')
+ expect(videoToFindInMine.waitTranscoding).to.be.true
+ }
- // Should not list this video
- const resVideos = await getVideosList(servers[1].url)
- const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name)
- expect(videoToFindInList).to.be.undefined
+ {
+ // Should not list this video
+ const { data } = await servers[1].videosCommand.list()
+ const videoToFindInList = data.find(v => v.name === attributes.name)
+ expect(videoToFindInList).to.be.undefined
+ }
// Server 1 should not have the video yet
- await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404)
+ await servers[0].videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videoToFind = res.body.data.find(v => v.name === 'waiting video')
+ const { data } = await server.videosCommand.list()
+ const videoToFind = data.find(v => v.name === 'waiting video')
expect(videoToFind).not.to.be.undefined
- const res2 = await getVideo(server.url, videoToFind.id)
- const videoDetails: VideoDetails = res2.body
+ const videoDetails = await server.videosCommand.get({ id: videoToFind.id })
expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED)
expect(videoDetails.state.label).to.equal('Published')
}
for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) {
- const videoAttributes = {
+ const attributes = {
name: fixture,
fixture
}
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
-
- const video = res.body.data.find(v => v.name === videoAttributes.name)
- const res2 = await getVideo(server.url, video.id)
- const videoDetails = res2.body
+ const { data } = await server.videosCommand.list()
+ const video = data.find(v => v.name === attributes.name)
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
const magnetUri = videoDetails.files[0].magnetUri
it('Should transcode a 4k video', async function () {
this.timeout(200_000)
- const videoAttributes = {
+ const attributes = {
name: '4k video',
fixture: 'video_short_4k.mp4'
}
- const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
- video4k = resUpload.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes })
+ video4k = uuid
await waitJobs(servers)
const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ]
for (const server of servers) {
- const res = await getVideo(server.url, video4k)
- const videoDetails: VideoDetails = res.body
-
+ const videoDetails = await server.videosCommand.get({ id: video4k })
expect(videoDetails.files).to.have.lengthOf(resolutions.length)
for (const r of resolutions) {
it('Should transcode high bit rate mp3 to proper bit rate', async function () {
this.timeout(60_000)
- const videoAttributes = {
+ const attributes = {
name: 'mp3_256k',
fixture: 'video_short_mp3_256k.mp4'
}
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === videoAttributes.name)
- const res2 = await getVideo(server.url, video.id)
- const videoDetails: VideoDetails = res2.body
+ const video = data.find(v => v.name === attributes.name)
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
it('Should transcode video with no audio and have no audio itself', async function () {
this.timeout(60_000)
- const videoAttributes = {
+ const attributes = {
name: 'no_audio',
fixture: 'video_short_no_audio.mp4'
}
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === videoAttributes.name)
- const res2 = await getVideo(server.url, video.id)
- const videoDetails: VideoDetails = res2.body
+ const video = data.find(v => v.name === attributes.name)
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4'))
it('Should leave the audio untouched, but properly transcode the video', async function () {
this.timeout(60_000)
- const videoAttributes = {
+ const attributes = {
name: 'untouched_audio',
fixture: 'video_short.mp4'
}
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === videoAttributes.name)
- const res2 = await getVideo(server.url, video.id)
- const videoDetails: VideoDetails = res2.body
+ const video = data.find(v => v.name === attributes.name)
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
- const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture)
+ const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
const fixtureVideoProbe = await getAudioStream(fixturePath)
const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4'))
it('Should merge an audio file with the preview file', async function () {
this.timeout(60_000)
- const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
+ const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
+ await servers[1].videosCommand.upload({ attributes, mode })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === 'audio_with_preview')
- const res2 = await getVideo(server.url, video.id)
- const videoDetails: VideoDetails = res2.body
+ const video = data.find(v => v.name === 'audio_with_preview')
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(1)
it('Should upload an audio file and choose a default background image', async function () {
this.timeout(60_000)
- const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' }
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
+ const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' }
+ await servers[1].videosCommand.upload({ attributes, mode })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === 'audio_without_preview')
- const res2 = await getVideo(server.url, video.id)
- const videoDetails = res2.body
+ const video = data.find(v => v.name === 'audio_without_preview')
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(1)
}
})
- const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
- const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
+ const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
+ const { id } = await servers[1].videosCommand.upload({ attributes, mode })
await waitJobs(servers)
for (const server of servers) {
- const res2 = await getVideo(server.url, resVideo.body.video.id)
- const videoDetails: VideoDetails = res2.body
+ const videoDetails = await server.videosCommand.get({ id })
for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
expect(files).to.have.lengthOf(2)
it('Should transcode a 60 FPS video', async function () {
this.timeout(60_000)
- const videoAttributes = {
+ const attributes = {
name: 'my super 30fps name for server 2',
description: 'my super 30fps description for server 2',
fixture: '60fps_720p_small.mp4'
}
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === videoAttributes.name)
- const res2 = await getVideo(server.url, video.id)
- const videoDetails: VideoDetails = res2.body
+ const video = data.find(v => v.name === attributes.name)
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.files[0].fps).to.be.above(58).and.below(62)
expect(fps).to.be.equal(59)
}
- const videoAttributes = {
+ const attributes = {
name: '59fps video',
description: '59fps video',
fixture: tempFixturePath
}
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === videoAttributes.name)
+ const video = data.find(v => v.name === attributes.name)
{
const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4'))
expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
}
- const videoAttributes = {
+ const attributes = {
name: 'high bitrate video',
description: 'high bitrate video',
fixture: tempFixturePath
}
- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.name === videoAttributes.name)
+ const video = data.find(v => v.name === attributes.name)
for (const resolution of [ '240', '360', '480', '720', '1080' ]) {
const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
}
await servers[1].configCommand.updateCustomSubConfig({ newConfig })
- const videoAttributes = {
+ const attributes = {
name: 'low bitrate',
fixture: 'low-bitrate.mp4'
}
- const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
- const videoUUID = resUpload.body.video.uuid
+ const { uuid } = await servers[1].videosCommand.upload({ attributes })
await waitJobs(servers)
const resolutions = [ 240, 360, 480, 720, 1080 ]
for (const r of resolutions) {
- const path = `videos/${videoUUID}-${r}.mp4`
+ const path = `videos/${uuid}-${r}.mp4`
const size = await servers[1].serversCommand.getServerFileSize(path)
expect(size, `${path} not below ${60_000}`).to.be.below(60_000)
}
it('Should provide valid ffprobe data', async function () {
this.timeout(160_000)
- const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid
+ const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'ffprobe data' })).uuid
await waitJobs(servers)
{
}
for (const server of servers) {
- const res2 = await getVideo(server.url, videoUUID)
- const videoDetails: VideoDetails = res2.body
+ const videoDetails = await server.videosCommand.get({ id: videoUUID })
const videoFiles = videoDetails.files
.concat(videoDetails.streamingPlaylists[0].files)
expect(file.metadataUrl).to.contain(servers[1].url)
expect(file.metadataUrl).to.contain(videoUUID)
- const res3 = await getVideoFileMetadataUrl(file.metadataUrl)
- const metadata: FfprobeData = res3.body
+ const metadata = await server.videosCommand.getFileMetadata({ url: file.metadataUrl })
expect(metadata).to.have.nested.property('format.size')
}
}
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
-import * as chai from 'chai'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { expect } from 'chai'
+import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
makeGetRequest,
ServerInfo,
- setAccessTokensToServers,
- uploadVideo
-} from '../../../../shared/extra-utils'
-import { UserRole } from '../../../../shared/models/users'
-import { Video, VideoPrivacy } from '../../../../shared/models/videos'
-
-const expect = chai.expect
+ setAccessTokensToServers
+} from '@shared/extra-utils'
+import { UserRole, Video, VideoPrivacy } from '@shared/models'
async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
const paths = [
await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator)
- await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber })
+ await server.videosCommand.upload({ attributes: { name: 'public ' + server.serverNumber } })
{
const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
- await uploadVideo(server.url, server.accessToken, attributes)
+ await server.videosCommand.upload({ attributes })
}
{
const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
- await uploadVideo(server.url, server.accessToken, attributes)
+ await server.videosCommand.upload({ attributes })
}
}
import {
cleanupTests,
flushAndRunServer,
- getVideosListWithToken,
- getVideoWithToken,
HistoryCommand,
killallServers,
reRunServer,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
wait
} from '@shared/extra-utils'
-import { Video, VideoDetails } from '@shared/models'
+import { Video } from '@shared/models'
const expect = chai.expect
command = server.historyCommand
{
- const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
- video1UUID = res.body.video.uuid
+ const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 1' } })
+ video1UUID = uuid
}
{
- const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
- video2UUID = res.body.video.uuid
+ const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 2' } })
+ video2UUID = uuid
}
{
- const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
- video3UUID = res.body.video.uuid
+ const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 3' } })
+ video3UUID = uuid
}
const user = {
})
it('Should get videos, without watching history', async function () {
- const res = await getVideosListWithToken(server.url, server.accessToken)
- const videos: Video[] = res.body.data
+ const { data } = await server.videosCommand.listWithToken()
- for (const video of videos) {
- const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id)
- const videoDetails: VideoDetails = resDetail.body
+ for (const video of data) {
+ const videoDetails = await server.videosCommand.getWithToken({ id: video.id })
expect(video.userHistory).to.be.undefined
expect(videoDetails.userHistory).to.be.undefined
const videosOfVideos: Video[][] = []
{
- const res = await getVideosListWithToken(server.url, server.accessToken)
- videosOfVideos.push(res.body.data)
+ const { data } = await server.videosCommand.listWithToken()
+ videosOfVideos.push(data)
}
{
}
{
- const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID)
- const videoDetails: VideoDetails = resDetail.body
+ const videoDetails = await server.videosCommand.getWithToken({ id: video1UUID })
expect(videoDetails.userHistory).to.not.be.undefined
expect(videoDetails.userHistory.currentTime).to.equal(3)
}
{
- const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID)
- const videoDetails: VideoDetails = resDetail.body
+ const videoDetails = await server.videosCommand.getWithToken({ id: video2UUID })
expect(videoDetails.userHistory).to.not.be.undefined
expect(videoDetails.userHistory.currentTime).to.equal(8)
}
{
- const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID)
- const videoDetails: VideoDetails = resDetail.body
+ const videoDetails = await server.videosCommand.getWithToken({ id: video3UUID })
expect(videoDetails.userHistory).to.be.undefined
}
import 'mocha'
import * as chai from 'chai'
-import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils'
+import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils'
import { VideosOverview } from '@shared/models'
const expect = chai.expect
await wait(3000)
- await uploadVideo(server.url, server.accessToken, {
- name: 'video 0',
- category: 3,
- tags: [ 'coucou1', 'coucou2' ]
+ await server.videosCommand.upload({
+ attributes: {
+ name: 'video 0',
+ category: 3,
+ tags: [ 'coucou1', 'coucou2' ]
+ }
})
const body = await server.overviewsCommand.getVideos({ page: 1 })
{
for (let i = 1; i < 6; i++) {
- await uploadVideo(server.url, server.accessToken, {
- name: 'video ' + i,
- category: 3,
- tags: [ 'coucou1', 'coucou2' ]
+ await server.videosCommand.upload({
+ attributes: {
+ name: 'video ' + i,
+ category: 3,
+ tags: [ 'coucou1', 'coucou2' ]
+ }
})
}
reRunServer,
ServerInfo,
setAccessTokensToServers,
- uploadVideoAndGetId,
- viewVideo,
wait,
waitJobs
} from '../../../../shared/extra-utils'
await doubleFollow(servers[0], servers[1])
- videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid
- videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid
+ videoIdServer1 = (await servers[0].videosCommand.quickUpload({ name: 'video server 1' })).uuid
+ videoIdServer2 = (await servers[1].videosCommand.quickUpload({ name: 'video server 2' })).uuid
await waitJobs(servers)
- await viewVideo(servers[0].url, videoIdServer1)
- await viewVideo(servers[1].url, videoIdServer1)
- await viewVideo(servers[0].url, videoIdServer2)
- await viewVideo(servers[1].url, videoIdServer2)
+ await servers[0].videosCommand.view({ id: videoIdServer1 })
+ await servers[1].videosCommand.view({ id: videoIdServer1 })
+ await servers[0].videosCommand.view({ id: videoIdServer2 })
+ await servers[1].videosCommand.view({ id: videoIdServer2 })
await waitJobs(servers)
})
import 'mocha'
import * as chai from 'chai'
-import { VideoFile } from '@shared/models/videos/video-file.model'
-import {
- cleanupTests,
- doubleFollow,
- flushAndRunMultipleServers,
- getVideo,
- getVideosList,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo
-} from '../../../shared/extra-utils'
-import { waitJobs } from '../../../shared/extra-utils/server/jobs'
-import { VideoDetails } from '../../../shared/models/videos'
+import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
+import { VideoFile } from '@shared/models'
const expect = chai.expect
await doubleFollow(servers[0], servers[1])
// Upload two videos for our needs
- const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
- video1UUID = res1.body.video.uuid
- const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
- video2UUID = res2.body.video.uuid
+ {
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video1' } })
+ video1UUID = uuid
+ }
+
+ {
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video2' } })
+ video2UUID = uuid
+ }
// Transcoding
await waitJobs(servers)
await waitJobs(servers)
for (const server of servers) {
- const { data: videos } = (await getVideosList(server.url)).body
+ const { data: videos } = await server.videosCommand.list()
expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video1UUID)
- const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
+ const videoDetails = await server.videosCommand.get({ id: video.uuid })
- expect(videoDetail.files).to.have.lengthOf(2)
- const [ originalVideo, transcodedVideo ] = videoDetail.files
+ expect(videoDetails.files).to.have.lengthOf(2)
+ const [ originalVideo, transcodedVideo ] = videoDetails.files
assertVideoProperties(originalVideo, 720, 'webm', 218910)
assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
}
await waitJobs(servers)
for (const server of servers) {
- const { data: videos } = (await getVideosList(server.url)).body
+ const { data: videos } = await server.videosCommand.list()
expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video2UUID)
- const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
+ const videoDetails = await server.videosCommand.get({ id: video.uuid })
- expect(videoDetail.files).to.have.lengthOf(4)
- const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files
+ expect(videoDetails.files).to.have.lengthOf(4)
+ const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
assertVideoProperties(originalVideo, 720, 'ogv', 140849)
assertVideoProperties(transcodedVideo420, 480, 'mp4')
assertVideoProperties(transcodedVideo320, 360, 'mp4')
await waitJobs(servers)
for (const server of servers) {
- const { data: videos } = (await getVideosList(server.url)).body
+ const { data: videos } = await server.videosCommand.list()
expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video1UUID)
- const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
+ const videoDetails = await server.videosCommand.get({ id: video.uuid })
- expect(videoDetail.files).to.have.lengthOf(2)
- const [ video720, video480 ] = videoDetail.files
+ expect(videoDetails.files).to.have.lengthOf(2)
+ const [ video720, video480 ] = videoDetails.files
assertVideoProperties(video720, 720, 'webm', 942961)
assertVideoProperties(video480, 480, 'webm', 69217)
}
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
- getVideosList,
ServerInfo,
setAccessTokensToServers,
- uploadVideo
+ waitJobs
} from '../../../shared/extra-utils'
-import { waitJobs } from '../../../shared/extra-utils/server/jobs'
-import { VideoDetails } from '../../../shared/models/videos'
const expect = chai.expect
await doubleFollow(servers[0], servers[1])
for (let i = 1; i <= 5; i++) {
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' + i })
- videosUUID.push(res.body.video.uuid)
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' + i } })
+ videosUUID.push(uuid)
}
await waitJobs(servers)
this.timeout(30000)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videos = res.body.data
- expect(videos).to.have.lengthOf(videosUUID.length)
+ const { data } = await server.videosCommand.list()
+ expect(data).to.have.lengthOf(videosUUID.length)
- for (const video of videos) {
- const res2 = await getVideo(server.url, video.uuid)
- const videoDetail: VideoDetails = res2.body
+ for (const video of data) {
+ const videoDetail = await server.videosCommand.get({ id: video.uuid })
expect(videoDetail.files).to.have.lengthOf(1)
expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
}
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videos = res.body.data
+ const { data } = await server.videosCommand.list()
let infoHashes: { [id: number]: string }
- for (const video of videos) {
- const res2 = await getVideo(server.url, video.uuid)
- const videoDetail: VideoDetails = res2.body
+ for (const video of data) {
+ const videoDetail = await server.videosCommand.get({ id: video.uuid })
if (video.uuid === videosUUID[1]) {
expect(videoDetail.files).to.have.lengthOf(4)
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videos = res.body.data
- expect(videos).to.have.lengthOf(videosUUID.length)
+ const { data } = await server.videosCommand.list()
+ expect(data).to.have.lengthOf(videosUUID.length)
- const res2 = await getVideo(server.url, videosUUID[0])
- const videoDetail: VideoDetails = res2.body
+ const videoDetails = await server.videosCommand.get({ id: videosUUID[0] })
- expect(videoDetail.files).to.have.lengthOf(2)
- expect(videoDetail.files[0].resolution.id).to.equal(720)
- expect(videoDetail.files[1].resolution.id).to.equal(480)
+ expect(videoDetails.files).to.have.lengthOf(2)
+ expect(videoDetails.files[0].resolution.id).to.equal(720)
+ expect(videoDetails.files[1].resolution.id).to.equal(480)
- expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
+ expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videosUUID[2])
- const videoDetail: VideoDetails = res.body
+ const videoDetails = await server.videosCommand.get({ id: videosUUID[2] })
- expect(videoDetail.files).to.have.lengthOf(1)
- expect(videoDetail.streamingPlaylists).to.have.lengthOf(1)
+ expect(videoDetails.files).to.have.lengthOf(1)
+ expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
- const files = videoDetail.streamingPlaylists[0].files
+ const files = videoDetails.streamingPlaylists[0].files
expect(files).to.have.lengthOf(1)
expect(files[0].resolution.id).to.equal(480)
}
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videosUUID[2])
- const videoDetail: VideoDetails = res.body
+ const videoDetails = await server.videosCommand.get({ id: videosUUID[2] })
- const files = videoDetail.streamingPlaylists[0].files
+ const files = videoDetails.streamingPlaylists[0].files
expect(files).to.have.lengthOf(1)
expect(files[0].resolution.id).to.equal(480)
}
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videosUUID[3])
- const videoDetail: VideoDetails = res.body
+ const videoDetails = await server.videosCommand.get({ id: videosUUID[3] })
- expect(videoDetail.files).to.have.lengthOf(1)
- expect(videoDetail.streamingPlaylists).to.have.lengthOf(1)
+ expect(videoDetails.files).to.have.lengthOf(1)
+ expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
- const files = videoDetail.streamingPlaylists[0].files
+ const files = videoDetails.streamingPlaylists[0].files
expect(files).to.have.lengthOf(4)
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideo(server.url, videosUUID[4])
- const videoDetail: VideoDetails = res.body
+ const videoDetails = await server.videosCommand.get({ id: videosUUID[4] })
- expect(videoDetail.files).to.have.lengthOf(4)
- expect(videoDetail.streamingPlaylists).to.have.lengthOf(1)
- expect(videoDetail.streamingPlaylists[0].files).to.have.lengthOf(4)
+ expect(videoDetails.files).to.have.lengthOf(4)
+ expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
+ expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(4)
}
})
doubleFollow,
flushAndRunMultipleServers,
generateHighBitrateVideo,
- getVideo,
- getVideosList,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
- viewVideo,
- wait
-} from '../../../shared/extra-utils'
-import { waitJobs } from '../../../shared/extra-utils/server/jobs'
-import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos'
+ wait,
+ waitJobs
+} from '@shared/extra-utils'
+import { getMaxBitrate, VideoResolution } from '@shared/models'
import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils'
import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
}
// Upload two videos for our needs
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1', fixture: tempFixturePath })
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2', fixture: tempFixturePath })
+ await servers[0].videosCommand.upload({ attributes: { name: 'video1', fixture: tempFixturePath } })
+ await servers[0].videosCommand.upload({ attributes: { name: 'video2', fixture: tempFixturePath } })
await waitJobs(servers)
})
this.timeout(30000)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videos = res.body.data
- expect(videos).to.have.lengthOf(2)
-
- for (const video of videos) {
- const res2 = await getVideo(server.url, video.uuid)
- const videoDetail: VideoDetails = res2.body
- expect(videoDetail.files).to.have.lengthOf(1)
+ const { data } = await server.videosCommand.list()
+ expect(data).to.have.lengthOf(2)
+
+ for (const video of data) {
+ const videoDetails = await server.videosCommand.get({ id: video.uuid })
+ expect(videoDetails.files).to.have.lengthOf(1)
}
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videos: Video[] = res.body.data
-
- expect(videos).to.have.lengthOf(2)
+ const { data } = await server.videosCommand.list()
+ expect(data).to.have.lengthOf(2)
- for (const video of videos) {
- await viewVideo(server.url, video.uuid)
+ for (const video of data) {
+ await server.videosCommand.view({ id: video.uuid })
// Refresh video
await waitJobs(servers)
await wait(5000)
await waitJobs(servers)
- const res2 = await getVideo(server.url, video.uuid)
- const videosDetails: VideoDetails = res2.body
+ const videoDetails = await server.videosCommand.get({ id: video.uuid })
- expect(videosDetails.files).to.have.lengthOf(1)
- const file = videosDetails.files[0]
+ expect(videoDetails.files).to.have.lengthOf(1)
+ const file = videoDetails.files[0]
expect(file.size).to.be.below(8000000)
import 'mocha'
import { expect } from 'chai'
-import { Video, VideoDetails } from '../../../shared'
import {
areHttpImportTestsDisabled,
buildAbsoluteFixturePath,
CLICommand,
doubleFollow,
flushAndRunServer,
- getLocalIdByUUID,
- getVideo,
- getVideosList,
ImportsCommand,
- removeVideo,
ServerInfo,
setAccessTokensToServers,
testHelloWorldRegisteredSettings,
- uploadVideoAndGetId,
waitJobs
} from '../../../shared/extra-utils'
})
it('Should have the video uploaded', async function () {
- const res = await getVideosList(server.url)
-
- expect(res.body.total).to.equal(1)
-
- const videos: Video[] = res.body.data
-
- const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
+ const { total, data } = await server.videosCommand.list()
+ expect(total).to.equal(1)
+ const video = await server.videosCommand.get({ id: data[0].uuid })
expect(video.name).to.equal('test upload')
expect(video.support).to.equal('support_text')
expect(video.channel.name).to.equal('user_channel')
await waitJobs([ server ])
- const res = await getVideosList(server.url)
-
- expect(res.body.total).to.equal(2)
+ const { total, data } = await server.videosCommand.list()
+ expect(total).to.equal(2)
- const videos: Video[] = res.body.data
- const video = videos.find(v => v.name === 'small video - youtube')
+ const video = data.find(v => v.name === 'small video - youtube')
expect(video).to.not.be.undefined
- const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.channel.name).to.equal('user_channel')
expect(videoDetails.support).to.equal('super support text')
expect(videoDetails.nsfw).to.be.false
// So we can reimport it
- await removeVideo(server.url, userAccessToken, video.id)
+ await server.videosCommand.remove({ token: userAccessToken, id: video.id })
})
it('Should import and override some imported attributes', async function () {
await waitJobs([ server ])
{
- const res = await getVideosList(server.url)
- expect(res.body.total).to.equal(2)
+ const { total, data } = await server.videosCommand.list()
+ expect(total).to.equal(2)
- const videos: Video[] = res.body.data
- const video = videos.find(v => v.name === 'toto')
+ const video = data.find(v => v.name === 'toto')
expect(video).to.not.be.undefined
- const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.channel.name).to.equal('user_channel')
expect(videoDetails.support).to.equal('support')
expect(videoDetails.nsfw).to.be.true
servers = [ server, anotherServer ]
await waitJobs(servers)
- const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
+ const { uuid } = await anotherServer.videosCommand.quickUpload({ name: 'super video' })
await waitJobs(servers)
- video1Server2 = await getLocalIdByUUID(server.url, uuid)
+ video1Server2 = await server.videosCommand.getId({ uuid })
})
it('Should add a redundancy', async function () {
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- uploadVideo,
wait,
waitJobs
} from '@shared/extra-utils'
await setDefaultVideoChannel(servers)
for (const server of servers) {
- await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
- await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
+ await server.videosCommand.upload({ attributes: { name: 'video 1' } })
+ await server.videosCommand.upload({ attributes: { name: 'video 2' } })
await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
import { expect } from 'chai'
import { writeFile } from 'fs-extra'
import { basename, join } from 'path'
-import { Video, VideoDetails } from '@shared/models'
+import { HttpStatusCode } from '@shared/core-utils'
+import { Video } from '@shared/models'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
makeRawRequest,
ServerInfo,
setAccessTokensToServers,
- uploadVideoAndGetId,
waitJobs
} from '../../../shared/extra-utils'
-import { HttpStatusCode } from '@shared/core-utils'
async function testThumbnail (server: ServerInfo, videoId: number | string) {
- const res = await getVideo(server.url, videoId)
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: videoId })
- const res1 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
- expect(res1.body).to.not.have.lengthOf(0)
+ const requests = [
+ makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200),
+ makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
+ ]
- const res2 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
- expect(res2.body).to.not.have.lengthOf(0)
+ for (const req of requests) {
+ const res = await req
+ expect(res.body).to.not.have.lengthOf(0)
+ }
}
describe('Test regenerate thumbnails script', function () {
await doubleFollow(servers[0], servers[1])
{
- const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid
- video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body))
+ const videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid
+ video1 = await servers[0].videosCommand.get({ id: videoUUID1 })
thumbnail1Path = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(video1.thumbnailPath))
- const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid
- video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body))
+ const videoUUID2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid
+ video2 = await servers[0].videosCommand.get({ id: videoUUID2 })
}
{
- const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid
+ const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'video 3' })).uuid
await waitJobs(servers)
- remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body))
+ remoteVideo = await servers[0].videosCommand.get({ id: videoUUID })
thumbnailRemotePath = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath))
}
import {
cleanupTests,
flushAndRunServer,
- getVideo,
- getVideosList,
killallServers,
makeActivityPubGetRequest,
parseTorrentVideo,
reRunServer,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
-import { VideoDetails } from '@shared/models'
describe('Test update host scripts', function () {
let server: ServerInfo
await setAccessTokensToServers([ server ])
// Upload two videos for our needs
- const videoAttributes = {}
- const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
- const video1UUID = resVideo1.body.video.uuid
- await uploadVideo(server.url, server.accessToken, videoAttributes)
+ const { uuid: video1UUID } = await server.videosCommand.upload()
+ await server.videosCommand.upload()
// Create a user
await server.usersCommand.create({ username: 'toto', password: 'coucou' })
})
it('Should have updated videos url', async function () {
- const res = await getVideosList(server.url)
- expect(res.body.total).to.equal(2)
+ const { total, data } = await server.videosCommand.list()
+ expect(total).to.equal(2)
- for (const video of res.body.data) {
+ for (const video of data) {
const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
- const res = await getVideo(server.url, video.uuid)
- const videoDetails: VideoDetails = res.body
+ const videoDetails = await server.videosCommand.get({ id: video.uuid })
expect(videoDetails.trackerUrls[0]).to.include(server.host)
expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
it('Should have updated torrent hosts', async function () {
this.timeout(30000)
- const res = await getVideosList(server.url)
- const videos = res.body.data
- expect(videos).to.have.lengthOf(2)
+ const { data } = await server.videosCommand.list()
+ expect(data).to.have.lengthOf(2)
- for (const video of videos) {
- const res2 = await getVideo(server.url, video.id)
- const videoDetails: VideoDetails = res2.body
+ for (const video of data) {
+ const videoDetails = await server.videosCommand.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideosList,
makeGetRequest,
makeHTMLRequest,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- uploadVideo,
waitJobs
} from '../../shared/extra-utils'
// Video
- const videoAttributes = { name: videoName, description: videoDescription }
- await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
+ {
+ const attributes = { name: videoName, description: videoDescription }
+ await servers[0].videosCommand.upload({ attributes })
- const resVideosRequest = await getVideosList(servers[0].url)
- const videos = resVideosRequest.body.data
- expect(videos.length).to.equal(1)
+ const { data } = await servers[0].videosCommand.list()
+ expect(data.length).to.equal(1)
- const video = videos[0]
- servers[0].video = video
- videoIds = [ video.id, video.uuid, video.shortUUID ]
+ const video = data[0]
+ servers[0].video = video
+ videoIds = [ video.id, video.uuid, video.shortUUID ]
+ }
// Playlist
- const attributes = {
- displayName: playlistName,
- description: playlistDescription,
- privacy: VideoPlaylistPrivacy.PUBLIC,
- videoChannelId: servers[0].videoChannel.id
- }
+ {
+ const attributes = {
+ displayName: playlistName,
+ description: playlistDescription,
+ privacy: VideoPlaylistPrivacy.PUBLIC,
+ videoChannelId: servers[0].videoChannel.id
+ }
- playlist = await servers[0].playlistsCommand.create({ attributes })
- playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ]
+ playlist = await servers[0].playlistsCommand.create({ attributes })
+ playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ]
- await servers[0].playlistsCommand.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: video.id } })
+ await servers[0].playlistsCommand.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: servers[0].video.id } })
+ }
// Account
- await servers[0].usersCommand.updateMe({ description: 'my account description' })
+ {
+ await servers[0].usersCommand.updateMe({ description: 'my account description' })
- account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` })
+ account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` })
+ }
await waitJobs(servers)
})
import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils'
+import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
describe('Official plugin auth-ldap', function () {
let server: ServerInfo
})
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 () {
import 'mocha'
import { expect } from 'chai'
-import { Video } from '@shared/models'
-import {
- doubleFollow,
- getVideosList,
- MockBlocklist,
- setAccessTokensToServers,
- uploadVideoAndGetId,
- wait
-} from '../../../shared/extra-utils'
import {
cleanupTests,
+ doubleFollow,
flushAndRunMultipleServers,
killallServers,
+ MockBlocklist,
reRunServer,
- ServerInfo
-} from '../../../shared/extra-utils/server/servers'
+ ServerInfo,
+ setAccessTokensToServers,
+ wait
+} from '@shared/extra-utils'
+import { Video } from '@shared/models'
async function check (server: ServerInfo, videoUUID: string, exists = true) {
- const res = await getVideosList(server.url)
+ const { data } = await server.videosCommand.list()
- const video = res.body.data.find(v => v.uuid === videoUUID)
+ const video = data.find(v => v.uuid === videoUUID)
if (exists) expect(video).to.not.be.undefined
else expect(video).to.be.undefined
blocklistServer = new MockBlocklist()
port = await blocklistServer.initialize()
- await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
- await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
- await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2 server 2' })
- await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2' })
+ await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
+ await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
+ await await servers[1].videosCommand.quickUpload({ name: 'video 2 server 2' })
+ await await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2' })
{
- const res = await getVideosList(servers[0].url)
- server1Videos = res.body.data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid }))
+ const { data } = await servers[0].videosCommand.list()
+ server1Videos = data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid }))
}
{
- const res = await getVideosList(servers[1].url)
- server2Videos = res.body.data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid }))
+ const { data } = await servers[1].videosCommand.list()
+ server2Videos = data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid }))
}
await doubleFollow(servers[0], servers[1])
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideosList,
killallServers,
makeGetRequest,
MockBlocklist,
reRunServer,
ServerInfo,
setAccessTokensToServers,
- uploadVideoAndGetId,
wait
} from '@shared/extra-utils'
blocklistServer = new MockBlocklist()
port = await blocklistServer.initialize()
- await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
- await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
+ await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
+ await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
await doubleFollow(servers[0], servers[1])
})
await wait(2000)
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(1)
+ const { total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(1)
})
it('Should remove a server blocklist', async function () {
await wait(2000)
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(2)
+ const { total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(2)
})
it('Should add an account blocklist', async function () {
await wait(2000)
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(1)
+ const { total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(1)
})
it('Should remove an account blocklist', async function () {
await wait(2000)
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(2)
+ const { total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(2)
})
it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
await wait(2000)
{
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(1)
+ const { total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(1)
}
await servers[0].blocklistCommand.removeFromServerBlocklist({ account })
{
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(2)
+ const { total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(2)
}
await killallServers([ servers[0] ])
await wait(2000)
{
- const res = await getVideosList(servers[0].url)
- expect(res.body.total).to.equal(2)
+ const { total } = await servers[0].videosCommand.list()
+ expect(total).to.equal(2)
}
})
await wait(2000)
for (const server of servers) {
- const res = await getVideosList(server.url)
- expect(res.body.total).to.equal(1)
+ const { total } = await server.videosCommand.list()
+ expect(total).to.equal(1)
}
})
flushAndRunServer,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
- uploadVideoAndGetId,
waitJobs
} from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models'
}
{
- await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' })
+ await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'user video' } })
}
{
- const videoAttributes = {
+ const attributes = {
name: 'my super name for server 1',
description: 'my super description for server 1',
fixture: 'video_short.webm'
}
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
- const videoId = res.body.video.id
+ const { id } = await servers[0].videosCommand.upload({ attributes })
- await servers[0].commentsCommand.createThread({ videoId, text: 'super comment 1' })
- await servers[0].commentsCommand.createThread({ videoId, text: 'super comment 2' })
+ await servers[0].commentsCommand.createThread({ videoId: id, text: 'super comment 1' })
+ await servers[0].commentsCommand.createThread({ videoId: id, text: 'super comment 2' })
}
{
- const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
- const videoId = res.body.video.id
+ const attributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
+ const { id } = await servers[0].videosCommand.upload({ attributes })
- await servers[0].commentsCommand.createThread({ videoId, text: 'comment on unlisted video' })
+ await servers[0].commentsCommand.createThread({ videoId: id, text: 'comment on unlisted video' })
}
await waitJobs(servers)
it('Should correctly have videos feed with HLS only', async function () {
this.timeout(120000)
- await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' })
+ await serverHLSOnly.videosCommand.upload({ attributes: { name: 'hls only video' } })
await waitJobs([ serverHLSOnly ])
await servers[1].blocklistCommand.removeFromServerBlocklist({ account: remoteHandle })
{
- const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
+ const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid
await waitJobs(servers)
await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'super comment' })
await waitJobs(servers)
import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import {
- cleanupTests,
- flushAndRunServer,
- makeGetRequest,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo
-} from '../../shared/extra-utils'
-import { VideoPrivacy } from '../../shared/models/videos'
+import { cleanupTests, flushAndRunServer, makeGetRequest, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
+import { VideoPrivacy } from '@shared/models'
const expect = chai.expect
it('Should add videos, channel and accounts and get sitemap', async function () {
this.timeout(35000)
- await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
- await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
- await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
+ await server.videosCommand.upload({ attributes: { name: 'video 1', nsfw: false } })
+ await server.videosCommand.upload({ attributes: { name: 'video 2', nsfw: false } })
+ await server.videosCommand.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
reRunServer,
ServerInfo,
setAccessTokensToServers,
- setDefaultVideoChannel,
- updateVideo,
- uploadVideo,
- viewVideo
+ setDefaultVideoChannel
} from '@shared/extra-utils'
import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
describe('Videos hooks', function () {
it('Should run action:api.video.uploaded', async function () {
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
- videoUUID = res.body.video.uuid
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
+ videoUUID = uuid
await checkHook('action:api.video.uploaded')
})
it('Should run action:api.video.updated', async function () {
- await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
+ await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video updated' } })
await checkHook('action:api.video.updated')
})
it('Should run action:api.video.viewed', async function () {
- await viewVideo(servers[0].url, videoUUID)
+ await servers[0].videosCommand.view({ id: videoUUID })
await checkHook('action:api.video.viewed')
})
}
{
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
- videoId = res.body.video.id
+ const { id } = await servers[0].videosCommand.upload({ attributes: { name: 'my super name' } })
+ videoId = id
}
})
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getAccountVideos,
- getMyVideos,
- getVideo,
- getVideoChannelVideos,
- getVideosList,
- getVideosListPagination,
- getVideoWithToken,
ImportsCommand,
makeRawRequest,
PluginsCommand,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- updateVideo,
- uploadVideo,
- uploadVideoAndGetId,
waitJobs
} from '@shared/extra-utils'
import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
for (let i = 0; i < 10; i++) {
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i })
+ await servers[0].videosCommand.upload({ attributes: { name: 'default video ' + i } })
}
- const res = await getVideosList(servers[0].url)
- videoUUID = res.body.data[0].uuid
+ const { data } = await servers[0].videosCommand.list()
+ videoUUID = data[0].uuid
await servers[0].configCommand.updateCustomSubConfig({
newConfig: {
})
it('Should run filter:api.videos.list.params', async function () {
- const res = await getVideosListPagination(servers[0].url, 0, 2)
+ const { data } = await servers[0].videosCommand.list({ start: 0, count: 2 })
// 2 plugins do +1 to the count parameter
- expect(res.body.data).to.have.lengthOf(4)
+ expect(data).to.have.lengthOf(4)
})
it('Should run filter:api.videos.list.result', async function () {
- const res = await getVideosListPagination(servers[0].url, 0, 0)
+ const { total } = await servers[0].videosCommand.list({ start: 0, count: 0 })
// Plugin do +1 to the total result
- expect(res.body.total).to.equal(11)
+ expect(total).to.equal(11)
})
it('Should run filter:api.accounts.videos.list.params', async function () {
- const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2)
+ const { data } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 })
// 1 plugin do +1 to the count parameter
- expect(res.body.data).to.have.lengthOf(3)
+ expect(data).to.have.lengthOf(3)
})
it('Should run filter:api.accounts.videos.list.result', async function () {
- const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2)
+ const { total } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 })
// Plugin do +2 to the total result
- expect(res.body.total).to.equal(12)
+ expect(total).to.equal(12)
})
it('Should run filter:api.video-channels.videos.list.params', async function () {
- const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2)
+ const { data } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 })
// 1 plugin do +3 to the count parameter
- expect(res.body.data).to.have.lengthOf(5)
+ expect(data).to.have.lengthOf(5)
})
it('Should run filter:api.video-channels.videos.list.result', async function () {
- const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2)
+ const { total } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 })
// Plugin do +3 to the total result
- expect(res.body.total).to.equal(13)
+ expect(total).to.equal(13)
})
it('Should run filter:api.user.me.videos.list.params', async function () {
- const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2)
+ const { data } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 })
// 1 plugin do +4 to the count parameter
- expect(res.body.data).to.have.lengthOf(6)
+ expect(data).to.have.lengthOf(6)
})
it('Should run filter:api.user.me.videos.list.result', async function () {
- const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2)
+ const { total } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 })
// Plugin do +4 to the total result
- expect(res.body.total).to.equal(14)
+ expect(total).to.equal(14)
})
it('Should run filter:api.video.get.result', async function () {
- const res = await getVideo(servers[0].url, videoUUID)
-
- expect(res.body.name).to.contain('<3')
+ const video = await servers[0].videosCommand.get({ id: videoUUID })
+ expect(video.name).to.contain('<3')
})
it('Should run filter:api.video.upload.accept.result', async function () {
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403)
+ await servers[0].videosCommand.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should run filter:api.live-video.create.accept.result', async function () {
describe('Should run filter:video.auto-blacklist.result', function () {
async function checkIsBlacklisted (id: number | string, value: boolean) {
- const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id)
- const video: VideoDetails = res.body
+ const video = await servers[0].videosCommand.getWithToken({ id })
expect(video.blacklisted).to.equal(value)
}
it('Should blacklist on upload', async function () {
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' })
- await checkIsBlacklisted(res.body.video.uuid, true)
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video please blacklist me' } })
+ await checkIsBlacklisted(uuid, true)
})
it('Should blacklist on import', async function () {
})
it('Should blacklist on update', async function () {
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
- const videoId = res.body.video.uuid
- await checkIsBlacklisted(videoId, false)
+ const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
+ await checkIsBlacklisted(uuid, false)
- await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' })
- await checkIsBlacklisted(videoId, true)
+ await servers[0].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } })
+ await checkIsBlacklisted(uuid, true)
})
it('Should blacklist on remote upload', async function () {
this.timeout(120000)
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' })
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'remote please blacklist me' } })
await waitJobs(servers)
- await checkIsBlacklisted(res.body.video.uuid, true)
+ await checkIsBlacklisted(uuid, true)
})
it('Should blacklist on remote update', async function () {
this.timeout(120000)
- const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' })
+ const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video' } })
await waitJobs(servers)
- const videoId = res.body.video.uuid
- await checkIsBlacklisted(videoId, false)
+ await checkIsBlacklisted(uuid, false)
- await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' })
+ await servers[1].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } })
await waitJobs(servers)
- await checkIsBlacklisted(videoId, true)
+ await checkIsBlacklisted(uuid, true)
})
})
const uuids: string[] = []
for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
- const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid
+ const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid
uuids.push(uuid)
}
await waitJobs(servers)
for (const uuid of uuids) {
- const res = await getVideo(servers[0].url, uuid)
- downloadVideos.push(res.body)
+ downloadVideos.push(await servers[0].videosCommand.get({ id: uuid }))
}
})
for (const name of [ 'bad embed', 'good embed' ]) {
{
- const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid
- const res = await getVideo(servers[0].url, uuid)
- embedVideos.push(res.body)
+ const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid
+ embedVideos.push(await servers[0].videosCommand.get({ id: uuid }))
}
{
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getVideo,
- getVideosList,
makeGetRequest,
makePostBodyRequest,
PluginsCommand,
ServerInfo,
setAccessTokensToServers,
- uploadVideoAndGetId,
- viewVideo,
waitJobs
} from '@shared/extra-utils'
this.timeout(60000)
{
- const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
+ const res = await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
videoUUIDServer1 = res.uuid
}
{
- await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
+ await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
}
await waitJobs(servers)
- const res = await getVideosList(servers[0].url)
- const videos = res.body.data
+ const { data } = await servers[0].videosCommand.list()
- expect(videos).to.have.lengthOf(2)
+ expect(data).to.have.lengthOf(2)
})
it('Should mute server 2', async function () {
this.timeout(10000)
await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
- const res = await getVideosList(servers[0].url)
- const videos = res.body.data
+ const { data } = await servers[0].videosCommand.list()
- expect(videos).to.have.lengthOf(1)
- expect(videos[0].name).to.equal('video server 1')
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].name).to.equal('video server 1')
})
it('Should unmute server 2', async function () {
await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
- const res = await getVideosList(servers[0].url)
- const videos = res.body.data
+ const { data } = await servers[0].videosCommand.list()
- expect(videos).to.have.lengthOf(2)
+ expect(data).to.have.lengthOf(2)
})
it('Should mute account of server 2', async function () {
await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
- const res = await getVideosList(servers[0].url)
- const videos = res.body.data
+ const { data } = await servers[0].videosCommand.list()
- expect(videos).to.have.lengthOf(1)
- expect(videos[0].name).to.equal('video server 1')
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].name).to.equal('video server 1')
})
it('Should unmute account of server 2', async function () {
await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
- const res = await getVideosList(servers[0].url)
- const videos = res.body.data
+ const { data } = await servers[0].videosCommand.list()
- expect(videos).to.have.lengthOf(2)
+ expect(data).to.have.lengthOf(2)
})
it('Should blacklist video', async function () {
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videos = res.body.data
+ const { data } = await server.videosCommand.list()
- expect(videos).to.have.lengthOf(1)
- expect(videos[0].name).to.equal('video server 2')
+ expect(data).to.have.lengthOf(1)
+ expect(data[0].name).to.equal('video server 2')
}
})
await waitJobs(servers)
for (const server of servers) {
- const res = await getVideosList(server.url)
- const videos = res.body.data
+ const { data } = await server.videosCommand.list()
- expect(videos).to.have.lengthOf(2)
+ expect(data).to.have.lengthOf(2)
}
})
})
let videoUUID: string
before(async () => {
- const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' })
+ const res = await await servers[0].videosCommand.quickUpload({ name: 'video1' })
videoUUID = res.uuid
})
this.timeout(40000)
// Should not throw -> video exists
- await getVideo(servers[0].url, videoUUID)
+ await servers[0].videosCommand.get({ id: videoUUID })
// Should delete the video
- await viewVideo(servers[0].url, videoUUID)
+ await servers[0].videosCommand.view({ id: videoUUID })
await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.')
try {
// Should throw because the video should have been deleted
- await getVideo(servers[0].url, videoUUID)
+ await servers[0].videosCommand.get({ id: videoUUID })
throw new Error('Video exists')
} catch (err) {
if (err.message.includes('exists')) throw err
import {
cleanupTests,
flushAndRunServer,
- getVideo,
PluginsCommand,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
testFfmpegStreamError,
- uploadVideoAndGetId,
waitJobs
} from '@shared/extra-utils'
-import { VideoDetails, VideoPrivacy } from '@shared/models'
+import { VideoPrivacy } from '@shared/models'
async function createLiveWrapper (server: ServerInfo) {
const liveAttributes = {
describe('When using a plugin adding profiles to existing encoders', function () {
async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) {
- const res = await getVideo(server.url, uuid)
- const video = res.body as VideoDetails
+ const video = await server.videosCommand.get({ id: uuid })
const files = video.files.concat(...video.streamingPlaylists.map(p => p.files))
for (const file of files) {
it('Should not use the plugin profile if not chosen by the admin', async function () {
this.timeout(240000)
- const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
+ const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ])
await checkVideoFPS(videoUUID, 'above', 20)
await updateConf(server, 'low-vod', 'default')
- const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
+ const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ])
await checkVideoFPS(videoUUID, 'below', 12)
await updateConf(server, 'input-options-vod', 'default')
- const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
+ const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ])
await checkVideoFPS(videoUUID, 'below', 6)
await updateConf(server, 'bad-scale-vod', 'default')
- const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
+ const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ])
// Transcoding failed
- const res = await getVideo(server.url, videoUUID)
- const video: VideoDetails = res.body
-
+ const video = await server.videosCommand.get({ id: videoUUID })
expect(video.files).to.have.lengthOf(1)
expect(video.streamingPlaylists).to.have.lengthOf(0)
})
expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ])
expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ])
- const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
+ const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs([ server ])
await checkVideoFPS(videoUUID, 'above', 20)
it('Should use the new vod encoders', async function () {
this.timeout(240000)
- const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid
+ const videoUUID = (await server.videosCommand.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid
await waitJobs([ server ])
const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4'))
import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import {
- cleanupTests,
- flushAndRunServer,
- getVideo,
- getVideoCategories,
- getVideoLanguages,
- getVideoLicences,
- getVideoPrivacies,
- PluginsCommand,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo
-} from '@shared/extra-utils'
-import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models'
+import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
+import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect
})
it('Should have updated languages', async function () {
- const res = await getVideoLanguages(server.url)
- const languages = res.body
+ const languages = await server.videosCommand.getLanguages()
expect(languages['en']).to.not.exist
expect(languages['fr']).to.not.exist
})
it('Should have updated categories', async function () {
- const res = await getVideoCategories(server.url)
- const categories = res.body
+ const categories = await server.videosCommand.getCategories()
expect(categories[1]).to.not.exist
expect(categories[2]).to.not.exist
})
it('Should have updated licences', async function () {
- const res = await getVideoLicences(server.url)
- const licences = res.body
+ const licences = await server.videosCommand.getLicences()
expect(licences[1]).to.not.exist
expect(licences[7]).to.not.exist
})
it('Should have updated video privacies', async function () {
- const res = await getVideoPrivacies(server.url)
- const privacies = res.body
+ const privacies = await server.videosCommand.getPrivacies()
expect(privacies[1]).to.exist
expect(privacies[2]).to.not.exist
})
it('Should not be able to create a video with this privacy', async function () {
- const attrs = { name: 'video', privacy: 2 }
- await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400)
+ const attributes = { name: 'video', privacy: 2 }
+ await server.videosCommand.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should not be able to create a video with this privacy', async function () {
})
it('Should be able to upload a video with these values', async function () {
- const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
- const resUpload = await uploadVideo(server.url, server.accessToken, attrs)
+ const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
+ const { uuid } = await server.videosCommand.upload({ attributes })
- const res = await getVideo(server.url, resUpload.body.video.uuid)
-
- const video: VideoDetails = res.body
+ const video = await server.videosCommand.get({ id: uuid })
expect(video.language.label).to.equal('Al Bhed 2')
expect(video.licence.label).to.equal('Best licence')
expect(video.category.label).to.equal('Best category')
await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
{
- const res = await getVideoLanguages(server.url)
- const languages = res.body
+ const languages = await server.videosCommand.getLanguages()
expect(languages['en']).to.equal('English')
expect(languages['fr']).to.equal('French')
}
{
- const res = await getVideoCategories(server.url)
- const categories = res.body
+ const categories = await server.videosCommand.getCategories()
expect(categories[1]).to.equal('Music')
expect(categories[2]).to.equal('Films')
}
{
- const res = await getVideoLicences(server.url)
- const licences = res.body
+ const licences = await server.videosCommand.getLicences()
expect(licences[1]).to.equal('Attribution')
expect(licences[7]).to.equal('Public Domain Dedication')
}
{
- const res = await getVideoPrivacies(server.url)
- const privacies = res.body
+ const privacies = await server.videosCommand.getPrivacies()
expect(privacies[1]).to.exist
expect(privacies[2]).to.exist
async function getAdminTokenOrDie (server: ServerInfo, username: string, password: string) {
const token = await server.loginCommand.getAccessToken(username, password)
- const me = await server.usersCommand.getMyUserInformation({ token })
+ const me = await server.usersCommand.getMyInfo({ token })
if (me.role !== UserRole.ADMINISTRATOR) {
console.error('You must be an administrator.')
import * as prompt from 'prompt'
import { promisify } from 'util'
import { YoutubeDL } from '@server/helpers/youtube-dl'
-import { getVideoCategories, uploadVideo } from '../../shared/extra-utils/index'
import { sha256 } from '../helpers/core-utils'
import { doRequestAndSaveToFile } from '../helpers/requests'
import { CONSTRAINTS_FIELDS } from '../initializers/constants'
getLogger,
getServerCredentials
} from './cli'
+import { ServerInfo } from '@shared/extra-utils'
const processOptions = {
maxBuffer: Infinity
}) {
const { youtubeDL, videoInfo, videoPath, cwd, url, username, password } = parameters
- const category = await getCategory(videoInfo.categories, url)
+ const server = buildServer(url)
+ await assignToken(server, username, password)
+
+ const category = await getCategory(server, videoInfo.categories)
const licence = getLicence(videoInfo.license)
let tags = []
if (Array.isArray(videoInfo.tags)) {
tags
}
- const server = buildServer(url)
- await assignToken(server, username, password)
+ const baseAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes)
- const videoAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes)
+ const attributes = {
+ ...baseAttributes,
- Object.assign(videoAttributes, {
originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null,
thumbnailfile,
previewfile: thumbnailfile,
fixture: videoPath
- })
+ }
- log.info('\nUploading on PeerTube video "%s".', videoAttributes.name)
+ log.info('\nUploading on PeerTube video "%s".', attributes.name)
try {
- await uploadVideo(url, server.accessToken, videoAttributes)
+ await server.videosCommand.upload({ attributes })
} catch (err) {
if (err.message.indexOf('401') !== -1) {
log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.')
server.accessToken = await server.loginCommand.getAccessToken(username, password)
- await uploadVideo(url, server.accessToken, videoAttributes)
+ await server.videosCommand.upload({ attributes })
} else {
exitError(err.message)
}
await remove(videoPath)
if (thumbnailfile) await remove(thumbnailfile)
- log.warn('Uploaded video "%s"!\n', videoAttributes.name)
+ log.warn('Uploaded video "%s"!\n', attributes.name)
}
/* ---------------------------------------------------------- */
-async function getCategory (categories: string[], url: string) {
+async function getCategory (server: ServerInfo, categories: string[]) {
if (!categories) return undefined
const categoryString = categories[0]
if (categoryString === 'News & Politics') return 11
- const res = await getVideoCategories(url)
- const categoriesServer = res.body
+ const categoriesServer = await server.videosCommand.getCategories()
for (const key of Object.keys(categoriesServer)) {
const categoryServer = categoriesServer[key]
import { program } from 'commander'
import { access, constants } from 'fs-extra'
import { isAbsolute } from 'path'
-import { uploadVideo } from '../../shared/extra-utils/'
import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
let command = program
console.log('Uploading %s video...', options.videoName)
- const videoAttributes = await buildVideoAttributesFromCommander(server, program)
+ const baseAttributes = await buildVideoAttributesFromCommander(server, program)
+
+ const attributes = {
+ ...baseAttributes,
- Object.assign(videoAttributes, {
fixture: options.file,
thumbnailfile: options.thumbnail,
previewfile: options.preview
- })
+ }
try {
- await uploadVideo(url, server.accessToken, videoAttributes)
+ await server.videosCommand.upload({ attributes })
console.log(`Video ${options.videoName} uploaded.`)
process.exit(0)
} catch (err) {
+import { readFile } from 'fs-extra'
+import * as parseTorrent from 'parse-torrent'
+import { join } from 'path'
import * as WebTorrent from 'webtorrent'
+import { ServerInfo } from '../server'
let webtorrent: WebTorrent.Instance
return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
}
+async function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
+ const torrentName = videoUUID + '-' + resolution + '.torrent'
+ const torrentPath = server.serversCommand.buildDirectory(join('torrents', torrentName))
+
+ const data = await readFile(torrentPath)
+
+ return parseTorrent(data)
+}
+
export {
- webtorrentAdd
+ webtorrentAdd,
+ parseTorrentVideo
}
method?: 'POST' | 'PUT'
path: string
token?: string
+
fields: { [ fieldName: string ]: any }
attaches?: { [ attachName: string ]: any | any[] }
+
+ headers?: { [ name: string ]: string }
+
statusCodeExpected?: HttpStatusCode
}) {
- if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400
+ if (options.statusCodeExpected === undefined) {
+ options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400
+ }
let req: request.Test
if (options.method === 'PUT') {
if (options.token) req.set('Authorization', 'Bearer ' + options.token)
+ Object.keys(options.headers || {}).forEach(name => {
+ req.set(name, options.headers[name])
+ })
+
Object.keys(options.fields).forEach(field => {
const value = options.fields[field]
}
})
- return req.expect(options.statusCodeExpected)
+ if (options.statusCodeExpected) {
+ req.expect(options.statusCodeExpected)
+ }
+
+ return req
}
function makePostBodyRequest (options: {
path: string
token?: string
fields?: { [ fieldName: string ]: any }
+ headers?: { [ name: string ]: string }
type?: string
+ xForwardedFor?: string
statusCodeExpected?: HttpStatusCode
}) {
if (!options.fields) options.fields = {}
.set('Accept', 'application/json')
if (options.token) req.set('Authorization', 'Bearer ' + options.token)
+ if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor)
if (options.type) req.type(options.type)
+ Object.keys(options.headers || {}).forEach(name => {
+ req.set(name, options.headers[name])
+ })
+
return req.send(options.fields)
.expect(options.statusCodeExpected)
}
LiveCommand,
PlaylistsCommand,
ServicesCommand,
- StreamingPlaylistsCommand
+ StreamingPlaylistsCommand,
+ VideosCommand
} from '../videos'
import { CommentsCommand } from '../videos/comments-command'
import { ConfigCommand } from './config-command'
serversCommand?: ServersCommand
loginCommand?: LoginCommand
usersCommand?: UsersCommand
+ videosCommand?: VideosCommand
}
function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) {
server.serversCommand = new ServersCommand(server)
server.loginCommand = new LoginCommand(server)
server.usersCommand = new UsersCommand(server)
+ server.videosCommand = new VideosCommand(server)
}
async function reRunServer (server: ServerInfo, configOverride?: any) {
import { isAbsolute, join } from 'path'
-import { HttpStatusCode } from '@shared/core-utils'
import { root } from '../miscs/tests'
import {
makeDeleteRequest,
abstract class AbstractCommand {
- private expectedStatus: HttpStatusCode
-
constructor (
protected server: ServerInfo
) {
}
- setServer (server: ServerInfo) {
- this.server = server
- }
-
- setExpectedStatus (status: HttpStatusCode) {
- this.expectedStatus = status
- }
-
protected getRequestBody <T> (options: InternalGetCommandOptions) {
return unwrapBody<T>(this.getRequest(options))
}
protected postBodyRequest (options: InternalCommonCommandOptions & {
fields?: { [ fieldName: string ]: any }
+ headers?: { [ name: string ]: string }
type?: string
+ xForwardedFor?: string
}) {
- const { type, fields } = options
+ const { type, fields, xForwardedFor, headers } = options
return makePostBodyRequest({
...this.buildCommonRequestOptions(options),
fields,
- type
+ xForwardedFor,
+ type,
+ headers
})
}
protected postUploadRequest (options: InternalCommonCommandOptions & {
fields?: { [ fieldName: string ]: any }
- attaches?: any
+ attaches?: { [ fieldName: string ]: any }
+ headers?: { [ name: string ]: string }
}) {
- const { fields, attaches } = options
+ const { fields, attaches, headers } = options
return makeUploadRequest({
...this.buildCommonRequestOptions(options),
method: 'POST',
fields,
- attaches
+ attaches,
+ headers
})
}
protected putUploadRequest (options: InternalCommonCommandOptions & {
fields?: { [ fieldName: string ]: any }
- attaches?: any
+ attaches?: { [ fieldName: string ]: any }
+ headers?: { [ name: string ]: string }
}) {
- const { fields, attaches } = options
+ const { fields, attaches, headers } = options
return makeUploadRequest({
...this.buildCommonRequestOptions(options),
method: 'PUT',
+ headers,
fields,
attaches
})
})
}
- private buildCommonRequestOptions (options: InternalCommonCommandOptions) {
+ protected buildCommonRequestOptions (options: InternalCommonCommandOptions) {
const { url, path } = options
return {
}
}
- private buildCommonRequestToken (options: Pick<InternalCommonCommandOptions, 'token' | 'implicitToken'>) {
+ protected buildCommonRequestToken (options: Pick<InternalCommonCommandOptions, 'token' | 'implicitToken'>) {
const { token } = options
const fallbackToken = options.implicitToken
return token !== undefined ? token : fallbackToken
}
- private buildStatusCodeExpected (options: Pick<InternalCommonCommandOptions, 'expectedStatus' | 'defaultExpectedStatus'>) {
+ protected buildStatusCodeExpected (options: Pick<InternalCommonCommandOptions, 'expectedStatus' | 'defaultExpectedStatus'>) {
const { expectedStatus, defaultExpectedStatus } = options
- return expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus
+ return expectedStatus !== undefined ? expectedStatus : defaultExpectedStatus
}
}
export * from './streaming-playlists-command'
export * from './streaming-playlists'
export * from './comments-command'
+export * from './videos-command'
export * from './videos'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
import { sendRTMPStream, testFfmpegStreamError } from './live'
-import { getVideoWithToken } from './videos'
export class LiveCommand extends AbstractCommand {
let video: VideoDetails
do {
- const res = await getVideoWithToken(this.server.url, options.token ?? this.server.accessToken, options.videoId)
- video = res.body
+ video = await this.server.videosCommand.getWithToken({ token: options.token, id: options.videoId })
await wait(500)
} while (video.isLive === true && video.state.id !== VideoState.PUBLISHED)
let video: VideoDetails
do {
- const res = await getVideoWithToken(this.server.url, options.token ?? this.server.accessToken, options.videoId)
- video = res.body
+ video = await this.server.videosCommand.getWithToken({ token: options.token, id: options.videoId })
await wait(500)
} while (video.state.id !== options.state)
import { omit, pick } from 'lodash'
+import { HttpStatusCode } from '@shared/core-utils'
import {
BooleanBothQuery,
ResultList,
VideoExistInPlaylist,
VideoPlaylist,
+ VideoPlaylistCreate,
VideoPlaylistCreateResult,
VideoPlaylistElement,
+ VideoPlaylistElementCreate,
VideoPlaylistElementCreateResult,
- VideoPlaylistReorder
+ VideoPlaylistElementUpdate,
+ VideoPlaylistReorder,
+ VideoPlaylistType,
+ VideoPlaylistUpdate
} from '@shared/models'
-import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
-import { VideoPlaylistCreate } from '../../models/videos/playlist/video-playlist-create.model'
-import { VideoPlaylistElementCreate } from '../../models/videos/playlist/video-playlist-element-create.model'
-import { VideoPlaylistElementUpdate } from '../../models/videos/playlist/video-playlist-element-update.model'
-import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model'
-import { VideoPlaylistUpdate } from '../../models/videos/playlist/video-playlist-update.model'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
-import { videoUUIDToId } from './videos'
export class PlaylistsCommand extends AbstractCommand {
const attributes = {
...options.attributes,
- videoId: await videoUUIDToId(this.server.url, options.attributes.videoId)
+ videoId: await this.server.videosCommand.getId({ ...options, uuid: options.attributes.videoId })
}
const path = '/api/v1/video-playlists/' + options.playlistId + '/videos'
--- /dev/null
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
+
+import { expect } from 'chai'
+import { createReadStream, stat } from 'fs-extra'
+import got, { Response as GotResponse } from 'got'
+import { omit, pick } from 'lodash'
+import validator from 'validator'
+import { buildUUID } from '@server/helpers/uuid'
+import { loadLanguages } from '@server/initializers/constants'
+import { HttpStatusCode } from '@shared/core-utils'
+import {
+ ResultList,
+ UserVideoRateType,
+ Video,
+ VideoCreate,
+ VideoCreateResult,
+ VideoDetails,
+ VideoFileMetadata,
+ VideoPrivacy,
+ VideosCommonQuery,
+ VideosWithSearchCommonQuery
+} from '@shared/models'
+import { buildAbsoluteFixturePath, wait } from '../miscs'
+import { unwrapBody } from '../requests'
+import { ServerInfo, waitJobs } from '../server'
+import { AbstractCommand, OverrideCommandOptions } from '../shared'
+
+export type VideoEdit = Partial<Omit<VideoCreate, 'thumbnailfile' | 'previewfile'>> & {
+ fixture?: string
+ thumbnailfile?: string
+ previewfile?: string
+}
+
+export class VideosCommand extends AbstractCommand {
+
+ constructor (server: ServerInfo) {
+ super(server)
+
+ loadLanguages()
+ }
+
+ getCategories (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/videos/categories'
+
+ return this.getRequestBody<{ [id: number]: string }>({
+ ...options,
+ path,
+
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ getLicences (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/videos/licences'
+
+ return this.getRequestBody<{ [id: number]: string }>({
+ ...options,
+ path,
+
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ getLanguages (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/videos/languages'
+
+ return this.getRequestBody<{ [id: string]: string }>({
+ ...options,
+ path,
+
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ getPrivacies (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/videos/privacies'
+
+ return this.getRequestBody<{ [id in VideoPrivacy]: string }>({
+ ...options,
+ path,
+
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ getDescription (options: OverrideCommandOptions & {
+ descriptionPath: string
+ }) {
+ return this.getRequestBody<{ description: string }>({
+ ...options,
+ path: options.descriptionPath,
+
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ getFileMetadata (options: OverrideCommandOptions & {
+ url: string
+ }) {
+ return unwrapBody<VideoFileMetadata>(this.getRawRequest({
+ ...options,
+
+ url: options.url,
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ }))
+ }
+
+ // ---------------------------------------------------------------------------
+
+ view (options: OverrideCommandOptions & {
+ id: number | string
+ xForwardedFor?: string
+ }) {
+ const { id, xForwardedFor } = options
+ const path = '/api/v1/videos/' + id + '/views'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ xForwardedFor,
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ rate (options: OverrideCommandOptions & {
+ id: number | string
+ rating: UserVideoRateType
+ }) {
+ const { id, rating } = options
+ const path = '/api/v1/videos/' + id + '/rate'
+
+ return this.putBodyRequest({
+ ...options,
+
+ path,
+ fields: { rating },
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ get (options: OverrideCommandOptions & {
+ id: number | string
+ }) {
+ const path = '/api/v1/videos/' + options.id
+
+ return this.getRequestBody<VideoDetails>({
+ ...options,
+
+ path,
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ getWithToken (options: OverrideCommandOptions & {
+ id: number | string
+ }) {
+ return this.get({
+ ...options,
+
+ token: this.buildCommonRequestToken({ ...options, implicitToken: true })
+ })
+ }
+
+ async getId (options: OverrideCommandOptions & {
+ uuid: number | string
+ }) {
+ const { uuid } = options
+
+ if (validator.isUUID('' + uuid) === false) return uuid as number
+
+ const { id } = await this.get({ ...options, id: uuid })
+
+ return id
+ }
+
+ // ---------------------------------------------------------------------------
+
+ listMyVideos (options: OverrideCommandOptions & {
+ start?: number
+ count?: number
+ sort?: string
+ search?: string
+ isLive?: boolean
+ } = {}) {
+ const path = '/api/v1/users/me/videos'
+
+ return this.getRequestBody<ResultList<Video>>({
+ ...options,
+
+ path,
+ query: pick(options, [ 'start', 'count', 'sort', 'search', 'isLive' ]),
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ list (options: OverrideCommandOptions & VideosCommonQuery = {}) {
+ const path = '/api/v1/videos'
+
+ const query = this.buildListQuery(options)
+
+ return this.getRequestBody<ResultList<Video>>({
+ ...options,
+
+ path,
+ query: { sort: 'name', ...query },
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ listWithToken (options: OverrideCommandOptions & VideosCommonQuery = {}) {
+ return this.list({
+ ...options,
+
+ token: this.buildCommonRequestToken({ ...options, implicitToken: true })
+ })
+ }
+
+ listByAccount (options: OverrideCommandOptions & VideosWithSearchCommonQuery & {
+ accountName: string
+ }) {
+ const { accountName, search } = options
+ const path = '/api/v1/accounts/' + accountName + '/videos'
+
+ return this.getRequestBody<ResultList<Video>>({
+ ...options,
+
+ path,
+ query: { search, ...this.buildListQuery(options) },
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ listByChannel (options: OverrideCommandOptions & VideosWithSearchCommonQuery & {
+ videoChannelName: string
+ }) {
+ const { videoChannelName } = options
+ const path = '/api/v1/video-channels/' + videoChannelName + '/videos'
+
+ return this.getRequestBody<ResultList<Video>>({
+ ...options,
+
+ path,
+ query: this.buildListQuery(options),
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ update (options: OverrideCommandOptions & {
+ id: number | string
+ attributes?: VideoEdit
+ }) {
+ const { id, attributes = {} } = options
+ const path = '/api/v1/videos/' + id
+
+ // Upload request
+ if (attributes.thumbnailfile || attributes.previewfile) {
+ const attaches: any = {}
+ if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile
+ if (attributes.previewfile) attaches.previewfile = attributes.previewfile
+
+ return this.putUploadRequest({
+ ...options,
+
+ path,
+ fields: options.attributes,
+ attaches: {
+ thumbnailfile: attributes.thumbnailfile,
+ previewfile: attributes.previewfile
+ },
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ return this.putBodyRequest({
+ ...options,
+
+ path,
+ fields: options.attributes,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ remove (options: OverrideCommandOptions & {
+ id: number | string
+ }) {
+ const path = '/api/v1/videos/' + options.id
+
+ return this.deleteRequest({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ async removeAll () {
+ const { data } = await this.list()
+
+ for (const v of data) {
+ await this.remove({ id: v.id })
+ }
+ }
+
+ // ---------------------------------------------------------------------------
+
+ async upload (options: OverrideCommandOptions & {
+ attributes?: VideoEdit
+ mode?: 'legacy' | 'resumable' // default legacy
+ } = {}) {
+ const { mode = 'legacy', expectedStatus } = options
+ let defaultChannelId = 1
+
+ try {
+ const { videoChannels } = await this.server.usersCommand.getMyInfo({ token: options.token })
+ defaultChannelId = videoChannels[0].id
+ } catch (e) { /* empty */ }
+
+ // Override default attributes
+ const attributes = {
+ name: 'my super video',
+ category: 5,
+ licence: 4,
+ language: 'zh',
+ channelId: defaultChannelId,
+ nsfw: true,
+ waitTranscoding: false,
+ description: 'my super description',
+ support: 'my super support text',
+ tags: [ 'tag' ],
+ privacy: VideoPrivacy.PUBLIC,
+ commentsEnabled: true,
+ downloadEnabled: true,
+ fixture: 'video_short.webm',
+
+ ...options.attributes
+ }
+
+ const res = mode === 'legacy'
+ ? await this.buildLegacyUpload({ ...options, attributes })
+ : await this.buildResumeUpload({ ...options, attributes })
+
+ // Wait torrent generation
+ if (expectedStatus === HttpStatusCode.OK_200) {
+ let video: VideoDetails
+
+ do {
+ video = await this.getWithToken({ ...options, id: video.uuid })
+
+ await wait(50)
+ } while (!video.files[0].torrentUrl)
+ }
+
+ return res
+ }
+
+ async buildLegacyUpload (options: OverrideCommandOptions & {
+ attributes: VideoEdit
+ }): Promise<VideoCreateResult> {
+ const path = '/api/v1/videos/upload'
+
+ return unwrapBody<{ video: VideoCreateResult }>(this.postUploadRequest({
+ ...options,
+
+ path,
+ fields: this.buildUploadFields(options.attributes),
+ attaches: this.buildUploadAttaches(options.attributes),
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })).then(body => body.video || body as any)
+ }
+
+ async buildResumeUpload (options: OverrideCommandOptions & {
+ attributes: VideoEdit
+ }) {
+ const { attributes, expectedStatus } = options
+
+ let size = 0
+ let videoFilePath: string
+ let mimetype = 'video/mp4'
+
+ if (attributes.fixture) {
+ videoFilePath = buildAbsoluteFixturePath(attributes.fixture)
+ size = (await stat(videoFilePath)).size
+
+ if (videoFilePath.endsWith('.mkv')) {
+ mimetype = 'video/x-matroska'
+ } else if (videoFilePath.endsWith('.webm')) {
+ mimetype = 'video/webm'
+ }
+ }
+
+ const initializeSessionRes = await this.prepareResumableUpload({ ...options, attributes, size, mimetype })
+ const initStatus = initializeSessionRes.status
+
+ if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) {
+ const locationHeader = initializeSessionRes.header['location']
+ expect(locationHeader).to.not.be.undefined
+
+ const pathUploadId = locationHeader.split('?')[1]
+
+ const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size })
+
+ return result.body.video
+ }
+
+ const expectedInitStatus = expectedStatus === HttpStatusCode.OK_200
+ ? HttpStatusCode.CREATED_201
+ : expectedStatus
+
+ expect(initStatus).to.equal(expectedInitStatus)
+
+ return initializeSessionRes.body.video as VideoCreateResult
+ }
+
+ async prepareResumableUpload (options: OverrideCommandOptions & {
+ attributes: VideoEdit
+ size: number
+ mimetype: string
+ }) {
+ const { attributes, size, mimetype } = options
+
+ const path = '/api/v1/videos/upload-resumable'
+
+ return this.postUploadRequest({
+ ...options,
+
+ path,
+ headers: {
+ 'X-Upload-Content-Type': mimetype,
+ 'X-Upload-Content-Length': size.toString()
+ },
+ fields: { filename: attributes.fixture, ...this.buildUploadFields(options.attributes) },
+ implicitToken: true,
+ defaultExpectedStatus: null
+ })
+ }
+
+ sendResumableChunks (options: OverrideCommandOptions & {
+ pathUploadId: string
+ videoFilePath: string
+ size: number
+ contentLength?: number
+ contentRangeBuilder?: (start: number, chunk: any) => string
+ }) {
+ const { pathUploadId, videoFilePath, size, contentLength, contentRangeBuilder, expectedStatus = HttpStatusCode.OK_200 } = options
+
+ const path = '/api/v1/videos/upload-resumable'
+ let start = 0
+
+ const token = this.buildCommonRequestToken({ ...options, implicitToken: true })
+ const url = this.server.url
+
+ const readable = createReadStream(videoFilePath, { highWaterMark: 8 * 1024 })
+ return new Promise<GotResponse<{ video: VideoCreateResult }>>((resolve, reject) => {
+ readable.on('data', async function onData (chunk) {
+ readable.pause()
+
+ const headers = {
+ 'Authorization': 'Bearer ' + token,
+ 'Content-Type': 'application/octet-stream',
+ 'Content-Range': contentRangeBuilder
+ ? contentRangeBuilder(start, chunk)
+ : `bytes ${start}-${start + chunk.length - 1}/${size}`,
+ 'Content-Length': contentLength ? contentLength + '' : chunk.length + ''
+ }
+
+ const res = await got<{ video: VideoCreateResult }>({
+ url,
+ method: 'put',
+ headers,
+ path: path + '?' + pathUploadId,
+ body: chunk,
+ responseType: 'json',
+ throwHttpErrors: false
+ })
+
+ start += chunk.length
+
+ if (res.statusCode === expectedStatus) {
+ return resolve(res)
+ }
+
+ if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) {
+ readable.off('data', onData)
+ return reject(new Error('Incorrect transient behaviour sending intermediary chunks'))
+ }
+
+ readable.resume()
+ })
+ })
+ }
+
+ quickUpload (options: OverrideCommandOptions & {
+ name: string
+ nsfw?: boolean
+ privacy?: VideoPrivacy
+ fixture?: string
+ }) {
+ const attributes: VideoEdit = { name: options.name }
+ if (options.nsfw) attributes.nsfw = options.nsfw
+ if (options.privacy) attributes.privacy = options.privacy
+ if (options.fixture) attributes.fixture = options.fixture
+
+ return this.upload({ ...options, attributes })
+ }
+
+ async randomUpload (options: OverrideCommandOptions & {
+ wait?: boolean // default true
+ additionalParams?: VideoEdit & { prefixName: string }
+ } = {}) {
+ const { wait = true, additionalParams } = options
+ const prefixName = additionalParams?.prefixName || ''
+ const name = prefixName + buildUUID()
+
+ const attributes = { name, additionalParams }
+
+ if (wait) await waitJobs([ this.server ])
+
+ const result = await this.upload({ ...options, attributes })
+
+ return { ...result, name }
+ }
+
+ // ---------------------------------------------------------------------------
+
+ private buildListQuery (options: VideosCommonQuery) {
+ return pick(options, [
+ 'start',
+ 'count',
+ 'sort',
+ 'nsfw',
+ 'isLive',
+ 'categoryOneOf',
+ 'licenceOneOf',
+ 'languageOneOf',
+ 'tagsOneOf',
+ 'tagsAllOf',
+ 'filter',
+ 'skipCount'
+ ])
+ }
+
+ private buildUploadFields (attributes: VideoEdit) {
+ return omit(attributes, [ 'thumbnailfile', 'previewfile' ])
+ }
+
+ private buildUploadAttaches (attributes: VideoEdit) {
+ const attaches: { [ name: string ]: string } = {}
+
+ for (const key of [ 'thumbnailfile', 'previewfile' ]) {
+ if (attributes[key]) attaches[key] = buildAbsoluteFixturePath(attributes[key])
+ }
+
+ if (attributes.fixture) attaches.videofile = buildAbsoluteFixturePath(attributes.fixture)
+
+ return attaches
+ }
+}
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
import { expect } from 'chai'
-import { createReadStream, pathExists, readdir, readFile, stat } from 'fs-extra'
-import got, { Response as GotResponse } from 'got/dist/source'
-import * as parseTorrent from 'parse-torrent'
+import { pathExists, readdir } from 'fs-extra'
import { join } from 'path'
-import * as request from 'supertest'
-import validator from 'validator'
import { getLowercaseExtension } from '@server/helpers/core-utils'
-import { buildUUID } from '@server/helpers/uuid'
import { HttpStatusCode } from '@shared/core-utils'
-import { BooleanBothQuery, VideosCommonQuery } from '@shared/models'
-import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
-import { VideoDetails, VideoPrivacy } from '../../models/videos'
-import { buildAbsoluteFixturePath, dateIsValid, testImage, wait, webtorrentAdd } from '../miscs'
-import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests'
-import { waitJobs } from '../server/jobs'
+import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
+import { dateIsValid, testImage, webtorrentAdd } from '../miscs'
+import { makeRawRequest } from '../requests/requests'
+import { waitJobs } from '../server'
import { ServerInfo } from '../server/servers'
-import { xxxgetMyUserInformation } from '../users'
-
-loadLanguages()
-
-type VideoAttributes = {
- name?: string
- category?: number
- licence?: number
- language?: string
- nsfw?: boolean
- commentsEnabled?: boolean
- downloadEnabled?: boolean
- waitTranscoding?: boolean
- description?: string
- originallyPublishedAt?: string
- tags?: string[]
- channelId?: number
- privacy?: VideoPrivacy
- fixture?: string
- support?: string
- thumbnailfile?: string
- previewfile?: string
- scheduleUpdate?: {
- updateAt: string
- privacy?: VideoPrivacy
- }
-}
-
-function getVideoCategories (url: string) {
- const path = '/api/v1/videos/categories'
-
- return makeGetRequest({
- url,
- path,
- statusCodeExpected: HttpStatusCode.OK_200
- })
-}
-
-function getVideoLicences (url: string) {
- const path = '/api/v1/videos/licences'
-
- return makeGetRequest({
- url,
- path,
- statusCodeExpected: HttpStatusCode.OK_200
- })
-}
-
-function getVideoLanguages (url: string) {
- const path = '/api/v1/videos/languages'
-
- return makeGetRequest({
- url,
- path,
- statusCodeExpected: HttpStatusCode.OK_200
- })
-}
-
-function getVideoPrivacies (url: string) {
- const path = '/api/v1/videos/privacies'
-
- return makeGetRequest({
- url,
- path,
- statusCodeExpected: HttpStatusCode.OK_200
- })
-}
-
-function getVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) {
- const path = '/api/v1/videos/' + id
-
- return request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(expectedStatus)
-}
-
-async function getVideoIdFromUUID (url: string, uuid: string) {
- const res = await getVideo(url, uuid)
-
- return res.body.id
-}
-
-function getVideoFileMetadataUrl (url: string) {
- return request(url)
- .get('/')
- .set('Accept', 'application/json')
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function viewVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204, xForwardedFor?: string) {
- const path = '/api/v1/videos/' + id + '/views'
-
- const req = request(url)
- .post(path)
- .set('Accept', 'application/json')
-
- if (xForwardedFor) {
- req.set('X-Forwarded-For', xForwardedFor)
- }
-
- return req.expect(expectedStatus)
-}
-
-function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) {
- const path = '/api/v1/videos/' + id
-
- return request(url)
- .get(path)
- .set('Authorization', 'Bearer ' + token)
- .set('Accept', 'application/json')
- .expect(expectedStatus)
-}
-
-function getVideoDescription (url: string, descriptionPath: string) {
- return request(url)
- .get(descriptionPath)
- .set('Accept', 'application/json')
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getVideosList (url: string) {
- const path = '/api/v1/videos'
-
- return request(url)
- .get(path)
- .query({ sort: 'name' })
- .set('Accept', 'application/json')
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getVideosListWithToken (url: string, token: string, query: { nsfw?: BooleanBothQuery } = {}) {
- const path = '/api/v1/videos'
-
- return request(url)
- .get(path)
- .set('Authorization', 'Bearer ' + token)
- .query({ sort: 'name', ...query })
- .set('Accept', 'application/json')
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getLocalVideos (url: string) {
- const path = '/api/v1/videos'
-
- return request(url)
- .get(path)
- .query({ sort: 'name', filter: 'local' })
- .set('Accept', 'application/json')
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string, search?: string) {
- const path = '/api/v1/users/me/videos'
-
- const req = request(url)
- .get(path)
- .query({ start: start })
- .query({ count: count })
- .query({ search: search })
-
- if (sort) req.query({ sort })
-
- return req.set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getMyVideosWithFilter (url: string, accessToken: string, query: { isLive?: boolean }) {
- const path = '/api/v1/users/me/videos'
-
- return makeGetRequest({
- url,
- path,
- token: accessToken,
- query,
- statusCodeExpected: HttpStatusCode.OK_200
- })
-}
-
-function getAccountVideos (
- url: string,
- accessToken: string,
- accountName: string,
- start: number,
- count: number,
- sort?: string,
- query: {
- nsfw?: BooleanBothQuery
- search?: string
- } = {}
-) {
- const path = '/api/v1/accounts/' + accountName + '/videos'
-
- return makeGetRequest({
- url,
- path,
- query: { ...query, start, count, sort },
- token: accessToken,
- statusCodeExpected: HttpStatusCode.OK_200
- })
-}
-
-function getVideoChannelVideos (
- url: string,
- accessToken: string,
- videoChannelName: string,
- start: number,
- count: number,
- sort?: string,
- query: { nsfw?: BooleanBothQuery } = {}
-) {
- const path = '/api/v1/video-channels/' + videoChannelName + '/videos'
-
- return makeGetRequest({
- url,
- path,
- query: { ...query, start, count, sort },
- token: accessToken,
- statusCodeExpected: HttpStatusCode.OK_200
- })
-}
-
-function getVideosListPagination (url: string, start: number, count: number, sort?: string, skipCount?: boolean) {
- const path = '/api/v1/videos'
-
- const req = request(url)
- .get(path)
- .query({ start: start })
- .query({ count: count })
-
- if (sort) req.query({ sort })
- if (skipCount) req.query({ skipCount })
-
- return req.set('Accept', 'application/json')
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getVideosListSort (url: string, sort: string) {
- const path = '/api/v1/videos'
-
- return request(url)
- .get(path)
- .query({ sort: sort })
- .set('Accept', 'application/json')
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getVideosWithFilters (url: string, query: VideosCommonQuery) {
- const path = '/api/v1/videos'
-
- return request(url)
- .get(path)
- .query(query)
- .set('Accept', 'application/json')
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function removeVideo (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
- const path = '/api/v1/videos'
-
- return request(url)
- .delete(path + '/' + id)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + token)
- .expect(expectedStatus)
-}
-
-async function removeAllVideos (server: ServerInfo) {
- const resVideos = await getVideosList(server.url)
-
- for (const v of resVideos.body.data) {
- await removeVideo(server.url, server.accessToken, v.id)
- }
-}
+import { VideoEdit } from './videos-command'
async function checkVideoFilesWereRemoved (
videoUUID: string,
}
}
-async function uploadVideo (
- url: string,
- accessToken: string,
- videoAttributesArg: VideoAttributes,
- specialStatus = HttpStatusCode.OK_200,
- mode: 'legacy' | 'resumable' = 'legacy'
-) {
- let defaultChannelId = '1'
-
- try {
- const res = await xxxgetMyUserInformation(url, accessToken)
- defaultChannelId = res.body.videoChannels[0].id
- } catch (e) { /* empty */ }
-
- // Override default attributes
- const attributes = Object.assign({
- name: 'my super video',
- category: 5,
- licence: 4,
- language: 'zh',
- channelId: defaultChannelId,
- nsfw: true,
- waitTranscoding: false,
- description: 'my super description',
- support: 'my super support text',
- tags: [ 'tag' ],
- privacy: VideoPrivacy.PUBLIC,
- commentsEnabled: true,
- downloadEnabled: true,
- fixture: 'video_short.webm'
- }, videoAttributesArg)
-
- const res = mode === 'legacy'
- ? await buildLegacyUpload(url, accessToken, attributes, specialStatus)
- : await buildResumeUpload(url, accessToken, attributes, specialStatus)
-
- // Wait torrent generation
- if (specialStatus === HttpStatusCode.OK_200) {
- let video: VideoDetails
- do {
- const resVideo = await getVideoWithToken(url, accessToken, res.body.video.uuid)
- video = resVideo.body
-
- await wait(50)
- } while (!video.files[0].torrentUrl)
- }
-
- return res
-}
-
function checkUploadVideoParam (
- url: string,
+ server: ServerInfo,
token: string,
- attributes: Partial<VideoAttributes>,
- specialStatus = HttpStatusCode.OK_200,
+ attributes: Partial<VideoEdit>,
+ expectedStatus = HttpStatusCode.OK_200,
mode: 'legacy' | 'resumable' = 'legacy'
) {
return mode === 'legacy'
- ? buildLegacyUpload(url, token, attributes, specialStatus)
- : buildResumeUpload(url, token, attributes, specialStatus)
-}
-
-async function buildLegacyUpload (url: string, token: string, attributes: VideoAttributes, specialStatus = HttpStatusCode.OK_200) {
- const path = '/api/v1/videos/upload'
- const req = request(url)
- .post(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + token)
-
- buildUploadReq(req, attributes)
-
- if (attributes.fixture !== undefined) {
- req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture))
- }
-
- return req.expect(specialStatus)
-}
-
-async function buildResumeUpload (url: string, token: string, attributes: VideoAttributes, specialStatus = HttpStatusCode.OK_200) {
- let size = 0
- let videoFilePath: string
- let mimetype = 'video/mp4'
-
- if (attributes.fixture) {
- videoFilePath = buildAbsoluteFixturePath(attributes.fixture)
- size = (await stat(videoFilePath)).size
-
- if (videoFilePath.endsWith('.mkv')) {
- mimetype = 'video/x-matroska'
- } else if (videoFilePath.endsWith('.webm')) {
- mimetype = 'video/webm'
- }
- }
-
- const initializeSessionRes = await prepareResumableUpload({ url, token, attributes, size, mimetype })
- const initStatus = initializeSessionRes.status
-
- if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) {
- const locationHeader = initializeSessionRes.header['location']
- expect(locationHeader).to.not.be.undefined
-
- const pathUploadId = locationHeader.split('?')[1]
-
- return sendResumableChunks({ url, token, pathUploadId, videoFilePath, size, specialStatus })
- }
-
- const expectedInitStatus = specialStatus === HttpStatusCode.OK_200
- ? HttpStatusCode.CREATED_201
- : specialStatus
-
- expect(initStatus).to.equal(expectedInitStatus)
-
- return initializeSessionRes
-}
-
-async function prepareResumableUpload (options: {
- url: string
- token: string
- attributes: VideoAttributes
- size: number
- mimetype: string
-}) {
- const { url, token, attributes, size, mimetype } = options
-
- const path = '/api/v1/videos/upload-resumable'
-
- const req = request(url)
- .post(path)
- .set('Authorization', 'Bearer ' + token)
- .set('X-Upload-Content-Type', mimetype)
- .set('X-Upload-Content-Length', size.toString())
-
- buildUploadReq(req, attributes)
-
- if (attributes.fixture) {
- req.field('filename', attributes.fixture)
- }
-
- return req
-}
-
-function sendResumableChunks (options: {
- url: string
- token: string
- pathUploadId: string
- videoFilePath: string
- size: number
- specialStatus?: HttpStatusCode
- contentLength?: number
- contentRangeBuilder?: (start: number, chunk: any) => string
-}) {
- const { url, token, pathUploadId, videoFilePath, size, specialStatus, contentLength, contentRangeBuilder } = options
-
- const expectedStatus = specialStatus || HttpStatusCode.OK_200
-
- const path = '/api/v1/videos/upload-resumable'
- let start = 0
-
- const readable = createReadStream(videoFilePath, { highWaterMark: 8 * 1024 })
- return new Promise<GotResponse>((resolve, reject) => {
- readable.on('data', async function onData (chunk) {
- readable.pause()
-
- const headers = {
- 'Authorization': 'Bearer ' + token,
- 'Content-Type': 'application/octet-stream',
- 'Content-Range': contentRangeBuilder
- ? contentRangeBuilder(start, chunk)
- : `bytes ${start}-${start + chunk.length - 1}/${size}`,
- 'Content-Length': contentLength ? contentLength + '' : chunk.length + ''
- }
-
- const res = await got({
- url,
- method: 'put',
- headers,
- path: path + '?' + pathUploadId,
- body: chunk,
- responseType: 'json',
- throwHttpErrors: false
- })
-
- start += chunk.length
-
- if (res.statusCode === expectedStatus) {
- return resolve(res)
- }
-
- if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) {
- readable.off('data', onData)
- return reject(new Error('Incorrect transient behaviour sending intermediary chunks'))
- }
-
- readable.resume()
- })
- })
-}
-
-function updateVideo (
- url: string,
- accessToken: string,
- id: number | string,
- attributes: VideoAttributes,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/videos/' + id
- const body = {}
-
- if (attributes.name) body['name'] = attributes.name
- if (attributes.category) body['category'] = attributes.category
- if (attributes.licence) body['licence'] = attributes.licence
- if (attributes.language) body['language'] = attributes.language
- if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw)
- if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled)
- if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled)
- if (attributes.originallyPublishedAt !== undefined) body['originallyPublishedAt'] = attributes.originallyPublishedAt
- if (attributes.description) body['description'] = attributes.description
- if (attributes.tags) body['tags'] = attributes.tags
- if (attributes.privacy) body['privacy'] = attributes.privacy
- if (attributes.channelId) body['channelId'] = attributes.channelId
- if (attributes.scheduleUpdate) body['scheduleUpdate'] = attributes.scheduleUpdate
-
- // Upload request
- if (attributes.thumbnailfile || attributes.previewfile) {
- const attaches: any = {}
- if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile
- if (attributes.previewfile) attaches.previewfile = attributes.previewfile
-
- return makeUploadRequest({
- url,
- method: 'PUT',
- path,
- token: accessToken,
- fields: body,
- attaches,
- statusCodeExpected
- })
- }
-
- return makePutBodyRequest({
- url,
- path,
- fields: body,
- token: accessToken,
- statusCodeExpected
- })
-}
-
-function rateVideo (url: string, accessToken: string, id: number | string, rating: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
- const path = '/api/v1/videos/' + id + '/rate'
-
- return request(url)
- .put(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .send({ rating })
- .expect(specialStatus)
-}
-
-function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
- return new Promise<any>((res, rej) => {
- const torrentName = videoUUID + '-' + resolution + '.torrent'
- const torrentPath = server.serversCommand.buildDirectory(join('torrents', torrentName))
-
- readFile(torrentPath, (err, data) => {
- if (err) return rej(err)
-
- return res(parseTorrent(data))
- })
- })
+ ? server.videosCommand.buildLegacyUpload({ token, attributes, expectedStatus })
+ : server.videosCommand.buildResumeUpload({ token, attributes, expectedStatus })
}
async function completeVideoCheck (
- url: string,
+ server: ServerInfo,
video: any,
attributes: {
name: string
if (!attributes.likes) attributes.likes = 0
if (!attributes.dislikes) attributes.dislikes = 0
- const host = new URL(url).host
+ const host = new URL(server.url).host
const originHost = attributes.account.host
expect(video.name).to.equal(attributes.name)
expect(video.originallyPublishedAt).to.be.null
}
- const res = await getVideo(url, video.uuid)
- const videoDetails: VideoDetails = res.body
+ const videoDetails = await server.videosCommand.get({ id: video.uuid })
expect(videoDetails.files).to.have.lengthOf(attributes.files.length)
expect(videoDetails.tags).to.deep.equal(attributes.tags)
}
expect(videoDetails.thumbnailPath).to.exist
- await testImage(url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath)
+ await testImage(server.url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath)
if (attributes.previewfile) {
expect(videoDetails.previewPath).to.exist
- await testImage(url, attributes.previewfile, videoDetails.previewPath)
+ await testImage(server.url, attributes.previewfile, videoDetails.previewPath)
}
}
-async function videoUUIDToId (url: string, id: number | string) {
- if (validator.isUUID('' + id) === false) return id
-
- const res = await getVideo(url, id)
- return res.body.id
-}
-
-async function uploadVideoAndGetId (options: {
- server: ServerInfo
- videoName: string
- nsfw?: boolean
- privacy?: VideoPrivacy
- token?: string
- fixture?: string
-}) {
- const videoAttrs: any = { name: options.videoName }
- if (options.nsfw) videoAttrs.nsfw = options.nsfw
- if (options.privacy) videoAttrs.privacy = options.privacy
- if (options.fixture) videoAttrs.fixture = options.fixture
-
- const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs)
-
- return res.body.video as { id: number, uuid: string, shortUUID: string }
-}
-
-async function getLocalIdByUUID (url: string, uuid: string) {
- const res = await getVideo(url, uuid)
-
- return res.body.id
-}
-
// serverNumber starts from 1
-async function uploadRandomVideoOnServers (servers: ServerInfo[], serverNumber: number, additionalParams: any = {}) {
+async function uploadRandomVideoOnServers (
+ servers: ServerInfo[],
+ serverNumber: number,
+ additionalParams?: VideoEdit & { prefixName?: string }
+) {
const server = servers.find(s => s.serverNumber === serverNumber)
- const res = await uploadRandomVideo(server, false, additionalParams)
+ const res = await server.videosCommand.randomUpload({ wait: false, ...additionalParams })
await waitJobs(servers)
return res
}
-async function uploadRandomVideo (server: ServerInfo, wait = true, additionalParams: any = {}) {
- const prefixName = additionalParams.prefixName || ''
- const name = prefixName + buildUUID()
-
- const data = Object.assign({ name }, additionalParams)
- const res = await uploadVideo(server.url, server.accessToken, data)
-
- if (wait) await waitJobs([ server ])
-
- return { uuid: res.body.video.uuid, name }
-}
-
// ---------------------------------------------------------------------------
export {
- getVideoDescription,
- getVideoCategories,
- uploadRandomVideo,
- getVideoLicences,
- videoUUIDToId,
- getVideoPrivacies,
- getVideoLanguages,
- getMyVideos,
- getAccountVideos,
- getVideoChannelVideos,
- getVideo,
- getVideoFileMetadataUrl,
- getVideoWithToken,
- getVideosList,
- removeAllVideos,
checkUploadVideoParam,
- getVideosListPagination,
- getVideosListSort,
- removeVideo,
- getVideosListWithToken,
- uploadVideo,
- sendResumableChunks,
- getVideosWithFilters,
- uploadRandomVideoOnServers,
- updateVideo,
- rateVideo,
- viewVideo,
- parseTorrentVideo,
- getLocalVideos,
completeVideoCheck,
- checkVideoFilesWereRemoved,
- getMyVideosWithFilter,
- uploadVideoAndGetId,
- getLocalIdByUUID,
- getVideoIdFromUUID,
- prepareResumableUpload
-}
-
-// ---------------------------------------------------------------------------
-
-function buildUploadReq (req: request.Test, attributes: VideoAttributes) {
-
- for (const key of [ 'name', 'support', 'channelId', 'description', 'originallyPublishedAt' ]) {
- if (attributes[key] !== undefined) {
- req.field(key, attributes[key])
- }
- }
-
- for (const key of [ 'nsfw', 'commentsEnabled', 'downloadEnabled', 'waitTranscoding' ]) {
- if (attributes[key] !== undefined) {
- req.field(key, JSON.stringify(attributes[key]))
- }
- }
-
- for (const key of [ 'language', 'privacy', 'category', 'licence' ]) {
- if (attributes[key] !== undefined) {
- req.field(key, attributes[key].toString())
- }
- }
-
- const tags = attributes.tags || []
- for (let i = 0; i < tags.length; i++) {
- req.field('tags[' + i + ']', attributes.tags[i])
- }
-
- for (const key of [ 'thumbnailfile', 'previewfile' ]) {
- if (attributes[key] !== undefined) {
- req.attach(key, buildAbsoluteFixturePath(attributes[key]))
- }
- }
-
- if (attributes.scheduleUpdate) {
- if (attributes.scheduleUpdate.updateAt) {
- req.field('scheduleUpdate[updateAt]', attributes.scheduleUpdate.updateAt)
- }
-
- if (attributes.scheduleUpdate.privacy) {
- req.field('scheduleUpdate[privacy]', attributes.scheduleUpdate.privacy)
- }
- }
+ uploadRandomVideoOnServers,
+ checkVideoFilesWereRemoved
}
tagsAllOf?: string[]
filter?: VideoFilter
+
+ skipCount?: boolean
}
export interface VideosWithSearchCommonQuery extends VideosCommonQuery {
import { VideoPrivacy } from './video-privacy.enum'
import { VideoScheduleUpdate } from './video-schedule-update.model'
+
export interface VideoUpdate {
name?: string
category?: number