aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/video-captions.ts35
-rw-r--r--server/tests/api/videos/video-captions.ts53
-rw-r--r--server/tests/fixtures/subtitle-bad.txt11
-rw-r--r--server/tests/fixtures/subtitle-good.srt11
-rw-r--r--server/tests/utils/videos/videos.ts2
5 files changed, 109 insertions, 3 deletions
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index 12f890db8..a3d7ac35d 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -1,6 +1,5 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { 4import {
6 createUser, 5 createUser,
@@ -127,6 +126,40 @@ describe('Test video captions API validator', function () {
127 }) 126 })
128 }) 127 })
129 128
129 it('Should fail with an invalid captionfile extension', async function () {
130 const attaches = {
131 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
132 }
133
134 const captionPath = path + videoUUID + '/captions/fr'
135 await makeUploadRequest({
136 method: 'PUT',
137 url: server.url,
138 path: captionPath,
139 token: server.accessToken,
140 fields,
141 attaches,
142 statusCodeExpected: 400
143 })
144 })
145
146 // it('Should fail with an invalid captionfile srt', async function () {
147 // const attaches = {
148 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
149 // }
150 //
151 // const captionPath = path + videoUUID + '/captions/fr'
152 // await makeUploadRequest({
153 // method: 'PUT',
154 // url: server.url,
155 // path: captionPath,
156 // token: server.accessToken,
157 // fields,
158 // attaches,
159 // statusCodeExpected: 500
160 // })
161 // })
162
130 it('Should success with the correct parameters', async function () { 163 it('Should success with the correct parameters', async function () {
131 const captionPath = path + videoUUID + '/captions/fr' 164 const captionPath = path + videoUUID + '/captions/fr'
132 await makeUploadRequest({ 165 await makeUploadRequest({
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index cbf5268f0..eb73c5baf 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -2,7 +2,7 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { doubleFollow, flushAndRunMultipleServers, uploadVideo } from '../../utils' 5import { checkVideoFilesWereRemoved, doubleFollow, flushAndRunMultipleServers, removeVideo, uploadVideo, wait } from '../../utils'
6import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index' 6import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
7import { waitJobs } from '../../utils/server/jobs' 7import { waitJobs } from '../../utils/server/jobs'
8import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions' 8import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions'
@@ -110,6 +110,51 @@ describe('Test video captions', function () {
110 } 110 }
111 }) 111 })
112 112
113 it('Should replace an existing caption with a srt file and convert it', async function () {
114 this.timeout(30000)
115
116 await createVideoCaption({
117 url: servers[0].url,
118 accessToken: servers[0].accessToken,
119 language: 'ar',
120 videoId: videoUUID,
121 fixture: 'subtitle-good.srt'
122 })
123
124 await waitJobs(servers)
125
126 // Cache invalidation
127 await wait(3000)
128 })
129
130 it('Should have this caption updated and converted', async function () {
131 for (const server of servers) {
132 const res = await listVideoCaptions(server.url, videoUUID)
133 expect(res.body.total).to.equal(2)
134 expect(res.body.data).to.have.lengthOf(2)
135
136 const caption1: VideoCaption = res.body.data[0]
137 expect(caption1.language.id).to.equal('ar')
138 expect(caption1.language.label).to.equal('Arabic')
139 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
140
141 const expected = 'WEBVTT FILE\r\n' +
142 '\r\n' +
143 '1\r\n' +
144 '00:00:01.600 --> 00:00:04.200\r\n' +
145 'English (US)\r\n' +
146 '\r\n' +
147 '2\r\n' +
148 '00:00:05.900 --> 00:00:07.999\r\n' +
149 'This is a subtitle in American English\r\n' +
150 '\r\n' +
151 '3\r\n' +
152 '00:00:10.000 --> 00:00:14.000\r\n' +
153 'Adding subtitles is very easy to do\r\n'
154 await testCaptionFile(server.url, caption1.captionPath, expected)
155 }
156 })
157
113 it('Should remove one caption', async function () { 158 it('Should remove one caption', async function () {
114 this.timeout(30000) 159 this.timeout(30000)
115 160
@@ -133,6 +178,12 @@ describe('Test video captions', function () {
133 } 178 }
134 }) 179 })
135 180
181 it('Should remove the video, and thus all video captions', async function () {
182 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
183
184 await checkVideoFilesWereRemoved(videoUUID, 1)
185 })
186
136 after(async function () { 187 after(async function () {
137 killallServers(servers) 188 killallServers(servers)
138 }) 189 })
diff --git a/server/tests/fixtures/subtitle-bad.txt b/server/tests/fixtures/subtitle-bad.txt
new file mode 100644
index 000000000..a2a30ae47
--- /dev/null
+++ b/server/tests/fixtures/subtitle-bad.txt
@@ -0,0 +1,11 @@
11
200:00:01,600 --> 00:00:04,200
3English (US)
4
52
600:00:05,900 --> 00:00:07,999
7This is a subtitle in American English
8
93
1000:00:10,000 --> 00:00:14,000
11Adding subtitles is very easy to do \ No newline at end of file
diff --git a/server/tests/fixtures/subtitle-good.srt b/server/tests/fixtures/subtitle-good.srt
new file mode 100644
index 000000000..a2a30ae47
--- /dev/null
+++ b/server/tests/fixtures/subtitle-good.srt
@@ -0,0 +1,11 @@
11
200:00:01,600 --> 00:00:04,200
3English (US)
4
52
600:00:05,900 --> 00:00:07,999
7This is a subtitle in American English
8
93
1000:00:10,000 --> 00:00:14,000
11Adding subtitles is very easy to do \ No newline at end of file
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 4f7ce6d6b..74bf7354e 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -301,7 +301,7 @@ function searchVideoWithSort (url: string, search: string, sort: string) {
301async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) { 301async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) {
302 const testDirectory = 'test' + serverNumber 302 const testDirectory = 'test' + serverNumber
303 303
304 for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews' ]) { 304 for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]) {
305 const directoryPath = join(root(), testDirectory, directory) 305 const directoryPath = join(root(), testDirectory, directory)
306 306
307 const directoryExists = existsSync(directoryPath) 307 const directoryExists = existsSync(directoryPath)