diff options
Diffstat (limited to 'server/tests/api/check-params/video-captions.ts')
-rw-r--r-- | server/tests/api/check-params/video-captions.ts | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index c0595c04d..90f429314 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts | |||
@@ -1,27 +1,22 @@ | |||
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' | ||
6 | import { | 4 | import { |
7 | buildAbsoluteFixturePath, | 5 | buildAbsoluteFixturePath, |
8 | cleanupTests, | 6 | cleanupTests, |
9 | createUser, | 7 | createSingleServer, |
10 | flushAndRunServer, | ||
11 | makeDeleteRequest, | 8 | makeDeleteRequest, |
12 | makeGetRequest, | 9 | makeGetRequest, |
13 | makeUploadRequest, | 10 | makeUploadRequest, |
14 | ServerInfo, | 11 | PeerTubeServer, |
15 | setAccessTokensToServers, | 12 | setAccessTokensToServers |
16 | uploadVideo, | 13 | } from '@shared/extra-utils' |
17 | userLogin | 14 | import { HttpStatusCode, VideoCreateResult } from '@shared/models' |
18 | } from '../../../../shared/extra-utils' | ||
19 | import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' | ||
20 | 15 | ||
21 | describe('Test video captions API validator', function () { | 16 | describe('Test video captions API validator', function () { |
22 | const path = '/api/v1/videos/' | 17 | const path = '/api/v1/videos/' |
23 | 18 | ||
24 | let server: ServerInfo | 19 | let server: PeerTubeServer |
25 | let userAccessToken: string | 20 | let userAccessToken: string |
26 | let video: VideoCreateResult | 21 | let video: VideoCreateResult |
27 | 22 | ||
@@ -30,22 +25,19 @@ describe('Test video captions API validator', function () { | |||
30 | before(async function () { | 25 | before(async function () { |
31 | this.timeout(30000) | 26 | this.timeout(30000) |
32 | 27 | ||
33 | server = await flushAndRunServer(1) | 28 | server = await createSingleServer(1) |
34 | 29 | ||
35 | await setAccessTokensToServers([ server ]) | 30 | await setAccessTokensToServers([ server ]) |
36 | 31 | ||
37 | { | 32 | video = await server.videos.upload() |
38 | const res = await uploadVideo(server.url, server.accessToken, {}) | ||
39 | video = res.body.video | ||
40 | } | ||
41 | 33 | ||
42 | { | 34 | { |
43 | const user = { | 35 | const user = { |
44 | username: 'user1', | 36 | username: 'user1', |
45 | password: 'my super password' | 37 | password: 'my super password' |
46 | } | 38 | } |
47 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | 39 | await server.users.create({ username: user.username, password: user.password }) |
48 | userAccessToken = await userLogin(server, user) | 40 | userAccessToken = await server.login.getAccessToken(user) |
49 | } | 41 | } |
50 | }) | 42 | }) |
51 | 43 | ||
@@ -74,7 +66,7 @@ describe('Test video captions API validator', function () { | |||
74 | token: server.accessToken, | 66 | token: server.accessToken, |
75 | fields, | 67 | fields, |
76 | attaches, | 68 | attaches, |
77 | statusCodeExpected: 404 | 69 | expectedStatus: 404 |
78 | }) | 70 | }) |
79 | }) | 71 | }) |
80 | 72 | ||
@@ -110,7 +102,7 @@ describe('Test video captions API validator', function () { | |||
110 | path: captionPath, | 102 | path: captionPath, |
111 | fields, | 103 | fields, |
112 | attaches, | 104 | attaches, |
113 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | 105 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
114 | }) | 106 | }) |
115 | }) | 107 | }) |
116 | 108 | ||
@@ -123,7 +115,7 @@ describe('Test video captions API validator', function () { | |||
123 | token: 'blabla', | 115 | token: 'blabla', |
124 | fields, | 116 | fields, |
125 | attaches, | 117 | attaches, |
126 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | 118 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
127 | }) | 119 | }) |
128 | }) | 120 | }) |
129 | 121 | ||
@@ -141,7 +133,7 @@ describe('Test video captions API validator', function () { | |||
141 | // token: server.accessToken, | 133 | // token: server.accessToken, |
142 | // fields, | 134 | // fields, |
143 | // attaches, | 135 | // attaches, |
144 | // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | 136 | // expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
145 | // }) | 137 | // }) |
146 | // }) | 138 | // }) |
147 | 139 | ||
@@ -154,14 +146,12 @@ describe('Test video captions API validator', function () { | |||
154 | // videoId: video.uuid, | 146 | // videoId: video.uuid, |
155 | // fixture: 'subtitle-bad.txt', | 147 | // fixture: 'subtitle-bad.txt', |
156 | // mimeType: 'application/octet-stream', | 148 | // mimeType: 'application/octet-stream', |
157 | // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | 149 | // expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
158 | // }) | 150 | // }) |
159 | // }) | 151 | // }) |
160 | 152 | ||
161 | it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { | 153 | it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { |
162 | await createVideoCaption({ | 154 | await server.captions.add({ |
163 | url: server.url, | ||
164 | accessToken: server.accessToken, | ||
165 | language: 'zh', | 155 | language: 'zh', |
166 | videoId: video.uuid, | 156 | videoId: video.uuid, |
167 | fixture: 'subtitle-good.srt', | 157 | fixture: 'subtitle-good.srt', |
@@ -183,7 +173,7 @@ describe('Test video captions API validator', function () { | |||
183 | // token: server.accessToken, | 173 | // token: server.accessToken, |
184 | // fields, | 174 | // fields, |
185 | // attaches, | 175 | // attaches, |
186 | // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500 | 176 | // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500 |
187 | // }) | 177 | // }) |
188 | // }) | 178 | // }) |
189 | 179 | ||
@@ -196,7 +186,7 @@ describe('Test video captions API validator', function () { | |||
196 | token: server.accessToken, | 186 | token: server.accessToken, |
197 | fields, | 187 | fields, |
198 | attaches, | 188 | attaches, |
199 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | 189 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
200 | }) | 190 | }) |
201 | }) | 191 | }) |
202 | }) | 192 | }) |
@@ -210,12 +200,12 @@ describe('Test video captions API validator', function () { | |||
210 | await makeGetRequest({ | 200 | await makeGetRequest({ |
211 | url: server.url, | 201 | url: server.url, |
212 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', | 202 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', |
213 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | 203 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
214 | }) | 204 | }) |
215 | }) | 205 | }) |
216 | 206 | ||
217 | it('Should success with the correct parameters', async function () { | 207 | it('Should success with the correct parameters', async function () { |
218 | await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) | 208 | await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 }) |
219 | }) | 209 | }) |
220 | }) | 210 | }) |
221 | 211 | ||
@@ -233,7 +223,7 @@ describe('Test video captions API validator', function () { | |||
233 | url: server.url, | 223 | url: server.url, |
234 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', | 224 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', |
235 | token: server.accessToken, | 225 | token: server.accessToken, |
236 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | 226 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
237 | }) | 227 | }) |
238 | }) | 228 | }) |
239 | 229 | ||
@@ -257,12 +247,12 @@ describe('Test video captions API validator', function () { | |||
257 | 247 | ||
258 | it('Should fail without access token', async function () { | 248 | it('Should fail without access token', async function () { |
259 | const captionPath = path + video.shortUUID + '/captions/fr' | 249 | const captionPath = path + video.shortUUID + '/captions/fr' |
260 | await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | 250 | await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
261 | }) | 251 | }) |
262 | 252 | ||
263 | it('Should fail with a bad access token', async function () { | 253 | it('Should fail with a bad access token', async function () { |
264 | const captionPath = path + video.shortUUID + '/captions/fr' | 254 | const captionPath = path + video.shortUUID + '/captions/fr' |
265 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | 255 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
266 | }) | 256 | }) |
267 | 257 | ||
268 | it('Should fail with another user', async function () { | 258 | it('Should fail with another user', async function () { |
@@ -271,7 +261,7 @@ describe('Test video captions API validator', function () { | |||
271 | url: server.url, | 261 | url: server.url, |
272 | path: captionPath, | 262 | path: captionPath, |
273 | token: userAccessToken, | 263 | token: userAccessToken, |
274 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | 264 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
275 | }) | 265 | }) |
276 | }) | 266 | }) |
277 | 267 | ||
@@ -281,7 +271,7 @@ describe('Test video captions API validator', function () { | |||
281 | url: server.url, | 271 | url: server.url, |
282 | path: captionPath, | 272 | path: captionPath, |
283 | token: server.accessToken, | 273 | token: server.accessToken, |
284 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | 274 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
285 | }) | 275 | }) |
286 | }) | 276 | }) |
287 | }) | 277 | }) |