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