1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 addAccountToAccountBlocklist,
9 generateUserAccessToken,
11 setAccessTokensToServers,
14 } from '@shared/extra-utils'
15 import { VideosOverview } from '@shared/models'
17 const expect = chai.expect
19 describe('Test a videos overview', function () {
20 let server: ServerInfo = null
22 function testOverviewCount (overview: VideosOverview, expected: number) {
23 expect(overview.tags).to.have.lengthOf(expected)
24 expect(overview.categories).to.have.lengthOf(expected)
25 expect(overview.channels).to.have.lengthOf(expected)
28 before(async function () {
31 server = await flushAndRunServer(1)
33 await setAccessTokensToServers([ server ])
36 it('Should send empty overview', async function () {
37 const body = await server.overviewsCommand.getVideos({ page: 1 })
39 testOverviewCount(body, 0)
42 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
47 await uploadVideo(server.url, server.accessToken, {
50 tags: [ 'coucou1', 'coucou2' ]
53 const body = await server.overviewsCommand.getVideos({ page: 1 })
55 testOverviewCount(body, 0)
58 it('Should upload another video and include all videos in the overview', async function () {
62 for (let i = 1; i < 6; i++) {
63 await uploadVideo(server.url, server.accessToken, {
66 tags: [ 'coucou1', 'coucou2' ]
74 const body = await server.overviewsCommand.getVideos({ page: 1 })
76 testOverviewCount(body, 1)
80 const overview = await server.overviewsCommand.getVideos({ page: 2 })
82 expect(overview.tags).to.have.lengthOf(1)
83 expect(overview.categories).to.have.lengthOf(0)
84 expect(overview.channels).to.have.lengthOf(0)
88 it('Should have the correct overview', async function () {
89 const overview1 = await server.overviewsCommand.getVideos({ page: 1 })
90 const overview2 = await server.overviewsCommand.getVideos({ page: 2 })
92 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
93 expect(arr).to.have.lengthOf(1)
97 expect(obj.videos).to.have.lengthOf(6)
98 expect(obj.videos[0].name).to.equal('video 5')
99 expect(obj.videos[1].name).to.equal('video 4')
100 expect(obj.videos[2].name).to.equal('video 3')
101 expect(obj.videos[3].name).to.equal('video 2')
102 expect(obj.videos[4].name).to.equal('video 1')
103 expect(obj.videos[5].name).to.equal('video 0')
106 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
107 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
108 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
110 expect(overview1.categories[0].category.id).to.equal(3)
112 expect(overview1.channels[0].channel.name).to.equal('root_channel')
115 it('Should hide muted accounts', async function () {
116 const token = await generateUserAccessToken(server, 'choco')
118 await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
121 const body = await server.overviewsCommand.getVideos({ page: 1 })
123 testOverviewCount(body, 1)
127 const body = await server.overviewsCommand.getVideos({ page: 1, token })
129 testOverviewCount(body, 0)
133 after(async function () {
134 await cleanupTests([ server ])