X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fcli%2Fcreate-import-video-file-job.ts;h=49758ff56cf64872c89e1d8778b45205058864f7;hb=a6a79eae0d8564099b6957e76d7a18528d9ef124;hp=d486db600e2916d295de929c6e1ef5cf4fad435b;hpb=0138af9237b77dd7d3a49260d164193b4048de84;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts index d486db600..49758ff56 100644 --- a/server/tests/cli/create-import-video-file-job.ts +++ b/server/tests/cli/create-import-video-file-job.ts @@ -1,31 +1,33 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' import * as chai from 'chai' -import { VideoDetails, VideoFile } from '../../../shared/models/videos' -const expect = chai.expect - +import { VideoFile } from '@shared/models/videos/video-file.model' import { + cleanupTests, + doubleFollow, execCLI, - flushTests, + flushAndRunMultipleServers, getEnvCli, + getVideo, getVideosList, - killallServers, - parseTorrentVideo, - runServer, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait, - getVideo, flushAndRunMultipleServers, doubleFollow -} from '../utils' + uploadVideo +} from '../../../shared/extra-utils' +import { waitJobs } from '../../../shared/extra-utils/server/jobs' +import { VideoDetails } from '../../../shared/models/videos' + +const expect = chai.expect -function assertVideoProperties (video: VideoFile, resolution: number, extname: string) { +function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) { expect(video).to.have.nested.property('resolution.id', resolution) - expect(video).to.have.property('magnetUri').that.includes(`.${extname}`) expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`) expect(video).to.have.property('fileUrl').that.includes(`.${extname}`) + expect(video).to.have.property('magnetUri').that.includes(`.${extname}`) expect(video).to.have.property('size').that.is.above(0) + + if (size) expect(video.size).to.equal(size) } describe('Test create import video jobs', function () { @@ -37,7 +39,6 @@ describe('Test create import video jobs', function () { before(async function () { this.timeout(90000) - await flushTests() // Run server 2 to have transcoding enabled servers = await flushAndRunMultipleServers(2) @@ -51,61 +52,73 @@ describe('Test create import video jobs', function () { const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) video2UUID = res2.body.video.uuid - await wait(40000) + // Transcoding + await waitJobs(servers) }) it('Should run a import job on video 1 with a lower resolution', async function () { const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/api/fixtures/video_short-480.webm`) + await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`) - await wait(30000) + await waitJobs(servers) for (const server of servers) { const { data: videos } = (await getVideosList(server.url)).body expect(videos).to.have.lengthOf(2) - let infoHashes: { [ id: number ]: string } = {} - const video = videos.find(({ uuid }) => uuid === video1UUID) const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body expect(videoDetail.files).to.have.lengthOf(2) - const [originalVideo, transcodedVideo] = videoDetail.files - assertVideoProperties(originalVideo, 720, 'webm') - assertVideoProperties(transcodedVideo, 480, 'webm') + const [ originalVideo, transcodedVideo ] = videoDetail.files + assertVideoProperties(originalVideo, 720, 'webm', 218910) + assertVideoProperties(transcodedVideo, 480, 'webm', 69217) } }) - it('Should run a import job on video 2 with the same resolution', async function () { + it('Should run a import job on video 2 with the same resolution and a different extension', async function () { const env = getEnvCli(servers[1]) - await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/api/fixtures/video_short.ogv`) + await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`) - await wait(30000) + await waitJobs(servers) - for (const server of servers.reverse()) { + for (const server of servers) { const { data: videos } = (await getVideosList(server.url)).body expect(videos).to.have.lengthOf(2) - let infoHashes: { [ id: number ]: string } - const video = videos.find(({ uuid }) => uuid === video2UUID) const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body expect(videoDetail.files).to.have.lengthOf(4) - const [originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240] = videoDetail.files - assertVideoProperties(originalVideo, 720, 'ogv') + const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files + assertVideoProperties(originalVideo, 720, 'ogv', 140849) assertVideoProperties(transcodedVideo420, 480, 'mp4') assertVideoProperties(transcodedVideo320, 360, 'mp4') assertVideoProperties(transcodedVideo240, 240, 'mp4') } }) - after(async function () { - killallServers(servers) + it('Should run a import job on video 2 with the same resolution and the same extension', async function () { + const env = getEnvCli(servers[0]) + await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`) - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() + await waitJobs(servers) + + for (const server of servers) { + const { data: videos } = (await getVideosList(server.url)).body + expect(videos).to.have.lengthOf(2) + + const video = videos.find(({ uuid }) => uuid === video1UUID) + const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body + + expect(videoDetail.files).to.have.lengthOf(2) + const [ video720, video480 ] = videoDetail.files + assertVideoProperties(video720, 720, 'webm', 942961) + assertVideoProperties(video480, 480, 'webm', 69217) } }) + + after(async function () { + await cleanupTests(servers) + }) })