1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils'
6 import { VideosOverview } from '@shared/models'
8 const expect = chai.expect
10 describe('Test a videos overview', function () {
11 let server: PeerTubeServer = null
13 function testOverviewCount (overview: VideosOverview, expected: number) {
14 expect(overview.tags).to.have.lengthOf(expected)
15 expect(overview.categories).to.have.lengthOf(expected)
16 expect(overview.channels).to.have.lengthOf(expected)
19 before(async function () {
22 server = await createSingleServer(1)
24 await setAccessTokensToServers([ server ])
27 it('Should send empty overview', async function () {
28 const body = await server.overviews.getVideos({ page: 1 })
30 testOverviewCount(body, 0)
33 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
38 await server.videos.upload({
42 tags: [ 'coucou1', 'coucou2' ]
46 const body = await server.overviews.getVideos({ page: 1 })
48 testOverviewCount(body, 0)
51 it('Should upload another video and include all videos in the overview', async function () {
55 for (let i = 1; i < 6; i++) {
56 await server.videos.upload({
60 tags: [ 'coucou1', 'coucou2' ]
69 const body = await server.overviews.getVideos({ page: 1 })
71 testOverviewCount(body, 1)
75 const overview = await server.overviews.getVideos({ page: 2 })
77 expect(overview.tags).to.have.lengthOf(1)
78 expect(overview.categories).to.have.lengthOf(0)
79 expect(overview.channels).to.have.lengthOf(0)
83 it('Should have the correct overview', async function () {
84 const overview1 = await server.overviews.getVideos({ page: 1 })
85 const overview2 = await server.overviews.getVideos({ page: 2 })
87 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
88 expect(arr).to.have.lengthOf(1)
92 expect(obj.videos).to.have.lengthOf(6)
93 expect(obj.videos[0].name).to.equal('video 5')
94 expect(obj.videos[1].name).to.equal('video 4')
95 expect(obj.videos[2].name).to.equal('video 3')
96 expect(obj.videos[3].name).to.equal('video 2')
97 expect(obj.videos[4].name).to.equal('video 1')
98 expect(obj.videos[5].name).to.equal('video 0')
101 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
102 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
103 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
105 expect(overview1.categories[0].category.id).to.equal(3)
107 expect(overview1.channels[0].channel.name).to.equal('root_channel')
110 it('Should hide muted accounts', async function () {
111 const token = await server.users.generateUserAndToken('choco')
113 await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host })
116 const body = await server.overviews.getVideos({ page: 1 })
118 testOverviewCount(body, 1)
122 const body = await server.overviews.getVideos({ page: 1, token })
124 testOverviewCount(body, 0)
128 after(async function () {
129 await cleanupTests([ server ])