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