PeerTube/server/tests/api/videos/video-playlists.ts

1159 lines
40 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2019-02-26 03:55:40 -06:00
2022-08-17 08:44:32 -05:00
import { expect } from 'chai'
import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared'
import { wait } from '@shared/core-utils'
import {
HttpStatusCode,
VideoPlaylist,
VideoPlaylistCreateResult,
VideoPlaylistElementType,
VideoPlaylistPrivacy,
VideoPlaylistType,
VideoPrivacy
} from '@shared/models'
2019-02-26 03:55:40 -06:00
import {
2019-04-24 10:19:00 -05:00
cleanupTests,
2021-07-16 02:47:51 -05:00
createMultipleServers,
2021-07-16 07:27:30 -05:00
doubleFollow,
2021-07-16 02:47:51 -05:00
PeerTubeServer,
2021-07-16 07:27:30 -05:00
PlaylistsCommand,
2019-02-26 03:55:40 -06:00
setAccessTokensToServers,
setDefaultAccountAvatar,
2019-03-05 03:58:44 -06:00
setDefaultVideoChannel,
2019-07-31 08:57:32 -05:00
waitJobs
} from '@shared/server-commands'
import { uuidToShort } from '@shared/extra-utils'
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
async function checkPlaylistElementType (
2021-07-16 02:47:51 -05:00
servers: PeerTubeServer[],
2019-07-31 08:57:32 -05:00
playlistId: string,
type: VideoPlaylistElementType,
position: number,
name: string,
total: number
) {
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const body = await server.playlists.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(total)
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
const videoElement = body.data.find(e => e.position === position)
2019-07-31 08:57:32 -05:00
expect(videoElement.type).to.equal(type, 'On server ' + server.url)
if (type === VideoPlaylistElementType.REGULAR) {
expect(videoElement.video).to.not.be.null
expect(videoElement.video.name).to.equal(name)
} else {
expect(videoElement.video).to.be.null
}
}
}
2019-02-26 03:55:40 -06:00
describe('Test video playlists', function () {
2021-07-16 02:47:51 -05:00
let servers: PeerTubeServer[] = []
2019-02-26 03:55:40 -06:00
2019-03-05 03:58:44 -06:00
let playlistServer2Id1: number
let playlistServer2Id2: number
2021-07-08 08:54:39 -05:00
let playlistServer2UUID2: string
2019-03-05 03:58:44 -06:00
let playlistServer1Id: number
let playlistServer1DisplayName: string
2019-03-05 03:58:44 -06:00
let playlistServer1UUID: string
2019-07-31 08:57:32 -05:00
let playlistServer1UUID2: string
let playlistElementServer1Video4: number
let playlistElementServer1Video5: number
let playlistElementNSFW: number
2019-03-05 03:58:44 -06:00
let nsfwVideoServer1: number
2021-07-08 08:54:39 -05:00
let userTokenServer1: string
let commands: PlaylistsCommand[]
2019-07-31 08:57:32 -05:00
2019-02-26 03:55:40 -06:00
before(async function () {
2022-09-28 01:24:18 -05:00
this.timeout(240000)
2019-02-26 03:55:40 -06:00
2022-02-11 03:51:33 -06:00
servers = await createMultipleServers(3)
2019-02-26 03:55:40 -06:00
// Get the access tokens
await setAccessTokensToServers(servers)
2019-03-05 03:58:44 -06:00
await setDefaultVideoChannel(servers)
await setDefaultAccountAvatar(servers)
2019-02-26 03:55:40 -06:00
2022-02-11 03:51:33 -06:00
for (const server of servers) {
await server.config.disableTranscoding()
}
2019-02-26 03:55:40 -06:00
// Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1])
// Server 1 and server 3 follow each other
await doubleFollow(servers[0], servers[2])
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
commands = servers.map(s => s.playlists)
2021-07-08 08:54:39 -05:00
2019-03-05 03:58:44 -06:00
{
2021-07-16 02:04:35 -05:00
servers[0].store.videos = []
servers[1].store.videos = []
servers[2].store.videos = []
2019-03-05 03:58:44 -06:00
for (const server of servers) {
for (let i = 0; i < 7; i++) {
2020-12-11 03:36:05 -06:00
const name = `video ${i} server ${server.serverNumber}`
2021-07-16 02:04:35 -05:00
const video = await server.videos.upload({ attributes: { name, nsfw: false } })
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
server.store.videos.push(video)
2020-12-11 03:36:05 -06:00
}
2019-03-05 03:58:44 -06:00
}
}
2021-07-16 02:04:35 -05:00
nsfwVideoServer1 = (await servers[0].videos.quickUpload({ name: 'NSFW video', nsfw: true })).id
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
userTokenServer1 = await servers[0].users.generateUserAndToken('user1')
2019-07-31 08:57:32 -05:00
2019-03-05 03:58:44 -06:00
await waitJobs(servers)
2019-02-26 03:55:40 -06:00
})
2019-07-31 08:57:32 -05:00
describe('Get default playlists', function () {
2021-07-08 08:54:39 -05:00
2019-07-31 08:57:32 -05:00
it('Should list video playlist privacies', async function () {
2021-07-08 08:54:39 -05:00
const privacies = await commands[0].getPrivacies()
2019-03-06 04:32:53 -06:00
2019-07-31 08:57:32 -05:00
expect(Object.keys(privacies)).to.have.length.at.least(3)
2020-01-31 09:56:52 -06:00
expect(privacies[3]).to.equal('Private')
2019-07-31 08:57:32 -05:00
})
2019-03-06 04:32:53 -06:00
2019-07-31 08:57:32 -05:00
it('Should list watch later playlist', async function () {
2021-07-08 08:54:39 -05:00
const token = servers[0].accessToken
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-08 08:54:39 -05:00
const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.WATCH_LATER })
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
const playlist = body.data[0]
2019-07-31 08:57:32 -05:00
expect(playlist.displayName).to.equal('Watch later')
expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER)
expect(playlist.type.label).to.equal('Watch later')
}
{
2021-07-08 08:54:39 -05:00
const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.REGULAR })
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
2019-07-31 08:57:32 -05:00
}
{
2021-07-08 08:54:39 -05:00
const body = await commands[0].listByAccount({ handle: 'root' })
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
2019-07-31 08:57:32 -05:00
}
})
it('Should get private playlist for a classic user', async function () {
2021-07-16 02:04:35 -05:00
const token = await servers[0].users.generateUserAndToken('toto')
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
const body = await commands[0].listByAccount({ token, handle: 'toto' })
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
2019-02-26 03:55:40 -06:00
2021-07-08 08:54:39 -05:00
const playlistId = body.data[0].id
await commands[0].listVideos({ token, playlistId })
2019-07-31 08:57:32 -05:00
})
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
describe('Create and federate playlists', function () {
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
await commands[0].create({
attributes: {
2019-07-31 08:57:32 -05:00
displayName: 'my super playlist',
privacy: VideoPlaylistPrivacy.PUBLIC,
description: 'my super description',
thumbnailfile: 'thumbnail.jpg',
2021-07-16 02:04:35 -05:00
videoChannelId: servers[0].store.channel.id
2019-07-31 08:57:32 -05:00
}
})
await waitJobs(servers)
2020-11-18 06:41:27 -06:00
// Processing a playlist by the receiver could be long
await wait(3000)
2019-07-31 08:57:32 -05:00
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const body = await server.playlists.list({ start: 0, count: 5 })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
const playlistFromList = body.data[0]
2019-07-31 08:57:32 -05:00
2021-07-16 02:04:35 -05:00
const playlistFromGet = await server.playlists.get({ playlistId: playlistFromList.uuid })
2019-07-31 08:57:32 -05:00
for (const playlist of [ playlistFromGet, playlistFromList ]) {
expect(playlist.id).to.be.a('number')
expect(playlist.uuid).to.be.a('string')
expect(playlist.isLocal).to.equal(server.serverNumber === 1)
expect(playlist.displayName).to.equal('my super playlist')
expect(playlist.description).to.equal('my super description')
expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
expect(playlist.privacy.label).to.equal('Public')
expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
expect(playlist.type.label).to.equal('Regular')
expect(playlist.embedPath).to.equal('/video-playlists/embed/' + playlist.uuid)
2019-07-31 08:57:32 -05:00
expect(playlist.videosLength).to.equal(0)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
expect(playlist.ownerAccount.name).to.equal('root')
expect(playlist.ownerAccount.displayName).to.equal('root')
expect(playlist.videoChannel.name).to.equal('root_channel')
expect(playlist.videoChannel.displayName).to.equal('Main root channel')
}
}
})
2019-05-28 02:50:27 -05:00
2019-07-31 08:57:32 -05:00
it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
this.timeout(30000)
{
2021-07-16 02:04:35 -05:00
const playlist = await servers[1].playlists.create({
2021-07-08 08:54:39 -05:00
attributes: {
2019-07-31 08:57:32 -05:00
displayName: 'playlist 2',
privacy: VideoPlaylistPrivacy.PUBLIC,
2021-07-16 02:04:35 -05:00
videoChannelId: servers[1].store.channel.id
2019-07-31 08:57:32 -05:00
}
})
2021-07-08 08:54:39 -05:00
playlistServer2Id1 = playlist.id
2019-07-31 08:57:32 -05:00
}
2019-05-28 02:50:27 -05:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const playlist = await servers[1].playlists.create({
2021-07-08 08:54:39 -05:00
attributes: {
2019-07-31 08:57:32 -05:00
displayName: 'playlist 3',
privacy: VideoPlaylistPrivacy.PUBLIC,
thumbnailfile: 'thumbnail.jpg',
2021-07-16 02:04:35 -05:00
videoChannelId: servers[1].store.channel.id
2019-07-31 08:57:32 -05:00
}
})
2021-07-08 08:54:39 -05:00
playlistServer2Id2 = playlist.id
playlistServer2UUID2 = playlist.uuid
2019-07-31 08:57:32 -05:00
}
2020-01-31 09:56:52 -06:00
for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) {
2021-07-16 02:04:35 -05:00
await servers[1].playlists.addElement({
2019-07-31 08:57:32 -05:00
playlistId: id,
2021-07-16 02:04:35 -05:00
attributes: { videoId: servers[1].store.videos[0].id, startTimestamp: 1, stopTimestamp: 2 }
2019-07-31 08:57:32 -05:00
})
2021-07-16 02:04:35 -05:00
await servers[1].playlists.addElement({
2019-07-31 08:57:32 -05:00
playlistId: id,
2021-07-16 02:04:35 -05:00
attributes: { videoId: servers[1].store.videos[1].id }
2019-07-31 08:57:32 -05:00
})
}
await waitJobs(servers)
2020-11-18 06:41:27 -06:00
await wait(3000)
2019-07-31 08:57:32 -05:00
2020-01-31 09:56:52 -06:00
for (const server of [ servers[0], servers[1] ]) {
2021-07-16 02:04:35 -05:00
const body = await server.playlists.list({ start: 0, count: 5 })
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
const playlist2 = body.data.find(p => p.displayName === 'playlist 2')
2019-07-31 08:57:32 -05:00
expect(playlist2).to.not.be.undefined
await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath)
2021-07-08 08:54:39 -05:00
const playlist3 = body.data.find(p => p.displayName === 'playlist 3')
2019-07-31 08:57:32 -05:00
expect(playlist3).to.not.be.undefined
await testImage(server.url, 'thumbnail', playlist3.thumbnailPath)
}
2019-05-28 02:50:27 -05:00
2021-07-16 02:04:35 -05:00
const body = await servers[2].playlists.list({ start: 0, count: 5 })
2021-07-08 08:54:39 -05:00
expect(body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined
expect(body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined
2019-07-31 08:57:32 -05:00
})
it('Should have the playlist on server 3 after a new follow', async function () {
this.timeout(30000)
// Server 2 and server 3 follow each other
2020-01-31 09:56:52 -06:00
await doubleFollow(servers[1], servers[2])
2019-07-31 08:57:32 -05:00
2021-07-16 02:04:35 -05:00
const body = await servers[2].playlists.list({ start: 0, count: 5 })
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
const playlist2 = body.data.find(p => p.displayName === 'playlist 2')
2019-07-31 08:57:32 -05:00
expect(playlist2).to.not.be.undefined
2020-01-31 09:56:52 -06:00
await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath)
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
expect(body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
2019-07-31 08:57:32 -05:00
})
2019-05-28 02:50:27 -05:00
})
2019-07-31 08:57:32 -05:00
describe('List playlists', function () {
2019-07-31 08:57:32 -05:00
it('Should correctly list the playlists', async function () {
this.timeout(30000)
{
2021-07-16 02:04:35 -05:00
const body = await servers[2].playlists.list({ start: 1, count: 2, sort: 'createdAt' })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(3)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const data = body.data
2019-07-31 08:57:32 -05:00
expect(data).to.have.lengthOf(2)
2020-01-31 09:56:52 -06:00
expect(data[0].displayName).to.equal('playlist 2')
expect(data[1].displayName).to.equal('playlist 3')
2019-07-31 08:57:32 -05:00
}
{
2021-07-16 02:04:35 -05:00
const body = await servers[2].playlists.list({ start: 1, count: 2, sort: '-createdAt' })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(3)
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
const data = body.data
2019-07-31 08:57:32 -05:00
expect(data).to.have.lengthOf(2)
2020-01-31 09:56:52 -06:00
expect(data[0].displayName).to.equal('playlist 2')
expect(data[1].displayName).to.equal('my super playlist')
2019-03-05 03:58:44 -06:00
}
})
2019-07-31 08:57:32 -05:00
it('Should list video channel playlists', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-08 08:54:39 -05:00
const body = await commands[0].listByChannel({ handle: 'root_channel', start: 0, count: 2, sort: '-createdAt' })
expect(body.total).to.equal(1)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const data = body.data
2019-07-31 08:57:32 -05:00
expect(data).to.have.lengthOf(1)
2020-01-31 09:56:52 -06:00
expect(data[0].displayName).to.equal('my super playlist')
2019-07-31 08:57:32 -05:00
}
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should list account playlists', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(2)
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
const data = body.data
2019-07-31 08:57:32 -05:00
expect(data).to.have.lengthOf(1)
2020-01-31 09:56:52 -06:00
expect(data[0].displayName).to.equal('playlist 2')
2019-07-31 08:57:32 -05:00
}
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(2)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const data = body.data
2019-07-31 08:57:32 -05:00
expect(data).to.have.lengthOf(1)
2020-01-31 09:56:52 -06:00
expect(data[0].displayName).to.equal('playlist 3')
2019-03-05 03:58:44 -06:00
}
2019-12-27 02:04:04 -06:00
{
2021-07-16 02:04:35 -05:00
const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(1)
2019-12-27 02:04:04 -06:00
2021-07-08 08:54:39 -05:00
const data = body.data
2019-12-27 02:04:04 -06:00
expect(data).to.have.lengthOf(1)
2020-01-31 09:56:52 -06:00
expect(data[0].displayName).to.equal('playlist 3')
2019-12-27 02:04:04 -06:00
}
{
2021-07-16 02:04:35 -05:00
const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(0)
2019-12-27 02:04:04 -06:00
2021-07-08 08:54:39 -05:00
const data = body.data
2019-12-27 02:04:04 -06:00
expect(data).to.have.lengthOf(0)
}
2019-07-31 08:57:32 -05:00
})
})
2019-02-26 03:55:40 -06:00
describe('Playlist rights', function () {
let unlistedPlaylist: VideoPlaylistCreateResult
let privatePlaylist: VideoPlaylistCreateResult
before(async function () {
2019-07-31 08:57:32 -05:00
this.timeout(30000)
2019-03-05 03:58:44 -06:00
{
2021-07-16 02:04:35 -05:00
unlistedPlaylist = await servers[1].playlists.create({
2021-07-08 08:54:39 -05:00
attributes: {
displayName: 'playlist unlisted',
privacy: VideoPlaylistPrivacy.UNLISTED,
2021-07-16 02:04:35 -05:00
videoChannelId: servers[1].store.channel.id
}
})
}
2019-03-05 03:58:44 -06:00
{
2021-07-16 02:04:35 -05:00
privatePlaylist = await servers[1].playlists.create({
2021-07-08 08:54:39 -05:00
attributes: {
displayName: 'playlist private',
privacy: VideoPlaylistPrivacy.PRIVATE
}
})
}
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2020-11-18 06:41:27 -06:00
await wait(3000)
})
2019-03-05 03:58:44 -06:00
it('Should not list unlisted or private playlists', async function () {
2019-07-31 08:57:32 -05:00
for (const server of servers) {
const results = [
2022-12-09 04:14:47 -06:00
await server.playlists.listByAccount({ handle: 'root@' + servers[1].host, sort: '-createdAt' }),
2021-07-16 02:04:35 -05:00
await server.playlists.list({ start: 0, count: 2, sort: '-createdAt' })
2019-07-31 08:57:32 -05:00
]
2021-07-08 08:54:39 -05:00
expect(results[0].total).to.equal(2)
expect(results[1].total).to.equal(3)
2019-07-31 08:57:32 -05:00
2021-07-08 08:54:39 -05:00
for (const body of results) {
const data = body.data
2019-07-31 08:57:32 -05:00
expect(data).to.have.lengthOf(2)
2020-01-31 09:56:52 -06:00
expect(data[0].displayName).to.equal('playlist 3')
expect(data[1].displayName).to.equal('playlist 2')
2019-07-31 08:57:32 -05:00
}
}
})
it('Should not get unlisted playlist using only the id', async function () {
2021-07-16 02:04:35 -05:00
await servers[1].playlists.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 })
})
it('Should get unlisted plyaylist using uuid or shortUUID', async function () {
2021-07-16 02:04:35 -05:00
await servers[1].playlists.get({ playlistId: unlistedPlaylist.uuid })
await servers[1].playlists.get({ playlistId: unlistedPlaylist.shortUUID })
})
it('Should not get private playlist without token', async function () {
for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) {
2021-07-16 02:04:35 -05:00
await servers[1].playlists.get({ playlistId: id, expectedStatus: 401 })
}
})
it('Should get private playlist with a token', async function () {
for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) {
2021-07-16 02:04:35 -05:00
await servers[1].playlists.get({ token: servers[1].accessToken, playlistId: id })
}
})
2019-07-31 08:57:32 -05:00
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
describe('Update playlists', function () {
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should update a playlist', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
await servers[1].playlists.update({
2021-07-08 08:54:39 -05:00
attributes: {
2019-07-31 08:57:32 -05:00
displayName: 'playlist 3 updated',
description: 'description updated',
privacy: VideoPlaylistPrivacy.UNLISTED,
thumbnailfile: 'thumbnail.jpg',
2021-07-16 02:04:35 -05:00
videoChannelId: servers[1].store.channel.id
2019-07-31 08:57:32 -05:00
},
playlistId: playlistServer2Id2
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const playlist = await server.playlists.get({ playlistId: playlistServer2UUID2 })
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
expect(playlist.displayName).to.equal('playlist 3 updated')
expect(playlist.description).to.equal('description updated')
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.UNLISTED)
expect(playlist.privacy.label).to.equal('Unlisted')
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
expect(playlist.type.label).to.equal('Regular')
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
expect(playlist.videosLength).to.equal(2)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
expect(playlist.ownerAccount.name).to.equal('root')
expect(playlist.ownerAccount.displayName).to.equal('root')
expect(playlist.videoChannel.name).to.equal('root_channel')
expect(playlist.videoChannel.displayName).to.equal('Main root channel')
}
})
2019-02-26 03:55:40 -06:00
})
2019-07-31 08:57:32 -05:00
describe('Element timestamps', function () {
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const addVideo = (attributes: any) => {
return commands[0].addElement({ playlistId: playlistServer1Id, attributes })
2019-07-31 08:57:32 -05:00
}
2019-03-05 03:58:44 -06:00
const playlistDisplayName = 'playlist 4'
2021-07-08 08:54:39 -05:00
const playlist = await commands[0].create({
attributes: {
displayName: playlistDisplayName,
2019-07-31 08:57:32 -05:00
privacy: VideoPlaylistPrivacy.PUBLIC,
2021-07-16 02:04:35 -05:00
videoChannelId: servers[0].store.channel.id
2019-07-31 08:57:32 -05:00
}
})
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
playlistServer1Id = playlist.id
playlistServer1DisplayName = playlistDisplayName
2021-07-08 08:54:39 -05:00
playlistServer1UUID = playlist.uuid
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
await addVideo({ videoId: servers[0].store.videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 })
await addVideo({ videoId: servers[2].store.videos[1].uuid, startTimestamp: 35 })
await addVideo({ videoId: servers[2].store.videos[2].uuid })
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const element = await addVideo({ videoId: servers[0].store.videos[3].uuid, stopTimestamp: 35 })
2021-07-08 08:54:39 -05:00
playlistElementServer1Video4 = element.id
2019-07-31 08:57:32 -05:00
}
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const element = await addVideo({ videoId: servers[0].store.videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 })
2021-07-08 08:54:39 -05:00
playlistElementServer1Video5 = element.id
2019-07-31 08:57:32 -05:00
}
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-08 08:54:39 -05:00
const element = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 })
playlistElementNSFW = element.id
await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 4 })
await addVideo({ videoId: nsfwVideoServer1 })
2019-07-31 08:57:32 -05:00
}
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should correctly list playlist videos', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
for (const server of servers) {
2021-07-08 08:54:39 -05:00
{
2021-07-16 02:04:35 -05:00
const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(8)
const videoElements = body.data
expect(videoElements).to.have.lengthOf(8)
expect(videoElements[0].video.name).to.equal('video 0 server 1')
expect(videoElements[0].position).to.equal(1)
expect(videoElements[0].startTimestamp).to.equal(15)
expect(videoElements[0].stopTimestamp).to.equal(28)
expect(videoElements[1].video.name).to.equal('video 1 server 3')
expect(videoElements[1].position).to.equal(2)
expect(videoElements[1].startTimestamp).to.equal(35)
expect(videoElements[1].stopTimestamp).to.be.null
expect(videoElements[2].video.name).to.equal('video 2 server 3')
expect(videoElements[2].position).to.equal(3)
expect(videoElements[2].startTimestamp).to.be.null
expect(videoElements[2].stopTimestamp).to.be.null
expect(videoElements[3].video.name).to.equal('video 3 server 1')
expect(videoElements[3].position).to.equal(4)
expect(videoElements[3].startTimestamp).to.be.null
expect(videoElements[3].stopTimestamp).to.equal(35)
expect(videoElements[4].video.name).to.equal('video 4 server 1')
expect(videoElements[4].position).to.equal(5)
expect(videoElements[4].startTimestamp).to.equal(45)
expect(videoElements[4].stopTimestamp).to.equal(60)
expect(videoElements[5].video.name).to.equal('NSFW video')
expect(videoElements[5].position).to.equal(6)
expect(videoElements[5].startTimestamp).to.equal(5)
expect(videoElements[5].stopTimestamp).to.be.null
expect(videoElements[6].video.name).to.equal('NSFW video')
expect(videoElements[6].position).to.equal(7)
expect(videoElements[6].startTimestamp).to.equal(4)
expect(videoElements[6].stopTimestamp).to.be.null
expect(videoElements[7].video.name).to.equal('NSFW video')
expect(videoElements[7].position).to.equal(8)
expect(videoElements[7].startTimestamp).to.be.null
expect(videoElements[7].stopTimestamp).to.be.null
}
{
2021-07-16 02:04:35 -05:00
const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 })
2021-07-08 08:54:39 -05:00
expect(body.data).to.have.lengthOf(2)
}
2019-03-05 03:58:44 -06:00
}
})
2019-07-31 08:57:32 -05:00
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
describe('Element type', function () {
2021-07-16 02:47:51 -05:00
let groupUser1: PeerTubeServer[]
let groupWithoutToken1: PeerTubeServer[]
let group1: PeerTubeServer[]
let group2: PeerTubeServer[]
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
let video1: string
let video2: string
let video3: string
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
before(async function () {
this.timeout(60000)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
groupUser1 = [ Object.assign({}, servers[0], { accessToken: userTokenServer1 }) ]
2020-01-31 09:56:52 -06:00
groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ]
group1 = [ servers[0] ]
group2 = [ servers[1], servers[2] ]
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const playlist = await commands[0].create({
token: userTokenServer1,
attributes: {
2019-07-31 08:57:32 -05:00
displayName: 'playlist 56',
privacy: VideoPlaylistPrivacy.PUBLIC,
2021-07-16 02:04:35 -05:00
videoChannelId: servers[0].store.channel.id
2019-07-31 08:57:32 -05:00
}
})
2019-02-26 03:55:40 -06:00
2021-07-08 08:54:39 -05:00
const playlistServer1Id2 = playlist.id
playlistServer1UUID2 = playlist.uuid
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const addVideo = (attributes: any) => {
return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes })
2019-07-31 08:57:32 -05:00
}
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
video1 = (await servers[0].videos.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid
video2 = (await servers[1].videos.quickUpload({ name: 'video 90' })).uuid
video3 = (await servers[0].videos.quickUpload({ name: 'video 91', nsfw: true })).uuid
2019-03-05 03:58:44 -06:00
await waitJobs(servers)
2019-07-31 08:57:32 -05:00
await addVideo({ videoId: video1, startTimestamp: 15, stopTimestamp: 28 })
await addVideo({ videoId: video2, startTimestamp: 35 })
await addVideo({ videoId: video3 })
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should update the element type if the video is private', async function () {
this.timeout(20000)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
const name = 'video 89'
const position = 1
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3)
await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
}
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
// We deleted the video, so even if we recreated it, the old entry is still deleted
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
2019-03-05 03:58:44 -06:00
}
})
2019-07-31 08:57:32 -05:00
it('Should update the element type if the video is blacklisted', async function () {
this.timeout(20000)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
const name = 'video 89'
const position = 1
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
await servers[0].blacklist.add({ videoId: video1, reason: 'reason', unfederate: true })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
}
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
await servers[0].blacklist.remove({ videoId: video1 })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
// We deleted the video (because unfederated), so even if we recreated it, the old entry is still deleted
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
}
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should update the element type if the account or server of the video is blocked', async function () {
this.timeout(90000)
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
const command = servers[0].blocklist
2021-07-07 09:02:46 -05:00
2019-07-31 08:57:32 -05:00
const name = 'video 90'
const position = 2
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2022-12-09 04:14:47 -06:00
await command.addToMyBlocklist({ token: userTokenServer1, account: 'root@' + servers[1].host })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
2019-03-05 03:58:44 -06:00
2022-12-09 04:14:47 -06:00
await command.removeFromMyBlocklist({ token: userTokenServer1, account: 'root@' + servers[1].host })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
}
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2022-12-09 04:14:47 -06:00
await command.addToMyBlocklist({ token: userTokenServer1, server: servers[1].host })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
2019-03-05 03:58:44 -06:00
2022-12-09 04:14:47 -06:00
await command.removeFromMyBlocklist({ token: userTokenServer1, server: servers[1].host })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
}
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2022-12-09 04:14:47 -06:00
await command.addToServerBlocklist({ account: 'root@' + servers[1].host })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
2019-03-05 03:58:44 -06:00
2022-12-09 04:14:47 -06:00
await command.removeFromServerBlocklist({ account: 'root@' + servers[1].host })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
2019-03-05 03:58:44 -06:00
}
2019-07-31 08:57:32 -05:00
{
2022-12-09 04:14:47 -06:00
await command.addToServerBlocklist({ server: servers[1].host })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
2019-03-05 03:58:44 -06:00
2022-12-09 04:14:47 -06:00
await command.removeFromServerBlocklist({ server: servers[1].host })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
2019-03-05 03:58:44 -06:00
}
2019-07-31 08:57:32 -05:00
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should hide the video if it is NSFW', async function () {
2021-07-08 08:54:39 -05:00
const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } })
expect(body.total).to.equal(3)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const elements = body.data
2019-07-31 08:57:32 -05:00
const element = elements.find(e => e.position === 3)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
expect(element).to.exist
expect(element.video).to.be.null
expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE)
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
describe('Managing playlist elements', function () {
it('Should reorder the playlist', async function () {
this.timeout(30000)
{
2021-07-08 08:54:39 -05:00
await commands[0].reorderElements({
2019-07-31 08:57:32 -05:00
playlistId: playlistServer1Id,
2021-07-08 08:54:39 -05:00
attributes: {
2019-07-31 08:57:32 -05:00
startPosition: 2,
insertAfterPosition: 3
}
})
await waitJobs(servers)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
2021-07-08 08:54:39 -05:00
const names = body.data.map(v => v.video.name)
2019-07-31 08:57:32 -05:00
expect(names).to.deep.equal([
'video 0 server 1',
'video 2 server 3',
'video 1 server 3',
'video 3 server 1',
'video 4 server 1',
'NSFW video',
'NSFW video',
2019-07-31 08:57:32 -05:00
'NSFW video'
])
2019-03-05 03:58:44 -06:00
}
}
2019-07-31 08:57:32 -05:00
{
2021-07-08 08:54:39 -05:00
await commands[0].reorderElements({
2019-07-31 08:57:32 -05:00
playlistId: playlistServer1Id,
2021-07-08 08:54:39 -05:00
attributes: {
2019-07-31 08:57:32 -05:00
startPosition: 1,
reorderLength: 3,
insertAfterPosition: 4
}
})
await waitJobs(servers)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
2021-07-08 08:54:39 -05:00
const names = body.data.map(v => v.video.name)
2019-07-31 08:57:32 -05:00
expect(names).to.deep.equal([
'video 3 server 1',
'video 0 server 1',
'video 2 server 3',
'video 1 server 3',
'video 4 server 1',
'NSFW video',
'NSFW video',
2019-07-31 08:57:32 -05:00
'NSFW video'
])
}
2019-03-05 03:58:44 -06:00
}
2019-07-31 08:57:32 -05:00
{
2021-07-08 08:54:39 -05:00
await commands[0].reorderElements({
2019-07-31 08:57:32 -05:00
playlistId: playlistServer1Id,
2021-07-08 08:54:39 -05:00
attributes: {
2019-07-31 08:57:32 -05:00
startPosition: 6,
insertAfterPosition: 3
}
})
await waitJobs(servers)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
2019-07-31 08:57:32 -05:00
const names = elements.map(v => v.video.name)
expect(names).to.deep.equal([
'video 3 server 1',
'video 0 server 1',
'video 2 server 3',
'NSFW video',
'video 1 server 3',
'video 4 server 1',
'NSFW video',
'NSFW video'
2019-07-31 08:57:32 -05:00
])
for (let i = 1; i <= elements.length; i++) {
2020-01-31 09:56:52 -06:00
expect(elements[i - 1].position).to.equal(i)
2019-07-31 08:57:32 -05:00
}
}
2019-03-05 03:58:44 -06:00
}
})
2019-07-31 08:57:32 -05:00
it('Should update startTimestamp/endTimestamp of some elements', async function () {
this.timeout(30000)
2021-07-08 08:54:39 -05:00
await commands[0].updateElement({
2019-07-31 08:57:32 -05:00
playlistId: playlistServer1Id,
2021-07-08 08:54:39 -05:00
elementId: playlistElementServer1Video4,
attributes: {
2019-07-31 08:57:32 -05:00
startTimestamp: 1
}
})
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
await commands[0].updateElement({
2019-07-31 08:57:32 -05:00
playlistId: playlistServer1Id,
2021-07-08 08:54:39 -05:00
elementId: playlistElementServer1Video5,
attributes: {
2019-07-31 08:57:32 -05:00
stopTimestamp: null
}
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
2019-02-26 03:55:40 -06:00
2020-01-31 09:56:52 -06:00
expect(elements[0].video.name).to.equal('video 3 server 1')
expect(elements[0].position).to.equal(1)
expect(elements[0].startTimestamp).to.equal(1)
expect(elements[0].stopTimestamp).to.equal(35)
2019-03-13 10:03:03 -05:00
2020-01-31 09:56:52 -06:00
expect(elements[5].video.name).to.equal('video 4 server 1')
expect(elements[5].position).to.equal(6)
expect(elements[5].startTimestamp).to.equal(45)
expect(elements[5].stopTimestamp).to.be.null
2019-07-31 08:57:32 -05:00
}
})
2019-03-13 10:03:03 -05:00
2019-07-31 08:57:32 -05:00
it('Should check videos existence in my playlist', async function () {
const videoIds = [
2021-07-16 02:04:35 -05:00
servers[0].store.videos[0].id,
2019-07-31 08:57:32 -05:00
42000,
2021-07-16 02:04:35 -05:00
servers[0].store.videos[3].id,
2019-07-31 08:57:32 -05:00
43000,
2021-07-16 02:04:35 -05:00
servers[0].store.videos[4].id
2019-07-31 08:57:32 -05:00
]
2021-07-08 08:54:39 -05:00
const obj = await commands[0].videosExist({ videoIds })
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const elem = obj[servers[0].store.videos[0].id]
2019-07-31 08:57:32 -05:00
expect(elem).to.have.lengthOf(1)
2020-01-31 09:56:52 -06:00
expect(elem[0].playlistElementId).to.exist
expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName)
expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID))
2020-01-31 09:56:52 -06:00
expect(elem[0].playlistId).to.equal(playlistServer1Id)
expect(elem[0].startTimestamp).to.equal(15)
expect(elem[0].stopTimestamp).to.equal(28)
2019-07-31 08:57:32 -05:00
}
2019-03-13 10:03:03 -05:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const elem = obj[servers[0].store.videos[3].id]
2019-07-31 08:57:32 -05:00
expect(elem).to.have.lengthOf(1)
2020-01-31 09:56:52 -06:00
expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4)
expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName)
expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID))
2020-01-31 09:56:52 -06:00
expect(elem[0].playlistId).to.equal(playlistServer1Id)
expect(elem[0].startTimestamp).to.equal(1)
expect(elem[0].stopTimestamp).to.equal(35)
2019-07-31 08:57:32 -05:00
}
2019-03-13 10:03:03 -05:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const elem = obj[servers[0].store.videos[4].id]
2019-07-31 08:57:32 -05:00
expect(elem).to.have.lengthOf(1)
2020-01-31 09:56:52 -06:00
expect(elem[0].playlistId).to.equal(playlistServer1Id)
expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName)
expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID))
2020-01-31 09:56:52 -06:00
expect(elem[0].startTimestamp).to.equal(45)
expect(elem[0].stopTimestamp).to.equal(null)
2019-07-31 08:57:32 -05:00
}
2019-03-13 10:03:03 -05:00
2020-01-31 09:56:52 -06:00
expect(obj[42000]).to.have.lengthOf(0)
expect(obj[43000]).to.have.lengthOf(0)
2019-07-31 08:57:32 -05:00
})
2019-03-14 03:19:03 -05:00
2019-07-31 08:57:32 -05:00
it('Should automatically update updatedAt field of playlists', async function () {
2020-01-31 09:56:52 -06:00
const server = servers[1]
2021-07-16 02:04:35 -05:00
const videoId = servers[1].store.videos[5].id
2019-03-14 03:19:03 -05:00
2019-07-31 08:57:32 -05:00
async function getPlaylistNames () {
2021-07-16 02:04:35 -05:00
const { data } = await server.playlists.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' })
2019-03-14 03:19:03 -05:00
2021-07-08 08:54:39 -05:00
return data.map(p => p.displayName)
2019-07-31 08:57:32 -05:00
}
2019-03-14 03:19:03 -05:00
2021-07-08 08:54:39 -05:00
const attributes = { videoId }
2021-07-16 02:04:35 -05:00
const element1 = await server.playlists.addElement({ playlistId: playlistServer2Id1, attributes })
const element2 = await server.playlists.addElement({ playlistId: playlistServer2Id2, attributes })
2019-03-14 03:19:03 -05:00
2019-07-31 08:57:32 -05:00
const names1 = await getPlaylistNames()
2020-01-31 09:56:52 -06:00
expect(names1[0]).to.equal('playlist 3 updated')
expect(names1[1]).to.equal('playlist 2')
2019-03-14 03:19:03 -05:00
2021-07-16 02:04:35 -05:00
await server.playlists.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id })
2019-03-14 03:19:03 -05:00
2019-07-31 08:57:32 -05:00
const names2 = await getPlaylistNames()
2020-01-31 09:56:52 -06:00
expect(names2[0]).to.equal('playlist 2')
expect(names2[1]).to.equal('playlist 3 updated')
2019-03-14 03:19:03 -05:00
2021-07-16 02:04:35 -05:00
await server.playlists.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id })
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
const names3 = await getPlaylistNames()
2020-01-31 09:56:52 -06:00
expect(names3[0]).to.equal('playlist 3 updated')
expect(names3[1]).to.equal('playlist 2')
2019-03-05 03:58:44 -06:00
})
2019-07-31 08:57:32 -05:00
it('Should delete some elements', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementServer1Video4 })
await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementNSFW })
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(6)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const elements = body.data
expect(elements).to.have.lengthOf(6)
2019-03-05 03:58:44 -06:00
2020-01-31 09:56:52 -06:00
expect(elements[0].video.name).to.equal('video 0 server 1')
expect(elements[0].position).to.equal(1)
2019-03-05 03:58:44 -06:00
2020-01-31 09:56:52 -06:00
expect(elements[1].video.name).to.equal('video 2 server 3')
expect(elements[1].position).to.equal(2)
2019-02-26 03:55:40 -06:00
2020-01-31 09:56:52 -06:00
expect(elements[2].video.name).to.equal('video 1 server 3')
expect(elements[2].position).to.equal(3)
2020-01-31 09:56:52 -06:00
expect(elements[3].video.name).to.equal('video 4 server 1')
expect(elements[3].position).to.equal(4)
expect(elements[4].video.name).to.equal('NSFW video')
expect(elements[4].position).to.equal(5)
expect(elements[5].video.name).to.equal('NSFW video')
expect(elements[5].position).to.equal(6)
}
})
2019-07-31 08:57:32 -05:00
it('Should be able to create a public playlist, and set it to private', async function () {
this.timeout(30000)
2021-07-08 08:54:39 -05:00
const videoPlaylistIds = await commands[0].create({
attributes: {
2019-07-31 08:57:32 -05:00
displayName: 'my super public playlist',
privacy: VideoPlaylistPrivacy.PUBLIC,
2021-07-16 02:04:35 -05:00
videoChannelId: servers[0].store.channel.id
2019-07-31 08:57:32 -05:00
}
})
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-07-31 08:57:32 -05:00
for (const server of servers) {
2021-07-16 02:04:35 -05:00
await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 })
2019-07-31 08:57:32 -05:00
}
2021-07-08 08:54:39 -05:00
const attributes = { privacy: VideoPlaylistPrivacy.PRIVATE }
await commands[0].update({ playlistId: videoPlaylistIds.id, attributes })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2020-01-31 09:56:52 -06:00
for (const server of [ servers[1], servers[2] ]) {
2021-07-16 02:04:35 -05:00
await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
2019-07-31 08:57:32 -05:00
}
2019-02-26 03:55:40 -06:00
2021-07-08 08:54:39 -05:00
await commands[0].get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await commands[0].get({ token: servers[0].accessToken, playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 })
2019-07-31 08:57:32 -05:00
})
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
describe('Playlist deletion', function () {
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
this.timeout(30000)
2019-02-26 03:55:40 -06:00
2021-07-08 08:54:39 -05:00
await commands[0].delete({ playlistId: playlistServer1Id })
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
for (const server of servers) {
2021-07-16 02:04:35 -05:00
await server.playlists.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
2019-07-31 08:57:32 -05:00
}
})
2019-02-26 03:55:40 -06:00
2019-07-31 08:57:32 -05:00
it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
for (const server of servers) {
await checkPlaylistFilesWereRemoved(playlistServer1UUID, server)
2019-07-31 08:57:32 -05:00
}
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'my super playlist')
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const body = await servers[2].playlists.list({ start: 0, count: 5 })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(3)
expect(finder(body.data)).to.not.be.undefined
2019-07-31 08:57:32 -05:00
}
2019-02-26 03:55:40 -06:00
2021-07-16 02:04:35 -05:00
await servers[2].follows.unfollow({ target: servers[0] })
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2021-07-16 02:04:35 -05:00
const body = await servers[2].playlists.list({ start: 0, count: 5 })
2021-07-08 08:54:39 -05:00
expect(body.total).to.equal(1)
2019-02-26 03:55:40 -06:00
2021-07-08 08:54:39 -05:00
expect(finder(body.data)).to.be.undefined
2019-03-05 03:58:44 -06:00
}
})
2019-07-31 08:57:32 -05:00
it('Should delete a channel and put the associated playlist in private mode', async function () {
this.timeout(30000)
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
const channel = await servers[0].channels.create({ attributes: { name: 'super_channel', displayName: 'super channel' } })
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
const playlistCreated = await commands[0].create({
attributes: {
2019-07-31 08:57:32 -05:00
displayName: 'channel playlist',
privacy: VideoPlaylistPrivacy.PUBLIC,
2021-07-09 04:21:30 -05:00
videoChannelId: channel.id
2019-07-31 08:57:32 -05:00
}
})
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
await servers[0].channels.delete({ channelName: 'super_channel' })
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-02-26 03:55:40 -06:00
2021-07-08 08:54:39 -05:00
const body = await commands[0].get({ token: servers[0].accessToken, playlistId: playlistCreated.uuid })
expect(body.displayName).to.equal('channel playlist')
expect(body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
await servers[1].playlists.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
2019-04-15 03:49:46 -05:00
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
it('Should delete an account and delete its playlists', async function () {
this.timeout(30000)
2019-02-26 03:55:40 -06:00
2021-07-16 02:04:35 -05:00
const { userId, token } = await servers[0].users.generate('user_1')
2019-03-05 03:58:44 -06:00
2021-07-16 02:04:35 -05:00
const { videoChannels } = await servers[0].users.getMyInfo({ token })
2021-07-13 07:23:01 -05:00
const userChannel = videoChannels[0]
2019-03-05 03:58:44 -06:00
2021-07-08 08:54:39 -05:00
await commands[0].create({
attributes: {
2019-07-31 08:57:32 -05:00
displayName: 'playlist to be deleted',
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: userChannel.id
}
})
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2021-07-08 08:54:39 -05:00
const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'playlist to be deleted')
2019-07-31 08:57:32 -05:00
{
2020-01-31 09:56:52 -06:00
for (const server of [ servers[0], servers[1] ]) {
2021-07-16 02:04:35 -05:00
const body = await server.playlists.list({ start: 0, count: 15 })
2021-07-08 08:54:39 -05:00
expect(finder(body.data)).to.not.be.undefined
2019-07-31 08:57:32 -05:00
}
2019-03-05 03:58:44 -06:00
}
2021-07-16 02:04:35 -05:00
await servers[0].users.remove({ userId })
2019-07-31 08:57:32 -05:00
await waitJobs(servers)
2019-03-05 03:58:44 -06:00
2019-07-31 08:57:32 -05:00
{
2020-01-31 09:56:52 -06:00
for (const server of [ servers[0], servers[1] ]) {
2021-07-16 02:04:35 -05:00
const body = await server.playlists.list({ start: 0, count: 15 })
2021-07-08 08:54:39 -05:00
expect(finder(body.data)).to.be.undefined
2019-07-31 08:57:32 -05:00
}
2019-03-05 03:58:44 -06:00
}
2019-07-31 08:57:32 -05:00
})
2019-02-26 03:55:40 -06:00
})
2019-04-24 08:10:37 -05:00
after(async function () {
await cleanupTests(servers)
2019-02-26 03:55:40 -06:00
})
})