1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 generateUserAccessToken,
10 setAccessTokensToServers,
13 } from '@shared/extra-utils'
14 import { VideosOverview } from '@shared/models'
16 const expect = chai.expect
18 describe('Test a videos overview', function () {
19 let server: ServerInfo = null
21 function testOverviewCount (overview: VideosOverview, expected: number) {
22 expect(overview.tags).to.have.lengthOf(expected)
23 expect(overview.categories).to.have.lengthOf(expected)
24 expect(overview.channels).to.have.lengthOf(expected)
27 before(async function () {
30 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
35 it('Should send empty overview', async function () {
36 const body = await server.overviewsCommand.getVideos({ page: 1 })
38 testOverviewCount(body, 0)
41 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
46 await uploadVideo(server.url, server.accessToken, {
49 tags: [ 'coucou1', 'coucou2' ]
52 const body = await server.overviewsCommand.getVideos({ page: 1 })
54 testOverviewCount(body, 0)
57 it('Should upload another video and include all videos in the overview', async function () {
61 for (let i = 1; i < 6; i++) {
62 await uploadVideo(server.url, server.accessToken, {
65 tags: [ 'coucou1', 'coucou2' ]
73 const body = await server.overviewsCommand.getVideos({ page: 1 })
75 testOverviewCount(body, 1)
79 const overview = await server.overviewsCommand.getVideos({ page: 2 })
81 expect(overview.tags).to.have.lengthOf(1)
82 expect(overview.categories).to.have.lengthOf(0)
83 expect(overview.channels).to.have.lengthOf(0)
87 it('Should have the correct overview', async function () {
88 const overview1 = await server.overviewsCommand.getVideos({ page: 1 })
89 const overview2 = await server.overviewsCommand.getVideos({ page: 2 })
91 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
92 expect(arr).to.have.lengthOf(1)
96 expect(obj.videos).to.have.lengthOf(6)
97 expect(obj.videos[0].name).to.equal('video 5')
98 expect(obj.videos[1].name).to.equal('video 4')
99 expect(obj.videos[2].name).to.equal('video 3')
100 expect(obj.videos[3].name).to.equal('video 2')
101 expect(obj.videos[4].name).to.equal('video 1')
102 expect(obj.videos[5].name).to.equal('video 0')
105 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
106 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
107 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
109 expect(overview1.categories[0].category.id).to.equal(3)
111 expect(overview1.channels[0].channel.name).to.equal('root_channel')
114 it('Should hide muted accounts', async function () {
115 const token = await generateUserAccessToken(server, 'choco')
117 await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host })
120 const body = await server.overviewsCommand.getVideos({ page: 1 })
122 testOverviewCount(body, 1)
126 const body = await server.overviewsCommand.getVideos({ page: 1, token })
128 testOverviewCount(body, 0)
132 after(async function () {
133 await cleanupTests([ server ])