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.ts26
-rw-r--r--server/tests/api/videos/video-captions.ts3
-rw-r--r--server/tests/utils/requests/requests.ts8
-rw-r--r--server/tests/utils/videos/video-captions.ts11
4 files changed, 42 insertions, 6 deletions
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index a3d7ac35d..8d46971a1 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -15,6 +15,7 @@ import {
15 userLogin 15 userLogin
16} from '../../utils' 16} from '../../utils'
17import { join } from 'path' 17import { join } from 'path'
18import { createVideoCaption } from '../../utils/videos/video-captions'
18 19
19describe('Test video captions API validator', function () { 20describe('Test video captions API validator', function () {
20 const path = '/api/v1/videos/' 21 const path = '/api/v1/videos/'
@@ -143,6 +144,31 @@ describe('Test video captions API validator', function () {
143 }) 144 })
144 }) 145 })
145 146
147 // We don't check the extension yet
148 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
149 // await createVideoCaption({
150 // url: server.url,
151 // accessToken: server.accessToken,
152 // language: 'zh',
153 // videoId: videoUUID,
154 // fixture: 'subtitle-bad.txt',
155 // mimeType: 'application/octet-stream',
156 // statusCodeExpected: 400
157 // })
158 // })
159
160 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
161 await createVideoCaption({
162 url: server.url,
163 accessToken: server.accessToken,
164 language: 'zh',
165 videoId: videoUUID,
166 fixture: 'subtitle-good.srt',
167 mimeType: 'application/octet-stream'
168 })
169 })
170
171 // We don't check the file validity yet
146 // it('Should fail with an invalid captionfile srt', async function () { 172 // it('Should fail with an invalid captionfile srt', async function () {
147 // const attaches = { 173 // const attaches = {
148 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt') 174 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index eb73c5baf..ba9ebbdd6 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -56,7 +56,8 @@ describe('Test video captions', function () {
56 accessToken: servers[0].accessToken, 56 accessToken: servers[0].accessToken,
57 language: 'zh', 57 language: 'zh',
58 videoId: videoUUID, 58 videoId: videoUUID,
59 fixture: 'subtitle-good2.vtt' 59 fixture: 'subtitle-good2.vtt',
60 mimeType: 'application/octet-stream'
60 }) 61 })
61 62
62 await waitJobs(servers) 63 await waitJobs(servers)
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts
index b88b3ce5b..fc7b38b8c 100644
--- a/server/tests/utils/requests/requests.ts
+++ b/server/tests/utils/requests/requests.ts
@@ -48,7 +48,7 @@ function makeUploadRequest (options: {
48 path: string, 48 path: string,
49 token?: string, 49 token?: string,
50 fields: { [ fieldName: string ]: any }, 50 fields: { [ fieldName: string ]: any },
51 attaches: { [ attachName: string ]: any }, 51 attaches: { [ attachName: string ]: any | any[] },
52 statusCodeExpected?: number 52 statusCodeExpected?: number
53}) { 53}) {
54 if (!options.statusCodeExpected) options.statusCodeExpected = 400 54 if (!options.statusCodeExpected) options.statusCodeExpected = 400
@@ -78,7 +78,11 @@ function makeUploadRequest (options: {
78 78
79 Object.keys(options.attaches).forEach(attach => { 79 Object.keys(options.attaches).forEach(attach => {
80 const value = options.attaches[attach] 80 const value = options.attaches[attach]
81 req.attach(attach, buildAbsoluteFixturePath(value)) 81 if (Array.isArray(value)) {
82 req.attach(attach, buildAbsoluteFixturePath(value[0]), value[1])
83 } else {
84 req.attach(attach, buildAbsoluteFixturePath(value))
85 }
82 }) 86 })
83 87
84 return req.expect(options.statusCodeExpected) 88 return req.expect(options.statusCodeExpected)
diff --git a/server/tests/utils/videos/video-captions.ts b/server/tests/utils/videos/video-captions.ts
index 207e89632..41e52be07 100644
--- a/server/tests/utils/videos/video-captions.ts
+++ b/server/tests/utils/videos/video-captions.ts
@@ -10,10 +10,15 @@ function createVideoCaption (args: {
10 accessToken: string 10 accessToken: string
11 videoId: string | number 11 videoId: string | number
12 language: string 12 language: string
13 fixture: string 13 fixture: string,
14 mimeType?: string,
15 statusCodeExpected?: number
14}) { 16}) {
15 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language 17 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
16 18
19 const captionfile = buildAbsoluteFixturePath(args.fixture)
20 const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
21
17 return makeUploadRequest({ 22 return makeUploadRequest({
18 method: 'PUT', 23 method: 'PUT',
19 url: args.url, 24 url: args.url,
@@ -21,9 +26,9 @@ function createVideoCaption (args: {
21 token: args.accessToken, 26 token: args.accessToken,
22 fields: {}, 27 fields: {},
23 attaches: { 28 attaches: {
24 captionfile: buildAbsoluteFixturePath(args.fixture) 29 captionfile: captionfileAttach
25 }, 30 },
26 statusCodeExpected: 204 31 statusCodeExpected: args.statusCodeExpected || 204
27 }) 32 })
28} 33}
29 34