]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/video-captions.ts
Add videos list filters
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-captions.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import {
5 createUser,
6 flushTests,
7 killallServers,
8 makeDeleteRequest,
9 makeGetRequest,
10 makeUploadRequest,
11 runServer,
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo,
15 userLogin
16 } from '../../utils'
17 import { join } from 'path'
18
19 describe('Test video captions API validator', function () {
20 const path = '/api/v1/videos/'
21
22 let server: ServerInfo
23 let userAccessToken: string
24 let videoUUID: string
25
26 // ---------------------------------------------------------------
27
28 before(async function () {
29 this.timeout(30000)
30
31 await flushTests()
32
33 server = await runServer(1)
34
35 await setAccessTokensToServers([ server ])
36
37 {
38 const res = await uploadVideo(server.url, server.accessToken, {})
39 videoUUID = res.body.video.uuid
40 }
41
42 {
43 const user = {
44 username: 'user1',
45 password: 'my super password'
46 }
47 await createUser(server.url, server.accessToken, user.username, user.password)
48 userAccessToken = await userLogin(server, user)
49 }
50 })
51
52 describe('When adding video caption', function () {
53 const fields = { }
54 const attaches = {
55 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt')
56 }
57
58 it('Should fail without a valid uuid', async function () {
59 await makeUploadRequest({
60 method: 'PUT',
61 url: server.url,
62 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions',
63 token: server.accessToken,
64 fields,
65 attaches
66 })
67 })
68
69 it('Should fail with an unknown id', async function () {
70 await makeUploadRequest({
71 method: 'PUT',
72 url: server.url,
73 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
74 token: server.accessToken,
75 fields,
76 attaches
77 })
78 })
79
80 it('Should fail with a missing language in path', async function () {
81 const captionPath = path + videoUUID + '/captions'
82 await makeUploadRequest({
83 method: 'PUT',
84 url: server.url,
85 path: captionPath,
86 token: server.accessToken,
87 fields,
88 attaches
89 })
90 })
91
92 it('Should fail with an unknown language', async function () {
93 const captionPath = path + videoUUID + '/captions/15'
94 await makeUploadRequest({
95 method: 'PUT',
96 url: server.url,
97 path: captionPath,
98 token: server.accessToken,
99 fields,
100 attaches
101 })
102 })
103
104 it('Should fail without access token', async function () {
105 const captionPath = path + videoUUID + '/captions/fr'
106 await makeUploadRequest({
107 method: 'PUT',
108 url: server.url,
109 path: captionPath,
110 fields,
111 attaches,
112 statusCodeExpected: 401
113 })
114 })
115
116 it('Should fail with a bad access token', async function () {
117 const captionPath = path + videoUUID + '/captions/fr'
118 await makeUploadRequest({
119 method: 'PUT',
120 url: server.url,
121 path: captionPath,
122 token: 'blabla',
123 fields,
124 attaches,
125 statusCodeExpected: 401
126 })
127 })
128
129 it('Should fail with an invalid captionfile extension', async function () {
130 const attaches = {
131 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
132 }
133
134 const captionPath = path + videoUUID + '/captions/fr'
135 await makeUploadRequest({
136 method: 'PUT',
137 url: server.url,
138 path: captionPath,
139 token: server.accessToken,
140 fields,
141 attaches,
142 statusCodeExpected: 400
143 })
144 })
145
146 // it('Should fail with an invalid captionfile srt', async function () {
147 // const attaches = {
148 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
149 // }
150 //
151 // const captionPath = path + videoUUID + '/captions/fr'
152 // await makeUploadRequest({
153 // method: 'PUT',
154 // url: server.url,
155 // path: captionPath,
156 // token: server.accessToken,
157 // fields,
158 // attaches,
159 // statusCodeExpected: 500
160 // })
161 // })
162
163 it('Should success with the correct parameters', async function () {
164 const captionPath = path + videoUUID + '/captions/fr'
165 await makeUploadRequest({
166 method: 'PUT',
167 url: server.url,
168 path: captionPath,
169 token: server.accessToken,
170 fields,
171 attaches,
172 statusCodeExpected: 204
173 })
174 })
175 })
176
177 describe('When listing video captions', function () {
178 it('Should fail without a valid uuid', async function () {
179 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
180 })
181
182 it('Should fail with an unknown id', async function () {
183 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 })
184 })
185
186 it('Should success with the correct parameters', async function () {
187 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 })
188 })
189 })
190
191 describe('When deleting video caption', function () {
192 it('Should fail without a valid uuid', async function () {
193 await makeDeleteRequest({
194 url: server.url,
195 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
196 token: server.accessToken
197 })
198 })
199
200 it('Should fail with an unknown id', async function () {
201 await makeDeleteRequest({
202 url: server.url,
203 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
204 token: server.accessToken,
205 statusCodeExpected: 404
206 })
207 })
208
209 it('Should fail with an invalid language', async function () {
210 await makeDeleteRequest({
211 url: server.url,
212 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
213 token: server.accessToken
214 })
215 })
216
217 it('Should fail with a missing language', async function () {
218 const captionPath = path + videoUUID + '/captions'
219 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
220 })
221
222 it('Should fail with an unknown language', async function () {
223 const captionPath = path + videoUUID + '/captions/15'
224 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
225 })
226
227 it('Should fail without access token', async function () {
228 const captionPath = path + videoUUID + '/captions/fr'
229 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 })
230 })
231
232 it('Should fail with a bad access token', async function () {
233 const captionPath = path + videoUUID + '/captions/fr'
234 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 })
235 })
236
237 it('Should fail with another user', async function () {
238 const captionPath = path + videoUUID + '/captions/fr'
239 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 })
240 })
241
242 it('Should success with the correct parameters', async function () {
243 const captionPath = path + videoUUID + '/captions/fr'
244 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 })
245 })
246 })
247
248 after(async function () {
249 killallServers([ server ])
250
251 // Keep the logs if the test failed
252 if (this['ok']) {
253 await flushTests()
254 }
255 })
256 })