aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/videos.ts')
-rw-r--r--server/tests/api/check-params/videos.ts374
1 files changed, 151 insertions, 223 deletions
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index b0c850f0c..b9484afc4 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -1,64 +1,23 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as request from 'supertest'
4import { join } from 'path'
5import 'mocha'
6import * as chai from 'chai' 3import * as chai from 'chai'
7const expect = chai.expect 4import { omit } from 'lodash'
8 5import 'mocha'
6import { join } from 'path'
7import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
9import { 8import {
10 ServerInfo, 9 createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest,
11 flushTests, 10 makeGetRequest, makePostUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin
12 runServer,
13 getVideosList,
14 makePutBodyRequest,
15 setAccessTokensToServers,
16 killallServers,
17 makePostUploadRequest,
18 getMyUserInformation,
19 createUser,
20 userLogin
21} from '../../utils' 11} from '../../utils'
22import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 12import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
13
14const expect = chai.expect
23 15
24describe('Test videos API validator', function () { 16describe('Test videos API validator', function () {
25 const path = '/api/v1/videos/' 17 const path = '/api/v1/videos/'
26 let server: ServerInfo 18 let server: ServerInfo
27 let channelId: number 19 let channelId: number
28 20
29 function getCompleteVideoUploadAttributes () {
30 return {
31 name: 'my super name',
32 category: 5,
33 licence: 1,
34 language: 6,
35 nsfw: false,
36 description: 'my super description',
37 tags: [ 'tag1', 'tag2' ],
38 privacy: VideoPrivacy.PUBLIC,
39 channelId
40 }
41 }
42
43 function getCompleteVideoUpdateAttributes () {
44 return {
45 name: 'my super name',
46 category: 5,
47 licence: 2,
48 language: 6,
49 nsfw: false,
50 description: 'my super description',
51 privacy: VideoPrivacy.PUBLIC,
52 tags: [ 'tag1', 'tag2' ]
53 }
54 }
55
56 function getVideoUploadAttaches () {
57 return {
58 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
59 }
60 }
61
62 // --------------------------------------------------------------- 21 // ---------------------------------------------------------------
63 22
64 before(async function () { 23 before(async function () {
@@ -76,60 +35,38 @@ describe('Test videos API validator', function () {
76 35
77 describe('When listing a video', function () { 36 describe('When listing a video', function () {
78 it('Should fail with a bad start pagination', async function () { 37 it('Should fail with a bad start pagination', async function () {
79 await request(server.url) 38 await checkBadStartPagination(server.url, path)
80 .get(path)
81 .query({ start: 'hello' })
82 .set('Accept', 'application/json')
83 .expect(400)
84 }) 39 })
85 40
86 it('Should fail with a bad count pagination', async function () { 41 it('Should fail with a bad count pagination', async function () {
87 await request(server.url) 42 await checkBadCountPagination(server.url, path)
88 .get(path)
89 .query({ count: 'hello' })
90 .set('Accept', 'application/json')
91 .expect(400)
92 }) 43 })
93 44
94 it('Should fail with an incorrect sort', async function () { 45 it('Should fail with an incorrect sort', async function () {
95 await request(server.url) 46 await checkBadSortPagination(server.url, path)
96 .get(path)
97 .query({ sort: 'hello' })
98 .set('Accept', 'application/json')
99 .expect(400)
100 }) 47 })
101 }) 48 })
102 49
103 describe('When searching a video', function () { 50 describe('When searching a video', function () {
51
104 it('Should fail with nothing', async function () { 52 it('Should fail with nothing', async function () {
105 await request(server.url) 53 await makeGetRequest({
106 .get(join(path, 'search')) 54 url: server.url,
107 .set('Accept', 'application/json') 55 path: join(path, 'search'),
108 .expect(400) 56 statusCodeExpected: 400
57 })
109 }) 58 })
110 59
111 it('Should fail with a bad start pagination', async function () { 60 it('Should fail with a bad start pagination', async function () {
112 await request(server.url) 61 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
113 .get(join(path, 'search', 'test'))
114 .query({ start: 'hello' })
115 .set('Accept', 'application/json')
116 .expect(400)
117 }) 62 })
118 63
119 it('Should fail with a bad count pagination', async function () { 64 it('Should fail with a bad count pagination', async function () {
120 await request(server.url) 65 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
121 .get(join(path, 'search', 'test'))
122 .query({ count: 'hello' })
123 .set('Accept', 'application/json')
124 .expect(400)
125 }) 66 })
126 67
127 it('Should fail with an incorrect sort', async function () { 68 it('Should fail with an incorrect sort', async function () {
128 await request(server.url) 69 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
129 .get(join(path, 'search', 'test'))
130 .query({ sort: 'hello' })
131 .set('Accept', 'application/json')
132 .expect(400)
133 }) 70 })
134 }) 71 })
135 72
@@ -137,34 +74,39 @@ describe('Test videos API validator', function () {
137 const path = '/api/v1/users/me/videos' 74 const path = '/api/v1/users/me/videos'
138 75
139 it('Should fail with a bad start pagination', async function () { 76 it('Should fail with a bad start pagination', async function () {
140 await request(server.url) 77 await checkBadStartPagination(server.url, path, server.accessToken)
141 .get(path)
142 .set('Authorization', 'Bearer ' + server.accessToken)
143 .query({ start: 'hello' })
144 .set('Accept', 'application/json')
145 .expect(400)
146 }) 78 })
147 79
148 it('Should fail with a bad count pagination', async function () { 80 it('Should fail with a bad count pagination', async function () {
149 await request(server.url) 81 await checkBadCountPagination(server.url, path, server.accessToken)
150 .get(path)
151 .set('Authorization', 'Bearer ' + server.accessToken)
152 .query({ count: 'hello' })
153 .set('Accept', 'application/json')
154 .expect(400)
155 }) 82 })
156 83
157 it('Should fail with an incorrect sort', async function () { 84 it('Should fail with an incorrect sort', async function () {
158 await request(server.url) 85 await checkBadSortPagination(server.url, path, server.accessToken)
159 .get(path)
160 .set('Authorization', 'Bearer ' + server.accessToken)
161 .query({ sort: 'hello' })
162 .set('Accept', 'application/json')
163 .expect(400)
164 }) 86 })
165 }) 87 })
166 88
167 describe('When adding a video', function () { 89 describe('When adding a video', function () {
90 let baseCorrectParams
91 const baseCorrectAttaches = {
92 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
93 }
94
95 before(function () {
96 // Put in before to have channelId
97 baseCorrectParams = {
98 name: 'my super name',
99 category: 5,
100 licence: 1,
101 language: 6,
102 nsfw: false,
103 description: 'my super description',
104 tags: [ 'tag1', 'tag2' ],
105 privacy: VideoPrivacy.PUBLIC,
106 channelId
107 }
108 })
109
168 it('Should fail with nothing', async function () { 110 it('Should fail with nothing', async function () {
169 const fields = {} 111 const fields = {}
170 const attaches = {} 112 const attaches = {}
@@ -172,84 +114,72 @@ describe('Test videos API validator', function () {
172 }) 114 })
173 115
174 it('Should fail without name', async function () { 116 it('Should fail without name', async function () {
175 const fields = getCompleteVideoUploadAttributes() 117 const fields = omit(baseCorrectParams, 'name')
176 delete fields.name 118 const attaches = baseCorrectAttaches
177 119
178 const attaches = getVideoUploadAttaches()
179 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 120 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
180 }) 121 })
181 122
182 it('Should fail with a long name', async function () { 123 it('Should fail with a long name', async function () {
183 const fields = getCompleteVideoUploadAttributes() 124 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
184 fields.name = 'My very very very very very very very very very very very very very very very very very ' + 125 const attaches = baseCorrectAttaches
185 'very very very very very very very very very very very very very very very very long long' +
186 'very very very very very very very very very very very very very very very very long name'
187 126
188 const attaches = getVideoUploadAttaches
189 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 127 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
190 }) 128 })
191 129
192 it('Should fail with a bad category', async function () { 130 it('Should fail with a bad category', async function () {
193 const fields = getCompleteVideoUploadAttributes() 131 const fields = immutableAssign(baseCorrectParams, { category: 125 })
194 fields.category = 125 132 const attaches = baseCorrectAttaches
195 133
196 const attaches = getVideoUploadAttaches
197 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 134 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
198 }) 135 })
199 136
200 it('Should fail with a bad licence', async function () { 137 it('Should fail with a bad licence', async function () {
201 const fields = getCompleteVideoUploadAttributes() 138 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
202 fields.licence = 125 139 const attaches = baseCorrectAttaches
203 140
204 const attaches = getVideoUploadAttaches()
205 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 141 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
206 }) 142 })
207 143
208 it('Should fail with a bad language', async function () { 144 it('Should fail with a bad language', async function () {
209 const fields = getCompleteVideoUploadAttributes() 145 const fields = immutableAssign(baseCorrectParams, { language: 125 })
210 fields.language = 563 146 const attaches = baseCorrectAttaches
211 147
212 const attaches = getVideoUploadAttaches()
213 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 148 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
214 }) 149 })
215 150
216 it('Should fail without nsfw attribute', async function () { 151 it('Should fail without nsfw attribute', async function () {
217 const fields = getCompleteVideoUploadAttributes() 152 const fields = omit(baseCorrectParams, 'nsfw')
218 delete fields.nsfw 153 const attaches = baseCorrectAttaches
219 154
220 const attaches = getVideoUploadAttaches()
221 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 155 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
222 }) 156 })
223 157
224 it('Should fail with a bad nsfw attribute', async function () { 158 it('Should fail with a bad nsfw attribute', async function () {
225 const fields = getCompleteVideoUploadAttributes() 159 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
226 fields.nsfw = 2 as any 160 const attaches = baseCorrectAttaches
227 161
228 const attaches = getVideoUploadAttaches()
229 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 162 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
230 }) 163 })
231 164
232 it('Should fail with a long description', async function () { 165 it('Should fail with a long description', async function () {
233 const fields = getCompleteVideoUploadAttributes() 166 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
234 fields.description = 'my super description which is very very very very very very very very very very very very long'.repeat(35) 167 const attaches = baseCorrectAttaches
235 168
236 const attaches = getVideoUploadAttaches()
237 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 169 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
238 }) 170 })
239 171
240 it('Should fail without a channel', async function () { 172 it('Should fail without a channel', async function () {
241 const fields = getCompleteVideoUploadAttributes() 173 const fields = omit(baseCorrectParams, 'channelId')
242 delete fields.channelId 174 const attaches = baseCorrectAttaches
243 175
244 const attaches = getVideoUploadAttaches()
245 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 176 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
246 }) 177 })
247 178
248 it('Should fail with a bad channel', async function () { 179 it('Should fail with a bad channel', async function () {
249 const fields = getCompleteVideoUploadAttributes() 180 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
250 fields.channelId = 545454 181 const attaches = baseCorrectAttaches
251 182
252 const attaches = getVideoUploadAttaches()
253 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 183 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
254 }) 184 })
255 185
@@ -264,45 +194,41 @@ describe('Test videos API validator', function () {
264 const res = await getMyUserInformation(server.url, accessTokenUser) 194 const res = await getMyUserInformation(server.url, accessTokenUser)
265 const customChannelId = res.body.videoChannels[0].id 195 const customChannelId = res.body.videoChannels[0].id
266 196
267 const fields = getCompleteVideoUploadAttributes() 197 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
268 fields.channelId = customChannelId 198 const attaches = baseCorrectAttaches
269 199
270 const attaches = getVideoUploadAttaches()
271 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 200 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
272 }) 201 })
273 202
274 it('Should fail with too many tags', async function () { 203 it('Should fail with too many tags', async function () {
275 const fields = getCompleteVideoUploadAttributes() 204 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
276 fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] 205 const attaches = baseCorrectAttaches
277 206
278 const attaches = getVideoUploadAttaches()
279 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 207 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
280 }) 208 })
281 209
282 it('Should fail with a tag length too low', async function () { 210 it('Should fail with a tag length too low', async function () {
283 const fields = getCompleteVideoUploadAttributes() 211 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
284 fields.tags = [ 'tag1', 't' ] 212 const attaches = baseCorrectAttaches
285 213
286 const attaches = getVideoUploadAttaches()
287 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 214 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
288 }) 215 })
289 216
290 it('Should fail with a tag length too big', async function () { 217 it('Should fail with a tag length too big', async function () {
291 const fields = getCompleteVideoUploadAttributes() 218 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
292 fields.tags = [ 'my_super_tag_too_long_long_long_long_long_long', 'tag1' ] 219 const attaches = baseCorrectAttaches
293 220
294 const attaches = getVideoUploadAttaches()
295 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 221 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
296 }) 222 })
297 223
298 it('Should fail without an input file', async function () { 224 it('Should fail without an input file', async function () {
299 const fields = getCompleteVideoUploadAttributes() 225 const fields = baseCorrectParams
300 const attaches = {} 226 const attaches = {}
301 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 227 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
302 }) 228 })
303 229
304 it('Should fail without an incorrect input file', async function () { 230 it('Should fail without an incorrect input file', async function () {
305 const fields = getCompleteVideoUploadAttributes() 231 const fields = baseCorrectParams
306 const attaches = { 232 const attaches = {
307 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') 233 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
308 } 234 }
@@ -312,41 +238,63 @@ describe('Test videos API validator', function () {
312 it('Should succeed with the correct parameters', async function () { 238 it('Should succeed with the correct parameters', async function () {
313 this.timeout(10000) 239 this.timeout(10000)
314 240
315 const fields = getCompleteVideoUploadAttributes() 241 const fields = baseCorrectParams
316 const attaches = getVideoUploadAttaches() 242
317 243 {
318 await makePostUploadRequest({ 244 const attaches = baseCorrectAttaches
319 url: server.url, 245 await makePostUploadRequest({
320 path: path + '/upload', 246 url: server.url,
321 token: server.accessToken, 247 path: path + '/upload',
322 fields, 248 token: server.accessToken,
323 attaches, 249 fields,
324 statusCodeExpected: 200 250 attaches,
325 }) 251 statusCodeExpected: 200
252 })
253 }
326 254
327 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4') 255 {
328 await makePostUploadRequest({ 256 const attaches = immutableAssign(baseCorrectAttaches, {
329 url: server.url, 257 videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4')
330 path: path + '/upload', 258 })
331 token: server.accessToken, 259
332 fields, 260 await makePostUploadRequest({
333 attaches, 261 url: server.url,
334 statusCodeExpected: 200 262 path: path + '/upload',
335 }) 263 token: server.accessToken,
264 fields,
265 attaches,
266 statusCodeExpected: 200
267 })
268 }
336 269
337 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv') 270 {
338 await makePostUploadRequest({ 271 const attaches = immutableAssign(baseCorrectAttaches, {
339 url: server.url, 272 videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv')
340 path: path + '/upload', 273 })
341 token: server.accessToken, 274
342 fields, 275 await makePostUploadRequest({
343 attaches, 276 url: server.url,
344 statusCodeExpected: 200 277 path: path + '/upload',
345 }) 278 token: server.accessToken,
279 fields,
280 attaches,
281 statusCodeExpected: 200
282 })
283 }
346 }) 284 })
347 }) 285 })
348 286
349 describe('When updating a video', function () { 287 describe('When updating a video', function () {
288 const baseCorrectParams = {
289 name: 'my super name',
290 category: 5,
291 licence: 2,
292 language: 6,
293 nsfw: false,
294 description: 'my super description',
295 privacy: VideoPrivacy.PUBLIC,
296 tags: [ 'tag1', 'tag2' ]
297 }
350 let videoId 298 let videoId
351 299
352 before(async function () { 300 before(async function () {
@@ -360,12 +308,12 @@ describe('Test videos API validator', function () {
360 }) 308 })
361 309
362 it('Should fail without a valid uuid', async function () { 310 it('Should fail without a valid uuid', async function () {
363 const fields = getCompleteVideoUpdateAttributes() 311 const fields = baseCorrectParams
364 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields }) 312 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
365 }) 313 })
366 314
367 it('Should fail with an unknown id', async function () { 315 it('Should fail with an unknown id', async function () {
368 const fields = getCompleteVideoUpdateAttributes() 316 const fields = baseCorrectParams
369 317
370 await makePutBodyRequest({ 318 await makePutBodyRequest({
371 url: server.url, 319 url: server.url,
@@ -377,64 +325,55 @@ describe('Test videos API validator', function () {
377 }) 325 })
378 326
379 it('Should fail with a long name', async function () { 327 it('Should fail with a long name', async function () {
380 const fields = getCompleteVideoUpdateAttributes() 328 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
381 fields.name = 'My very very very very very very very very very very very very very very very very long'.repeat(3)
382 329
383 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 330 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
384 }) 331 })
385 332
386 it('Should fail with a bad category', async function () { 333 it('Should fail with a bad category', async function () {
387 const fields = getCompleteVideoUpdateAttributes() 334 const fields = immutableAssign(baseCorrectParams, { category: 125 })
388 fields.category = 128
389 335
390 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 336 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
391 }) 337 })
392 338
393 it('Should fail with a bad licence', async function () { 339 it('Should fail with a bad licence', async function () {
394 const fields = getCompleteVideoUpdateAttributes() 340 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
395 fields.licence = 128
396 341
397 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 342 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
398 }) 343 })
399 344
400 it('Should fail with a bad language', async function () { 345 it('Should fail with a bad language', async function () {
401 const fields = getCompleteVideoUpdateAttributes() 346 const fields = immutableAssign(baseCorrectParams, { language: 125 })
402 fields.language = 896
403 347
404 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 348 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
405 }) 349 })
406 350
407 it('Should fail with a bad nsfw attribute', async function () { 351 it('Should fail with a bad nsfw attribute', async function () {
408 const fields = getCompleteVideoUpdateAttributes() 352 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
409 fields.nsfw = (-4 as any)
410 353
411 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 354 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
412 }) 355 })
413 356
414 it('Should fail with a long description', async function () { 357 it('Should fail with a long description', async function () {
415 const fields = getCompleteVideoUpdateAttributes() 358 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
416 fields.description = 'my super description which is very very very very very very very very very very very very very long'.repeat(35)
417 359
418 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 360 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
419 }) 361 })
420 362
421 it('Should fail with too many tags', async function () { 363 it('Should fail with too many tags', async function () {
422 const fields = getCompleteVideoUpdateAttributes() 364 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
423 fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ]
424 365
425 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 366 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
426 }) 367 })
427 368
428 it('Should fail with a tag length too low', async function () { 369 it('Should fail with a tag length too low', async function () {
429 const fields = getCompleteVideoUpdateAttributes() 370 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
430 fields.tags = [ 'tag1', 't' ]
431 371
432 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 372 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
433 }) 373 })
434 374
435 it('Should fail with a tag length too big', async function () { 375 it('Should fail with a tag length too big', async function () {
436 const fields = getCompleteVideoUpdateAttributes() 376 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
437 fields.tags = [ 'my_super_tag_too_long_long_long_long', 'tag1' ]
438 377
439 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 378 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
440 }) 379 })
@@ -444,7 +383,7 @@ describe('Test videos API validator', function () {
444 it('Should fail with a video of another server') 383 it('Should fail with a video of another server')
445 384
446 it('Should succeed with the correct parameters', async function () { 385 it('Should succeed with the correct parameters', async function () {
447 const fields = getCompleteVideoUpdateAttributes() 386 const fields = baseCorrectParams
448 387
449 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) 388 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
450 }) 389 })
@@ -452,28 +391,22 @@ describe('Test videos API validator', function () {
452 391
453 describe('When getting a video', function () { 392 describe('When getting a video', function () {
454 it('Should return the list of the videos with nothing', async function () { 393 it('Should return the list of the videos with nothing', async function () {
455 const res = await request(server.url) 394 const res = await makeGetRequest({
456 .get(path) 395 url: server.url,
457 .set('Accept', 'application/json') 396 path,
458 .expect(200) 397 statusCodeExpected: 200
459 .expect('Content-Type', /json/) 398 })
460 399
461 expect(res.body.data).to.be.an('array') 400 expect(res.body.data).to.be.an('array')
462 expect(res.body.data.length).to.equal(3) 401 expect(res.body.data.length).to.equal(3)
463 }) 402 })
464 403
465 it('Should fail without a correct uuid', async function () { 404 it('Should fail without a correct uuid', async function () {
466 await request(server.url) 405 await getVideo(server.url, 'coucou', 400)
467 .get(path + 'coucou')
468 .set('Accept', 'application/json')
469 .expect(400)
470 }) 406 })
471 407
472 it('Should return 404 with an incorrect video', async function () { 408 it('Should return 404 with an incorrect video', async function () {
473 await request(server.url) 409 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
474 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
475 .set('Accept', 'application/json')
476 .expect(404)
477 }) 410 })
478 411
479 it('Should succeed with the correct parameters') 412 it('Should succeed with the correct parameters')
@@ -530,24 +463,19 @@ describe('Test videos API validator', function () {
530 463
531 describe('When removing a video', function () { 464 describe('When removing a video', function () {
532 it('Should have 404 with nothing', async function () { 465 it('Should have 404 with nothing', async function () {
533 await request(server.url) 466 await makeDeleteRequest({
534 .delete(path) 467 url: server.url,
535 .set('Authorization', 'Bearer ' + server.accessToken) 468 path,
536 .expect(400) 469 statusCodeExpected: 400
470 })
537 }) 471 })
538 472
539 it('Should fail without a correct uuid', async function () { 473 it('Should fail without a correct uuid', async function () {
540 await request(server.url) 474 await removeVideo(server.url, server.accessToken, 'hello', 400)
541 .delete(path + 'hello')
542 .set('Authorization', 'Bearer ' + server.accessToken)
543 .expect(400)
544 }) 475 })
545 476
546 it('Should fail with a video which does not exist', async function () { 477 it('Should fail with a video which does not exist', async function () {
547 await request(server.url) 478 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
548 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
549 .set('Authorization', 'Bearer ' + server.accessToken)
550 .expect(404)
551 }) 479 })
552 480
553 it('Should fail with a video of another user') 481 it('Should fail with a video of another user')