Verified Commit d23dd9fb authored by Chocobozzz's avatar Chocobozzz
Browse files

Introduce videos command

parent 7926c5f9
import * as autocannon from 'autocannon'
import { writeJson } from 'fs-extra'
import { flushAndRunServer, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils'
import { flushAndRunServer, killallServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models'
import { registerTSPaths } from '../server/helpers/register-ts-paths'
......@@ -197,7 +197,7 @@ async function prepare () {
})
await setAccessTokensToServers([ server ])
const videoAttributes = {
const attributes = {
name: 'my super video',
category: 2,
nsfw: true,
......@@ -210,12 +210,11 @@ async function prepare () {
}
for (let i = 0; i < 10; i++) {
Object.assign(videoAttributes, { name: 'my super video ' + i })
await uploadVideo(server.url, server.accessToken, videoAttributes)
await server.videosCommand.upload({ attributes: { ...attributes, name: 'my super video ' + i } })
}
const resVideos = await getVideosList(server.url)
video = resVideos.body.data.find(v => v.name === 'my super video 1')
const { data } = await server.videosCommand.list()
video = data.find(v => v.name === 'my super video 1')
for (let i = 0; i < 10; i++) {
const text = 'my super first comment'
......
......@@ -6,11 +6,8 @@ import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
rateVideo,
ServerInfo,
setAccessTokensToServers,
uploadVideoAndGetId,
wait,
waitJobs
} from '@shared/extra-utils'
......@@ -49,9 +46,9 @@ describe('Test AP cleaner', function () {
// Create 1 comment per video
// Update 1 remote URL and 1 local URL on
videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid
videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid
videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid
videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid
videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid
videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ]
......@@ -59,7 +56,7 @@ describe('Test AP cleaner', function () {
for (const server of servers) {
for (const uuid of videoUUIDs) {
await rateVideo(server.url, server.accessToken, uuid, 'like')
await server.videosCommand.rate({ id: uuid, rating: 'like' })
await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' })
}
}
......@@ -70,9 +67,10 @@ describe('Test AP cleaner', function () {
it('Should have the correct likes', async function () {
for (const server of servers) {
for (const uuid of videoUUIDs) {
const res = await getVideo(server.url, uuid)
expect(res.body.likes).to.equal(3)
expect(res.body.dislikes).to.equal(0)
const video = await server.videosCommand.get({ id: uuid })
expect(video.likes).to.equal(3)
expect(video.dislikes).to.equal(0)
}
}
})
......@@ -90,16 +88,16 @@ describe('Test AP cleaner', function () {
// Updated rates of my video
{
const res = await getVideo(servers[0].url, videoUUID1)
expect(res.body.likes).to.equal(2)
expect(res.body.dislikes).to.equal(0)
const video = await servers[0].videosCommand.get({ id: videoUUID1 })
expect(video.likes).to.equal(2)
expect(video.dislikes).to.equal(0)
}
// Did not update rates of a remote video
{
const res = await getVideo(servers[0].url, videoUUID2)
expect(res.body.likes).to.equal(3)
expect(res.body.dislikes).to.equal(0)
const video = await servers[0].videosCommand.get({ id: videoUUID2 })
expect(video.likes).to.equal(3)
expect(video.dislikes).to.equal(0)
}
})
......@@ -108,7 +106,7 @@ describe('Test AP cleaner', function () {
for (const server of servers) {
for (const uuid of videoUUIDs) {
await rateVideo(server.url, server.accessToken, uuid, 'dislike')
await server.videosCommand.rate({ id: uuid, rating: 'dislike' })
}
}
......@@ -116,9 +114,9 @@ describe('Test AP cleaner', function () {
for (const server of servers) {
for (const uuid of videoUUIDs) {
const res = await getVideo(server.url, uuid)
expect(res.body.likes).to.equal(0)
expect(res.body.dislikes).to.equal(3)
const video = await server.videosCommand.get({ id: uuid })
expect(video.likes).to.equal(0)
expect(video.dislikes).to.equal(3)
}
}
})
......@@ -137,16 +135,16 @@ describe('Test AP cleaner', function () {
// Updated rates of my video
{
const res = await getVideo(servers[0].url, videoUUID1)
expect(res.body.likes).to.equal(0)
expect(res.body.dislikes).to.equal(2)
const video = await servers[0].videosCommand.get({ id: videoUUID1 })
expect(video.likes).to.equal(0)
expect(video.dislikes).to.equal(2)
}
// Did not update rates of a remote video
{
const res = await getVideo(servers[0].url, videoUUID2)
expect(res.body.likes).to.equal(0)
expect(res.body.dislikes).to.equal(3)
const video = await servers[0].videosCommand.get({ id: videoUUID2 })
expect(video.likes).to.equal(0)
expect(video.dislikes).to.equal(3)
}
})
......
......@@ -2,8 +2,7 @@
import 'mocha'
import * as chai from 'chai'
import { VideoPlaylistPrivacy } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
doubleFollow,
......@@ -11,9 +10,9 @@ import {
makeActivityPubGetRequest,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
uploadVideoAndGetId
} from '../../../../shared/extra-utils'
setDefaultVideoChannel
} from '@shared/extra-utils'
import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect
......@@ -69,7 +68,7 @@ describe('Test activitypub', function () {
await setDefaultVideoChannel(servers)
{
video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })
video = await await servers[0].videosCommand.quickUpload({ name: 'video' })
}
{
......
......@@ -2,17 +2,7 @@
import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideosListSort,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
waitJobs
} from '../../../../shared/extra-utils'
import { Video } from '../../../../shared/models/videos'
import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
const expect = chai.expect
......@@ -36,10 +26,9 @@ describe('Test ActivityPub fetcher', function () {
const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' })
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' })
const badVideoUUID = res.body.video.uuid
await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
await servers[0].videosCommand.upload({ attributes: { name: 'video root' } })
const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'bad video root' } })
await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'video user' } })
{
const to = 'http://localhost:' + servers[0].port + '/accounts/user1'
......@@ -48,8 +37,8 @@ describe('Test ActivityPub fetcher', function () {
}
{
const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID
await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value)
const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid
await servers[0].sqlCommand.setVideoField(uuid, 'url', value)
}
})
......@@ -60,20 +49,18 @@ describe('Test ActivityPub fetcher', function () {
await waitJobs(servers)
{
const res = await getVideosListSort(servers[0].url, 'createdAt')
expect(res.body.total).to.equal(3)
const { total, data } = await servers[0].videosCommand.list({ sort: 'createdAt' })
const data: Video[] = res.body.data
expect(total).to.equal(3)
expect(data[0].name).to.equal('video root')
expect(data[1].name).to.equal('bad video root')
expect(data[2].name).to.equal('video user')
}
{
const res = await getVideosListSort(servers[1].url, 'createdAt')
expect(res.body.total).to.equal(1)
const { total, data } = await servers[1].videosCommand.list({ sort: 'createdAt' })
const data: Video[] = res.body.data
expect(total).to.equal(1)
expect(data[0].name).to.equal('video root')
}
})
......
......@@ -6,14 +6,11 @@ import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
killallServers,
reRunServer,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
uploadVideo,
uploadVideoAndGetId,
wait,
waitJobs
} from '@shared/extra-utils'
......@@ -37,17 +34,17 @@ describe('Test AP refresher', function () {
await setDefaultVideoChannel(servers)
{
videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid
videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid
videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid
videoUUID1 = (await servers[1].videosCommand.quickUpload({ name: 'video1' })).uuid
videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'video2' })).uuid
videoUUID3 = (await servers[1].videosCommand.quickUpload({ name: 'video3' })).uuid
}
{
const a1 = await servers[1].usersCommand.generateUserAndToken('user1')
await uploadVideo(servers[1].url, a1, { name: 'video4' })
const token1 = await servers[1].usersCommand.generateUserAndToken('user1')
await servers[1].videosCommand.upload({ token: token1, attributes: { name: 'video4' } })
const a2 = await servers[1].usersCommand.generateUserAndToken('user2')
await uploadVideo(servers[1].url, a2, { name: 'video5' })
const token2 = await servers[1].usersCommand.generateUserAndToken('user2')
await servers[1].videosCommand.upload({ token: token2, attributes: { name: 'video5' } })
}
{
......@@ -75,13 +72,13 @@ describe('Test AP refresher', function () {
// Change UUID so the remote server returns a 404
await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
await getVideo(servers[0].url, videoUUID1)
await getVideo(servers[0].url, videoUUID2)
await servers[0].videosCommand.get({ id: videoUUID1 })
await servers[0].videosCommand.get({ id: videoUUID2 })
await waitJobs(servers)
await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
await servers[0].videosCommand.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
await servers[0].videosCommand.get({ id: videoUUID2 })
})
it('Should not update a remote video if the remote instance is down', async function () {
......@@ -94,13 +91,13 @@ describe('Test AP refresher', function () {
// Video will need a refresh
await wait(10000)
await getVideo(servers[0].url, videoUUID3)
await servers[0].videosCommand.get({ id: videoUUID3 })
// The refresh should fail
await waitJobs([ servers[0] ])
await reRunServer(servers[1])
await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
await servers[0].videosCommand.get({ id: videoUUID3 })
})
})
......
......@@ -10,12 +10,10 @@ import {
cleanupTests,
doubleFollow,
flushAndRunServer,
getVideoIdFromUUID,
makeGetRequest,
makePostBodyRequest,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { AbuseCreate, AbuseState } from '@shared/models'
......@@ -41,15 +39,10 @@ describe('Test abuses API validators', function () {
await setAccessTokensToServers([ server ])
const username = 'user1'
const password = 'my super password'
await server.usersCommand.create({ username: username, password: password })
userToken = await server.loginCommand.getAccessToken({ username, password })
userToken = await server.usersCommand.generateUserAndToken('user_1')
userToken2 = await server.usersCommand.generateUserAndToken('user_2')
const res = await uploadVideo(server.url, server.accessToken, {})
server.video = res.body.video
server.video = await server.videosCommand.upload()
command = server.abusesCommand
})
......@@ -421,7 +414,7 @@ describe('Test abuses API validators', function () {
await doubleFollow(anotherServer, server)
const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid)
const server2VideoId = await anotherServer.videosCommand.getId({ uuid: server.video.uuid })
await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId })
await waitJobs([ server, anotherServer ])
......
......@@ -13,8 +13,7 @@ import {
sendRTMPStream,
ServerInfo,
setAccessTokensToServers,
stopFfmpeg,
uploadVideoAndGetId
stopFfmpeg
} from '@shared/extra-utils'
import { VideoCreateResult, VideoPrivacy } from '@shared/models'
......@@ -58,7 +57,7 @@ describe('Test video lives API validator', function () {
}
{
videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
videoIdNotLive = (await server.videosCommand.quickUpload({ name: 'not live' })).id
}
command = server.liveCommand
......
......@@ -10,14 +10,12 @@ import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
makeDeleteRequest,
makeGetRequest,
makePostBodyRequest,
makePutBodyRequest,
ServerInfo,
setAccessTokensToServers,
uploadVideoAndGetId,
waitJobs
} from '../../../../shared/extra-utils'
......@@ -45,14 +43,13 @@ describe('Test server redundancy API validators', function () {
await servers[0].usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(user)
videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
videoIdLocal = (await servers[0].videosCommand.quickUpload({ name: 'video' })).id
const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid
const remoteUUID = (await servers[1].videosCommand.quickUpload({ name: 'video' })).uuid
await waitJobs(servers)
const resVideo = await getVideo(servers[0].url, remoteUUID)
videoRemote = resVideo.body
videoRemote = await servers[0].videosCommand.get({ id: remoteUUID })
})
describe('When listing redundancies', function () {
......
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import { VideoPlaylistPrivacy } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
flushAndRunServer,
makeGetRequest,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
uploadVideo
} from '../../../../shared/extra-utils'
setDefaultVideoChannel
} from '@shared/extra-utils'
import { VideoPlaylistPrivacy } from '@shared/models'
describe('Test services API validators', function () {
let server: ServerInfo
......@@ -26,10 +25,7 @@ describe('Test services API validators', function () {
await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ])
{
const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
server.video = res.body.video
}
server.video = await server.videosCommand.upload({ attributes: { name: 'my super name' } })
{
const created = await server.playlistsCommand.create({
......
......@@ -3,7 +3,6 @@
import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode, randomInt } from '@shared/core-utils'
import { VideoImportState, VideoPrivacy } from '@shared/models'
import {
cleanupTests,
flushAndRunServer,
......@@ -11,13 +10,15 @@ import {
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
uploadVideo,
VideosCommand,
waitJobs
} from '../../../../shared/extra-utils'
} from '@shared/extra-utils'
import { VideoImportState, VideoPrivacy } from '@shared/models'
describe('Test upload quota', function () {
let server: ServerInfo
let rootId: number
let command: VideosCommand
// ---------------------------------------------------------------
......@@ -32,6 +33,8 @@ describe('Test upload quota', function () {
rootId = user.id
await server.usersCommand.update({ userId: rootId, videoQuota: 42 })
command = server.videosCommand
})
describe('When having a video quota', function () {
......@@ -41,14 +44,14 @@ describe('Test upload quota', function () {
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
await server.usersCommand.register(user)
const userAccessToken = await server.loginCommand.getAccessToken(user)
const userToken = await server.loginCommand.getAccessToken(user)
const videoAttributes = { fixture: 'video_short2.webm' }
const attributes = { fixture: 'video_short2.webm' }
for (let i = 0; i < 5; i++) {
await uploadVideo(server.url, userAccessToken, videoAttributes)
await command.upload({ token: userToken, attributes })
}
await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
})
it('Should fail with a registered user having too many videos with resumable upload', async function () {
......@@ -56,14 +59,14 @@ describe('Test upload quota', function () {
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
await server.usersCommand.register(user)
const userAccessToken = await server.loginCommand.getAccessToken(user)
const userToken = await server.loginCommand.getAccessToken(user)
const videoAttributes = { fixture: 'video_short2.webm' }
const attributes = { fixture: 'video_short2.webm' }
for (let i = 0; i < 5; i++) {
await uploadVideo(server.url, userAccessToken, videoAttributes)
await command.upload({ token: userToken, attributes })
}
await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
})
it('Should fail to import with HTTP/Torrent/magnet', async function () {
......@@ -97,8 +100,8 @@ describe('Test upload quota', function () {
it('Should fail with a user having too many videos daily', async function () {
await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 })
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
})
})
......@@ -110,8 +113,8 @@ describe('Test upload quota', function () {
videoQuotaDaily: 1024 * 1024 * 1024
})
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
})
it('Should fail if exceeding daily quota', async function () {
......@@ -121,8 +124,8 @@ describe('Test upload quota', function () {
videoQuotaDaily: 42
})
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
})
})
......
......@@ -2,10 +2,12 @@
import 'mocha'
import { omit } from 'lodash'
import { UserRole, VideoCreateResult } from '../../../../shared'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { HttpStatusCode } from '@shared/core-utils'
import {
buildAbsoluteFixturePath,
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
flushAndRunServer,
killallServers,
......@@ -13,19 +15,13 @@ import {
makePostBodyRequest,
makePutBodyRequest,