diff options
Diffstat (limited to 'server/tests/utils')
-rw-r--r-- | server/tests/utils/videos.ts | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 2a5d00255..d4d5faf0a 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts | |||
@@ -7,6 +7,7 @@ import { makeGetRequest } from './requests' | |||
7 | import { readFilePromise } from './miscs' | 7 | import { readFilePromise } from './miscs' |
8 | import { ServerInfo } from './servers' | 8 | import { ServerInfo } from './servers' |
9 | import { getMyUserInformation } from './users' | 9 | import { getMyUserInformation } from './users' |
10 | import { VideoPrivacy } from '../../../shared' | ||
10 | 11 | ||
11 | type VideoAttributes = { | 12 | type VideoAttributes = { |
12 | name?: string | 13 | name?: string |
@@ -17,6 +18,7 @@ type VideoAttributes = { | |||
17 | description?: string | 18 | description?: string |
18 | tags?: string[] | 19 | tags?: string[] |
19 | channelId?: number | 20 | channelId?: number |
21 | privacy?: VideoPrivacy | ||
20 | fixture?: string | 22 | fixture?: string |
21 | } | 23 | } |
22 | 24 | ||
@@ -38,6 +40,12 @@ function getVideoLanguages (url: string) { | |||
38 | return makeGetRequest(url, path) | 40 | return makeGetRequest(url, path) |
39 | } | 41 | } |
40 | 42 | ||
43 | function getVideoPrivacies (url: string) { | ||
44 | const path = '/api/v1/videos/privacies' | ||
45 | |||
46 | return makeGetRequest(url, path) | ||
47 | } | ||
48 | |||
41 | function getAllVideosListBy (url: string) { | 49 | function getAllVideosListBy (url: string) { |
42 | const path = '/api/v1/videos' | 50 | const path = '/api/v1/videos' |
43 | 51 | ||
@@ -51,14 +59,23 @@ function getAllVideosListBy (url: string) { | |||
51 | .expect('Content-Type', /json/) | 59 | .expect('Content-Type', /json/) |
52 | } | 60 | } |
53 | 61 | ||
54 | function getVideo (url: string, id: number | string) { | 62 | function getVideo (url: string, id: number | string, expectedStatus = 200) { |
55 | const path = '/api/v1/videos/' + id | 63 | const path = '/api/v1/videos/' + id |
56 | 64 | ||
57 | return request(url) | 65 | return request(url) |
58 | .get(path) | 66 | .get(path) |
59 | .set('Accept', 'application/json') | 67 | .set('Accept', 'application/json') |
60 | .expect(200) | 68 | .expect(expectedStatus) |
61 | .expect('Content-Type', /json/) | 69 | } |
70 | |||
71 | function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) { | ||
72 | const path = '/api/v1/videos/' + id | ||
73 | |||
74 | return request(url) | ||
75 | .get(path) | ||
76 | .set('Authorization', 'Bearer ' + token) | ||
77 | .set('Accept', 'application/json') | ||
78 | .expect(expectedStatus) | ||
62 | } | 79 | } |
63 | 80 | ||
64 | function getVideoDescription (url: string, descriptionPath: string) { | 81 | function getVideoDescription (url: string, descriptionPath: string) { |
@@ -80,6 +97,22 @@ function getVideosList (url: string) { | |||
80 | .expect('Content-Type', /json/) | 97 | .expect('Content-Type', /json/) |
81 | } | 98 | } |
82 | 99 | ||
100 | function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string) { | ||
101 | const path = '/api/v1/users/me/videos' | ||
102 | |||
103 | const req = request(url) | ||
104 | .get(path) | ||
105 | .query({ start: start }) | ||
106 | .query({ count: count }) | ||
107 | |||
108 | if (sort) req.query({ sort }) | ||
109 | |||
110 | return req.set('Accept', 'application/json') | ||
111 | .set('Authorization', 'Bearer ' + accessToken) | ||
112 | .expect(200) | ||
113 | .expect('Content-Type', /json/) | ||
114 | } | ||
115 | |||
83 | function getVideosListPagination (url: string, start: number, count: number, sort?: string) { | 116 | function getVideosListPagination (url: string, start: number, count: number, sort?: string) { |
84 | const path = '/api/v1/videos' | 117 | const path = '/api/v1/videos' |
85 | 118 | ||
@@ -191,6 +224,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
191 | nsfw: true, | 224 | nsfw: true, |
192 | description: 'my super description', | 225 | description: 'my super description', |
193 | tags: [ 'tag' ], | 226 | tags: [ 'tag' ], |
227 | privacy: VideoPrivacy.PUBLIC, | ||
194 | fixture: 'video_short.webm' | 228 | fixture: 'video_short.webm' |
195 | } | 229 | } |
196 | attributes = Object.assign(attributes, videoAttributesArg) | 230 | attributes = Object.assign(attributes, videoAttributesArg) |
@@ -204,6 +238,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
204 | .field('licence', attributes.licence.toString()) | 238 | .field('licence', attributes.licence.toString()) |
205 | .field('nsfw', JSON.stringify(attributes.nsfw)) | 239 | .field('nsfw', JSON.stringify(attributes.nsfw)) |
206 | .field('description', attributes.description) | 240 | .field('description', attributes.description) |
241 | .field('privacy', attributes.privacy.toString()) | ||
207 | .field('channelId', attributes.channelId) | 242 | .field('channelId', attributes.channelId) |
208 | 243 | ||
209 | if (attributes.language !== undefined) { | 244 | if (attributes.language !== undefined) { |
@@ -236,6 +271,7 @@ function updateVideo (url: string, accessToken: string, id: number, attributes: | |||
236 | if (attributes.nsfw) body['nsfw'] = attributes.nsfw | 271 | if (attributes.nsfw) body['nsfw'] = attributes.nsfw |
237 | if (attributes.description) body['description'] = attributes.description | 272 | if (attributes.description) body['description'] = attributes.description |
238 | if (attributes.tags) body['tags'] = attributes.tags | 273 | if (attributes.tags) body['tags'] = attributes.tags |
274 | if (attributes.privacy) body['privacy'] = attributes.privacy | ||
239 | 275 | ||
240 | return request(url) | 276 | return request(url) |
241 | .put(path) | 277 | .put(path) |
@@ -274,9 +310,12 @@ export { | |||
274 | getVideoDescription, | 310 | getVideoDescription, |
275 | getVideoCategories, | 311 | getVideoCategories, |
276 | getVideoLicences, | 312 | getVideoLicences, |
313 | getVideoPrivacies, | ||
277 | getVideoLanguages, | 314 | getVideoLanguages, |
278 | getAllVideosListBy, | 315 | getAllVideosListBy, |
316 | getMyVideos, | ||
279 | getVideo, | 317 | getVideo, |
318 | getVideoWithToken, | ||
280 | getVideosList, | 319 | getVideosList, |
281 | getVideosListPagination, | 320 | getVideosListPagination, |
282 | getVideosListSort, | 321 | getVideosListSort, |