From 6302d599cdf98b5a5363a2a1dcdc266447950191 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Feb 2021 14:08:16 +0100 Subject: Generate a name for caption files --- server/tests/api/server/services.ts | 27 ++++++++++++++------------- server/tests/api/videos/video-captions.ts | 12 +++++++----- 2 files changed, 21 insertions(+), 18 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts index 680e7a817..df910c111 100644 --- a/server/tests/api/server/services.ts +++ b/server/tests/api/server/services.ts @@ -2,24 +2,25 @@ import 'mocha' import * as chai from 'chai' +import { Video, VideoPlaylistPrivacy } from '@shared/models' import { + addVideoInPlaylist, + createVideoPlaylist, getOEmbed, getVideosList, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, - createVideoPlaylist, - addVideoInPlaylist + uploadVideo } from '../../../../shared/extra-utils' import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' -import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test services', function () { let server: ServerInfo = null let playlistUUID: string + let video: Video before(async function () { this.timeout(30000) @@ -36,7 +37,7 @@ describe('Test services', function () { await uploadVideo(server.url, server.accessToken, videoAttributes) const res = await getVideosList(server.url) - server.video = res.body.data[0] + video = res.body.data[0] } { @@ -57,23 +58,23 @@ describe('Test services', function () { token: server.accessToken, playlistId: res.body.videoPlaylist.id, elementAttrs: { - videoId: server.video.id + videoId: video.id } }) } }) it('Should have a valid oEmbed video response', async function () { - const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid + const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid const res = await getOEmbed(server.url, oembedUrl) const expectedHtml = '' - const expectedThumbnailUrl = 'http://localhost:' + server.port + '/lazy-static/previews/' + server.video.uuid + '.jpg' + const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath expect(res.body.html).to.equal(expectedHtml) - expect(res.body.title).to.equal(server.video.name) + expect(res.body.title).to.equal(video.name) expect(res.body.author_name).to.equal(server.videoChannel.displayName) expect(res.body.width).to.equal(560) expect(res.body.height).to.equal(315) @@ -101,18 +102,18 @@ describe('Test services', function () { }) it('Should have a valid oEmbed response with small max height query', async function () { - const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid + const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid const format = 'json' const maxHeight = 50 const maxWidth = 50 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth) const expectedHtml = '' expect(res.body.html).to.equal(expectedHtml) - expect(res.body.title).to.equal(server.video.name) + expect(res.body.title).to.equal(video.name) expect(res.body.author_name).to.equal(server.videoChannel.displayName) expect(res.body.height).to.equal(50) expect(res.body.width).to.equal(50) diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 5b36dc021..14ecedfa6 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -24,6 +24,8 @@ import { VideoCaption } from '../../../../shared/models/videos/caption/video-cap const expect = chai.expect describe('Test video captions', function () { + const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' + let servers: ServerInfo[] let videoUUID: string @@ -83,13 +85,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('/lazy-static/video-captions/' + videoUUID + '-ar.vtt') + expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-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('/lazy-static/video-captions/' + videoUUID + '-zh.vtt') + expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.') } }) @@ -117,7 +119,7 @@ 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('/lazy-static/video-captions/' + videoUUID + '-ar.vtt') + expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.') } }) @@ -148,7 +150,7 @@ 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('/lazy-static/video-captions/' + videoUUID + '-ar.vtt') + expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) const expected = 'WEBVTT FILE\r\n' + '\r\n' + @@ -185,7 +187,7 @@ describe('Test video captions', function () { expect(caption.language.id).to.equal('zh') expect(caption.language.label).to.equal('Chinese') - expect(caption.captionPath).to.equal('/lazy-static/video-captions/' + videoUUID + '-zh.vtt') + expect(caption.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.') } }) -- cgit v1.2.3