1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils'
6 import { getVideosOverview } from '../../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 () {
19 server = await runServer(1)
21 await setAccessTokensToServers([ server ])
24 it('Should send empty overview', async function () {
25 const res = await getVideosOverview(server.url)
27 const overview: VideosOverview = res.body
28 expect(overview.tags).to.have.lengthOf(0)
29 expect(overview.categories).to.have.lengthOf(0)
30 expect(overview.channels).to.have.lengthOf(0)
33 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
36 for (let i = 0; i < 5; i++) {
37 await uploadVideo(server.url, server.accessToken, {
40 tags: [ 'coucou1', 'coucou2' ]
44 const res = await getVideosOverview(server.url)
46 const overview: VideosOverview = res.body
47 expect(overview.tags).to.have.lengthOf(0)
48 expect(overview.categories).to.have.lengthOf(0)
49 expect(overview.channels).to.have.lengthOf(0)
52 it('Should upload another video and include all videos in the overview', async function () {
53 await uploadVideo(server.url, server.accessToken, {
56 tags: [ 'coucou1', 'coucou2' ]
59 const res = await getVideosOverview(server.url)
61 const overview: VideosOverview = res.body
62 expect(overview.tags).to.have.lengthOf(2)
63 expect(overview.categories).to.have.lengthOf(1)
64 expect(overview.channels).to.have.lengthOf(1)
67 it('Should have the correct overview', async function () {
68 const res = await getVideosOverview(server.url)
70 const overview: VideosOverview = res.body
72 for (const attr of [ 'tags', 'categories', 'channels' ]) {
73 const obj = overview[attr][0]
75 expect(obj.videos).to.have.lengthOf(6)
76 expect(obj.videos[0].name).to.equal('video 5')
77 expect(obj.videos[1].name).to.equal('video 4')
78 expect(obj.videos[2].name).to.equal('video 3')
79 expect(obj.videos[3].name).to.equal('video 2')
80 expect(obj.videos[4].name).to.equal('video 1')
81 expect(obj.videos[5].name).to.equal('video 0')
84 expect(overview.tags.find(t => t.tag === 'coucou1')).to.not.be.undefined
85 expect(overview.tags.find(t => t.tag === 'coucou2')).to.not.be.undefined
87 expect(overview.categories[0].category.id).to.equal(3)
89 expect(overview.channels[0].channel.name).to.equal('root_channel')
92 after(async function () {
93 killallServers([ server ])
95 // Keep the logs if the test failed