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