1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, 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: ServerInfo = 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 flushAndRunServer(1)
24 await setAccessTokensToServers([ server ])
27 it('Should send empty overview', async function () {
28 const body = await server.overviewsCommand.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 uploadVideo(server.url, server.accessToken, {
41 tags: [ 'coucou1', 'coucou2' ]
44 const body = await server.overviewsCommand.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 uploadVideo(server.url, server.accessToken, {
57 tags: [ 'coucou1', 'coucou2' ]
65 const body = await server.overviewsCommand.getVideos({ page: 1 })
67 testOverviewCount(body, 1)
71 const overview = await server.overviewsCommand.getVideos({ page: 2 })
73 expect(overview.tags).to.have.lengthOf(1)
74 expect(overview.categories).to.have.lengthOf(0)
75 expect(overview.channels).to.have.lengthOf(0)
79 it('Should have the correct overview', async function () {
80 const overview1 = await server.overviewsCommand.getVideos({ page: 1 })
81 const overview2 = await server.overviewsCommand.getVideos({ page: 2 })
83 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
84 expect(arr).to.have.lengthOf(1)
88 expect(obj.videos).to.have.lengthOf(6)
89 expect(obj.videos[0].name).to.equal('video 5')
90 expect(obj.videos[1].name).to.equal('video 4')
91 expect(obj.videos[2].name).to.equal('video 3')
92 expect(obj.videos[3].name).to.equal('video 2')
93 expect(obj.videos[4].name).to.equal('video 1')
94 expect(obj.videos[5].name).to.equal('video 0')
97 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
98 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
99 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
101 expect(overview1.categories[0].category.id).to.equal(3)
103 expect(overview1.channels[0].channel.name).to.equal('root_channel')
106 it('Should hide muted accounts', async function () {
107 const token = await server.usersCommand.generateUserAndToken('choco')
109 await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host })
112 const body = await server.overviewsCommand.getVideos({ page: 1 })
114 testOverviewCount(body, 1)
118 const body = await server.overviewsCommand.getVideos({ page: 1, token })
120 testOverviewCount(body, 0)
124 after(async function () {
125 await cleanupTests([ server ])