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