X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Ftests%2Fapi%2Fvideos%2Fvideo-captions.ts;h=00e04d69d3dcac19222bd8dd44b89d70a9653138;hb=f2eb23cd87cf32b8fe545178143b5f49e06a58da;hp=cbf5268f01d093e146acf2b537671790516bcf22;hpb=40e87e9ecc54e3513fb586928330a7855eb192c6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index cbf5268f0..00e04d69d 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -1,12 +1,25 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import * as chai from 'chai' import 'mocha' -import { doubleFollow, flushAndRunMultipleServers, uploadVideo } from '../../utils' -import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index' -import { waitJobs } from '../../utils/server/jobs' -import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions' -import { VideoCaption } from '../../../../shared/models/videos/video-caption.model' +import { + checkVideoFilesWereRemoved, + cleanupTests, + doubleFollow, + flushAndRunMultipleServers, + removeVideo, + uploadVideo, + wait +} from '../../../../shared/extra-utils' +import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' +import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { + createVideoCaption, + deleteVideoCaption, + listVideoCaptions, + testCaptionFile +} from '../../../../shared/extra-utils/videos/video-captions' +import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' const expect = chai.expect @@ -17,8 +30,6 @@ describe('Test video captions', function () { before(async function () { this.timeout(30000) - await flushTests() - servers = await flushAndRunMultipleServers(2) await setAccessTokensToServers(servers) @@ -26,7 +37,7 @@ describe('Test video captions', function () { await waitJobs(servers) - const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name' }) + const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' }) videoUUID = res.body.video.uuid await waitJobs(servers) @@ -56,7 +67,8 @@ describe('Test video captions', function () { accessToken: servers[0].accessToken, language: 'zh', videoId: videoUUID, - fixture: 'subtitle-good2.vtt' + fixture: 'subtitle-good2.vtt', + mimeType: 'application/octet-stream' }) await waitJobs(servers) @@ -71,13 +83,13 @@ describe('Test video captions', function () { const caption1: VideoCaption = res.body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') - expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt') + expect(caption1.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-ar.vtt') await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') const caption2: VideoCaption = res.body.data[1] expect(caption2.language.id).to.equal('zh') expect(caption2.language.label).to.equal('Chinese') - expect(caption2.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt') + expect(caption2.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-zh.vtt') await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.') } }) @@ -105,11 +117,56 @@ describe('Test video captions', function () { const caption1: VideoCaption = res.body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') - expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt') + expect(caption1.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-ar.vtt') await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.') } }) + it('Should replace an existing caption with a srt file and convert it', async function () { + this.timeout(30000) + + await createVideoCaption({ + url: servers[0].url, + accessToken: servers[0].accessToken, + language: 'ar', + videoId: videoUUID, + fixture: 'subtitle-good.srt' + }) + + await waitJobs(servers) + + // Cache invalidation + await wait(3000) + }) + + it('Should have this caption updated and converted', async function () { + for (const server of servers) { + const res = await listVideoCaptions(server.url, videoUUID) + expect(res.body.total).to.equal(2) + expect(res.body.data).to.have.lengthOf(2) + + const caption1: VideoCaption = res.body.data[0] + expect(caption1.language.id).to.equal('ar') + expect(caption1.language.label).to.equal('Arabic') + expect(caption1.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-ar.vtt') + + const expected = 'WEBVTT FILE\r\n' + + '\r\n' + + '1\r\n' + + '00:00:01.600 --> 00:00:04.200\r\n' + + 'English (US)\r\n' + + '\r\n' + + '2\r\n' + + '00:00:05.900 --> 00:00:07.999\r\n' + + 'This is a subtitle in American English\r\n' + + '\r\n' + + '3\r\n' + + '00:00:10.000 --> 00:00:14.000\r\n' + + 'Adding subtitles is very easy to do\r\n' + await testCaptionFile(server.url, caption1.captionPath, expected) + } + }) + it('Should remove one caption', async function () { this.timeout(30000) @@ -128,12 +185,18 @@ describe('Test video captions', function () { expect(caption.language.id).to.equal('zh') expect(caption.language.label).to.equal('Chinese') - expect(caption.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt') + expect(caption.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-zh.vtt') await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.') } }) + it('Should remove the video, and thus all video captions', async function () { + await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) + + await checkVideoFilesWereRemoved(videoUUID, 1) + }) + after(async function () { - killallServers(servers) + await cleanupTests(servers) }) })