2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-08-30 08:58:00 -04:00
|
|
|
|
|
|
|
import 'mocha'
|
2020-11-10 05:06:36 -05:00
|
|
|
import * as chai from 'chai'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { wait } from '@shared/core-utils'
|
2021-07-06 08:30:20 -04:00
|
|
|
import { VideosOverview } from '@shared/models'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
|
2018-08-30 08:58:00 -04:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test a videos overview', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let server: PeerTubeServer = null
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2021-07-06 08:30:20 -04:00
|
|
|
function testOverviewCount (overview: VideosOverview, expected: number) {
|
2020-11-10 05:06:36 -05:00
|
|
|
expect(overview.tags).to.have.lengthOf(expected)
|
|
|
|
expect(overview.categories).to.have.lengthOf(expected)
|
|
|
|
expect(overview.channels).to.have.lengthOf(expected)
|
|
|
|
}
|
|
|
|
|
2018-08-30 08:58:00 -04:00
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
server = await createSingleServer(1)
|
2018-08-30 08:58:00 -04:00
|
|
|
|
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send empty overview', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await server.overviews.getVideos({ page: 1 })
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2021-07-06 08:30:20 -04:00
|
|
|
testOverviewCount(body, 0)
|
2018-08-30 08:58:00 -04:00
|
|
|
})
|
|
|
|
|
2018-08-31 11:18:13 -04:00
|
|
|
it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
|
2021-07-12 04:03:46 -04:00
|
|
|
this.timeout(30000)
|
2018-08-31 11:18:13 -04:00
|
|
|
|
2020-03-11 09:39:28 -04:00
|
|
|
await wait(3000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.videos.upload({
|
2021-07-15 04:02:54 -04:00
|
|
|
attributes: {
|
|
|
|
name: 'video 0',
|
|
|
|
category: 3,
|
|
|
|
tags: [ 'coucou1', 'coucou2' ]
|
|
|
|
}
|
2020-03-11 09:39:28 -04:00
|
|
|
})
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await server.overviews.getVideos({ page: 1 })
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2021-07-06 08:30:20 -04:00
|
|
|
testOverviewCount(body, 0)
|
2018-08-30 08:58:00 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload another video and include all videos in the overview', async function () {
|
2021-07-12 09:34:03 -04:00
|
|
|
this.timeout(30000)
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2021-07-06 08:30:20 -04:00
|
|
|
{
|
|
|
|
for (let i = 1; i < 6; i++) {
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.videos.upload({
|
2021-07-15 04:02:54 -04:00
|
|
|
attributes: {
|
|
|
|
name: 'video ' + i,
|
|
|
|
category: 3,
|
|
|
|
tags: [ 'coucou1', 'coucou2' ]
|
|
|
|
}
|
2021-07-06 08:30:20 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
await wait(3000)
|
2020-03-11 09:39:28 -04:00
|
|
|
}
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2020-03-11 09:39:28 -04:00
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await server.overviews.getVideos({ page: 1 })
|
2020-03-11 09:39:28 -04:00
|
|
|
|
2021-07-06 08:30:20 -04:00
|
|
|
testOverviewCount(body, 1)
|
2020-03-11 09:39:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const overview = await server.overviews.getVideos({ page: 2 })
|
2020-03-11 09:39:28 -04:00
|
|
|
|
|
|
|
expect(overview.tags).to.have.lengthOf(1)
|
|
|
|
expect(overview.categories).to.have.lengthOf(0)
|
|
|
|
expect(overview.channels).to.have.lengthOf(0)
|
|
|
|
}
|
2018-08-30 08:58:00 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have the correct overview', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const overview1 = await server.overviews.getVideos({ page: 1 })
|
|
|
|
const overview2 = await server.overviews.getVideos({ page: 2 })
|
2020-03-11 09:39:28 -04:00
|
|
|
|
2021-07-06 08:30:20 -04:00
|
|
|
for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
|
2020-03-11 09:39:28 -04:00
|
|
|
expect(arr).to.have.lengthOf(1)
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2020-03-11 09:39:28 -04:00
|
|
|
const obj = arr[0]
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2018-08-31 11:18:13 -04:00
|
|
|
expect(obj.videos).to.have.lengthOf(6)
|
|
|
|
expect(obj.videos[0].name).to.equal('video 5')
|
|
|
|
expect(obj.videos[1].name).to.equal('video 4')
|
|
|
|
expect(obj.videos[2].name).to.equal('video 3')
|
|
|
|
expect(obj.videos[3].name).to.equal('video 2')
|
|
|
|
expect(obj.videos[4].name).to.equal('video 1')
|
|
|
|
expect(obj.videos[5].name).to.equal('video 0')
|
2018-08-30 08:58:00 -04:00
|
|
|
}
|
|
|
|
|
2020-03-11 09:39:28 -04:00
|
|
|
const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
|
|
|
|
expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
|
|
|
|
expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2020-03-11 09:39:28 -04:00
|
|
|
expect(overview1.categories[0].category.id).to.equal(3)
|
2018-08-30 08:58:00 -04:00
|
|
|
|
2020-03-11 09:39:28 -04:00
|
|
|
expect(overview1.channels[0].channel.name).to.equal('root_channel')
|
2018-08-30 08:58:00 -04:00
|
|
|
})
|
|
|
|
|
2020-11-10 05:06:36 -05:00
|
|
|
it('Should hide muted accounts', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const token = await server.users.generateUserAndToken('choco')
|
2020-11-10 05:06:36 -05:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host })
|
2020-11-10 05:06:36 -05:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await server.overviews.getVideos({ page: 1 })
|
2020-11-10 05:06:36 -05:00
|
|
|
|
2021-07-06 08:30:20 -04:00
|
|
|
testOverviewCount(body, 1)
|
2020-11-10 05:06:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await server.overviews.getVideos({ page: 1, token })
|
2020-11-10 05:06:36 -05:00
|
|
|
|
2021-07-06 08:30:20 -04:00
|
|
|
testOverviewCount(body, 0)
|
2020-11-10 05:06:36 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
2018-08-30 08:58:00 -04:00
|
|
|
})
|
|
|
|
})
|