1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { Response } from 'superagent'
7 addAccountToAccountBlocklist,
10 generateUserAccessToken,
12 setAccessTokensToServers,
15 } from '@shared/extra-utils'
16 import { VideosOverview } from '@shared/models'
18 const expect = chai.expect
20 describe('Test a videos overview', function () {
21 let server: ServerInfo = null
23 function testOverviewCount (overview: VideosOverview, expected: number) {
24 expect(overview.tags).to.have.lengthOf(expected)
25 expect(overview.categories).to.have.lengthOf(expected)
26 expect(overview.channels).to.have.lengthOf(expected)
29 before(async function () {
32 server = await flushAndRunServer(1)
34 await setAccessTokensToServers([ server ])
37 it('Should send empty overview', async function () {
38 const body = await server.overviewsCommand.getVideos({ page: 1 })
40 testOverviewCount(body, 0)
43 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
48 await uploadVideo(server.url, server.accessToken, {
51 tags: [ 'coucou1', 'coucou2' ]
54 const body = await server.overviewsCommand.getVideos({ page: 1 })
56 testOverviewCount(body, 0)
59 it('Should upload another video and include all videos in the overview', async function () {
63 for (let i = 1; i < 6; i++) {
64 await uploadVideo(server.url, server.accessToken, {
67 tags: [ 'coucou1', 'coucou2' ]
75 const body = await server.overviewsCommand.getVideos({ page: 1 })
77 testOverviewCount(body, 1)
81 const overview = await server.overviewsCommand.getVideos({ page: 2 })
83 expect(overview.tags).to.have.lengthOf(1)
84 expect(overview.categories).to.have.lengthOf(0)
85 expect(overview.channels).to.have.lengthOf(0)
89 it('Should have the correct overview', async function () {
90 const overview1 = await server.overviewsCommand.getVideos({ page: 1 })
91 const overview2 = await server.overviewsCommand.getVideos({ page: 2 })
93 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
94 expect(arr).to.have.lengthOf(1)
98 expect(obj.videos).to.have.lengthOf(6)
99 expect(obj.videos[0].name).to.equal('video 5')
100 expect(obj.videos[1].name).to.equal('video 4')
101 expect(obj.videos[2].name).to.equal('video 3')
102 expect(obj.videos[3].name).to.equal('video 2')
103 expect(obj.videos[4].name).to.equal('video 1')
104 expect(obj.videos[5].name).to.equal('video 0')
107 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
108 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
109 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
111 expect(overview1.categories[0].category.id).to.equal(3)
113 expect(overview1.channels[0].channel.name).to.equal('root_channel')
116 it('Should hide muted accounts', async function () {
117 const token = await generateUserAccessToken(server, 'choco')
119 await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
122 const body = await server.overviewsCommand.getVideos({ page: 1 })
124 testOverviewCount(body, 1)
128 const body = await server.overviewsCommand.getVideos({ page: 1, token })
130 testOverviewCount(body, 0)
134 after(async function () {
135 await cleanupTests([ server ])