]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/videos-overview.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-overview.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2d3741d6
C
2
3import * as chai from 'chai'
4import 'mocha'
7c3b7976 5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils'
94565d52 6import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews'
2d3741d6
C
7import { VideosOverview } from '../../../../shared/models/overviews'
8
9const expect = chai.expect
10
11describe('Test a videos overview', function () {
12 let server: ServerInfo = null
13
14 before(async function () {
15 this.timeout(30000)
16
210feb6c 17 server = await flushAndRunServer(1)
2d3741d6
C
18
19 await setAccessTokensToServers([ server ])
20 })
21
22 it('Should send empty overview', async function () {
23 const res = await getVideosOverview(server.url)
24
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)
29 })
30
9a629c6e
C
31 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
32 this.timeout(15000)
33
34 for (let i = 0; i < 5; i++) {
2d3741d6
C
35 await uploadVideo(server.url, server.accessToken, {
36 name: 'video ' + i,
37 category: 3,
38 tags: [ 'coucou1', 'coucou2' ]
39 })
40 }
41
42 const res = await getVideosOverview(server.url)
43
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)
48 })
49
50 it('Should upload another video and include all videos in the overview', async function () {
51 await uploadVideo(server.url, server.accessToken, {
9a629c6e 52 name: 'video 5',
2d3741d6
C
53 category: 3,
54 tags: [ 'coucou1', 'coucou2' ]
55 })
56
57 const res = await getVideosOverview(server.url)
58
59 const overview: VideosOverview = res.body
60 expect(overview.tags).to.have.lengthOf(2)
61 expect(overview.categories).to.have.lengthOf(1)
62 expect(overview.channels).to.have.lengthOf(1)
63 })
64
65 it('Should have the correct overview', async function () {
66 const res = await getVideosOverview(server.url)
67
68 const overview: VideosOverview = res.body
69
70 for (const attr of [ 'tags', 'categories', 'channels' ]) {
71 const obj = overview[attr][0]
72
9a629c6e
C
73 expect(obj.videos).to.have.lengthOf(6)
74 expect(obj.videos[0].name).to.equal('video 5')
75 expect(obj.videos[1].name).to.equal('video 4')
76 expect(obj.videos[2].name).to.equal('video 3')
77 expect(obj.videos[3].name).to.equal('video 2')
78 expect(obj.videos[4].name).to.equal('video 1')
79 expect(obj.videos[5].name).to.equal('video 0')
2d3741d6
C
80 }
81
82 expect(overview.tags.find(t => t.tag === 'coucou1')).to.not.be.undefined
83 expect(overview.tags.find(t => t.tag === 'coucou2')).to.not.be.undefined
84
85 expect(overview.categories[0].category.id).to.equal(3)
86
87 expect(overview.channels[0].channel.name).to.equal('root_channel')
88 })
89
7c3b7976
C
90 after(async function () {
91 await cleanupTests([ server ])
2d3741d6
C
92 })
93})