aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/config.ts3
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/video-captions.ts223
3 files changed, 227 insertions, 0 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 6aa31e38d..03855237f 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -35,6 +35,9 @@ describe('Test config API validators', function () {
35 cache: { 35 cache: {
36 previews: { 36 previews: {
37 size: 2 37 size: 2
38 },
39 captions: {
40 size: 3
38 } 41 }
39 }, 42 },
40 signup: { 43 signup: {
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 4c3b372f5..c0e0302df 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -6,6 +6,7 @@ import './services'
6import './users' 6import './users'
7import './video-abuses' 7import './video-abuses'
8import './video-blacklist' 8import './video-blacklist'
9import './video-captions'
9import './video-channels' 10import './video-channels'
10import './video-comments' 11import './video-comments'
11import './videos' 12import './videos'
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
new file mode 100644
index 000000000..12f890db8
--- /dev/null
+++ b/server/tests/api/check-params/video-captions.ts
@@ -0,0 +1,223 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 createUser,
7 flushTests,
8 killallServers,
9 makeDeleteRequest,
10 makeGetRequest,
11 makeUploadRequest,
12 runServer,
13 ServerInfo,
14 setAccessTokensToServers,
15 uploadVideo,
16 userLogin
17} from '../../utils'
18import { join } from 'path'
19
20describe('Test video captions API validator', function () {
21 const path = '/api/v1/videos/'
22
23 let server: ServerInfo
24 let userAccessToken: string
25 let videoUUID: string
26
27 // ---------------------------------------------------------------
28
29 before(async function () {
30 this.timeout(30000)
31
32 await flushTests()
33
34 server = await runServer(1)
35
36 await setAccessTokensToServers([ server ])
37
38 {
39 const res = await uploadVideo(server.url, server.accessToken, {})
40 videoUUID = res.body.video.uuid
41 }
42
43 {
44 const user = {
45 username: 'user1',
46 password: 'my super password'
47 }
48 await createUser(server.url, server.accessToken, user.username, user.password)
49 userAccessToken = await userLogin(server, user)
50 }
51 })
52
53 describe('When adding video caption', function () {
54 const fields = { }
55 const attaches = {
56 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt')
57 }
58
59 it('Should fail without a valid uuid', async function () {
60 await makeUploadRequest({
61 method: 'PUT',
62 url: server.url,
63 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions',
64 token: server.accessToken,
65 fields,
66 attaches
67 })
68 })
69
70 it('Should fail with an unknown id', async function () {
71 await makeUploadRequest({
72 method: 'PUT',
73 url: server.url,
74 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
75 token: server.accessToken,
76 fields,
77 attaches
78 })
79 })
80
81 it('Should fail with a missing language in path', async function () {
82 const captionPath = path + videoUUID + '/captions'
83 await makeUploadRequest({
84 method: 'PUT',
85 url: server.url,
86 path: captionPath,
87 token: server.accessToken,
88 fields,
89 attaches
90 })
91 })
92
93 it('Should fail with an unknown language', async function () {
94 const captionPath = path + videoUUID + '/captions/15'
95 await makeUploadRequest({
96 method: 'PUT',
97 url: server.url,
98 path: captionPath,
99 token: server.accessToken,
100 fields,
101 attaches
102 })
103 })
104
105 it('Should fail without access token', async function () {
106 const captionPath = path + videoUUID + '/captions/fr'
107 await makeUploadRequest({
108 method: 'PUT',
109 url: server.url,
110 path: captionPath,
111 fields,
112 attaches,
113 statusCodeExpected: 401
114 })
115 })
116
117 it('Should fail with a bad access token', async function () {
118 const captionPath = path + videoUUID + '/captions/fr'
119 await makeUploadRequest({
120 method: 'PUT',
121 url: server.url,
122 path: captionPath,
123 token: 'blabla',
124 fields,
125 attaches,
126 statusCodeExpected: 401
127 })
128 })
129
130 it('Should success with the correct parameters', async function () {
131 const captionPath = path + videoUUID + '/captions/fr'
132 await makeUploadRequest({
133 method: 'PUT',
134 url: server.url,
135 path: captionPath,
136 token: server.accessToken,
137 fields,
138 attaches,
139 statusCodeExpected: 204
140 })
141 })
142 })
143
144 describe('When listing video captions', function () {
145 it('Should fail without a valid uuid', async function () {
146 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
147 })
148
149 it('Should fail with an unknown id', async function () {
150 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 })
151 })
152
153 it('Should success with the correct parameters', async function () {
154 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 })
155 })
156 })
157
158 describe('When deleting video caption', function () {
159 it('Should fail without a valid uuid', async function () {
160 await makeDeleteRequest({
161 url: server.url,
162 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
163 token: server.accessToken
164 })
165 })
166
167 it('Should fail with an unknown id', async function () {
168 await makeDeleteRequest({
169 url: server.url,
170 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
171 token: server.accessToken,
172 statusCodeExpected: 404
173 })
174 })
175
176 it('Should fail with an invalid language', async function () {
177 await makeDeleteRequest({
178 url: server.url,
179 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
180 token: server.accessToken
181 })
182 })
183
184 it('Should fail with a missing language', async function () {
185 const captionPath = path + videoUUID + '/captions'
186 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
187 })
188
189 it('Should fail with an unknown language', async function () {
190 const captionPath = path + videoUUID + '/captions/15'
191 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
192 })
193
194 it('Should fail without access token', async function () {
195 const captionPath = path + videoUUID + '/captions/fr'
196 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 })
197 })
198
199 it('Should fail with a bad access token', async function () {
200 const captionPath = path + videoUUID + '/captions/fr'
201 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 })
202 })
203
204 it('Should fail with another user', async function () {
205 const captionPath = path + videoUUID + '/captions/fr'
206 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 })
207 })
208
209 it('Should success with the correct parameters', async function () {
210 const captionPath = path + videoUUID + '/captions/fr'
211 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 })
212 })
213 })
214
215 after(async function () {
216 killallServers([ server ])
217
218 // Keep the logs if the test failed
219 if (this['ok']) {
220 await flushTests()
221 }
222 })
223})