1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { wait } from '@shared/core-utils'
6 import { VideosOverview } from '@shared/models'
7 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
9 const expect = chai.expect
11 describe('Test a videos overview', function () {
12 let server: PeerTubeServer = null
14 function testOverviewCount (overview: VideosOverview, expected: number) {
15 expect(overview.tags).to.have.lengthOf(expected)
16 expect(overview.categories).to.have.lengthOf(expected)
17 expect(overview.channels).to.have.lengthOf(expected)
20 before(async function () {
23 server = await createSingleServer(1)
25 await setAccessTokensToServers([ server ])
28 it('Should send empty overview', async function () {
29 const body = await server.overviews.getVideos({ page: 1 })
31 testOverviewCount(body, 0)
34 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
39 await server.videos.upload({
43 tags: [ 'coucou1', 'coucou2' ]
47 const body = await server.overviews.getVideos({ page: 1 })
49 testOverviewCount(body, 0)
52 it('Should upload another video and include all videos in the overview', async function () {
56 for (let i = 1; i < 6; i++) {
57 await server.videos.upload({
61 tags: [ 'coucou1', 'coucou2' ]
70 const body = await server.overviews.getVideos({ page: 1 })
72 testOverviewCount(body, 1)
76 const overview = await server.overviews.getVideos({ page: 2 })
78 expect(overview.tags).to.have.lengthOf(1)
79 expect(overview.categories).to.have.lengthOf(0)
80 expect(overview.channels).to.have.lengthOf(0)
84 it('Should have the correct overview', async function () {
85 const overview1 = await server.overviews.getVideos({ page: 1 })
86 const overview2 = await server.overviews.getVideos({ page: 2 })
88 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
89 expect(arr).to.have.lengthOf(1)
93 expect(obj.videos).to.have.lengthOf(6)
94 expect(obj.videos[0].name).to.equal('video 5')
95 expect(obj.videos[1].name).to.equal('video 4')
96 expect(obj.videos[2].name).to.equal('video 3')
97 expect(obj.videos[3].name).to.equal('video 2')
98 expect(obj.videos[4].name).to.equal('video 1')
99 expect(obj.videos[5].name).to.equal('video 0')
102 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
103 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
104 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
106 expect(overview1.categories[0].category.id).to.equal(3)
108 expect(overview1.channels[0].channel.name).to.equal('root_channel')
111 it('Should hide muted accounts', async function () {
112 const token = await server.users.generateUserAndToken('choco')
114 await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host })
117 const body = await server.overviews.getVideos({ page: 1 })
119 testOverviewCount(body, 1)
123 const body = await server.overviews.getVideos({ page: 1, token })
125 testOverviewCount(body, 0)
129 after(async function () {
130 await cleanupTests([ server ])