aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-12 19:02:00 +0200
committerChocobozzz <me@florianbigard.com>2018-07-16 11:50:08 +0200
commit40e87e9ecc54e3513fb586928330a7855eb192c6 (patch)
treeaf1111ecba85f9cd8286811ff332a67cf21be2f6 /server/tests
parentd4557fd3ecc8d4ed4fb0e5c868929bc36c959ed2 (diff)
downloadPeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.tar.gz
PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.tar.zst
PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.zip
Implement captions/subtitles
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/config.ts3
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/video-captions.ts223
-rw-r--r--server/tests/api/index-fast.ts1
-rw-r--r--server/tests/api/server/config.ts158
-rw-r--r--server/tests/api/server/follows.ts28
-rw-r--r--server/tests/api/videos/video-captions.ts139
-rw-r--r--server/tests/fixtures/subtitle-good1.vtt8
-rw-r--r--server/tests/fixtures/subtitle-good2.vtt8
-rw-r--r--server/tests/utils/miscs/miscs.ts1
-rw-r--r--server/tests/utils/videos/video-captions.ts66
11 files changed, 538 insertions, 98 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 6aa31e38d..03855237f 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -35,6 +35,9 @@ describe('Test config API validators', function () {
35 cache: { 35 cache: {
36 previews: { 36 previews: {
37 size: 2 37 size: 2
38 },
39 captions: {
40 size: 3
38 } 41 }
39 }, 42 },
40 signup: { 43 signup: {
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 4c3b372f5..c0e0302df 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -6,6 +6,7 @@ import './services'
6import './users' 6import './users'
7import './video-abuses' 7import './video-abuses'
8import './video-blacklist' 8import './video-blacklist'
9import './video-captions'
9import './video-channels' 10import './video-channels'
10import './video-comments' 11import './video-comments'
11import './videos' 12import './videos'
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
new file mode 100644
index 000000000..12f890db8
--- /dev/null
+++ b/server/tests/api/check-params/video-captions.ts
@@ -0,0 +1,223 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 createUser,
7 flushTests,
8 killallServers,
9 makeDeleteRequest,
10 makeGetRequest,
11 makeUploadRequest,
12 runServer,
13 ServerInfo,
14 setAccessTokensToServers,
15 uploadVideo,
16 userLogin
17} from '../../utils'
18import { join } from 'path'
19
20describe('Test video captions API validator', function () {
21 const path = '/api/v1/videos/'
22
23 let server: ServerInfo
24 let userAccessToken: string
25 let videoUUID: string
26
27 // ---------------------------------------------------------------
28
29 before(async function () {
30 this.timeout(30000)
31
32 await flushTests()
33
34 server = await runServer(1)
35
36 await setAccessTokensToServers([ server ])
37
38 {
39 const res = await uploadVideo(server.url, server.accessToken, {})
40 videoUUID = res.body.video.uuid
41 }
42
43 {
44 const user = {
45 username: 'user1',
46 password: 'my super password'
47 }
48 await createUser(server.url, server.accessToken, user.username, user.password)
49 userAccessToken = await userLogin(server, user)
50 }
51 })
52
53 describe('When adding video caption', function () {
54 const fields = { }
55 const attaches = {
56 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt')
57 }
58
59 it('Should fail without a valid uuid', async function () {
60 await makeUploadRequest({
61 method: 'PUT',
62 url: server.url,
63 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions',
64 token: server.accessToken,
65 fields,
66 attaches
67 })
68 })
69
70 it('Should fail with an unknown id', async function () {
71 await makeUploadRequest({
72 method: 'PUT',
73 url: server.url,
74 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
75 token: server.accessToken,
76 fields,
77 attaches
78 })
79 })
80
81 it('Should fail with a missing language in path', async function () {
82 const captionPath = path + videoUUID + '/captions'
83 await makeUploadRequest({
84 method: 'PUT',
85 url: server.url,
86 path: captionPath,
87 token: server.accessToken,
88 fields,
89 attaches
90 })
91 })
92
93 it('Should fail with an unknown language', async function () {
94 const captionPath = path + videoUUID + '/captions/15'
95 await makeUploadRequest({
96 method: 'PUT',
97 url: server.url,
98 path: captionPath,
99 token: server.accessToken,
100 fields,
101 attaches
102 })
103 })
104
105 it('Should fail without access token', async function () {
106 const captionPath = path + videoUUID + '/captions/fr'
107 await makeUploadRequest({
108 method: 'PUT',
109 url: server.url,
110 path: captionPath,
111 fields,
112 attaches,
113 statusCodeExpected: 401
114 })
115 })
116
117 it('Should fail with a bad access token', async function () {
118 const captionPath = path + videoUUID + '/captions/fr'
119 await makeUploadRequest({
120 method: 'PUT',
121 url: server.url,
122 path: captionPath,
123 token: 'blabla',
124 fields,
125 attaches,
126 statusCodeExpected: 401
127 })
128 })
129
130 it('Should success with the correct parameters', async function () {
131 const captionPath = path + videoUUID + '/captions/fr'
132 await makeUploadRequest({
133 method: 'PUT',
134 url: server.url,
135 path: captionPath,
136 token: server.accessToken,
137 fields,
138 attaches,
139 statusCodeExpected: 204
140 })
141 })
142 })
143
144 describe('When listing video captions', function () {
145 it('Should fail without a valid uuid', async function () {
146 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
147 })
148
149 it('Should fail with an unknown id', async function () {
150 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 })
151 })
152
153 it('Should success with the correct parameters', async function () {
154 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 })
155 })
156 })
157
158 describe('When deleting video caption', function () {
159 it('Should fail without a valid uuid', async function () {
160 await makeDeleteRequest({
161 url: server.url,
162 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
163 token: server.accessToken
164 })
165 })
166
167 it('Should fail with an unknown id', async function () {
168 await makeDeleteRequest({
169 url: server.url,
170 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
171 token: server.accessToken,
172 statusCodeExpected: 404
173 })
174 })
175
176 it('Should fail with an invalid language', async function () {
177 await makeDeleteRequest({
178 url: server.url,
179 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
180 token: server.accessToken
181 })
182 })
183
184 it('Should fail with a missing language', async function () {
185 const captionPath = path + videoUUID + '/captions'
186 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
187 })
188
189 it('Should fail with an unknown language', async function () {
190 const captionPath = path + videoUUID + '/captions/15'
191 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
192 })
193
194 it('Should fail without access token', async function () {
195 const captionPath = path + videoUUID + '/captions/fr'
196 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 })
197 })
198
199 it('Should fail with a bad access token', async function () {
200 const captionPath = path + videoUUID + '/captions/fr'
201 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 })
202 })
203
204 it('Should fail with another user', async function () {
205 const captionPath = path + videoUUID + '/captions/fr'
206 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 })
207 })
208
209 it('Should success with the correct parameters', async function () {
210 const captionPath = path + videoUUID + '/captions/fr'
211 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 })
212 })
213 })
214
215 after(async function () {
216 killallServers([ server ])
217
218 // Keep the logs if the test failed
219 if (this['ok']) {
220 await flushTests()
221 }
222 })
223})
diff --git a/server/tests/api/index-fast.ts b/server/tests/api/index-fast.ts
index 2454ec2f9..d530dfc06 100644
--- a/server/tests/api/index-fast.ts
+++ b/server/tests/api/index-fast.ts
@@ -4,6 +4,7 @@ import './check-params'
4import './users/users' 4import './users/users'
5import './videos/single-server' 5import './videos/single-server'
6import './videos/video-abuse' 6import './videos/video-abuse'
7import './videos/video-captions'
7import './videos/video-blacklist' 8import './videos/video-blacklist'
8import './videos/video-blacklist-management' 9import './videos/video-blacklist-management'
9import './videos/video-description' 10import './videos/video-description'
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 4de0d6b10..79b5aaf2d 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -14,6 +14,61 @@ import {
14 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig 14 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
15} from '../../utils/index' 15} from '../../utils/index'
16 16
17function checkInitialConfig (data: CustomConfig) {
18 expect(data.instance.name).to.equal('PeerTube')
19 expect(data.instance.shortDescription).to.equal(
20 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
21 'with WebTorrent and Angular.'
22 )
23 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
24 expect(data.instance.terms).to.equal('No terms for now.')
25 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
26 expect(data.instance.defaultNSFWPolicy).to.equal('display')
27 expect(data.instance.customizations.css).to.be.empty
28 expect(data.instance.customizations.javascript).to.be.empty
29 expect(data.services.twitter.username).to.equal('@Chocobozzz')
30 expect(data.services.twitter.whitelisted).to.be.false
31 expect(data.cache.previews.size).to.equal(1)
32 expect(data.cache.captions.size).to.equal(1)
33 expect(data.signup.enabled).to.be.true
34 expect(data.signup.limit).to.equal(4)
35 expect(data.admin.email).to.equal('admin1@example.com')
36 expect(data.user.videoQuota).to.equal(5242880)
37 expect(data.transcoding.enabled).to.be.false
38 expect(data.transcoding.threads).to.equal(2)
39 expect(data.transcoding.resolutions['240p']).to.be.true
40 expect(data.transcoding.resolutions['360p']).to.be.true
41 expect(data.transcoding.resolutions['480p']).to.be.true
42 expect(data.transcoding.resolutions['720p']).to.be.true
43 expect(data.transcoding.resolutions['1080p']).to.be.true
44}
45
46function checkUpdatedConfig (data: CustomConfig) {
47 expect(data.instance.name).to.equal('PeerTube updated')
48 expect(data.instance.shortDescription).to.equal('my short description')
49 expect(data.instance.description).to.equal('my super description')
50 expect(data.instance.terms).to.equal('my super terms')
51 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
52 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
53 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
54 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
55 expect(data.services.twitter.username).to.equal('@Kuja')
56 expect(data.services.twitter.whitelisted).to.be.true
57 expect(data.cache.previews.size).to.equal(2)
58 expect(data.cache.captions.size).to.equal(3)
59 expect(data.signup.enabled).to.be.false
60 expect(data.signup.limit).to.equal(5)
61 expect(data.admin.email).to.equal('superadmin1@example.com')
62 expect(data.user.videoQuota).to.equal(5242881)
63 expect(data.transcoding.enabled).to.be.true
64 expect(data.transcoding.threads).to.equal(1)
65 expect(data.transcoding.resolutions['240p']).to.be.false
66 expect(data.transcoding.resolutions['360p']).to.be.true
67 expect(data.transcoding.resolutions['480p']).to.be.true
68 expect(data.transcoding.resolutions['720p']).to.be.false
69 expect(data.transcoding.resolutions['1080p']).to.be.false
70}
71
17describe('Test config', function () { 72describe('Test config', function () {
18 let server = null 73 let server = null
19 74
@@ -51,35 +106,11 @@ describe('Test config', function () {
51 const res = await getCustomConfig(server.url, server.accessToken) 106 const res = await getCustomConfig(server.url, server.accessToken)
52 const data = res.body as CustomConfig 107 const data = res.body as CustomConfig
53 108
54 expect(data.instance.name).to.equal('PeerTube') 109 checkInitialConfig(data)
55 expect(data.instance.shortDescription).to.equal(
56 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
57 'with WebTorrent and Angular.'
58 )
59 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
60 expect(data.instance.terms).to.equal('No terms for now.')
61 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
62 expect(data.instance.defaultNSFWPolicy).to.equal('display')
63 expect(data.instance.customizations.css).to.be.empty
64 expect(data.instance.customizations.javascript).to.be.empty
65 expect(data.services.twitter.username).to.equal('@Chocobozzz')
66 expect(data.services.twitter.whitelisted).to.be.false
67 expect(data.cache.previews.size).to.equal(1)
68 expect(data.signup.enabled).to.be.true
69 expect(data.signup.limit).to.equal(4)
70 expect(data.admin.email).to.equal('admin1@example.com')
71 expect(data.user.videoQuota).to.equal(5242880)
72 expect(data.transcoding.enabled).to.be.false
73 expect(data.transcoding.threads).to.equal(2)
74 expect(data.transcoding.resolutions['240p']).to.be.true
75 expect(data.transcoding.resolutions['360p']).to.be.true
76 expect(data.transcoding.resolutions['480p']).to.be.true
77 expect(data.transcoding.resolutions['720p']).to.be.true
78 expect(data.transcoding.resolutions['1080p']).to.be.true
79 }) 110 })
80 111
81 it('Should update the customized configuration', async function () { 112 it('Should update the customized configuration', async function () {
82 const newCustomConfig = { 113 const newCustomConfig: CustomConfig = {
83 instance: { 114 instance: {
84 name: 'PeerTube updated', 115 name: 'PeerTube updated',
85 shortDescription: 'my short description', 116 shortDescription: 'my short description',
@@ -101,6 +132,9 @@ describe('Test config', function () {
101 cache: { 132 cache: {
102 previews: { 133 previews: {
103 size: 2 134 size: 2
135 },
136 captions: {
137 size: 3
104 } 138 }
105 }, 139 },
106 signup: { 140 signup: {
@@ -130,28 +164,7 @@ describe('Test config', function () {
130 const res = await getCustomConfig(server.url, server.accessToken) 164 const res = await getCustomConfig(server.url, server.accessToken)
131 const data = res.body 165 const data = res.body
132 166
133 expect(data.instance.name).to.equal('PeerTube updated') 167 checkUpdatedConfig(data)
134 expect(data.instance.shortDescription).to.equal('my short description')
135 expect(data.instance.description).to.equal('my super description')
136 expect(data.instance.terms).to.equal('my super terms')
137 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
138 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
139 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
140 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
141 expect(data.services.twitter.username).to.equal('@Kuja')
142 expect(data.services.twitter.whitelisted).to.be.true
143 expect(data.cache.previews.size).to.equal(2)
144 expect(data.signup.enabled).to.be.false
145 expect(data.signup.limit).to.equal(5)
146 expect(data.admin.email).to.equal('superadmin1@example.com')
147 expect(data.user.videoQuota).to.equal(5242881)
148 expect(data.transcoding.enabled).to.be.true
149 expect(data.transcoding.threads).to.equal(1)
150 expect(data.transcoding.resolutions['240p']).to.be.false
151 expect(data.transcoding.resolutions['360p']).to.be.true
152 expect(data.transcoding.resolutions['480p']).to.be.true
153 expect(data.transcoding.resolutions['720p']).to.be.false
154 expect(data.transcoding.resolutions['1080p']).to.be.false
155 }) 168 })
156 169
157 it('Should have the configuration updated after a restart', async function () { 170 it('Should have the configuration updated after a restart', async function () {
@@ -164,28 +177,7 @@ describe('Test config', function () {
164 const res = await getCustomConfig(server.url, server.accessToken) 177 const res = await getCustomConfig(server.url, server.accessToken)
165 const data = res.body 178 const data = res.body
166 179
167 expect(data.instance.name).to.equal('PeerTube updated') 180 checkUpdatedConfig(data)
168 expect(data.instance.shortDescription).to.equal('my short description')
169 expect(data.instance.description).to.equal('my super description')
170 expect(data.instance.terms).to.equal('my super terms')
171 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
172 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
173 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
174 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
175 expect(data.services.twitter.username).to.equal('@Kuja')
176 expect(data.services.twitter.whitelisted).to.be.true
177 expect(data.cache.previews.size).to.equal(2)
178 expect(data.signup.enabled).to.be.false
179 expect(data.signup.limit).to.equal(5)
180 expect(data.admin.email).to.equal('superadmin1@example.com')
181 expect(data.user.videoQuota).to.equal(5242881)
182 expect(data.transcoding.enabled).to.be.true
183 expect(data.transcoding.threads).to.equal(1)
184 expect(data.transcoding.resolutions['240p']).to.be.false
185 expect(data.transcoding.resolutions['360p']).to.be.true
186 expect(data.transcoding.resolutions['480p']).to.be.true
187 expect(data.transcoding.resolutions['720p']).to.be.false
188 expect(data.transcoding.resolutions['1080p']).to.be.false
189 }) 181 })
190 182
191 it('Should fetch the about information', async function () { 183 it('Should fetch the about information', async function () {
@@ -206,31 +198,7 @@ describe('Test config', function () {
206 const res = await getCustomConfig(server.url, server.accessToken) 198 const res = await getCustomConfig(server.url, server.accessToken)
207 const data = res.body 199 const data = res.body
208 200
209 expect(data.instance.name).to.equal('PeerTube') 201 checkInitialConfig(data)
210 expect(data.instance.shortDescription).to.equal(
211 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
212 'with WebTorrent and Angular.'
213 )
214 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
215 expect(data.instance.terms).to.equal('No terms for now.')
216 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
217 expect(data.instance.defaultNSFWPolicy).to.equal('display')
218 expect(data.instance.customizations.css).to.be.empty
219 expect(data.instance.customizations.javascript).to.be.empty
220 expect(data.services.twitter.username).to.equal('@Chocobozzz')
221 expect(data.services.twitter.whitelisted).to.be.false
222 expect(data.cache.previews.size).to.equal(1)
223 expect(data.signup.enabled).to.be.true
224 expect(data.signup.limit).to.equal(4)
225 expect(data.admin.email).to.equal('admin1@example.com')
226 expect(data.user.videoQuota).to.equal(5242880)
227 expect(data.transcoding.enabled).to.be.false
228 expect(data.transcoding.threads).to.equal(2)
229 expect(data.transcoding.resolutions['240p']).to.be.true
230 expect(data.transcoding.resolutions['360p']).to.be.true
231 expect(data.transcoding.resolutions['480p']).to.be.true
232 expect(data.transcoding.resolutions['720p']).to.be.true
233 expect(data.transcoding.resolutions['1080p']).to.be.true
234 }) 202 })
235 203
236 after(async function () { 204 after(async function () {
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index ce42df0a6..a19b47509 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -26,6 +26,8 @@ import {
26} from '../../utils/videos/video-comments' 26} from '../../utils/videos/video-comments'
27import { rateVideo } from '../../utils/videos/videos' 27import { rateVideo } from '../../utils/videos/videos'
28import { waitJobs } from '../../utils/server/jobs' 28import { waitJobs } from '../../utils/server/jobs'
29import { createVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions'
30import { VideoCaption } from '../../../../shared/models/videos/video-caption.model'
29 31
30const expect = chai.expect 32const expect = chai.expect
31 33
@@ -244,6 +246,16 @@ describe('Test follows', function () {
244 const text3 = 'my second answer to thread 1' 246 const text3 = 'my second answer to thread 1'
245 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3) 247 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3)
246 } 248 }
249
250 {
251 await createVideoCaption({
252 url: servers[2].url,
253 accessToken: servers[2].accessToken,
254 language: 'ar',
255 videoId: video4.id,
256 fixture: 'subtitle-good2.vtt'
257 })
258 }
247 } 259 }
248 260
249 await waitJobs(servers) 261 await waitJobs(servers)
@@ -266,7 +278,7 @@ describe('Test follows', function () {
266 await expectAccountFollows(servers[2].url, 'peertube@localhost:9003', 1, 0) 278 await expectAccountFollows(servers[2].url, 'peertube@localhost:9003', 1, 0)
267 }) 279 })
268 280
269 it('Should propagate videos', async function () { 281 it('Should have propagated videos', async function () {
270 const res = await getVideosList(servers[ 0 ].url) 282 const res = await getVideosList(servers[ 0 ].url)
271 expect(res.body.total).to.equal(7) 283 expect(res.body.total).to.equal(7)
272 284
@@ -314,7 +326,7 @@ describe('Test follows', function () {
314 await completeVideoCheck(servers[ 0 ].url, video4, checkAttributes) 326 await completeVideoCheck(servers[ 0 ].url, video4, checkAttributes)
315 }) 327 })
316 328
317 it('Should propagate comments', async function () { 329 it('Should have propagated comments', async function () {
318 const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5) 330 const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5)
319 331
320 expect(res1.body.total).to.equal(1) 332 expect(res1.body.total).to.equal(1)
@@ -353,6 +365,18 @@ describe('Test follows', function () {
353 expect(secondChild.children).to.have.lengthOf(0) 365 expect(secondChild.children).to.have.lengthOf(0)
354 }) 366 })
355 367
368 it('Should have propagated captions', async function () {
369 const res = await listVideoCaptions(servers[0].url, video4.id)
370 expect(res.body.total).to.equal(1)
371 expect(res.body.data).to.have.lengthOf(1)
372
373 const caption1: VideoCaption = res.body.data[0]
374 expect(caption1.language.id).to.equal('ar')
375 expect(caption1.language.label).to.equal('Arabic')
376 expect(caption1.captionPath).to.equal('/static/video-captions/' + video4.uuid + '-ar.vtt')
377 await testCaptionFile(servers[0].url, caption1.captionPath, 'Subtitle good 2.')
378 })
379
356 it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () { 380 it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () {
357 this.timeout(5000) 381 this.timeout(5000)
358 382
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
new file mode 100644
index 000000000..cbf5268f0
--- /dev/null
+++ b/server/tests/api/videos/video-captions.ts
@@ -0,0 +1,139 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { doubleFollow, flushAndRunMultipleServers, uploadVideo } from '../../utils'
6import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
7import { waitJobs } from '../../utils/server/jobs'
8import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions'
9import { VideoCaption } from '../../../../shared/models/videos/video-caption.model'
10
11const expect = chai.expect
12
13describe('Test video captions', function () {
14 let servers: ServerInfo[]
15 let videoUUID: string
16
17 before(async function () {
18 this.timeout(30000)
19
20 await flushTests()
21
22 servers = await flushAndRunMultipleServers(2)
23
24 await setAccessTokensToServers(servers)
25 await doubleFollow(servers[0], servers[1])
26
27 await waitJobs(servers)
28
29 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name' })
30 videoUUID = res.body.video.uuid
31
32 await waitJobs(servers)
33 })
34
35 it('Should list the captions and return an empty list', async function () {
36 for (const server of servers) {
37 const res = await listVideoCaptions(server.url, videoUUID)
38 expect(res.body.total).to.equal(0)
39 expect(res.body.data).to.have.lengthOf(0)
40 }
41 })
42
43 it('Should create two new captions', async function () {
44 this.timeout(30000)
45
46 await createVideoCaption({
47 url: servers[0].url,
48 accessToken: servers[0].accessToken,
49 language: 'ar',
50 videoId: videoUUID,
51 fixture: 'subtitle-good1.vtt'
52 })
53
54 await createVideoCaption({
55 url: servers[0].url,
56 accessToken: servers[0].accessToken,
57 language: 'zh',
58 videoId: videoUUID,
59 fixture: 'subtitle-good2.vtt'
60 })
61
62 await waitJobs(servers)
63 })
64
65 it('Should list these uploaded captions', async function () {
66 for (const server of servers) {
67 const res = await listVideoCaptions(server.url, videoUUID)
68 expect(res.body.total).to.equal(2)
69 expect(res.body.data).to.have.lengthOf(2)
70
71 const caption1: VideoCaption = res.body.data[0]
72 expect(caption1.language.id).to.equal('ar')
73 expect(caption1.language.label).to.equal('Arabic')
74 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
75 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
76
77 const caption2: VideoCaption = res.body.data[1]
78 expect(caption2.language.id).to.equal('zh')
79 expect(caption2.language.label).to.equal('Chinese')
80 expect(caption2.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
81 await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.')
82 }
83 })
84
85 it('Should replace an existing caption', async function () {
86 this.timeout(30000)
87
88 await createVideoCaption({
89 url: servers[0].url,
90 accessToken: servers[0].accessToken,
91 language: 'ar',
92 videoId: videoUUID,
93 fixture: 'subtitle-good2.vtt'
94 })
95
96 await waitJobs(servers)
97 })
98
99 it('Should have this caption updated', async function () {
100 for (const server of servers) {
101 const res = await listVideoCaptions(server.url, videoUUID)
102 expect(res.body.total).to.equal(2)
103 expect(res.body.data).to.have.lengthOf(2)
104
105 const caption1: VideoCaption = res.body.data[0]
106 expect(caption1.language.id).to.equal('ar')
107 expect(caption1.language.label).to.equal('Arabic')
108 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
109 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.')
110 }
111 })
112
113 it('Should remove one caption', async function () {
114 this.timeout(30000)
115
116 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar')
117
118 await waitJobs(servers)
119 })
120
121 it('Should only list the caption that was not deleted', async function () {
122 for (const server of servers) {
123 const res = await listVideoCaptions(server.url, videoUUID)
124 expect(res.body.total).to.equal(1)
125 expect(res.body.data).to.have.lengthOf(1)
126
127 const caption: VideoCaption = res.body.data[0]
128
129 expect(caption.language.id).to.equal('zh')
130 expect(caption.language.label).to.equal('Chinese')
131 expect(caption.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
132 await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
133 }
134 })
135
136 after(async function () {
137 killallServers(servers)
138 })
139})
diff --git a/server/tests/fixtures/subtitle-good1.vtt b/server/tests/fixtures/subtitle-good1.vtt
new file mode 100644
index 000000000..04cd23946
--- /dev/null
+++ b/server/tests/fixtures/subtitle-good1.vtt
@@ -0,0 +1,8 @@
1WEBVTT
2
300:01.000 --> 00:04.000
4Subtitle good 1.
5
600:05.000 --> 00:09.000
7- It will perforate your stomach.
8- You could die. \ No newline at end of file
diff --git a/server/tests/fixtures/subtitle-good2.vtt b/server/tests/fixtures/subtitle-good2.vtt
new file mode 100644
index 000000000..4d3256def
--- /dev/null
+++ b/server/tests/fixtures/subtitle-good2.vtt
@@ -0,0 +1,8 @@
1WEBVTT
2
300:01.000 --> 00:04.000
4Subtitle good 2.
5
600:05.000 --> 00:09.000
7- It will perforate your stomach.
8- You could die. \ No newline at end of file
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index 7ac60a983..5e46004a7 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -5,7 +5,6 @@ import { isAbsolute, join } from 'path'
5import * as request from 'supertest' 5import * as request from 'supertest'
6import * as WebTorrent from 'webtorrent' 6import * as WebTorrent from 'webtorrent'
7import { readFileBufferPromise } from '../../../helpers/core-utils' 7import { readFileBufferPromise } from '../../../helpers/core-utils'
8import { ServerInfo } from '..'
9 8
10const expect = chai.expect 9const expect = chai.expect
11let webtorrent = new WebTorrent() 10let webtorrent = new WebTorrent()
diff --git a/server/tests/utils/videos/video-captions.ts b/server/tests/utils/videos/video-captions.ts
new file mode 100644
index 000000000..207e89632
--- /dev/null
+++ b/server/tests/utils/videos/video-captions.ts
@@ -0,0 +1,66 @@
1import { makeDeleteRequest, makeGetRequest } from '../'
2import { buildAbsoluteFixturePath, makeUploadRequest } from '../index'
3import * as request from 'supertest'
4import * as chai from 'chai'
5
6const expect = chai.expect
7
8function createVideoCaption (args: {
9 url: string,
10 accessToken: string
11 videoId: string | number
12 language: string
13 fixture: string
14}) {
15 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
16
17 return makeUploadRequest({
18 method: 'PUT',
19 url: args.url,
20 path,
21 token: args.accessToken,
22 fields: {},
23 attaches: {
24 captionfile: buildAbsoluteFixturePath(args.fixture)
25 },
26 statusCodeExpected: 204
27 })
28}
29
30function listVideoCaptions (url: string, videoId: string | number) {
31 const path = '/api/v1/videos/' + videoId + '/captions'
32
33 return makeGetRequest({
34 url,
35 path,
36 statusCodeExpected: 200
37 })
38}
39
40function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
41 const path = '/api/v1/videos/' + videoId + '/captions/' + language
42
43 return makeDeleteRequest({
44 url,
45 token,
46 path,
47 statusCodeExpected: 204
48 })
49}
50
51async function testCaptionFile (url: string, captionPath: string, containsString: string) {
52 const res = await request(url)
53 .get(captionPath)
54 .expect(200)
55
56 expect(res.text).to.contain(containsString)
57}
58
59// ---------------------------------------------------------------------------
60
61export {
62 createVideoCaption,
63 listVideoCaptions,
64 testCaptionFile,
65 deleteVideoCaption
66}