diff options
Diffstat (limited to 'server/tests/api/check-params/video-captions.ts')
-rw-r--r-- | server/tests/api/check-params/video-captions.ts | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 2f049c03d..c0595c04d 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts | |||
@@ -1,7 +1,10 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { VideoCreateResult } from '@shared/models' | ||
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
4 | import { | 6 | import { |
7 | buildAbsoluteFixturePath, | ||
5 | cleanupTests, | 8 | cleanupTests, |
6 | createUser, | 9 | createUser, |
7 | flushAndRunServer, | 10 | flushAndRunServer, |
@@ -13,16 +16,14 @@ import { | |||
13 | uploadVideo, | 16 | uploadVideo, |
14 | userLogin | 17 | userLogin |
15 | } from '../../../../shared/extra-utils' | 18 | } from '../../../../shared/extra-utils' |
16 | import { join } from 'path' | ||
17 | import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' | 19 | import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' |
18 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
19 | 20 | ||
20 | describe('Test video captions API validator', function () { | 21 | describe('Test video captions API validator', function () { |
21 | const path = '/api/v1/videos/' | 22 | const path = '/api/v1/videos/' |
22 | 23 | ||
23 | let server: ServerInfo | 24 | let server: ServerInfo |
24 | let userAccessToken: string | 25 | let userAccessToken: string |
25 | let videoUUID: string | 26 | let video: VideoCreateResult |
26 | 27 | ||
27 | // --------------------------------------------------------------- | 28 | // --------------------------------------------------------------- |
28 | 29 | ||
@@ -35,7 +36,7 @@ describe('Test video captions API validator', function () { | |||
35 | 36 | ||
36 | { | 37 | { |
37 | const res = await uploadVideo(server.url, server.accessToken, {}) | 38 | const res = await uploadVideo(server.url, server.accessToken, {}) |
38 | videoUUID = res.body.video.uuid | 39 | video = res.body.video |
39 | } | 40 | } |
40 | 41 | ||
41 | { | 42 | { |
@@ -51,7 +52,7 @@ describe('Test video captions API validator', function () { | |||
51 | describe('When adding video caption', function () { | 52 | describe('When adding video caption', function () { |
52 | const fields = { } | 53 | const fields = { } |
53 | const attaches = { | 54 | const attaches = { |
54 | captionfile: join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt') | 55 | captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt') |
55 | } | 56 | } |
56 | 57 | ||
57 | it('Should fail without a valid uuid', async function () { | 58 | it('Should fail without a valid uuid', async function () { |
@@ -78,7 +79,7 @@ describe('Test video captions API validator', function () { | |||
78 | }) | 79 | }) |
79 | 80 | ||
80 | it('Should fail with a missing language in path', async function () { | 81 | it('Should fail with a missing language in path', async function () { |
81 | const captionPath = path + videoUUID + '/captions' | 82 | const captionPath = path + video.uuid + '/captions' |
82 | await makeUploadRequest({ | 83 | await makeUploadRequest({ |
83 | method: 'PUT', | 84 | method: 'PUT', |
84 | url: server.url, | 85 | url: server.url, |
@@ -90,7 +91,7 @@ describe('Test video captions API validator', function () { | |||
90 | }) | 91 | }) |
91 | 92 | ||
92 | it('Should fail with an unknown language', async function () { | 93 | it('Should fail with an unknown language', async function () { |
93 | const captionPath = path + videoUUID + '/captions/15' | 94 | const captionPath = path + video.uuid + '/captions/15' |
94 | await makeUploadRequest({ | 95 | await makeUploadRequest({ |
95 | method: 'PUT', | 96 | method: 'PUT', |
96 | url: server.url, | 97 | url: server.url, |
@@ -102,7 +103,7 @@ describe('Test video captions API validator', function () { | |||
102 | }) | 103 | }) |
103 | 104 | ||
104 | it('Should fail without access token', async function () { | 105 | it('Should fail without access token', async function () { |
105 | const captionPath = path + videoUUID + '/captions/fr' | 106 | const captionPath = path + video.uuid + '/captions/fr' |
106 | await makeUploadRequest({ | 107 | await makeUploadRequest({ |
107 | method: 'PUT', | 108 | method: 'PUT', |
108 | url: server.url, | 109 | url: server.url, |
@@ -114,7 +115,7 @@ describe('Test video captions API validator', function () { | |||
114 | }) | 115 | }) |
115 | 116 | ||
116 | it('Should fail with a bad access token', async function () { | 117 | it('Should fail with a bad access token', async function () { |
117 | const captionPath = path + videoUUID + '/captions/fr' | 118 | const captionPath = path + video.uuid + '/captions/fr' |
118 | await makeUploadRequest({ | 119 | await makeUploadRequest({ |
119 | method: 'PUT', | 120 | method: 'PUT', |
120 | url: server.url, | 121 | url: server.url, |
@@ -129,10 +130,10 @@ describe('Test video captions API validator', function () { | |||
129 | // We accept any file now | 130 | // We accept any file now |
130 | // it('Should fail with an invalid captionfile extension', async function () { | 131 | // it('Should fail with an invalid captionfile extension', async function () { |
131 | // const attaches = { | 132 | // const attaches = { |
132 | // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt') | 133 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt') |
133 | // } | 134 | // } |
134 | // | 135 | // |
135 | // const captionPath = path + videoUUID + '/captions/fr' | 136 | // const captionPath = path + video.uuid + '/captions/fr' |
136 | // await makeUploadRequest({ | 137 | // await makeUploadRequest({ |
137 | // method: 'PUT', | 138 | // method: 'PUT', |
138 | // url: server.url, | 139 | // url: server.url, |
@@ -150,7 +151,7 @@ describe('Test video captions API validator', function () { | |||
150 | // url: server.url, | 151 | // url: server.url, |
151 | // accessToken: server.accessToken, | 152 | // accessToken: server.accessToken, |
152 | // language: 'zh', | 153 | // language: 'zh', |
153 | // videoId: videoUUID, | 154 | // videoId: video.uuid, |
154 | // fixture: 'subtitle-bad.txt', | 155 | // fixture: 'subtitle-bad.txt', |
155 | // mimeType: 'application/octet-stream', | 156 | // mimeType: 'application/octet-stream', |
156 | // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | 157 | // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
@@ -162,7 +163,7 @@ describe('Test video captions API validator', function () { | |||
162 | url: server.url, | 163 | url: server.url, |
163 | accessToken: server.accessToken, | 164 | accessToken: server.accessToken, |
164 | language: 'zh', | 165 | language: 'zh', |
165 | videoId: videoUUID, | 166 | videoId: video.uuid, |
166 | fixture: 'subtitle-good.srt', | 167 | fixture: 'subtitle-good.srt', |
167 | mimeType: 'application/octet-stream' | 168 | mimeType: 'application/octet-stream' |
168 | }) | 169 | }) |
@@ -171,10 +172,10 @@ describe('Test video captions API validator', function () { | |||
171 | // We don't check the file validity yet | 172 | // We don't check the file validity yet |
172 | // it('Should fail with an invalid captionfile srt', async function () { | 173 | // it('Should fail with an invalid captionfile srt', async function () { |
173 | // const attaches = { | 174 | // const attaches = { |
174 | // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt') | 175 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt') |
175 | // } | 176 | // } |
176 | // | 177 | // |
177 | // const captionPath = path + videoUUID + '/captions/fr' | 178 | // const captionPath = path + video.uuid + '/captions/fr' |
178 | // await makeUploadRequest({ | 179 | // await makeUploadRequest({ |
179 | // method: 'PUT', | 180 | // method: 'PUT', |
180 | // url: server.url, | 181 | // url: server.url, |
@@ -187,7 +188,7 @@ describe('Test video captions API validator', function () { | |||
187 | // }) | 188 | // }) |
188 | 189 | ||
189 | it('Should success with the correct parameters', async function () { | 190 | it('Should success with the correct parameters', async function () { |
190 | const captionPath = path + videoUUID + '/captions/fr' | 191 | const captionPath = path + video.uuid + '/captions/fr' |
191 | await makeUploadRequest({ | 192 | await makeUploadRequest({ |
192 | method: 'PUT', | 193 | method: 'PUT', |
193 | url: server.url, | 194 | url: server.url, |
@@ -214,7 +215,7 @@ describe('Test video captions API validator', function () { | |||
214 | }) | 215 | }) |
215 | 216 | ||
216 | it('Should success with the correct parameters', async function () { | 217 | it('Should success with the correct parameters', async function () { |
217 | await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) | 218 | await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) |
218 | }) | 219 | }) |
219 | }) | 220 | }) |
220 | 221 | ||
@@ -245,27 +246,27 @@ describe('Test video captions API validator', function () { | |||
245 | }) | 246 | }) |
246 | 247 | ||
247 | it('Should fail with a missing language', async function () { | 248 | it('Should fail with a missing language', async function () { |
248 | const captionPath = path + videoUUID + '/captions' | 249 | const captionPath = path + video.shortUUID + '/captions' |
249 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) | 250 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) |
250 | }) | 251 | }) |
251 | 252 | ||
252 | it('Should fail with an unknown language', async function () { | 253 | it('Should fail with an unknown language', async function () { |
253 | const captionPath = path + videoUUID + '/captions/15' | 254 | const captionPath = path + video.shortUUID + '/captions/15' |
254 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) | 255 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) |
255 | }) | 256 | }) |
256 | 257 | ||
257 | it('Should fail without access token', async function () { | 258 | it('Should fail without access token', async function () { |
258 | const captionPath = path + videoUUID + '/captions/fr' | 259 | const captionPath = path + video.shortUUID + '/captions/fr' |
259 | await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | 260 | await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
260 | }) | 261 | }) |
261 | 262 | ||
262 | it('Should fail with a bad access token', async function () { | 263 | it('Should fail with a bad access token', async function () { |
263 | const captionPath = path + videoUUID + '/captions/fr' | 264 | const captionPath = path + video.shortUUID + '/captions/fr' |
264 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | 265 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
265 | }) | 266 | }) |
266 | 267 | ||
267 | it('Should fail with another user', async function () { | 268 | it('Should fail with another user', async function () { |
268 | const captionPath = path + videoUUID + '/captions/fr' | 269 | const captionPath = path + video.shortUUID + '/captions/fr' |
269 | await makeDeleteRequest({ | 270 | await makeDeleteRequest({ |
270 | url: server.url, | 271 | url: server.url, |
271 | path: captionPath, | 272 | path: captionPath, |
@@ -275,7 +276,7 @@ describe('Test video captions API validator', function () { | |||
275 | }) | 276 | }) |
276 | 277 | ||
277 | it('Should success with the correct parameters', async function () { | 278 | it('Should success with the correct parameters', async function () { |
278 | const captionPath = path + videoUUID + '/captions/fr' | 279 | const captionPath = path + video.shortUUID + '/captions/fr' |
279 | await makeDeleteRequest({ | 280 | await makeDeleteRequest({ |
280 | url: server.url, | 281 | url: server.url, |
281 | path: captionPath, | 282 | path: captionPath, |