aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/videos/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/videos/videos.ts')
-rw-r--r--server/tests/utils/videos/videos.ts86
1 files changed, 26 insertions, 60 deletions
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index a42d0f043..8c49eb02b 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -7,7 +7,7 @@ import { extname, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { 8import {
9 buildAbsoluteFixturePath, 9 buildAbsoluteFixturePath,
10 getMyUserInformation, 10 getMyUserInformation, immutableAssign,
11 makeGetRequest, 11 makeGetRequest,
12 makePutBodyRequest, 12 makePutBodyRequest,
13 makeUploadRequest, 13 makeUploadRequest,
@@ -133,13 +133,13 @@ function getVideosList (url: string) {
133 .expect('Content-Type', /json/) 133 .expect('Content-Type', /json/)
134} 134}
135 135
136function getVideosListWithToken (url: string, token: string) { 136function getVideosListWithToken (url: string, token: string, query: { nsfw?: boolean } = {}) {
137 const path = '/api/v1/videos' 137 const path = '/api/v1/videos'
138 138
139 return request(url) 139 return request(url)
140 .get(path) 140 .get(path)
141 .set('Authorization', 'Bearer ' + token) 141 .set('Authorization', 'Bearer ' + token)
142 .query({ sort: 'name' }) 142 .query(immutableAssign(query, { sort: 'name' }))
143 .set('Accept', 'application/json') 143 .set('Accept', 'application/json')
144 .expect(200) 144 .expect(200)
145 .expect('Content-Type', /json/) 145 .expect('Content-Type', /json/)
@@ -172,17 +172,25 @@ function getMyVideos (url: string, accessToken: string, start: number, count: nu
172 .expect('Content-Type', /json/) 172 .expect('Content-Type', /json/)
173} 173}
174 174
175function getAccountVideos (url: string, accessToken: string, accountName: string, start: number, count: number, sort?: string) { 175function getAccountVideos (
176 url: string,
177 accessToken: string,
178 accountName: string,
179 start: number,
180 count: number,
181 sort?: string,
182 query: { nsfw?: boolean } = {}
183) {
176 const path = '/api/v1/accounts/' + accountName + '/videos' 184 const path = '/api/v1/accounts/' + accountName + '/videos'
177 185
178 return makeGetRequest({ 186 return makeGetRequest({
179 url, 187 url,
180 path, 188 path,
181 query: { 189 query: immutableAssign(query, {
182 start, 190 start,
183 count, 191 count,
184 sort 192 sort
185 }, 193 }),
186 token: accessToken, 194 token: accessToken,
187 statusCodeExpected: 200 195 statusCodeExpected: 200
188 }) 196 })
@@ -194,18 +202,19 @@ function getVideoChannelVideos (
194 videoChannelId: number | string, 202 videoChannelId: number | string,
195 start: number, 203 start: number,
196 count: number, 204 count: number,
197 sort?: string 205 sort?: string,
206 query: { nsfw?: boolean } = {}
198) { 207) {
199 const path = '/api/v1/video-channels/' + videoChannelId + '/videos' 208 const path = '/api/v1/video-channels/' + videoChannelId + '/videos'
200 209
201 return makeGetRequest({ 210 return makeGetRequest({
202 url, 211 url,
203 path, 212 path,
204 query: { 213 query: immutableAssign(query, {
205 start, 214 start,
206 count, 215 count,
207 sort 216 sort
208 }, 217 }),
209 token: accessToken, 218 token: accessToken,
210 statusCodeExpected: 200 219 statusCodeExpected: 200
211 }) 220 })
@@ -237,65 +246,25 @@ function getVideosListSort (url: string, sort: string) {
237 .expect('Content-Type', /json/) 246 .expect('Content-Type', /json/)
238} 247}
239 248
240function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) { 249function getVideosWithFilters (url: string, query: { tagsAllOf: string[], categoryOneOf: number[] | number }) {
241 const path = '/api/v1/videos' 250 const path = '/api/v1/videos'
242 251
243 return request(url) 252 return request(url)
244 .delete(path + '/' + id)
245 .set('Accept', 'application/json')
246 .set('Authorization', 'Bearer ' + token)
247 .expect(expectedStatus)
248}
249
250function searchVideo (url: string, search: string) {
251 const path = '/api/v1/search/videos'
252 const req = request(url)
253 .get(path) 253 .get(path)
254 .query({ search }) 254 .query(query)
255 .set('Accept', 'application/json') 255 .set('Accept', 'application/json')
256 256 .expect(200)
257 return req.expect(200)
258 .expect('Content-Type', /json/) 257 .expect('Content-Type', /json/)
259} 258}
260 259
261function searchVideoWithToken (url: string, search: string, token: string) { 260function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) {
262 const path = '/api/v1/videos' 261 const path = '/api/v1/videos'
263 const req = request(url)
264 .get(path + '/search')
265 .set('Authorization', 'Bearer ' + token)
266 .query({ search })
267 .set('Accept', 'application/json')
268
269 return req.expect(200)
270 .expect('Content-Type', /json/)
271}
272
273function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
274 const path = '/api/v1/search/videos'
275
276 const req = request(url)
277 .get(path)
278 .query({ start })
279 .query({ search })
280 .query({ count })
281
282 if (sort) req.query({ sort })
283
284 return req.set('Accept', 'application/json')
285 .expect(200)
286 .expect('Content-Type', /json/)
287}
288
289function searchVideoWithSort (url: string, search: string, sort: string) {
290 const path = '/api/v1/search/videos'
291 262
292 return request(url) 263 return request(url)
293 .get(path) 264 .delete(path + '/' + id)
294 .query({ search })
295 .query({ sort })
296 .set('Accept', 'application/json') 265 .set('Accept', 'application/json')
297 .expect(200) 266 .set('Authorization', 'Bearer ' + token)
298 .expect('Content-Type', /json/) 267 .expect(expectedStatus)
299} 268}
300 269
301async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) { 270async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) {
@@ -581,18 +550,15 @@ export {
581 getMyVideos, 550 getMyVideos,
582 getAccountVideos, 551 getAccountVideos,
583 getVideoChannelVideos, 552 getVideoChannelVideos,
584 searchVideoWithToken,
585 getVideo, 553 getVideo,
586 getVideoWithToken, 554 getVideoWithToken,
587 getVideosList, 555 getVideosList,
588 getVideosListPagination, 556 getVideosListPagination,
589 getVideosListSort, 557 getVideosListSort,
590 removeVideo, 558 removeVideo,
591 searchVideo,
592 searchVideoWithPagination,
593 searchVideoWithSort,
594 getVideosListWithToken, 559 getVideosListWithToken,
595 uploadVideo, 560 uploadVideo,
561 getVideosWithFilters,
596 updateVideo, 562 updateVideo,
597 rateVideo, 563 rateVideo,
598 viewVideo, 564 viewVideo,