]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/videos-filter.ts
Try to improve tools doc
[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
C
2
3import * as chai from 'chai'
4import 'mocha'
5import {
7c3b7976 6 cleanupTests,
1cd3facc
C
7 createUser,
8 doubleFollow,
9 flushAndRunMultipleServers,
1cd3facc
C
10 makeGetRequest,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo,
14 userLogin
94565d52 15} from '../../../../shared/extra-utils'
1cd3facc
C
16import { Video, VideoPrivacy } from '../../../../shared/models/videos'
17import { UserRole } from '../../../../shared/models/users'
2d53be02 18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
1cd3facc
C
19
20const expect = chai.expect
21
2d53be02 22async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
1cd3facc
C
23 const paths = [
24 '/api/v1/video-channels/root_channel/videos',
25 '/api/v1/accounts/root/videos',
26 '/api/v1/videos',
27 '/api/v1/search/videos'
28 ]
29
30 const videosResults: Video[][] = []
31
32 for (const path of paths) {
33 const res = await makeGetRequest({
34 url: server.url,
35 path,
36 token,
37 query: {
38 sort: 'createdAt',
39 filter
40 },
41 statusCodeExpected
42 })
43
44 videosResults.push(res.body.data.map(v => v.name))
45 }
46
47 return videosResults
48}
49
50describe('Test videos filter validator', function () {
51 let servers: ServerInfo[]
52
53 // ---------------------------------------------------------------
54
55 before(async function () {
56 this.timeout(120000)
57
1cd3facc
C
58 servers = await flushAndRunMultipleServers(2)
59
60 await setAccessTokensToServers(servers)
61
62 for (const server of servers) {
63 const moderator = { username: 'moderator', password: 'my super password' }
64 await createUser(
1eddc9a7
C
65 {
66 url: server.url,
67 accessToken: server.accessToken,
68 username: moderator.username,
69 password: moderator.password,
70 videoQuota: undefined,
71 videoQuotaDaily: undefined,
72 role: UserRole.MODERATOR
73 }
1cd3facc
C
74 )
75 server['moderatorAccessToken'] = await userLogin(server, moderator)
76
77 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber })
78
79 {
80 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
81 await uploadVideo(server.url, server.accessToken, attributes)
82 }
83
84 {
85 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
86 await uploadVideo(server.url, server.accessToken, attributes)
87 }
88 }
89
90 await doubleFollow(servers[0], servers[1])
91 })
92
93 describe('Check videos filter', function () {
94
95 it('Should display local videos', async function () {
96 for (const server of servers) {
97 const namesResults = await getVideosNames(server, server.accessToken, 'local')
98 for (const names of namesResults) {
99 expect(names).to.have.lengthOf(1)
a1587156 100 expect(names[0]).to.equal('public ' + server.serverNumber)
1cd3facc
C
101 }
102 }
103 })
104
105 it('Should display all local videos by the admin or the moderator', async function () {
106 for (const server of servers) {
107 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
108
109 const namesResults = await getVideosNames(server, token, 'all-local')
110 for (const names of namesResults) {
111 expect(names).to.have.lengthOf(3)
112
a1587156
C
113 expect(names[0]).to.equal('public ' + server.serverNumber)
114 expect(names[1]).to.equal('unlisted ' + server.serverNumber)
115 expect(names[2]).to.equal('private ' + server.serverNumber)
1cd3facc
C
116 }
117 }
118 }
119 })
0aa52e17
C
120
121 it('Should display all videos by the admin or the moderator', async function () {
122 for (const server of servers) {
123 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
124
125 const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all')
126 expect(channelVideos).to.have.lengthOf(3)
127 expect(accountVideos).to.have.lengthOf(3)
128
129 expect(videos).to.have.lengthOf(5)
130 expect(searchVideos).to.have.lengthOf(5)
131 }
132 }
133 })
1cd3facc
C
134 })
135
7c3b7976
C
136 after(async function () {
137 await cleanupTests(servers)
1cd3facc
C
138 })
139})