diff options
Diffstat (limited to 'server/tests/utils/videos/videos.ts')
-rw-r--r-- | server/tests/utils/videos/videos.ts | 83 |
1 files changed, 60 insertions, 23 deletions
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 9105b5f13..9d4267db8 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts | |||
@@ -5,7 +5,16 @@ import { existsSync, readFile } from 'fs' | |||
5 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
6 | import { extname, isAbsolute, join } from 'path' | 6 | import { extname, isAbsolute, join } from 'path' |
7 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
8 | import { getMyUserInformation, makeGetRequest, root, ServerInfo, testImage } from '../' | 8 | import { |
9 | buildAbsoluteFixturePath, | ||
10 | getMyUserInformation, | ||
11 | makeGetRequest, | ||
12 | makePutBodyRequest, | ||
13 | makeUploadRequest, | ||
14 | root, | ||
15 | ServerInfo, | ||
16 | testImage | ||
17 | } from '../' | ||
9 | import { VideoPrivacy } from '../../../../shared/models/videos' | 18 | import { VideoPrivacy } from '../../../../shared/models/videos' |
10 | import { readdirPromise } from '../../../helpers/core-utils' | 19 | import { readdirPromise } from '../../../helpers/core-utils' |
11 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' | 20 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' |
@@ -23,6 +32,8 @@ type VideoAttributes = { | |||
23 | channelId?: number | 32 | channelId?: number |
24 | privacy?: VideoPrivacy | 33 | privacy?: VideoPrivacy |
25 | fixture?: string | 34 | fixture?: string |
35 | thumbnailfile?: string | ||
36 | previewfile?: string | ||
26 | } | 37 | } |
27 | 38 | ||
28 | function getVideoCategories (url: string) { | 39 | function getVideoCategories (url: string) { |
@@ -228,8 +239,8 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
228 | defaultChannelId = res.body.videoChannels[0].id | 239 | defaultChannelId = res.body.videoChannels[0].id |
229 | } catch (e) { /* empty */ } | 240 | } catch (e) { /* empty */ } |
230 | 241 | ||
231 | // Default attributes | 242 | // Override default attributes |
232 | let attributes = { | 243 | const attributes = Object.assign({ |
233 | name: 'my super video', | 244 | name: 'my super video', |
234 | category: 5, | 245 | category: 5, |
235 | licence: 4, | 246 | licence: 4, |
@@ -241,8 +252,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
241 | privacy: VideoPrivacy.PUBLIC, | 252 | privacy: VideoPrivacy.PUBLIC, |
242 | commentsEnabled: true, | 253 | commentsEnabled: true, |
243 | fixture: 'video_short.webm' | 254 | fixture: 'video_short.webm' |
244 | } | 255 | }, videoAttributesArg) |
245 | attributes = Object.assign(attributes, videoAttributesArg) | ||
246 | 256 | ||
247 | const req = request(url) | 257 | const req = request(url) |
248 | .post(path) | 258 | .post(path) |
@@ -267,22 +277,22 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
267 | req.field('licence', attributes.licence.toString()) | 277 | req.field('licence', attributes.licence.toString()) |
268 | } | 278 | } |
269 | 279 | ||
270 | for (let i = 0; i < attributes.tags.length; i++) { | 280 | if (attributes.thumbnailfile !== undefined) { |
271 | req.field('tags[' + i + ']', attributes.tags[i]) | 281 | req.attach('thumbnailfile', buildAbsoluteFixturePath(attributes.thumbnailfile)) |
282 | } | ||
283 | if (attributes.previewfile !== undefined) { | ||
284 | req.attach('previewfile', buildAbsoluteFixturePath(attributes.previewfile)) | ||
272 | } | 285 | } |
273 | 286 | ||
274 | let filePath = '' | 287 | for (let i = 0; i < attributes.tags.length; i++) { |
275 | if (isAbsolute(attributes.fixture)) { | 288 | req.field('tags[' + i + ']', attributes.tags[i]) |
276 | filePath = attributes.fixture | ||
277 | } else { | ||
278 | filePath = join(__dirname, '..', '..', 'api', 'fixtures', attributes.fixture) | ||
279 | } | 289 | } |
280 | 290 | ||
281 | return req.attach('videofile', filePath) | 291 | return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) |
282 | .expect(specialStatus) | 292 | .expect(specialStatus) |
283 | } | 293 | } |
284 | 294 | ||
285 | function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, specialStatus = 204) { | 295 | function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, statusCodeExpected = 204) { |
286 | const path = '/api/v1/videos/' + id | 296 | const path = '/api/v1/videos/' + id |
287 | const body = {} | 297 | const body = {} |
288 | 298 | ||
@@ -296,12 +306,30 @@ function updateVideo (url: string, accessToken: string, id: number | string, att | |||
296 | if (attributes.tags) body['tags'] = attributes.tags | 306 | if (attributes.tags) body['tags'] = attributes.tags |
297 | if (attributes.privacy) body['privacy'] = attributes.privacy | 307 | if (attributes.privacy) body['privacy'] = attributes.privacy |
298 | 308 | ||
299 | return request(url) | 309 | // Upload request |
300 | .put(path) | 310 | if (attributes.thumbnailfile || attributes.previewfile) { |
301 | .send(body) | 311 | const attaches: any = {} |
302 | .set('Accept', 'application/json') | 312 | if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile |
303 | .set('Authorization', 'Bearer ' + accessToken) | 313 | if (attributes.previewfile) attaches.previewfile = attributes.previewfile |
304 | .expect(specialStatus) | 314 | |
315 | return makeUploadRequest({ | ||
316 | url, | ||
317 | method: 'PUT', | ||
318 | path, | ||
319 | token: accessToken, | ||
320 | fields: body, | ||
321 | attaches, | ||
322 | statusCodeExpected | ||
323 | }) | ||
324 | } | ||
325 | |||
326 | return makePutBodyRequest({ | ||
327 | url, | ||
328 | path, | ||
329 | fields: body, | ||
330 | token: accessToken, | ||
331 | statusCodeExpected | ||
332 | }) | ||
305 | } | 333 | } |
306 | 334 | ||
307 | function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { | 335 | function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { |
@@ -355,7 +383,9 @@ async function completeVideoCheck ( | |||
355 | files: { | 383 | files: { |
356 | resolution: number | 384 | resolution: number |
357 | size: number | 385 | size: number |
358 | }[] | 386 | }[], |
387 | thumbnailfile?: string | ||
388 | previewfile?: string | ||
359 | } | 389 | } |
360 | ) { | 390 | ) { |
361 | if (!attributes.likes) attributes.likes = 0 | 391 | if (!attributes.likes) attributes.likes = 0 |
@@ -414,8 +444,15 @@ async function completeVideoCheck ( | |||
414 | const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) | 444 | const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) |
415 | expect(file.size).to.be.above(minSize).and.below(maxSize) | 445 | expect(file.size).to.be.above(minSize).and.below(maxSize) |
416 | 446 | ||
417 | const test = await testImage(url, attributes.fixture, videoDetails.thumbnailPath) | 447 | { |
418 | expect(test).to.equal(true) | 448 | const test = await testImage(url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath) |
449 | expect(test).to.equal(true) | ||
450 | } | ||
451 | |||
452 | if (attributes.previewfile) { | ||
453 | const test = await testImage(url, attributes.previewfile, videoDetails.previewPath) | ||
454 | expect(test).to.equal(true) | ||
455 | } | ||
419 | 456 | ||
420 | const torrent = await webtorrentAdd(magnetUri, true) | 457 | const torrent = await webtorrentAdd(magnetUri, true) |
421 | expect(torrent.files).to.be.an('array') | 458 | expect(torrent.files).to.be.an('array') |