diff options
Diffstat (limited to 'server/tests/utils/videos')
-rw-r--r-- | server/tests/utils/videos/videos.ts | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 739394253..17c3dbc15 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts | |||
@@ -1,9 +1,14 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
1 | import { readFile } from 'fs' | 4 | import { readFile } from 'fs' |
2 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
3 | import { isAbsolute, join } from 'path' | 6 | import { isAbsolute, join } from 'path' |
4 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
5 | import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../' | 8 | import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../' |
6 | import { VideoPrivacy } from '../../../../shared/models/videos' | 9 | import { VideoPrivacy } from '../../../../shared/models/videos' |
10 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' | ||
11 | import { dateIsValid, webtorrentAdd } from '../index' | ||
7 | 12 | ||
8 | type VideoAttributes = { | 13 | type VideoAttributes = { |
9 | name?: string | 14 | name?: string |
@@ -312,6 +317,83 @@ function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: n | |||
312 | }) | 317 | }) |
313 | } | 318 | } |
314 | 319 | ||
320 | async function completeVideoCheck ( | ||
321 | url: string, | ||
322 | video: any, | ||
323 | attributes: { | ||
324 | name: string | ||
325 | category: number | ||
326 | licence: number | ||
327 | language: number | ||
328 | nsfw: boolean | ||
329 | description: string | ||
330 | host: string | ||
331 | account: string | ||
332 | isLocal: boolean, | ||
333 | tags: string[], | ||
334 | privacy: number, | ||
335 | channel: { | ||
336 | name: string, | ||
337 | isLocal: boolean | ||
338 | } | ||
339 | fixture: string, | ||
340 | files: { | ||
341 | resolution: number | ||
342 | size: number | ||
343 | }[] | ||
344 | } | ||
345 | ) { | ||
346 | expect(video.name).to.equal(attributes.name) | ||
347 | expect(video.category).to.equal(attributes.category) | ||
348 | expect(video.categoryLabel).to.equal(VIDEO_CATEGORIES[attributes.category]) | ||
349 | expect(video.licence).to.equal(attributes.licence) | ||
350 | expect(video.licenceLabel).to.equal(VIDEO_LICENCES[attributes.licence]) | ||
351 | expect(video.language).to.equal(attributes.language) | ||
352 | expect(video.languageLabel).to.equal(VIDEO_LANGUAGES[attributes.language]) | ||
353 | expect(video.nsfw).to.equal(attributes.nsfw) | ||
354 | expect(video.description).to.equal(attributes.description) | ||
355 | expect(video.serverHost).to.equal(attributes.host) | ||
356 | expect(video.accountName).to.equal(attributes.account) | ||
357 | expect(video.isLocal).to.equal(attributes.isLocal) | ||
358 | expect(dateIsValid(video.createdAt)).to.be.true | ||
359 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
360 | |||
361 | const res = await getVideo(url, video.id) | ||
362 | const videoDetails = res.body | ||
363 | |||
364 | expect(videoDetails.files).to.have.lengthOf(attributes.files.length) | ||
365 | expect(videoDetails.tags).to.deep.equal(attributes.tags) | ||
366 | expect(videoDetails.privacy).to.deep.equal(attributes.privacy) | ||
367 | expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy]) | ||
368 | expect(videoDetails.account.name).to.equal(attributes.account) | ||
369 | |||
370 | expect(videoDetails.channel.name).to.equal(attributes.channel.name) | ||
371 | expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal) | ||
372 | expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true | ||
373 | expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true | ||
374 | |||
375 | for (const attributeFile of attributes.files) { | ||
376 | const file = videoDetails.files.find(f => f.resolution === attributeFile.resolution) | ||
377 | expect(file).not.to.be.undefined | ||
378 | |||
379 | const magnetUri = file.magnetUri | ||
380 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
381 | expect(file.torrentUrl).to.equal(`${url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) | ||
382 | expect(file.fileUrl).to.equal(`${url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`) | ||
383 | expect(file.resolution).to.equal(attributeFile.resolution) | ||
384 | expect(file.resolutionLabel).to.equal(attributeFile.resolution + 'p') | ||
385 | expect(file.size).to.equal(attributeFile.size) | ||
386 | |||
387 | const test = await testVideoImage(url, attributes.fixture, videoDetails.thumbnailPath) | ||
388 | expect(test).to.equal(true) | ||
389 | |||
390 | const torrent = await webtorrentAdd(magnetUri, true) | ||
391 | expect(torrent.files).to.be.an('array') | ||
392 | expect(torrent.files.length).to.equal(1) | ||
393 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
394 | } | ||
395 | } | ||
396 | |||
315 | // --------------------------------------------------------------------------- | 397 | // --------------------------------------------------------------------------- |
316 | 398 | ||
317 | export { | 399 | export { |
@@ -335,5 +417,6 @@ export { | |||
335 | updateVideo, | 417 | updateVideo, |
336 | rateVideo, | 418 | rateVideo, |
337 | viewVideo, | 419 | viewVideo, |
338 | parseTorrentVideo | 420 | parseTorrentVideo, |
421 | completeVideoCheck | ||
339 | } | 422 | } |