1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { VideosOverview } from '@shared/models'
6 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
8 describe('Test a videos overview', function () {
9 let server: PeerTubeServer = null
11 function testOverviewCount (overview: VideosOverview, expected: number) {
12 expect(overview.tags).to.have.lengthOf(expected)
13 expect(overview.categories).to.have.lengthOf(expected)
14 expect(overview.channels).to.have.lengthOf(expected)
17 before(async function () {
20 server = await createSingleServer(1)
22 await setAccessTokensToServers([ server ])
25 it('Should send empty overview', async function () {
26 const body = await server.overviews.getVideos({ page: 1 })
28 testOverviewCount(body, 0)
31 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
36 await server.videos.upload({
40 tags: [ 'coucou1', 'coucou2' ]
44 const body = await server.overviews.getVideos({ page: 1 })
46 testOverviewCount(body, 0)
49 it('Should upload another video and include all videos in the overview', async function () {
53 for (let i = 1; i < 6; i++) {
54 await server.videos.upload({
58 tags: [ 'coucou1', 'coucou2' ]
67 const body = await server.overviews.getVideos({ page: 1 })
69 testOverviewCount(body, 1)
73 const overview = await server.overviews.getVideos({ page: 2 })
75 expect(overview.tags).to.have.lengthOf(1)
76 expect(overview.categories).to.have.lengthOf(0)
77 expect(overview.channels).to.have.lengthOf(0)
81 it('Should have the correct overview', async function () {
82 const overview1 = await server.overviews.getVideos({ page: 1 })
83 const overview2 = await server.overviews.getVideos({ page: 2 })
85 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
86 expect(arr).to.have.lengthOf(1)
90 expect(obj.videos).to.have.lengthOf(6)
91 expect(obj.videos[0].name).to.equal('video 5')
92 expect(obj.videos[1].name).to.equal('video 4')
93 expect(obj.videos[2].name).to.equal('video 3')
94 expect(obj.videos[3].name).to.equal('video 2')
95 expect(obj.videos[4].name).to.equal('video 1')
96 expect(obj.videos[5].name).to.equal('video 0')
99 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
100 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
101 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
103 expect(overview1.categories[0].category.id).to.equal(3)
105 expect(overview1.channels[0].channel.name).to.equal('root_channel')
108 it('Should hide muted accounts', async function () {
109 const token = await server.users.generateUserAndToken('choco')
111 await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host })
114 const body = await server.overviews.getVideos({ page: 1 })
116 testOverviewCount(body, 1)
120 const body = await server.overviews.getVideos({ page: 1, token })
122 testOverviewCount(body, 0)
126 after(async function () {
127 await cleanupTests([ server ])