1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '../../../../shared/extra-utils'
6 import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews'
7 import { VideosOverview } from '../../../../shared/models/overviews'
9 const expect = chai.expect
11 describe('Test a videos overview', function () {
12 let server: ServerInfo = null
14 before(async function () {
17 server = await flushAndRunServer(1)
19 await setAccessTokensToServers([ server ])
22 it('Should send empty overview', async function () {
23 const res = await getVideosOverview(server.url, 1)
25 const overview: VideosOverview = res.body
26 expect(overview.tags).to.have.lengthOf(0)
27 expect(overview.categories).to.have.lengthOf(0)
28 expect(overview.channels).to.have.lengthOf(0)
31 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
36 await uploadVideo(server.url, server.accessToken, {
39 tags: [ 'coucou1', 'coucou2' ]
42 const res = await getVideosOverview(server.url, 1)
44 const overview: VideosOverview = res.body
45 expect(overview.tags).to.have.lengthOf(0)
46 expect(overview.categories).to.have.lengthOf(0)
47 expect(overview.channels).to.have.lengthOf(0)
50 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' ]
64 const res = await getVideosOverview(server.url, 1)
66 const overview: VideosOverview = res.body
67 expect(overview.tags).to.have.lengthOf(1)
68 expect(overview.categories).to.have.lengthOf(1)
69 expect(overview.channels).to.have.lengthOf(1)
73 const res = await getVideosOverview(server.url, 2)
75 const overview: VideosOverview = res.body
76 expect(overview.tags).to.have.lengthOf(1)
77 expect(overview.categories).to.have.lengthOf(0)
78 expect(overview.channels).to.have.lengthOf(0)
82 it('Should have the correct overview', async function () {
83 const res1 = await getVideosOverview(server.url, 1)
84 const res2 = await getVideosOverview(server.url, 2)
86 const overview1: VideosOverview = res1.body
87 const overview2: VideosOverview = res2.body
96 for (const arr of tmp) {
97 expect(arr).to.have.lengthOf(1)
101 expect(obj.videos).to.have.lengthOf(6)
102 expect(obj.videos[0].name).to.equal('video 5')
103 expect(obj.videos[1].name).to.equal('video 4')
104 expect(obj.videos[2].name).to.equal('video 3')
105 expect(obj.videos[3].name).to.equal('video 2')
106 expect(obj.videos[4].name).to.equal('video 1')
107 expect(obj.videos[5].name).to.equal('video 0')
110 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
111 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
112 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
114 expect(overview1.categories[0].category.id).to.equal(3)
116 expect(overview1.channels[0].channel.name).to.equal('root_channel')
119 after(async function () {
120 await cleanupTests([ server ])