]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-captions.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-captions.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
40e87e9e 2
40e87e9e 3import 'mocha'
a2470c9f 4import { HttpStatusCode } from '@shared/core-utils'
40e87e9e 5import {
3d470a53 6 buildAbsoluteFixturePath,
7c3b7976 7 cleanupTests,
254d3579 8 createSingleServer,
40e87e9e
C
9 makeDeleteRequest,
10 makeGetRequest,
11 makeUploadRequest,
254d3579 12 PeerTubeServer,
d23dd9fb 13 setAccessTokensToServers
a2470c9f
C
14} from '@shared/extra-utils'
15import { VideoCreateResult } from '@shared/models'
40e87e9e
C
16
17describe('Test video captions API validator', function () {
18 const path = '/api/v1/videos/'
19
254d3579 20 let server: PeerTubeServer
40e87e9e 21 let userAccessToken: string
d4a8e7a6 22 let video: VideoCreateResult
40e87e9e
C
23
24 // ---------------------------------------------------------------
25
26 before(async function () {
27 this.timeout(30000)
28
254d3579 29 server = await createSingleServer(1)
40e87e9e
C
30
31 await setAccessTokensToServers([ server ])
32
89d241a7 33 video = await server.videos.upload()
40e87e9e
C
34
35 {
36 const user = {
37 username: 'user1',
38 password: 'my super password'
39 }
89d241a7
C
40 await server.users.create({ username: user.username, password: user.password })
41 userAccessToken = await server.login.getAccessToken(user)
40e87e9e
C
42 }
43 })
44
45 describe('When adding video caption', function () {
46 const fields = { }
47 const attaches = {
3d470a53 48 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
40e87e9e
C
49 }
50
51 it('Should fail without a valid uuid', async function () {
52 await makeUploadRequest({
53 method: 'PUT',
54 url: server.url,
59fd824c 55 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
40e87e9e
C
56 token: server.accessToken,
57 fields,
58 attaches
59 })
60 })
61
62 it('Should fail with an unknown id', async function () {
63 await makeUploadRequest({
64 method: 'PUT',
65 url: server.url,
59fd824c 66 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
40e87e9e
C
67 token: server.accessToken,
68 fields,
59fd824c
C
69 attaches,
70 statusCodeExpected: 404
40e87e9e
C
71 })
72 })
73
74 it('Should fail with a missing language in path', async function () {
d4a8e7a6 75 const captionPath = path + video.uuid + '/captions'
40e87e9e
C
76 await makeUploadRequest({
77 method: 'PUT',
78 url: server.url,
79 path: captionPath,
80 token: server.accessToken,
81 fields,
82 attaches
83 })
84 })
85
86 it('Should fail with an unknown language', async function () {
d4a8e7a6 87 const captionPath = path + video.uuid + '/captions/15'
40e87e9e
C
88 await makeUploadRequest({
89 method: 'PUT',
90 url: server.url,
91 path: captionPath,
92 token: server.accessToken,
93 fields,
94 attaches
95 })
96 })
97
98 it('Should fail without access token', async function () {
d4a8e7a6 99 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
100 await makeUploadRequest({
101 method: 'PUT',
102 url: server.url,
103 path: captionPath,
104 fields,
105 attaches,
2d53be02 106 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
40e87e9e
C
107 })
108 })
109
110 it('Should fail with a bad access token', async function () {
d4a8e7a6 111 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
112 await makeUploadRequest({
113 method: 'PUT',
114 url: server.url,
115 path: captionPath,
116 token: 'blabla',
117 fields,
118 attaches,
2d53be02 119 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
40e87e9e
C
120 })
121 })
122
39a26b2e
C
123 // We accept any file now
124 // it('Should fail with an invalid captionfile extension', async function () {
125 // const attaches = {
3d470a53 126 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
39a26b2e
C
127 // }
128 //
d4a8e7a6 129 // const captionPath = path + video.uuid + '/captions/fr'
39a26b2e
C
130 // await makeUploadRequest({
131 // method: 'PUT',
132 // url: server.url,
133 // path: captionPath,
134 // token: server.accessToken,
135 // fields,
136 // attaches,
2d53be02 137 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
39a26b2e
C
138 // })
139 // })
f4001cf4 140
2769e297
C
141 // We don't check the extension yet
142 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
143 // await createVideoCaption({
144 // url: server.url,
145 // accessToken: server.accessToken,
146 // language: 'zh',
d4a8e7a6 147 // videoId: video.uuid,
2769e297
C
148 // fixture: 'subtitle-bad.txt',
149 // mimeType: 'application/octet-stream',
2d53be02 150 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
2769e297
C
151 // })
152 // })
153
154 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
89d241a7 155 await server.captions.createVideoCaption({
2769e297 156 language: 'zh',
d4a8e7a6 157 videoId: video.uuid,
2769e297
C
158 fixture: 'subtitle-good.srt',
159 mimeType: 'application/octet-stream'
160 })
161 })
162
163 // We don't check the file validity yet
f4001cf4
C
164 // it('Should fail with an invalid captionfile srt', async function () {
165 // const attaches = {
3d470a53 166 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
f4001cf4
C
167 // }
168 //
d4a8e7a6 169 // const captionPath = path + video.uuid + '/captions/fr'
f4001cf4
C
170 // await makeUploadRequest({
171 // method: 'PUT',
172 // url: server.url,
173 // path: captionPath,
174 // token: server.accessToken,
175 // fields,
176 // attaches,
2d53be02 177 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
f4001cf4
C
178 // })
179 // })
180
40e87e9e 181 it('Should success with the correct parameters', async function () {
d4a8e7a6 182 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
183 await makeUploadRequest({
184 method: 'PUT',
185 url: server.url,
186 path: captionPath,
187 token: server.accessToken,
188 fields,
189 attaches,
2d53be02 190 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
40e87e9e
C
191 })
192 })
193 })
194
195 describe('When listing video captions', function () {
196 it('Should fail without a valid uuid', async function () {
197 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
198 })
199
200 it('Should fail with an unknown id', async function () {
2d53be02
RK
201 await makeGetRequest({
202 url: server.url,
203 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
204 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
205 })
40e87e9e
C
206 })
207
208 it('Should success with the correct parameters', async function () {
d4a8e7a6 209 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
40e87e9e
C
210 })
211 })
212
213 describe('When deleting video caption', function () {
214 it('Should fail without a valid uuid', async function () {
215 await makeDeleteRequest({
216 url: server.url,
217 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
218 token: server.accessToken
219 })
220 })
221
222 it('Should fail with an unknown id', async function () {
223 await makeDeleteRequest({
224 url: server.url,
225 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
226 token: server.accessToken,
2d53be02 227 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
40e87e9e
C
228 })
229 })
230
231 it('Should fail with an invalid language', async function () {
232 await makeDeleteRequest({
233 url: server.url,
234 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
235 token: server.accessToken
236 })
237 })
238
239 it('Should fail with a missing language', async function () {
d4a8e7a6 240 const captionPath = path + video.shortUUID + '/captions'
40e87e9e
C
241 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
242 })
243
244 it('Should fail with an unknown language', async function () {
d4a8e7a6 245 const captionPath = path + video.shortUUID + '/captions/15'
40e87e9e
C
246 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
247 })
248
249 it('Should fail without access token', async function () {
d4a8e7a6 250 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02 251 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
252 })
253
254 it('Should fail with a bad access token', async function () {
d4a8e7a6 255 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02 256 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
257 })
258
259 it('Should fail with another user', async function () {
d4a8e7a6 260 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02
RK
261 await makeDeleteRequest({
262 url: server.url,
263 path: captionPath,
264 token: userAccessToken,
265 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
266 })
40e87e9e
C
267 })
268
269 it('Should success with the correct parameters', async function () {
d4a8e7a6 270 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02
RK
271 await makeDeleteRequest({
272 url: server.url,
273 path: captionPath,
274 token: server.accessToken,
275 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
276 })
40e87e9e
C
277 })
278 })
279
7c3b7976
C
280 after(async function () {
281 await cleanupTests([ server ])
40e87e9e
C
282 })
283})