]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/videos-overview.ts
Improve advanced input filter
[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, createSingleServer, PeerTubeServer, setAccessTokensToServers, 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: PeerTubeServer = 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 createSingleServer(1)
23
24 await setAccessTokensToServers([ server ])
25 })
26
27 it('Should send empty overview', async function () {
28 const body = await server.overviews.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 server.videos.upload({
39 attributes: {
40 name: 'video 0',
41 category: 3,
42 tags: [ 'coucou1', 'coucou2' ]
43 }
44 })
45
46 const body = await server.overviews.getVideos({ page: 1 })
47
48 testOverviewCount(body, 0)
49 })
50
51 it('Should upload another video and include all videos in the overview', async function () {
52 this.timeout(30000)
53
54 {
55 for (let i = 1; i < 6; i++) {
56 await server.videos.upload({
57 attributes: {
58 name: 'video ' + i,
59 category: 3,
60 tags: [ 'coucou1', 'coucou2' ]
61 }
62 })
63 }
64
65 await wait(3000)
66 }
67
68 {
69 const body = await server.overviews.getVideos({ page: 1 })
70
71 testOverviewCount(body, 1)
72 }
73
74 {
75 const overview = await server.overviews.getVideos({ page: 2 })
76
77 expect(overview.tags).to.have.lengthOf(1)
78 expect(overview.categories).to.have.lengthOf(0)
79 expect(overview.channels).to.have.lengthOf(0)
80 }
81 })
82
83 it('Should have the correct overview', async function () {
84 const overview1 = await server.overviews.getVideos({ page: 1 })
85 const overview2 = await server.overviews.getVideos({ page: 2 })
86
87 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
88 expect(arr).to.have.lengthOf(1)
89
90 const obj = arr[0]
91
92 expect(obj.videos).to.have.lengthOf(6)
93 expect(obj.videos[0].name).to.equal('video 5')
94 expect(obj.videos[1].name).to.equal('video 4')
95 expect(obj.videos[2].name).to.equal('video 3')
96 expect(obj.videos[3].name).to.equal('video 2')
97 expect(obj.videos[4].name).to.equal('video 1')
98 expect(obj.videos[5].name).to.equal('video 0')
99 }
100
101 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
102 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
103 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
104
105 expect(overview1.categories[0].category.id).to.equal(3)
106
107 expect(overview1.channels[0].channel.name).to.equal('root_channel')
108 })
109
110 it('Should hide muted accounts', async function () {
111 const token = await server.users.generateUserAndToken('choco')
112
113 await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host })
114
115 {
116 const body = await server.overviews.getVideos({ page: 1 })
117
118 testOverviewCount(body, 1)
119 }
120
121 {
122 const body = await server.overviews.getVideos({ page: 1, token })
123
124 testOverviewCount(body, 0)
125 }
126 })
127
128 after(async function () {
129 await cleanupTests([ server ])
130 })
131 })