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