1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 generateUserAccessToken,
11 setAccessTokensToServers,
14 } from '../../../../shared/extra-utils'
15 import { getVideosOverview, getVideosOverviewWithToken } from '../../../../shared/extra-utils/overviews/overviews'
16 import { VideosOverview } from '../../../../shared/models/overviews'
17 import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist'
18 import { Response } from 'superagent'
20 const expect = chai.expect
22 describe('Test a videos overview', function () {
23 let server: ServerInfo = null
25 function testOverviewCount (res: Response, expected: number) {
26 const overview: VideosOverview = res.body
28 expect(overview.tags).to.have.lengthOf(expected)
29 expect(overview.categories).to.have.lengthOf(expected)
30 expect(overview.channels).to.have.lengthOf(expected)
33 before(async function () {
36 server = await flushAndRunServer(1)
38 await setAccessTokensToServers([ server ])
41 it('Should send empty overview', async function () {
42 const res = await getVideosOverview(server.url, 1)
44 testOverviewCount(res, 0)
47 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
52 await uploadVideo(server.url, server.accessToken, {
55 tags: [ 'coucou1', 'coucou2' ]
58 const res = await getVideosOverview(server.url, 1)
60 testOverviewCount(res, 0)
63 it('Should upload another video and include all videos in the overview', async function () {
66 for (let i = 1; i < 6; i++) {
67 await uploadVideo(server.url, server.accessToken, {
70 tags: [ 'coucou1', 'coucou2' ]
77 const res = await getVideosOverview(server.url, 1)
79 testOverviewCount(res, 1)
83 const res = await getVideosOverview(server.url, 2)
85 const overview: VideosOverview = res.body
86 expect(overview.tags).to.have.lengthOf(1)
87 expect(overview.categories).to.have.lengthOf(0)
88 expect(overview.channels).to.have.lengthOf(0)
92 it('Should have the correct overview', async function () {
93 const res1 = await getVideosOverview(server.url, 1)
94 const res2 = await getVideosOverview(server.url, 2)
96 const overview1: VideosOverview = res1.body
97 const overview2: VideosOverview = res2.body
101 overview1.categories,
106 for (const arr of tmp) {
107 expect(arr).to.have.lengthOf(1)
111 expect(obj.videos).to.have.lengthOf(6)
112 expect(obj.videos[0].name).to.equal('video 5')
113 expect(obj.videos[1].name).to.equal('video 4')
114 expect(obj.videos[2].name).to.equal('video 3')
115 expect(obj.videos[3].name).to.equal('video 2')
116 expect(obj.videos[4].name).to.equal('video 1')
117 expect(obj.videos[5].name).to.equal('video 0')
120 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
121 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
122 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
124 expect(overview1.categories[0].category.id).to.equal(3)
126 expect(overview1.channels[0].channel.name).to.equal('root_channel')
129 it('Should hide muted accounts', async function () {
130 const token = await generateUserAccessToken(server, 'choco')
132 await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
135 const res = await getVideosOverview(server.url, 1)
137 testOverviewCount(res, 1)
141 const res = await getVideosOverviewWithToken(server.url, 1, token)
143 testOverviewCount(res, 0)
147 after(async function () {
148 await cleanupTests([ server ])