aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/index.ts2
-rw-r--r--server/tests/api/check-params/videos-common-filters.ts203
-rw-r--r--server/tests/api/check-params/videos-filter.ts114
-rw-r--r--server/tests/api/videos/index.ts2
-rw-r--r--server/tests/api/videos/multiple-servers.ts6
-rw-r--r--server/tests/api/videos/single-server.ts13
-rw-r--r--server/tests/api/videos/videos-common-filters.ts403
-rw-r--r--server/tests/api/videos/videos-filter.ts122
8 files changed, 611 insertions, 254 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index a14e4d3e0..0882f8176 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -27,6 +27,6 @@ import './video-comments'
27import './video-imports' 27import './video-imports'
28import './video-playlists' 28import './video-playlists'
29import './videos' 29import './videos'
30import './videos-filter' 30import './videos-common-filters'
31import './videos-history' 31import './videos-history'
32import './videos-overviews' 32import './videos-overviews'
diff --git a/server/tests/api/check-params/videos-common-filters.ts b/server/tests/api/check-params/videos-common-filters.ts
new file mode 100644
index 000000000..afe42b0d5
--- /dev/null
+++ b/server/tests/api/check-params/videos-common-filters.ts
@@ -0,0 +1,203 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import {
5 cleanupTests,
6 createSingleServer,
7 makeGetRequest,
8 PeerTubeServer,
9 setAccessTokensToServers,
10 setDefaultVideoChannel
11} from '@shared/extra-utils'
12import { HttpStatusCode, UserRole, VideoInclude } from '@shared/models'
13
14describe('Test video filters validators', function () {
15 let server: PeerTubeServer
16 let userAccessToken: string
17 let moderatorAccessToken: string
18
19 // ---------------------------------------------------------------
20
21 before(async function () {
22 this.timeout(30000)
23
24 server = await createSingleServer(1)
25
26 await setAccessTokensToServers([ server ])
27 await setDefaultVideoChannel([ server ])
28
29 const user = { username: 'user1', password: 'my super password' }
30 await server.users.create({ username: user.username, password: user.password })
31 userAccessToken = await server.login.getAccessToken(user)
32
33 const moderator = { username: 'moderator', password: 'my super password' }
34 await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
35
36 moderatorAccessToken = await server.login.getAccessToken(moderator)
37 })
38
39 describe('When setting a deprecated video filter', function () {
40
41 async function testEndpoints (token: string, filter: string, expectedStatus: HttpStatusCode) {
42 const paths = [
43 '/api/v1/video-channels/root_channel/videos',
44 '/api/v1/accounts/root/videos',
45 '/api/v1/videos',
46 '/api/v1/search/videos'
47 ]
48
49 for (const path of paths) {
50 await makeGetRequest({
51 url: server.url,
52 path,
53 token,
54 query: {
55 filter
56 },
57 expectedStatus
58 })
59 }
60 }
61
62 it('Should fail with a bad filter', async function () {
63 await testEndpoints(server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400)
64 })
65
66 it('Should succeed with a good filter', async function () {
67 await testEndpoints(server.accessToken, 'local', HttpStatusCode.OK_200)
68 })
69
70 it('Should fail to list all-local/all with a simple user', async function () {
71 await testEndpoints(userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401)
72 await testEndpoints(userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401)
73 })
74
75 it('Should succeed to list all-local/all with a moderator', async function () {
76 await testEndpoints(moderatorAccessToken, 'all-local', HttpStatusCode.OK_200)
77 await testEndpoints(moderatorAccessToken, 'all', HttpStatusCode.OK_200)
78 })
79
80 it('Should succeed to list all-local/all with an admin', async function () {
81 await testEndpoints(server.accessToken, 'all-local', HttpStatusCode.OK_200)
82 await testEndpoints(server.accessToken, 'all', HttpStatusCode.OK_200)
83 })
84
85 // Because we cannot authenticate the user on the RSS endpoint
86 it('Should fail on the feeds endpoint with the all-local/all filter', async function () {
87 for (const filter of [ 'all', 'all-local' ]) {
88 await makeGetRequest({
89 url: server.url,
90 path: '/feeds/videos.json',
91 expectedStatus: HttpStatusCode.UNAUTHORIZED_401,
92 query: {
93 filter
94 }
95 })
96 }
97 })
98
99 it('Should succeed on the feeds endpoint with the local filter', async function () {
100 await makeGetRequest({
101 url: server.url,
102 path: '/feeds/videos.json',
103 expectedStatus: HttpStatusCode.OK_200,
104 query: {
105 filter: 'local'
106 }
107 })
108 })
109 })
110
111 describe('When setting video filters', function () {
112
113 const validIncludes = [
114 VideoInclude.NONE,
115 VideoInclude.HIDDEN_PRIVACY,
116 VideoInclude.NOT_PUBLISHED_STATE | VideoInclude.BLACKLISTED
117 ]
118
119 async function testEndpoints (options: {
120 token?: string
121 isLocal?: boolean
122 include?: VideoInclude
123 expectedStatus: HttpStatusCode
124 }) {
125 const paths = [
126 '/api/v1/video-channels/root_channel/videos',
127 '/api/v1/accounts/root/videos',
128 '/api/v1/videos',
129 '/api/v1/search/videos'
130 ]
131
132 for (const path of paths) {
133 await makeGetRequest({
134 url: server.url,
135 path,
136 token: options.token || server.accessToken,
137 query: {
138 isLocal: options.isLocal,
139 include: options.include
140 },
141 expectedStatus: options.expectedStatus
142 })
143 }
144 }
145
146 it('Should fail with a bad include', async function () {
147 await testEndpoints({ include: 'toto' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
148 })
149
150 it('Should succeed with a good include', async function () {
151 for (const include of validIncludes) {
152 await testEndpoints({ include, expectedStatus: HttpStatusCode.OK_200 })
153 }
154 })
155
156 it('Should fail to include more videos with a simple user', async function () {
157 for (const include of validIncludes) {
158 await testEndpoints({ token: userAccessToken, include, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
159 }
160 })
161
162 it('Should succeed to list all local/all with a moderator', async function () {
163 for (const include of validIncludes) {
164 await testEndpoints({ token: moderatorAccessToken, include, expectedStatus: HttpStatusCode.OK_200 })
165 }
166 })
167
168 it('Should succeed to list all local/all with an admin', async function () {
169 for (const include of validIncludes) {
170 await testEndpoints({ token: server.accessToken, include, expectedStatus: HttpStatusCode.OK_200 })
171 }
172 })
173
174 // Because we cannot authenticate the user on the RSS endpoint
175 it('Should fail on the feeds endpoint with the all filter', async function () {
176 for (const include of [ VideoInclude.NOT_PUBLISHED_STATE ]) {
177 await makeGetRequest({
178 url: server.url,
179 path: '/feeds/videos.json',
180 expectedStatus: HttpStatusCode.UNAUTHORIZED_401,
181 query: {
182 include
183 }
184 })
185 }
186 })
187
188 it('Should succeed on the feeds endpoint with the local filter', async function () {
189 await makeGetRequest({
190 url: server.url,
191 path: '/feeds/videos.json',
192 expectedStatus: HttpStatusCode.OK_200,
193 query: {
194 isLocal: true
195 }
196 })
197 })
198 })
199
200 after(async function () {
201 await cleanupTests([ server ])
202 })
203})
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts
deleted file mode 100644
index d08570bbe..000000000
--- a/server/tests/api/check-params/videos-filter.ts
+++ /dev/null
@@ -1,114 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import {
5 cleanupTests,
6 createSingleServer,
7 makeGetRequest,
8 PeerTubeServer,
9 setAccessTokensToServers,
10 setDefaultVideoChannel
11} from '@shared/extra-utils'
12import { HttpStatusCode, UserRole } from '@shared/models'
13
14async function testEndpoints (server: PeerTubeServer, token: string, filter: string, expectedStatus: HttpStatusCode) {
15 const paths = [
16 '/api/v1/video-channels/root_channel/videos',
17 '/api/v1/accounts/root/videos',
18 '/api/v1/videos',
19 '/api/v1/search/videos'
20 ]
21
22 for (const path of paths) {
23 await makeGetRequest({
24 url: server.url,
25 path,
26 token,
27 query: {
28 filter
29 },
30 expectedStatus
31 })
32 }
33}
34
35describe('Test video filters validators', function () {
36 let server: PeerTubeServer
37 let userAccessToken: string
38 let moderatorAccessToken: string
39
40 // ---------------------------------------------------------------
41
42 before(async function () {
43 this.timeout(30000)
44
45 server = await createSingleServer(1)
46
47 await setAccessTokensToServers([ server ])
48 await setDefaultVideoChannel([ server ])
49
50 const user = { username: 'user1', password: 'my super password' }
51 await server.users.create({ username: user.username, password: user.password })
52 userAccessToken = await server.login.getAccessToken(user)
53
54 const moderator = { username: 'moderator', password: 'my super password' }
55 await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
56
57 moderatorAccessToken = await server.login.getAccessToken(moderator)
58 })
59
60 describe('When setting a video filter', function () {
61
62 it('Should fail with a bad filter', async function () {
63 await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400)
64 })
65
66 it('Should succeed with a good filter', async function () {
67 await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200)
68 })
69
70 it('Should fail to list all-local/all with a simple user', async function () {
71 await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401)
72 await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401)
73 })
74
75 it('Should succeed to list all-local/all with a moderator', async function () {
76 await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200)
77 await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200)
78 })
79
80 it('Should succeed to list all-local/all with an admin', async function () {
81 await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200)
82 await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200)
83 })
84
85 // Because we cannot authenticate the user on the RSS endpoint
86 it('Should fail on the feeds endpoint with the all-local/all filter', async function () {
87 for (const filter of [ 'all', 'all-local' ]) {
88 await makeGetRequest({
89 url: server.url,
90 path: '/feeds/videos.json',
91 expectedStatus: HttpStatusCode.UNAUTHORIZED_401,
92 query: {
93 filter
94 }
95 })
96 }
97 })
98
99 it('Should succeed on the feeds endpoint with the local filter', async function () {
100 await makeGetRequest({
101 url: server.url,
102 path: '/feeds/videos.json',
103 expectedStatus: HttpStatusCode.OK_200,
104 query: {
105 filter: 'local'
106 }
107 })
108 })
109 })
110
111 after(async function () {
112 await cleanupTests([ server ])
113 })
114})
diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts
index 5c07f8926..c9c678e9d 100644
--- a/server/tests/api/videos/index.ts
+++ b/server/tests/api/videos/index.ts
@@ -15,7 +15,7 @@ import './video-playlist-thumbnails'
15import './video-privacy' 15import './video-privacy'
16import './video-schedule-update' 16import './video-schedule-update'
17import './video-transcoder' 17import './video-transcoder'
18import './videos-filter' 18import './videos-common-filters'
19import './videos-history' 19import './videos-history'
20import './videos-overview' 20import './videos-overview'
21import './videos-views-cleaner' 21import './videos-views-cleaner'
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index df9deb1e1..9c255c1c5 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -349,7 +349,7 @@ describe('Test multiple servers', function () {
349 349
350 describe('It should list local videos', function () { 350 describe('It should list local videos', function () {
351 it('Should list only local videos on server 1', async function () { 351 it('Should list only local videos on server 1', async function () {
352 const { data, total } = await servers[0].videos.list({ filter: 'local' }) 352 const { data, total } = await servers[0].videos.list({ isLocal: true })
353 353
354 expect(total).to.equal(1) 354 expect(total).to.equal(1)
355 expect(data).to.be.an('array') 355 expect(data).to.be.an('array')
@@ -358,7 +358,7 @@ describe('Test multiple servers', function () {
358 }) 358 })
359 359
360 it('Should list only local videos on server 2', async function () { 360 it('Should list only local videos on server 2', async function () {
361 const { data, total } = await servers[1].videos.list({ filter: 'local' }) 361 const { data, total } = await servers[1].videos.list({ isLocal: true })
362 362
363 expect(total).to.equal(1) 363 expect(total).to.equal(1)
364 expect(data).to.be.an('array') 364 expect(data).to.be.an('array')
@@ -367,7 +367,7 @@ describe('Test multiple servers', function () {
367 }) 367 })
368 368
369 it('Should list only local videos on server 3', async function () { 369 it('Should list only local videos on server 3', async function () {
370 const { data, total } = await servers[2].videos.list({ filter: 'local' }) 370 const { data, total } = await servers[2].videos.list({ isLocal: true })
371 371
372 expect(total).to.equal(2) 372 expect(total).to.equal(2)
373 expect(data).to.be.an('array') 373 expect(data).to.be.an('array')
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index 29dac6ec1..a0e4a156c 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -354,19 +354,6 @@ describe('Test a single server', function () {
354 await server.videos.update({ id: videoId, attributes }) 354 await server.videos.update({ id: videoId, attributes })
355 }) 355 })
356 356
357 it('Should filter by tags and category', async function () {
358 {
359 const { data, total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
360 expect(total).to.equal(1)
361 expect(data[0].name).to.equal('my super video updated')
362 }
363
364 {
365 const { total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
366 expect(total).to.equal(0)
367 }
368 })
369
370 it('Should have the video updated', async function () { 357 it('Should have the video updated', async function () {
371 this.timeout(60000) 358 this.timeout(60000)
372 359
diff --git a/server/tests/api/videos/videos-common-filters.ts b/server/tests/api/videos/videos-common-filters.ts
new file mode 100644
index 000000000..eb2d2ab50
--- /dev/null
+++ b/server/tests/api/videos/videos-common-filters.ts
@@ -0,0 +1,403 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { expect } from 'chai'
5import { pick } from '@shared/core-utils'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 makeGetRequest,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
14 waitJobs
15} from '@shared/extra-utils'
16import { HttpStatusCode, UserRole, Video, VideoInclude, VideoPrivacy } from '@shared/models'
17
18describe('Test videos filter', function () {
19 let servers: PeerTubeServer[]
20 let paths: string[]
21 let remotePaths: string[]
22
23 // ---------------------------------------------------------------
24
25 before(async function () {
26 this.timeout(160000)
27
28 servers = await createMultipleServers(2)
29
30 await setAccessTokensToServers(servers)
31 await setDefaultVideoChannel(servers)
32
33 for (const server of servers) {
34 const moderator = { username: 'moderator', password: 'my super password' }
35 await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
36 server['moderatorAccessToken'] = await server.login.getAccessToken(moderator)
37
38 await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } })
39
40 {
41 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
42 await server.videos.upload({ attributes })
43 }
44
45 {
46 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
47 await server.videos.upload({ attributes })
48 }
49 }
50
51 await doubleFollow(servers[0], servers[1])
52
53 paths = [
54 `/api/v1/video-channels/root_channel/videos`,
55 `/api/v1/accounts/root/videos`,
56 '/api/v1/videos',
57 '/api/v1/search/videos'
58 ]
59
60 remotePaths = [
61 `/api/v1/video-channels/root_channel@${servers[1].host}/videos`,
62 `/api/v1/accounts/root@${servers[1].host}/videos`,
63 '/api/v1/videos',
64 '/api/v1/search/videos'
65 ]
66 })
67
68 describe('Check deprecated videos filter', function () {
69
70 async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) {
71 const videosResults: Video[][] = []
72
73 for (const path of paths) {
74 const res = await makeGetRequest({
75 url: server.url,
76 path,
77 token,
78 query: {
79 sort: 'createdAt',
80 filter
81 },
82 expectedStatus
83 })
84
85 videosResults.push(res.body.data.map(v => v.name))
86 }
87
88 return videosResults
89 }
90
91 it('Should display local videos', async function () {
92 for (const server of servers) {
93 const namesResults = await getVideosNames(server, server.accessToken, 'local')
94 for (const names of namesResults) {
95 expect(names).to.have.lengthOf(1)
96 expect(names[0]).to.equal('public ' + server.serverNumber)
97 }
98 }
99 })
100
101 it('Should display all local videos by the admin or the moderator', async function () {
102 for (const server of servers) {
103 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
104
105 const namesResults = await getVideosNames(server, token, 'all-local')
106 for (const names of namesResults) {
107 expect(names).to.have.lengthOf(3)
108
109 expect(names[0]).to.equal('public ' + server.serverNumber)
110 expect(names[1]).to.equal('unlisted ' + server.serverNumber)
111 expect(names[2]).to.equal('private ' + server.serverNumber)
112 }
113 }
114 }
115 })
116
117 it('Should display all videos by the admin or the moderator', async function () {
118 for (const server of servers) {
119 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
120
121 const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all')
122 expect(channelVideos).to.have.lengthOf(3)
123 expect(accountVideos).to.have.lengthOf(3)
124
125 expect(videos).to.have.lengthOf(5)
126 expect(searchVideos).to.have.lengthOf(5)
127 }
128 }
129 })
130 })
131
132 describe('Check videos filters', function () {
133
134 async function listVideos (options: {
135 server: PeerTubeServer
136 path: string
137 isLocal?: boolean
138 include?: VideoInclude
139 category?: number
140 tagsAllOf?: string[]
141 token?: string
142 expectedStatus?: HttpStatusCode
143 }) {
144 const res = await makeGetRequest({
145 url: options.server.url,
146 path: options.path,
147 token: options.token ?? options.server.accessToken,
148 query: {
149 ...pick(options, [ 'isLocal', 'include', 'category', 'tagsAllOf' ]),
150
151 sort: 'createdAt'
152 },
153 expectedStatus: options.expectedStatus ?? HttpStatusCode.OK_200
154 })
155
156 return res.body.data as Video[]
157 }
158
159 async function getVideosNames (options: {
160 server: PeerTubeServer
161 isLocal?: boolean
162 include?: VideoInclude
163 token?: string
164 expectedStatus?: HttpStatusCode
165 }) {
166 const videosResults: string[][] = []
167
168 for (const path of paths) {
169 const videos = await listVideos({ ...options, path })
170
171 videosResults.push(videos.map(v => v.name))
172 }
173
174 return videosResults
175 }
176
177 it('Should display local videos', async function () {
178 for (const server of servers) {
179 const namesResults = await getVideosNames({ server, isLocal: true })
180
181 for (const names of namesResults) {
182 expect(names).to.have.lengthOf(1)
183 expect(names[0]).to.equal('public ' + server.serverNumber)
184 }
185 }
186 })
187
188 it('Should display local videos with hidden privacy by the admin or the moderator', async function () {
189 for (const server of servers) {
190 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
191
192 const namesResults = await getVideosNames({
193 server,
194 token,
195 isLocal: true,
196 include: VideoInclude.HIDDEN_PRIVACY
197 })
198
199 for (const names of namesResults) {
200 expect(names).to.have.lengthOf(3)
201
202 expect(names[0]).to.equal('public ' + server.serverNumber)
203 expect(names[1]).to.equal('unlisted ' + server.serverNumber)
204 expect(names[2]).to.equal('private ' + server.serverNumber)
205 }
206 }
207 }
208 })
209
210 it('Should display all videos by the admin or the moderator', async function () {
211 for (const server of servers) {
212 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
213
214 const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames({
215 server,
216 token,
217 include: VideoInclude.HIDDEN_PRIVACY
218 })
219
220 expect(channelVideos).to.have.lengthOf(3)
221 expect(accountVideos).to.have.lengthOf(3)
222
223 expect(videos).to.have.lengthOf(5)
224 expect(searchVideos).to.have.lengthOf(5)
225 }
226 }
227 })
228
229 it('Should display only remote videos', async function () {
230 this.timeout(40000)
231
232 await servers[1].videos.upload({ attributes: { name: 'remote video' } })
233
234 await waitJobs(servers)
235
236 const finder = (videos: Video[]) => videos.find(v => v.name === 'remote video')
237
238 for (const path of remotePaths) {
239 {
240 const videos = await listVideos({ server: servers[0], path })
241 const video = finder(videos)
242 expect(video).to.exist
243 }
244
245 {
246 const videos = await listVideos({ server: servers[0], path, isLocal: false })
247 const video = finder(videos)
248 expect(video).to.exist
249 }
250
251 {
252 const videos = await listVideos({ server: servers[0], path, isLocal: true })
253 const video = finder(videos)
254 expect(video).to.not.exist
255 }
256 }
257 })
258
259 it('Should include not published videos', async function () {
260 await servers[0].config.enableLive({ allowReplay: false, transcoding: false })
261 await servers[0].live.create({ fields: { name: 'live video', channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC } })
262
263 const finder = (videos: Video[]) => videos.find(v => v.name === 'live video')
264
265 for (const path of paths) {
266 {
267 const videos = await listVideos({ server: servers[0], path })
268 const video = finder(videos)
269 expect(video).to.not.exist
270 expect(videos[0].state).to.not.exist
271 expect(videos[0].waitTranscoding).to.not.exist
272 }
273
274 {
275 const videos = await listVideos({ server: servers[0], path, include: VideoInclude.NOT_PUBLISHED_STATE })
276 const video = finder(videos)
277 expect(video).to.exist
278 expect(video.state).to.exist
279 }
280 }
281 })
282
283 it('Should include blacklisted videos', async function () {
284 const { id } = await servers[0].videos.upload({ attributes: { name: 'blacklisted' } })
285
286 await servers[0].blacklist.add({ videoId: id })
287
288 const finder = (videos: Video[]) => videos.find(v => v.name === 'blacklisted')
289
290 for (const path of paths) {
291 {
292 const videos = await listVideos({ server: servers[0], path })
293 const video = finder(videos)
294 expect(video).to.not.exist
295 expect(videos[0].blacklisted).to.not.exist
296 }
297
298 {
299 const videos = await listVideos({ server: servers[0], path, include: VideoInclude.BLACKLISTED })
300 const video = finder(videos)
301 expect(video).to.exist
302 expect(video.blacklisted).to.be.true
303 }
304 }
305 })
306
307 it('Should include videos from muted account', async function () {
308 const finder = (videos: Video[]) => videos.find(v => v.name === 'remote video')
309
310 await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host })
311
312 for (const path of remotePaths) {
313 {
314 const videos = await listVideos({ server: servers[0], path })
315 const video = finder(videos)
316 expect(video).to.not.exist
317
318 // Some paths won't have videos
319 if (videos[0]) {
320 expect(videos[0].blockedOwner).to.not.exist
321 expect(videos[0].blockedServer).to.not.exist
322 }
323 }
324
325 {
326 const videos = await listVideos({ server: servers[0], path, include: VideoInclude.BLOCKED_OWNER })
327
328 const video = finder(videos)
329 expect(video).to.exist
330 expect(video.blockedServer).to.be.false
331 expect(video.blockedOwner).to.be.true
332 }
333 }
334
335 await servers[0].blocklist.removeFromServerBlocklist({ account: 'root@' + servers[1].host })
336 })
337
338 it('Should include videos from muted server', async function () {
339 const finder = (videos: Video[]) => videos.find(v => v.name === 'remote video')
340
341 await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host })
342
343 for (const path of remotePaths) {
344 {
345 const videos = await listVideos({ server: servers[0], path })
346 const video = finder(videos)
347 expect(video).to.not.exist
348
349 // Some paths won't have videos
350 if (videos[0]) {
351 expect(videos[0].blockedOwner).to.not.exist
352 expect(videos[0].blockedServer).to.not.exist
353 }
354 }
355
356 {
357 const videos = await listVideos({ server: servers[0], path, include: VideoInclude.BLOCKED_OWNER })
358 const video = finder(videos)
359 expect(video).to.exist
360 expect(video.blockedServer).to.be.true
361 expect(video.blockedOwner).to.be.false
362 }
363 }
364
365 await servers[0].blocklist.removeFromServerBlocklist({ server: servers[1].host })
366 })
367
368 it('Should filter by tags and category', async function () {
369 await servers[0].videos.upload({ attributes: { name: 'tag filter', tags: [ 'tag1', 'tag2' ] } })
370 await servers[0].videos.upload({ attributes: { name: 'tag filter with category', tags: [ 'tag3' ], category: 4 } })
371
372 for (const path of paths) {
373 {
374
375 const videos = await listVideos({ server: servers[0], path, tagsAllOf: [ 'tag1', 'tag2' ] })
376 expect(videos).to.have.lengthOf(1)
377 expect(videos[0].name).to.equal('tag filter')
378
379 }
380
381 {
382 const videos = await listVideos({ server: servers[0], path, tagsAllOf: [ 'tag1', 'tag3' ] })
383 expect(videos).to.have.lengthOf(0)
384 }
385
386 {
387 const { data, total } = await servers[0].videos.list({ tagsAllOf: [ 'tag3' ], categoryOneOf: [ 4 ] })
388 expect(total).to.equal(1)
389 expect(data[0].name).to.equal('tag filter with category')
390 }
391
392 {
393 const { total } = await servers[0].videos.list({ tagsAllOf: [ 'tag4' ], categoryOneOf: [ 4 ] })
394 expect(total).to.equal(0)
395 }
396 }
397 })
398 })
399
400 after(async function () {
401 await cleanupTests(servers)
402 })
403})
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
deleted file mode 100644
index 2306807bf..000000000
--- a/server/tests/api/videos/videos-filter.ts
+++ /dev/null
@@ -1,122 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { expect } from 'chai'
5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 makeGetRequest,
10 PeerTubeServer,
11 setAccessTokensToServers
12} from '@shared/extra-utils'
13import { HttpStatusCode, UserRole, Video, VideoPrivacy } from '@shared/models'
14
15async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) {
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 },
34 expectedStatus
35 })
36
37 videosResults.push(res.body.data.map(v => v.name))
38 }
39
40 return videosResults
41}
42
43describe('Test videos filter', function () {
44 let servers: PeerTubeServer[]
45
46 // ---------------------------------------------------------------
47
48 before(async function () {
49 this.timeout(160000)
50
51 servers = await createMultipleServers(2)
52
53 await setAccessTokensToServers(servers)
54
55 for (const server of servers) {
56 const moderator = { username: 'moderator', password: 'my super password' }
57 await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
58 server['moderatorAccessToken'] = await server.login.getAccessToken(moderator)
59
60 await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } })
61
62 {
63 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
64 await server.videos.upload({ attributes })
65 }
66
67 {
68 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
69 await server.videos.upload({ attributes })
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)
83 expect(names[0]).to.equal('public ' + server.serverNumber)
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
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)
99 }
100 }
101 }
102 })
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 })
117 })
118
119 after(async function () {
120 await cleanupTests(servers)
121 })
122})