aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-channels.ts')
-rw-r--r--server/tests/api/check-params/video-channels.ts310
1 files changed, 310 insertions, 0 deletions
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
new file mode 100644
index 000000000..b99b5eda8
--- /dev/null
+++ b/server/tests/api/check-params/video-channels.ts
@@ -0,0 +1,310 @@
1/* tslint:disable:no-unused-expression */
2
3import * as request from 'supertest'
4import { join } from 'path'
5import 'mocha'
6import * as chai from 'chai'
7const expect = chai.expect
8
9import {
10 ServerInfo,
11 flushTests,
12 runServer,
13 makePutBodyRequest,
14 setAccessTokensToServers,
15 killallServers,
16 getMyUserInformation,
17 makePostBodyRequest,
18 getVideoChannelsList,
19 createUser,
20 getUserAccessToken
21} from '../../utils'
22
23describe('Test videos API validator', function () {
24 const path = '/api/v1/videos/channels'
25 let server: ServerInfo
26 let channelId: number
27 let accessTokenUser: string
28
29 // ---------------------------------------------------------------
30
31 before(async function () {
32 this.timeout(20000)
33
34 await flushTests()
35
36 server = await runServer(1)
37
38 await setAccessTokensToServers([ server ])
39
40 const res = await getMyUserInformation(server.url, server.accessToken)
41 channelId = res.body.videoChannels[0].id
42
43 const user = {
44 username: 'fake',
45 password: 'fake_password'
46 }
47 await createUser(server.url, server.accessToken, user.username, user.password)
48
49 accessTokenUser = await getUserAccessToken(server, user)
50 })
51
52 describe('When listing a video channels', function () {
53 it('Should fail with a bad start pagination', async function () {
54 await request(server.url)
55 .get(path)
56 .query({ start: 'hello' })
57 .set('Accept', 'application/json')
58 .expect(400)
59 })
60
61 it('Should fail with a bad count pagination', async function () {
62 await request(server.url)
63 .get(path)
64 .query({ count: 'hello' })
65 .set('Accept', 'application/json')
66 .expect(400)
67 })
68
69 it('Should fail with an incorrect sort', async function () {
70 await request(server.url)
71 .get(path)
72 .query({ sort: 'hello' })
73 .set('Accept', 'application/json')
74 .expect(400)
75 })
76 })
77
78 describe('When listing author video channels', function () {
79 it('Should fail with bad author', async function () {
80 const path = '/api/v1/videos/authors/hello/channels'
81
82 await request(server.url)
83 .get(path)
84 .set('Accept', 'application/json')
85 .expect(400)
86 })
87
88 it('Should fail with a unknown author', async function () {
89 const path = '/api/v1/videos/authors/156/channels'
90
91 await request(server.url)
92 .get(path)
93 .set('Accept', 'application/json')
94 .expect(404)
95 })
96 })
97
98 describe('When adding a video channel', function () {
99
100 it('Should fail with a non authenticated user', async function () {
101 const fields = {
102 name: 'hello',
103 description: 'super description'
104 }
105 await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 })
106 })
107
108 it('Should fail with nothing', async function () {
109 const fields = {}
110 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
111 })
112
113 it('Should fail without name', async function () {
114 const fields = {
115 description: 'super description'
116 }
117 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
118 })
119
120 it('Should fail with a long name', async function () {
121 const fields = {
122 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
123 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
124 description: 'super description'
125 }
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
127 })
128
129 it('Should fail with a long description', async function () {
130 const fields = {
131 name: 'hello',
132 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
133 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
134 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
135 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
136 }
137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
138 })
139
140 it('Should succeed with the correct parameters', async function () {
141 const fields = {
142 name: 'hello',
143 description: 'super description'
144 }
145 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
146 })
147 })
148
149 describe('When updating a video channel', function () {
150 let videoChannelId
151
152 before(async function () {
153 const res = await getVideoChannelsList(server.url, 0, 1)
154 videoChannelId = res.body.data[0].id
155 })
156
157 it('Should fail with a non authenticated user', async function () {
158 const fields = {
159 name: 'hello',
160 description: 'super description'
161 }
162 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 })
163 })
164
165 it('Should fail with another authenticated user', async function () {
166 const fields = {
167 name: 'hello',
168 description: 'super description'
169 }
170 await makePutBodyRequest({
171 url: server.url,
172 path: path + '/' + videoChannelId,
173 token: accessTokenUser,
174 fields,
175 statusCodeExpected: 403
176 })
177 })
178
179 it('Should fail with a long name', async function () {
180 const fields = {
181 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
182 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
183 description: 'super description'
184 }
185 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
186 })
187
188 it('Should fail with a long description', async function () {
189 const fields = {
190 name: 'hello',
191 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
192 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
193 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
194 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
195 }
196 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
197 })
198
199 it('Should succeed with the correct parameters', async function () {
200 const fields = {
201 name: 'hello 2',
202 description: 'super description 2'
203 }
204 await makePutBodyRequest({
205 url: server.url,
206 path: path + '/' + videoChannelId,
207 token: server.accessToken,
208 fields,
209 statusCodeExpected: 204
210 })
211 })
212 })
213
214 describe('When getting a video channel', function () {
215 let videoChannelId: number
216
217 before(async function () {
218 const res = await getVideoChannelsList(server.url, 0, 1)
219 videoChannelId = res.body.data[0].id
220 })
221
222 it('Should return the list of the video channels with nothing', async function () {
223 const res = await request(server.url)
224 .get(path)
225 .set('Accept', 'application/json')
226 .expect(200)
227 .expect('Content-Type', /json/)
228
229 expect(res.body.data).to.be.an('array')
230 })
231
232 it('Should fail without a correct uuid', async function () {
233 await request(server.url)
234 .get(path + '/coucou')
235 .set('Accept', 'application/json')
236 .expect(400)
237 })
238
239 it('Should return 404 with an incorrect video channel', async function () {
240 await request(server.url)
241 .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06')
242 .set('Accept', 'application/json')
243 .expect(404)
244 })
245
246 it('Should succeed with the correct parameters', async function () {
247 await request(server.url)
248 .get(path + '/' + videoChannelId)
249 .set('Accept', 'application/json')
250 .expect(200)
251 })
252 })
253
254 describe('When deleting a video channel', function () {
255 let videoChannelId: number
256
257 before(async function () {
258 const res = await getVideoChannelsList(server.url, 0, 1)
259 videoChannelId = res.body.data[0].id
260 })
261
262 it('Should fail with a non authenticated user', async function () {
263 await request(server.url)
264 .delete(path + '/' + videoChannelId)
265 .set('Authorization', 'Bearer coucou')
266 .expect(401)
267 })
268
269 it('Should fail with another authenticated user', async function () {
270 await request(server.url)
271 .delete(path + '/' + videoChannelId)
272 .set('Authorization', 'Bearer ' + accessTokenUser)
273 .expect(403)
274 })
275
276 it('Should fail with an unknown id', async function () {
277 await request(server.url)
278 .delete(path + '/454554')
279 .set('Authorization', 'Bearer ' + server.accessToken)
280 .expect(404)
281 })
282
283 it('Should succeed with the correct parameters', async function () {
284 await request(server.url)
285 .delete(path + '/' + videoChannelId)
286 .set('Authorization', 'Bearer ' + server.accessToken)
287 .expect(204)
288 })
289
290 it('Should fail to delete the last user video channel', async function () {
291 const res = await getVideoChannelsList(server.url, 0, 1)
292 videoChannelId = res.body.data[0].id
293
294 await request(server.url)
295 .delete(path + '/' + videoChannelId)
296 .set('Authorization', 'Bearer ' + server.accessToken)
297 .expect(409
298 )
299 })
300 })
301
302 after(async function () {
303 killallServers([ server ])
304
305 // Keep the logs if the test failed
306 if (this['ok']) {
307 await flushTests()
308 }
309 })
310})