]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/videos-overview.ts
Introduce config command
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-overview.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 addAccountToAccountBlocklist,
7 cleanupTests,
8 flushAndRunServer,
9 generateUserAccessToken,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo,
13 wait
14 } from '@shared/extra-utils'
15 import { VideosOverview } from '@shared/models'
16
17 const expect = chai.expect
18
19 describe('Test a videos overview', function () {
20 let server: ServerInfo = null
21
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)
26 }
27
28 before(async function () {
29 this.timeout(30000)
30
31 server = await flushAndRunServer(1)
32
33 await setAccessTokensToServers([ server ])
34 })
35
36 it('Should send empty overview', async function () {
37 const body = await server.overviewsCommand.getVideos({ page: 1 })
38
39 testOverviewCount(body, 0)
40 })
41
42 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
43 this.timeout(30000)
44
45 await wait(3000)
46
47 await uploadVideo(server.url, server.accessToken, {
48 name: 'video 0',
49 category: 3,
50 tags: [ 'coucou1', 'coucou2' ]
51 })
52
53 const body = await server.overviewsCommand.getVideos({ page: 1 })
54
55 testOverviewCount(body, 0)
56 })
57
58 it('Should upload another video and include all videos in the overview', async function () {
59 this.timeout(30000)
60
61 {
62 for (let i = 1; i < 6; i++) {
63 await uploadVideo(server.url, server.accessToken, {
64 name: 'video ' + i,
65 category: 3,
66 tags: [ 'coucou1', 'coucou2' ]
67 })
68 }
69
70 await wait(3000)
71 }
72
73 {
74 const body = await server.overviewsCommand.getVideos({ page: 1 })
75
76 testOverviewCount(body, 1)
77 }
78
79 {
80 const overview = await server.overviewsCommand.getVideos({ page: 2 })
81
82 expect(overview.tags).to.have.lengthOf(1)
83 expect(overview.categories).to.have.lengthOf(0)
84 expect(overview.channels).to.have.lengthOf(0)
85 }
86 })
87
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 })
91
92 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
93 expect(arr).to.have.lengthOf(1)
94
95 const obj = arr[0]
96
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')
104 }
105
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
109
110 expect(overview1.categories[0].category.id).to.equal(3)
111
112 expect(overview1.channels[0].channel.name).to.equal('root_channel')
113 })
114
115 it('Should hide muted accounts', async function () {
116 const token = await generateUserAccessToken(server, 'choco')
117
118 await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
119
120 {
121 const body = await server.overviewsCommand.getVideos({ page: 1 })
122
123 testOverviewCount(body, 1)
124 }
125
126 {
127 const body = await server.overviewsCommand.getVideos({ page: 1, token })
128
129 testOverviewCount(body, 0)
130 }
131 })
132
133 after(async function () {
134 await cleanupTests([ server ])
135 })
136 })