import 'mocha'
import * as chai from 'chai'
+import { checkVideoFilesWereRemoved, completeVideoCheck, testImage } from '@server/tests/shared'
+import { wait } from '@shared/core-utils'
+import { Video, VideoPrivacy } from '@shared/models'
import {
- checkVideoFilesWereRemoved,
cleanupTests,
- completeVideoCheck,
- flushAndRunServer,
- ServerInfo,
+ createSingleServer,
+ PeerTubeServer,
setAccessTokensToServers,
- testImage,
- wait
-} from '@shared/extra-utils'
-import { Video, VideoPrivacy } from '@shared/models'
+ setDefaultAccountAvatar,
+ setDefaultChannelAvatar
+} from '@shared/server-commands'
const expect = chai.expect
describe('Test a single server', function () {
function runSuite (mode: 'legacy' | 'resumable') {
- let server: ServerInfo = null
+ let server: PeerTubeServer = null
let videoId: number | string
let videoId2: string
let videoUUID = ''
before(async function () {
this.timeout(30000)
- server = await flushAndRunServer(1)
+ server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
+ await setDefaultChannelAvatar(server)
+ await setDefaultAccountAvatar(server)
})
it('Should list video categories', async function () {
- const categories = await server.videosCommand.getCategories()
+ const categories = await server.videos.getCategories()
expect(Object.keys(categories)).to.have.length.above(10)
expect(categories[11]).to.equal('News & Politics')
})
it('Should list video licences', async function () {
- const licences = await server.videosCommand.getLicences()
+ const licences = await server.videos.getLicences()
expect(Object.keys(licences)).to.have.length.above(5)
expect(licences[3]).to.equal('Attribution - No Derivatives')
})
it('Should list video languages', async function () {
- const languages = await server.videosCommand.getLanguages()
+ const languages = await server.videos.getLanguages()
expect(Object.keys(languages)).to.have.length.above(5)
expect(languages['ru']).to.equal('Russian')
})
it('Should list video privacies', async function () {
- const privacies = await server.videosCommand.getPrivacies()
+ const privacies = await server.videos.getPrivacies()
expect(Object.keys(privacies)).to.have.length.at.least(3)
expect(privacies[3]).to.equal('Private')
})
it('Should not have videos', async function () {
- const { data, total } = await server.videosCommand.list()
+ const { data, total } = await server.videos.list()
expect(total).to.equal(0)
expect(data).to.be.an('array')
licence: 6,
tags: [ 'tag1', 'tag2', 'tag3' ]
}
- const video = await server.videosCommand.upload({ attributes, mode })
+ const video = await server.videos.upload({ attributes, mode })
expect(video).to.not.be.undefined
expect(video.id).to.equal(1)
expect(video.uuid).to.have.length.above(5)
it('Should get and seed the uploaded video', async function () {
this.timeout(5000)
- const { data, total } = await server.videosCommand.list()
+ const { data, total } = await server.videos.list()
expect(total).to.equal(1)
expect(data).to.be.an('array')
it('Should get the video by UUID', async function () {
this.timeout(5000)
- const video = await server.videosCommand.get({ id: videoUUID })
+ const video = await server.videos.get({ id: videoUUID })
await completeVideoCheck(server, video, getCheckAttributes())
})
it('Should have the views updated', async function () {
this.timeout(20000)
- await server.videosCommand.view({ id: videoId })
- await server.videosCommand.view({ id: videoId })
- await server.videosCommand.view({ id: videoId })
+ await server.views.simulateView({ id: videoId })
+ await server.views.simulateView({ id: videoId })
+ await server.views.simulateView({ id: videoId })
await wait(1500)
- await server.videosCommand.view({ id: videoId })
- await server.videosCommand.view({ id: videoId })
+ await server.views.simulateView({ id: videoId })
+ await server.views.simulateView({ id: videoId })
await wait(1500)
- await server.videosCommand.view({ id: videoId })
- await server.videosCommand.view({ id: videoId })
+ await server.views.simulateView({ id: videoId })
+ await server.views.simulateView({ id: videoId })
- // Wait the repeatable job
- await wait(8000)
+ await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
- const video = await server.videosCommand.get({ id: videoId })
+ const video = await server.videos.get({ id: videoId })
expect(video.views).to.equal(3)
})
it('Should remove the video', async function () {
- await server.videosCommand.remove({ id: videoId })
+ const video = await server.videos.get({ id: videoId })
+ await server.videos.remove({ id: videoId })
- await checkVideoFilesWereRemoved(videoUUID, server)
+ await checkVideoFilesWereRemoved({ video, server })
})
it('Should not have videos', async function () {
- const { total, data } = await server.videosCommand.list()
+ const { total, data } = await server.videos.list()
expect(total).to.equal(0)
expect(data).to.be.an('array')
fixture: video
}
- await server.videosCommand.upload({ attributes, mode })
+ await server.videos.upload({ attributes, mode })
}
})
it('Should have the correct durations', async function () {
- const { total, data } = await server.videosCommand.list()
+ const { total, data } = await server.videos.list()
expect(total).to.equal(6)
expect(data).to.be.an('array')
})
it('Should have the correct thumbnails', async function () {
- const { data } = await server.videosCommand.list()
+ const { data } = await server.videos.list()
// For the next test
videosListBase = data
})
it('Should list only the two first videos', async function () {
- const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: 'name' })
+ const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' })
expect(total).to.equal(6)
expect(data.length).to.equal(2)
})
it('Should list only the next three videos', async function () {
- const { total, data } = await server.videosCommand.list({ start: 2, count: 3, sort: 'name' })
+ const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' })
expect(total).to.equal(6)
expect(data.length).to.equal(3)
})
it('Should list the last video', async function () {
- const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name' })
+ const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' })
expect(total).to.equal(6)
expect(data.length).to.equal(1)
})
it('Should not have the total field', async function () {
- const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name', skipCount: true })
+ const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true })
expect(total).to.not.exist
expect(data.length).to.equal(1)
})
it('Should list and sort by name in descending order', async function () {
- const { total, data } = await server.videosCommand.list({ sort: '-name' })
+ const { total, data } = await server.videos.list({ sort: '-name' })
expect(total).to.equal(6)
expect(data.length).to.equal(6)
})
it('Should list and sort by trending in descending order', async function () {
- const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-trending' })
+ const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' })
expect(total).to.equal(6)
expect(data.length).to.equal(2)
})
it('Should list and sort by hotness in descending order', async function () {
- const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-hot' })
+ const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' })
expect(total).to.equal(6)
expect(data.length).to.equal(2)
})
it('Should list and sort by best in descending order', async function () {
- const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-best' })
+ const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' })
expect(total).to.equal(6)
expect(data.length).to.equal(2)
downloadEnabled: false,
tags: [ 'tagup1', 'tagup2' ]
}
- await server.videosCommand.update({ id: videoId, attributes })
- })
-
- it('Should filter by tags and category', async function () {
- {
- const { data, total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
- expect(total).to.equal(1)
- expect(data[0].name).to.equal('my super video updated')
- }
-
- {
- const { total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
- expect(total).to.equal(0)
- }
+ await server.videos.update({ id: videoId, attributes })
})
it('Should have the video updated', async function () {
this.timeout(60000)
- const video = await server.videosCommand.get({ id: videoId })
+ const video = await server.videos.get({ id: videoId })
await completeVideoCheck(server, video, updateCheckAttributes())
})
const attributes = {
tags: [ 'supertag', 'tag1', 'tag2' ]
}
- await server.videosCommand.update({ id: videoId, attributes })
+ await server.videos.update({ id: videoId, attributes })
- const video = await server.videosCommand.get({ id: videoId })
+ const video = await server.videos.get({ id: videoId })
await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes))
})
const attributes = {
description: 'hello everybody'
}
- await server.videosCommand.update({ id: videoId, attributes })
+ await server.videos.update({ id: videoId, attributes })
- const video = await server.videosCommand.get({ id: videoId })
+ const video = await server.videos.get({ id: videoId })
const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
await completeVideoCheck(server, video, expectedAttributes)
})
it('Should like a video', async function () {
- await server.videosCommand.rate({ id: videoId, rating: 'like' })
+ await server.videos.rate({ id: videoId, rating: 'like' })
- const video = await server.videosCommand.get({ id: videoId })
+ const video = await server.videos.get({ id: videoId })
expect(video.likes).to.equal(1)
expect(video.dislikes).to.equal(0)
})
it('Should dislike the same video', async function () {
- await server.videosCommand.rate({ id: videoId, rating: 'dislike' })
+ await server.videos.rate({ id: videoId, rating: 'dislike' })
- const video = await server.videosCommand.get({ id: videoId })
+ const video = await server.videos.get({ id: videoId })
expect(video.likes).to.equal(0)
expect(video.dislikes).to.equal(1)
{
const now = new Date()
const attributes = { originallyPublishedAt: now.toISOString() }
- await server.videosCommand.update({ id: videoId, attributes })
+ await server.videos.update({ id: videoId, attributes })
- const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' })
+ const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
const names = data.map(v => v.name)
expect(names[0]).to.equal('my super video updated')
{
const now = new Date()
const attributes = { originallyPublishedAt: now.toISOString() }
- await server.videosCommand.update({ id: videoId2, attributes })
+ await server.videos.update({ id: videoId2, attributes })
- const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' })
+ const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
const names = data.map(v => v.name)
expect(names[0]).to.equal('video_short1.webm name')