aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils')
-rw-r--r--server/tests/utils/videos/videos.ts85
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
3import { expect } from 'chai'
1import { readFile } from 'fs' 4import { readFile } from 'fs'
2import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
3import { isAbsolute, join } from 'path' 6import { isAbsolute, join } from 'path'
4import * as request from 'supertest' 7import * as request from 'supertest'
5import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../' 8import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../'
6import { VideoPrivacy } from '../../../../shared/models/videos' 9import { VideoPrivacy } from '../../../../shared/models/videos'
10import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers'
11import { dateIsValid, webtorrentAdd } from '../index'
7 12
8type VideoAttributes = { 13type 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
320async 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
317export { 399export {
@@ -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}