2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
import 'mocha'
|
2020-06-16 09:52:05 -04:00
|
|
|
import * as chai from 'chai'
|
2021-04-08 05:23:45 -04:00
|
|
|
import { basename } from 'path'
|
2021-05-07 11:14:39 -04:00
|
|
|
import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
|
2018-06-29 05:29:23 -04:00
|
|
|
import {
|
2019-04-24 09:10:37 -04:00
|
|
|
cleanupTests,
|
2021-07-16 03:47:51 -04:00
|
|
|
createMultipleServers,
|
2021-07-16 08:27:30 -04:00
|
|
|
doubleFollow,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2021-07-13 08:23:01 -04:00
|
|
|
setAccessTokensToServers,
|
2021-05-07 11:14:39 -04:00
|
|
|
setDefaultVideoChannel,
|
2021-07-01 10:47:14 -04:00
|
|
|
testFileExistsOrNot,
|
2018-11-19 11:08:18 -05:00
|
|
|
testImage,
|
2021-07-13 08:23:01 -04:00
|
|
|
wait,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/extra-utils'
|
2021-07-15 04:02:54 -04:00
|
|
|
import { User, VideoChannel } from '@shared/models'
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
const expect = chai.expect
|
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
async function findChannel (server: PeerTubeServer, channelId: number) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await server.channels.list({ sort: '-name' })
|
2021-04-07 04:36:13 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
return body.data.find(c => c.id === channelId)
|
2021-04-07 04:36:13 -04:00
|
|
|
}
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
describe('Test video channels', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let servers: PeerTubeServer[]
|
2017-10-24 13:41:30 -04:00
|
|
|
let userInfo: User
|
2018-05-11 09:10:13 -04:00
|
|
|
let secondVideoChannelId: number
|
2021-05-07 11:14:39 -04:00
|
|
|
let totoChannel: number
|
2018-05-11 09:10:13 -04:00
|
|
|
let videoUUID: string
|
2021-05-07 11:14:39 -04:00
|
|
|
let accountName: string
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2021-07-01 10:47:14 -04:00
|
|
|
const avatarPaths: { [ port: number ]: string } = {}
|
|
|
|
const bannerPaths: { [ port: number ]: string } = {}
|
|
|
|
|
2017-10-24 13:41:30 -04:00
|
|
|
before(async function () {
|
2019-04-26 02:50:52 -04:00
|
|
|
this.timeout(60000)
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
servers = await createMultipleServers(2)
|
2018-02-15 08:46:26 -05:00
|
|
|
|
|
|
|
await setAccessTokensToServers(servers)
|
2021-05-07 11:14:39 -04:00
|
|
|
await setDefaultVideoChannel(servers)
|
2018-04-24 11:05:32 -04:00
|
|
|
|
2021-05-07 11:14:39 -04:00
|
|
|
await doubleFollow(servers[0], servers[1])
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have one video channel (created with root)', async () => {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.list({ start: 0, count: 2 })
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(1)
|
|
|
|
expect(body.data).to.be.an('array')
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
it('Should create another video channel', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2018-05-11 09:10:13 -04:00
|
|
|
{
|
|
|
|
const videoChannel = {
|
2018-08-17 09:45:42 -04:00
|
|
|
name: 'second_video_channel',
|
2018-05-11 09:10:13 -04:00
|
|
|
displayName: 'second video channel',
|
|
|
|
description: 'super video channel description',
|
|
|
|
support: 'super video channel support text'
|
|
|
|
}
|
2021-07-16 03:04:35 -04:00
|
|
|
const created = await servers[0].channels.create({ attributes: videoChannel })
|
2021-07-09 05:21:30 -04:00
|
|
|
secondVideoChannelId = created.id
|
2017-10-24 13:41:30 -04:00
|
|
|
}
|
2018-02-15 08:46:26 -05:00
|
|
|
|
|
|
|
// The channel is 1 is propagated to servers 2
|
2018-05-11 09:10:13 -04:00
|
|
|
{
|
2021-07-15 04:02:54 -04:00
|
|
|
const attributes = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
|
2021-07-16 03:04:35 -04:00
|
|
|
const { uuid } = await servers[0].videos.upload({ attributes })
|
2021-07-15 04:02:54 -04:00
|
|
|
videoUUID = uuid
|
2018-05-11 09:10:13 -04:00
|
|
|
}
|
2018-02-15 08:46:26 -05:00
|
|
|
|
2018-06-13 04:06:50 -04:00
|
|
|
await waitJobs(servers)
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have two video channels when getting my information', async () => {
|
2021-07-16 03:04:35 -04:00
|
|
|
userInfo = await servers[0].users.getMyInfo()
|
2017-10-24 13:41:30 -04:00
|
|
|
|
|
|
|
expect(userInfo.videoChannels).to.be.an('array')
|
|
|
|
expect(userInfo.videoChannels).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const videoChannels = userInfo.videoChannels
|
2018-08-17 09:45:42 -04:00
|
|
|
expect(videoChannels[0].name).to.equal('root_channel')
|
|
|
|
expect(videoChannels[0].displayName).to.equal('Main root channel')
|
|
|
|
|
|
|
|
expect(videoChannels[1].name).to.equal('second_video_channel')
|
2018-01-11 05:40:18 -05:00
|
|
|
expect(videoChannels[1].displayName).to.equal('second video channel')
|
2017-10-24 13:41:30 -04:00
|
|
|
expect(videoChannels[1].description).to.equal('super video channel description')
|
2018-02-15 08:46:26 -05:00
|
|
|
expect(videoChannels[1].support).to.equal('super video channel support text')
|
2021-05-07 11:14:39 -04:00
|
|
|
|
|
|
|
accountName = userInfo.account.name + '@' + userInfo.account.host
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
it('Should have two video channels when getting account channels on server 1', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.listByAccount({ accountName })
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(2)
|
2019-05-29 09:09:38 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
const videoChannels = body.data
|
|
|
|
|
|
|
|
expect(videoChannels).to.be.an('array')
|
|
|
|
expect(videoChannels).to.have.lengthOf(2)
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2018-08-17 09:45:42 -04:00
|
|
|
expect(videoChannels[0].name).to.equal('root_channel')
|
|
|
|
expect(videoChannels[0].displayName).to.equal('Main root channel')
|
|
|
|
|
|
|
|
expect(videoChannels[1].name).to.equal('second_video_channel')
|
2018-01-11 05:40:18 -05:00
|
|
|
expect(videoChannels[1].displayName).to.equal('second video channel')
|
2017-10-24 13:41:30 -04:00
|
|
|
expect(videoChannels[1].description).to.equal('super video channel description')
|
2018-02-15 08:46:26 -05:00
|
|
|
expect(videoChannels[1].support).to.equal('super video channel support text')
|
|
|
|
})
|
|
|
|
|
2019-05-29 09:09:38 -04:00
|
|
|
it('Should paginate and sort account channels', async function () {
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.listByAccount({
|
2021-05-07 11:14:39 -04:00
|
|
|
accountName,
|
2019-05-29 09:09:38 -04:00
|
|
|
start: 0,
|
|
|
|
count: 1,
|
|
|
|
sort: 'createdAt'
|
|
|
|
})
|
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(2)
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
2019-05-29 09:09:38 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
const videoChannel: VideoChannel = body.data[0]
|
2019-05-29 09:09:38 -04:00
|
|
|
expect(videoChannel.name).to.equal('root_channel')
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.listByAccount({
|
2021-05-07 11:14:39 -04:00
|
|
|
accountName,
|
2019-05-29 09:09:38 -04:00
|
|
|
start: 0,
|
|
|
|
count: 1,
|
|
|
|
sort: '-createdAt'
|
|
|
|
})
|
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(2)
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
|
|
|
expect(body.data[0].name).to.equal('second_video_channel')
|
2019-05-29 09:09:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.listByAccount({
|
2021-05-07 11:14:39 -04:00
|
|
|
accountName,
|
2019-05-29 09:09:38 -04:00
|
|
|
start: 1,
|
|
|
|
count: 1,
|
|
|
|
sort: '-createdAt'
|
|
|
|
})
|
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(2)
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
|
|
|
expect(body.data[0].name).to.equal('root_channel')
|
2019-05-29 09:09:38 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
it('Should have one video channel when getting account channels on server 2', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[1].channels.listByAccount({ accountName })
|
2019-05-29 09:09:38 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(1)
|
|
|
|
expect(body.data).to.be.an('array')
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
const videoChannel = body.data[0]
|
|
|
|
expect(videoChannel.name).to.equal('second_video_channel')
|
|
|
|
expect(videoChannel.displayName).to.equal('second video channel')
|
|
|
|
expect(videoChannel.description).to.equal('super video channel description')
|
|
|
|
expect(videoChannel.support).to.equal('super video channel support text')
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
it('Should list video channels', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.list({ start: 1, count: 1, sort: '-name' })
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(2)
|
|
|
|
expect(body.data).to.be.an('array')
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
|
|
|
expect(body.data[0].name).to.equal('root_channel')
|
|
|
|
expect(body.data[0].displayName).to.equal('Main root channel')
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
it('Should update video channel', async function () {
|
2019-05-31 10:30:11 -04:00
|
|
|
this.timeout(15000)
|
2018-02-15 08:46:26 -05:00
|
|
|
|
2017-10-24 13:41:30 -04:00
|
|
|
const videoChannelAttributes = {
|
2018-04-26 10:11:38 -04:00
|
|
|
displayName: 'video channel updated',
|
2018-02-15 08:46:26 -05:00
|
|
|
description: 'video channel description updated',
|
2019-05-31 10:30:11 -04:00
|
|
|
support: 'support updated'
|
2017-10-24 13:41:30 -04:00
|
|
|
}
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].channels.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes })
|
2018-02-15 08:46:26 -05:00
|
|
|
|
2018-06-13 04:06:50 -04:00
|
|
|
await waitJobs(servers)
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
it('Should have video channel updated', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await server.channels.list({ start: 0, count: 1, sort: '-name' })
|
2021-07-09 05:21:30 -04:00
|
|
|
|
|
|
|
expect(body.total).to.equal(2)
|
|
|
|
expect(body.data).to.be.an('array')
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
|
|
|
|
|
|
|
expect(body.data[0].name).to.equal('second_video_channel')
|
|
|
|
expect(body.data[0].displayName).to.equal('video channel updated')
|
|
|
|
expect(body.data[0].description).to.equal('video channel description updated')
|
|
|
|
expect(body.data[0].support).to.equal('support updated')
|
2019-05-31 10:30:11 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have updated the video support field', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const video = await server.videos.get({ id: videoUUID })
|
2019-05-31 10:30:11 -04:00
|
|
|
expect(video.support).to.equal('video support field')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should update the channel support field and update videos too', async function () {
|
|
|
|
this.timeout(35000)
|
|
|
|
|
|
|
|
const videoChannelAttributes = {
|
|
|
|
support: 'video channel support text updated',
|
|
|
|
bulkVideosSupportUpdate: true
|
|
|
|
}
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].channels.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes })
|
2019-05-31 10:30:11 -04:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const video = await server.videos.get({ id: videoUUID })
|
2019-05-31 10:30:11 -04:00
|
|
|
expect(video.support).to.equal(videoChannelAttributes.support)
|
2018-02-15 08:46:26 -05:00
|
|
|
}
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2018-06-29 05:29:23 -04:00
|
|
|
it('Should update video channel avatar', async function () {
|
2021-04-07 04:36:13 -04:00
|
|
|
this.timeout(15000)
|
2018-06-29 05:29:23 -04:00
|
|
|
|
|
|
|
const fixture = 'avatar.png'
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].channels.updateImage({
|
2021-07-09 05:21:30 -04:00
|
|
|
channelName: 'second_video_channel',
|
2021-04-07 04:36:13 -04:00
|
|
|
fixture,
|
|
|
|
type: 'avatar'
|
2018-06-29 05:29:23 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
2021-04-07 04:36:13 -04:00
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoChannel = await findChannel(server, secondVideoChannelId)
|
|
|
|
|
2021-07-01 10:47:14 -04:00
|
|
|
avatarPaths[server.port] = videoChannel.avatar.path
|
|
|
|
await testImage(server.url, 'avatar-resized', avatarPaths[server.port], '.png')
|
|
|
|
await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true)
|
2021-04-08 05:23:45 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const row = await server.sql.getActorImage(basename(avatarPaths[server.port]))
|
2021-04-08 05:23:45 -04:00
|
|
|
expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height)
|
|
|
|
expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width)
|
2021-04-07 04:36:13 -04:00
|
|
|
}
|
2018-06-29 05:29:23 -04:00
|
|
|
})
|
|
|
|
|
2021-04-07 04:36:13 -04:00
|
|
|
it('Should update video channel banner', async function () {
|
|
|
|
this.timeout(15000)
|
|
|
|
|
|
|
|
const fixture = 'banner.jpg'
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].channels.updateImage({
|
2021-07-09 05:21:30 -04:00
|
|
|
channelName: 'second_video_channel',
|
2021-04-07 04:36:13 -04:00
|
|
|
fixture,
|
|
|
|
type: 'banner'
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2018-06-29 05:29:23 -04:00
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const videoChannel = await server.channels.get({ channelName: 'second_video_channel@' + servers[0].host })
|
2018-06-29 05:29:23 -04:00
|
|
|
|
2021-07-01 10:47:14 -04:00
|
|
|
bannerPaths[server.port] = videoChannel.banner.path
|
|
|
|
await testImage(server.url, 'banner-resized', bannerPaths[server.port])
|
|
|
|
await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true)
|
2021-04-08 05:23:45 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const row = await server.sql.getActorImage(basename(bannerPaths[server.port]))
|
2021-04-08 05:23:45 -04:00
|
|
|
expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height)
|
|
|
|
expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width)
|
2021-04-07 04:36:13 -04:00
|
|
|
}
|
|
|
|
})
|
2018-06-29 05:29:23 -04:00
|
|
|
|
2021-04-07 04:36:13 -04:00
|
|
|
it('Should delete the video channel avatar', async function () {
|
|
|
|
this.timeout(15000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].channels.deleteImage({ channelName: 'second_video_channel', type: 'avatar' })
|
2021-04-07 04:36:13 -04:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoChannel = await findChannel(server, secondVideoChannelId)
|
2021-07-01 10:47:14 -04:00
|
|
|
await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), false)
|
2021-04-07 04:36:13 -04:00
|
|
|
|
|
|
|
expect(videoChannel.avatar).to.be.null
|
2018-06-29 05:29:23 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-04-07 04:36:13 -04:00
|
|
|
it('Should delete the video channel banner', async function () {
|
|
|
|
this.timeout(15000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].channels.deleteImage({ channelName: 'second_video_channel', type: 'banner' })
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2021-04-07 04:36:13 -04:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoChannel = await findChannel(server, secondVideoChannelId)
|
2021-07-01 10:47:14 -04:00
|
|
|
await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), false)
|
2021-04-07 04:36:13 -04:00
|
|
|
|
|
|
|
expect(videoChannel.banner).to.be.null
|
|
|
|
}
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2018-05-11 09:10:13 -04:00
|
|
|
it('Should list the second video channel videos', async function () {
|
2018-04-25 04:21:38 -04:00
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2019-04-26 02:50:52 -04:00
|
|
|
const channelURI = 'second_video_channel@localhost:' + servers[0].port
|
2021-07-16 04:42:24 -04:00
|
|
|
const { total, data } = await server.videos.listByChannel({ handle: channelURI })
|
2021-07-15 04:02:54 -04:00
|
|
|
|
|
|
|
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')
|
2018-05-11 09:10:13 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should change the video channel of a video', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].videos.update({ id: videoUUID, attributes: { channelId: servers[0].store.channel.id } })
|
2018-05-11 09:10:13 -04:00
|
|
|
|
2018-06-13 04:06:50 -04:00
|
|
|
await waitJobs(servers)
|
2018-05-11 09:10:13 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the first video channel videos', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-15 04:02:54 -04:00
|
|
|
{
|
|
|
|
const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
|
2021-07-16 04:42:24 -04:00
|
|
|
const { total } = await server.videos.listByChannel({ handle: secondChannelURI })
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const channelURI = 'root_channel@localhost:' + servers[0].port
|
2021-07-16 04:42:24 -04:00
|
|
|
const { total, data } = await server.videos.listByChannel({ handle: channelURI })
|
2021-07-15 04:02:54 -04:00
|
|
|
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')
|
|
|
|
}
|
2018-04-25 04:21:38 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
it('Should delete video channel', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].channels.delete({ channelName: 'second_video_channel' })
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2018-02-15 08:46:26 -05:00
|
|
|
it('Should have video channel deleted', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.list({ start: 0, count: 10 })
|
2017-10-24 13:41:30 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(1)
|
|
|
|
expect(body.data).to.be.an('array')
|
|
|
|
expect(body.data).to.have.lengthOf(1)
|
|
|
|
expect(body.data[0].displayName).to.equal('Main root channel')
|
2018-08-17 09:45:42 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should create the main channel with an uuid if there is a conflict', async function () {
|
|
|
|
{
|
|
|
|
const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
|
2021-07-16 03:04:35 -04:00
|
|
|
const created = await servers[0].channels.create({ attributes: videoChannel })
|
2021-07-09 05:21:30 -04:00
|
|
|
totoChannel = created.id
|
2018-08-17 09:45:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].users.create({ username: 'toto', password: 'password' })
|
|
|
|
const accessToken = await servers[0].login.getAccessToken({ username: 'toto', password: 'password' })
|
2018-08-17 09:45:42 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const { videoChannels } = await servers[0].users.getMyInfo({ token: accessToken })
|
2021-07-13 08:23:01 -04:00
|
|
|
const videoChannel = videoChannels[0]
|
2018-08-17 09:45:42 -04:00
|
|
|
expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)
|
|
|
|
}
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
|
2020-06-16 08:13:01 -04:00
|
|
|
it('Should report correct channel views per days', async function () {
|
2020-06-12 10:01:42 -04:00
|
|
|
this.timeout(10000)
|
2020-03-27 17:26:39 -04:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true })
|
2020-06-16 08:13:01 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
for (const channel of data) {
|
2020-03-27 17:26:39 -04:00
|
|
|
expect(channel).to.haveOwnProperty('viewsPerDay')
|
|
|
|
expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
|
2020-06-16 08:13:01 -04:00
|
|
|
|
|
|
|
for (const v of channel.viewsPerDay) {
|
2020-03-27 17:26:39 -04:00
|
|
|
expect(v.date).to.be.an('string')
|
|
|
|
expect(v.views).to.equal(0)
|
2020-06-16 08:13:01 -04:00
|
|
|
}
|
|
|
|
}
|
2020-03-27 17:26:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
// video has been posted on channel servers[0].store.videoChannel.id since last update
|
|
|
|
await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' })
|
|
|
|
await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' })
|
2020-03-27 17:26:39 -04:00
|
|
|
|
|
|
|
// Wait the repeatable job
|
|
|
|
await wait(8000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true })
|
|
|
|
const channelWithView = data.find(channel => channel.id === servers[0].store.channel.id)
|
2020-03-27 17:26:39 -04:00
|
|
|
expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-06-16 08:13:01 -04:00
|
|
|
it('Should report correct videos count', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true })
|
2020-06-16 08:13:01 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
const totoChannel = data.find(c => c.name === 'toto_channel')
|
|
|
|
const rootChannel = data.find(c => c.name === 'root_channel')
|
2020-06-16 08:13:01 -04:00
|
|
|
|
|
|
|
expect(rootChannel.videosCount).to.equal(1)
|
|
|
|
expect(totoChannel.videosCount).to.equal(0)
|
|
|
|
})
|
|
|
|
|
2020-07-27 11:00:39 -04:00
|
|
|
it('Should search among account video channels', async function () {
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.listByAccount({ accountName, search: 'root' })
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(1)
|
2020-07-27 11:00:39 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
const channels = body.data
|
2020-07-27 11:00:39 -04:00
|
|
|
expect(channels).to.have.lengthOf(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].channels.listByAccount({ accountName, search: 'does not exist' })
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(body.total).to.equal(0)
|
2020-07-27 11:00:39 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
const channels = body.data
|
2020-07-27 11:00:39 -04:00
|
|
|
expect(channels).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-05-07 11:14:39 -04:00
|
|
|
it('Should list channels by updatedAt desc if a video has been uploaded', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].videos.upload({ attributes: { channelId: totoChannel } })
|
2021-05-07 11:14:39 -04:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await server.channels.listByAccount({ accountName, sort: '-updatedAt' })
|
2021-05-07 11:14:39 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(data[0].name).to.equal('toto_channel')
|
|
|
|
expect(data[1].name).to.equal('root_channel')
|
2021-05-07 11:14:39 -04:00
|
|
|
}
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].videos.upload({ attributes: { channelId: servers[0].store.channel.id } })
|
2021-05-07 11:14:39 -04:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await server.channels.listByAccount({ accountName, sort: '-updatedAt' })
|
2021-05-07 11:14:39 -04:00
|
|
|
|
2021-07-09 05:21:30 -04:00
|
|
|
expect(data[0].name).to.equal('root_channel')
|
|
|
|
expect(data[1].name).to.equal('toto_channel')
|
2021-05-07 11:14:39 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2017-10-24 13:41:30 -04:00
|
|
|
})
|
|
|
|
})
|