X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Futils%2Fvideos.ts;h=7f8bd39c094d2be5b61372fc3a3d80afc98f6228;hb=aa8b6df4a51c82eb91e6fd71a090b2128098af6b;hp=42b7dd05afb556ad3143b6c8c831c05b6a56d576;hpb=0e1dc3e7c69995c691e1dd82e3c2bc68748661ca;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 42b7dd05a..7f8bd39c0 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts @@ -1,8 +1,11 @@ +import { readFile } from 'fs' import * as request from 'supertest' import { join, isAbsolute } from 'path' +import * as parseTorrent from 'parse-torrent' import { makeGetRequest } from './requests' import { readFilePromise } from './miscs' +import { ServerInfo } from './servers' type VideoAttributes = { name?: string @@ -160,7 +163,7 @@ async function testVideoImage (url: string, imageName: string, imagePath: string } function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) { - const path = '/api/v1/videos' + const path = '/api/v1/videos/upload' // Default attributes let attributes = { @@ -182,10 +185,13 @@ function uploadVideo (url: string, accessToken: string, videoAttributesArg: Vide .field('name', attributes.name) .field('category', attributes.category.toString()) .field('licence', attributes.licence.toString()) - .field('language', attributes.language.toString()) .field('nsfw', JSON.stringify(attributes.nsfw)) .field('description', attributes.description) + if (attributes.language !== undefined) { + req.field('language', attributes.language.toString()) + } + for (let i = 0; i < attributes.tags.length; i++) { req.field('tags[' + i + ']', attributes.tags[i]) } @@ -232,6 +238,18 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string .expect(specialStatus) } +function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolutionLabel: string) { + return new Promise((res, rej) => { + const torrentName = videoUUID + '-' + resolutionLabel + '.torrent' + const torrentPath = join(__dirname, '..', '..', '..', 'test' + server.serverNumber, 'torrents', torrentName) + readFile(torrentPath, (err, data) => { + if (err) return rej(err) + + return res(parseTorrent(data)) + }) + }) +} + // --------------------------------------------------------------------------- export { @@ -250,5 +268,6 @@ export { testVideoImage, uploadVideo, updateVideo, - rateVideo + rateVideo, + parseTorrentVideo }