aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-20 14:35:18 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:04:05 +0200
commitd525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 (patch)
tree4305044c4a97bdf1275b241c63cb0e85151cfb6a /server/tests/utils
parent57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (diff)
downloadPeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.gz
PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.zst
PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.zip
Add videos list filters
Diffstat (limited to 'server/tests/utils')
-rw-r--r--server/tests/utils/index.ts1
-rw-r--r--server/tests/utils/requests/check-api-params.ts13
-rw-r--r--server/tests/utils/search/videos.ts77
-rw-r--r--server/tests/utils/videos/videos.ts86
4 files changed, 111 insertions, 66 deletions
diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts
index 5b560ca39..391db18cf 100644
--- a/server/tests/utils/index.ts
+++ b/server/tests/utils/index.ts
@@ -14,3 +14,4 @@ export * from './videos/video-blacklist'
14export * from './videos/video-channels' 14export * from './videos/video-channels'
15export * from './videos/videos' 15export * from './videos/videos'
16export * from './feeds/feeds' 16export * from './feeds/feeds'
17export * from './search/videos'
diff --git a/server/tests/utils/requests/check-api-params.ts b/server/tests/utils/requests/check-api-params.ts
index 7550eb3d8..edb47e0e9 100644
--- a/server/tests/utils/requests/check-api-params.ts
+++ b/server/tests/utils/requests/check-api-params.ts
@@ -1,31 +1,32 @@
1import { makeGetRequest } from './requests' 1import { makeGetRequest } from './requests'
2import { immutableAssign } from '..'
2 3
3function checkBadStartPagination (url: string, path: string, token?: string) { 4function checkBadStartPagination (url: string, path: string, token?: string, query = {}) {
4 return makeGetRequest({ 5 return makeGetRequest({
5 url, 6 url,
6 path, 7 path,
7 token, 8 token,
8 query: { start: 'hello' }, 9 query: immutableAssign(query, { start: 'hello' }),
9 statusCodeExpected: 400 10 statusCodeExpected: 400
10 }) 11 })
11} 12}
12 13
13function checkBadCountPagination (url: string, path: string, token?: string) { 14function checkBadCountPagination (url: string, path: string, token?: string, query = {}) {
14 return makeGetRequest({ 15 return makeGetRequest({
15 url, 16 url,
16 path, 17 path,
17 token, 18 token,
18 query: { count: 'hello' }, 19 query: immutableAssign(query, { count: 'hello' }),
19 statusCodeExpected: 400 20 statusCodeExpected: 400
20 }) 21 })
21} 22}
22 23
23function checkBadSortPagination (url: string, path: string, token?: string) { 24function checkBadSortPagination (url: string, path: string, token?: string, query = {}) {
24 return makeGetRequest({ 25 return makeGetRequest({
25 url, 26 url,
26 path, 27 path,
27 token, 28 token,
28 query: { sort: 'hello' }, 29 query: immutableAssign(query, { sort: 'hello' }),
29 statusCodeExpected: 400 30 statusCodeExpected: 400
30 }) 31 })
31} 32}
diff --git a/server/tests/utils/search/videos.ts b/server/tests/utils/search/videos.ts
new file mode 100644
index 000000000..3a0c10e42
--- /dev/null
+++ b/server/tests/utils/search/videos.ts
@@ -0,0 +1,77 @@
1/* tslint:disable:no-unused-expression */
2
3import * as request from 'supertest'
4import { VideosSearchQuery } from '../../../../shared/models/search'
5import { immutableAssign } from '..'
6
7function searchVideo (url: string, search: string) {
8 const path = '/api/v1/search/videos'
9 const req = request(url)
10 .get(path)
11 .query({ sort: '-publishedAt', search })
12 .set('Accept', 'application/json')
13
14 return req.expect(200)
15 .expect('Content-Type', /json/)
16}
17
18function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) {
19 const path = '/api/v1/search/videos'
20 const req = request(url)
21 .get(path)
22 .set('Authorization', 'Bearer ' + token)
23 .query(immutableAssign(query, { sort: '-publishedAt', search }))
24 .set('Accept', 'application/json')
25
26 return req.expect(200)
27 .expect('Content-Type', /json/)
28}
29
30function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
31 const path = '/api/v1/search/videos'
32
33 const req = request(url)
34 .get(path)
35 .query({ start })
36 .query({ search })
37 .query({ count })
38
39 if (sort) req.query({ sort })
40
41 return req.set('Accept', 'application/json')
42 .expect(200)
43 .expect('Content-Type', /json/)
44}
45
46function searchVideoWithSort (url: string, search: string, sort: string) {
47 const path = '/api/v1/search/videos'
48
49 return request(url)
50 .get(path)
51 .query({ search })
52 .query({ sort })
53 .set('Accept', 'application/json')
54 .expect(200)
55 .expect('Content-Type', /json/)
56}
57
58function advancedVideosSearch (url: string, options: VideosSearchQuery) {
59 const path = '/api/v1/search/videos'
60
61 return request(url)
62 .get(path)
63 .query(options)
64 .set('Accept', 'application/json')
65 .expect(200)
66 .expect('Content-Type', /json/)
67}
68
69// ---------------------------------------------------------------------------
70
71export {
72 searchVideo,
73 advancedVideosSearch,
74 searchVideoWithToken,
75 searchVideoWithPagination,
76 searchVideoWithSort
77}
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,