]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/videos-filter.ts
Use random names for VOD HLS playlists
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-filter.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
1cd3facc 2
1cd3facc 3import 'mocha'
d23dd9fb 4import { expect } from 'chai'
1cd3facc 5import {
7c3b7976 6 cleanupTests,
254d3579 7 createMultipleServers,
4c7e60bc 8 doubleFollow,
1cd3facc 9 makeGetRequest,
254d3579 10 PeerTubeServer,
d23dd9fb
C
11 setAccessTokensToServers
12} from '@shared/extra-utils'
4c7e60bc 13import { HttpStatusCode, UserRole, Video, VideoPrivacy } from '@shared/models'
1cd3facc 14
c0e8b12e 15async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) {
1cd3facc
C
16 const paths = [
17 '/api/v1/video-channels/root_channel/videos',
18 '/api/v1/accounts/root/videos',
19 '/api/v1/videos',
20 '/api/v1/search/videos'
21 ]
22
23 const videosResults: Video[][] = []
24
25 for (const path of paths) {
26 const res = await makeGetRequest({
27 url: server.url,
28 path,
29 token,
30 query: {
31 sort: 'createdAt',
32 filter
33 },
c0e8b12e 34 expectedStatus
1cd3facc
C
35 })
36
37 videosResults.push(res.body.data.map(v => v.name))
38 }
39
40 return videosResults
41}
42
3124b469 43describe('Test videos filter', function () {
254d3579 44 let servers: PeerTubeServer[]
1cd3facc
C
45
46 // ---------------------------------------------------------------
47
48 before(async function () {
3124b469 49 this.timeout(160000)
1cd3facc 50
254d3579 51 servers = await createMultipleServers(2)
1cd3facc
C
52
53 await setAccessTokensToServers(servers)
54
55 for (const server of servers) {
56 const moderator = { username: 'moderator', password: 'my super password' }
89d241a7
C
57 await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
58 server['moderatorAccessToken'] = await server.login.getAccessToken(moderator)
1cd3facc 59
89d241a7 60 await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } })
1cd3facc
C
61
62 {
63 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
89d241a7 64 await server.videos.upload({ attributes })
1cd3facc
C
65 }
66
67 {
68 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
89d241a7 69 await server.videos.upload({ attributes })
1cd3facc
C
70 }
71 }
72
73 await doubleFollow(servers[0], servers[1])
74 })
75
76 describe('Check videos filter', function () {
77
78 it('Should display local videos', async function () {
79 for (const server of servers) {
80 const namesResults = await getVideosNames(server, server.accessToken, 'local')
81 for (const names of namesResults) {
82 expect(names).to.have.lengthOf(1)
a1587156 83 expect(names[0]).to.equal('public ' + server.serverNumber)
1cd3facc
C
84 }
85 }
86 })
87
88 it('Should display all local videos by the admin or the moderator', async function () {
89 for (const server of servers) {
90 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
91
92 const namesResults = await getVideosNames(server, token, 'all-local')
93 for (const names of namesResults) {
94 expect(names).to.have.lengthOf(3)
95
a1587156
C
96 expect(names[0]).to.equal('public ' + server.serverNumber)
97 expect(names[1]).to.equal('unlisted ' + server.serverNumber)
98 expect(names[2]).to.equal('private ' + server.serverNumber)
1cd3facc
C
99 }
100 }
101 }
102 })
0aa52e17
C
103
104 it('Should display all videos by the admin or the moderator', async function () {
105 for (const server of servers) {
106 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
107
108 const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all')
109 expect(channelVideos).to.have.lengthOf(3)
110 expect(accountVideos).to.have.lengthOf(3)
111
112 expect(videos).to.have.lengthOf(5)
113 expect(searchVideos).to.have.lengthOf(5)
114 }
115 }
116 })
1cd3facc
C
117 })
118
7c3b7976
C
119 after(async function () {
120 await cleanupTests(servers)
1cd3facc
C
121 })
122})