1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { keyBy } from 'lodash'
6 import { join } from 'path'
7 import { VideoPrivacy } from '../../../../shared/models/videos'
8 import { readdirPromise } from '../../../helpers/core-utils'
10 completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies,
11 getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, searchVideo,
12 searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo
15 const expect = chai.expect
17 describe('Test a single server', function () {
18 let server: ServerInfo = null
21 let videosListBase: any[] = null
23 const getCheckAttributes = {
24 name: 'my super name',
29 description: 'my super description',
30 host: 'localhost:9001',
34 tags: [ 'tag1', 'tag2', 'tag3' ],
35 privacy: VideoPrivacy.PUBLIC,
36 commentsEnabled: true,
38 name: 'Default root channel',
42 fixture: 'video_short.webm',
51 const updateCheckAttributes = {
52 name: 'my super video updated',
57 description: 'my super description updated',
58 host: 'localhost:9001',
61 tags: [ 'tagup1', 'tagup2' ],
62 privacy: VideoPrivacy.PUBLIC,
64 commentsEnabled: false,
66 name: 'Default root channel',
70 fixture: 'video_short3.webm',
79 before(async function () {
84 server = await runServer(1)
86 await setAccessTokensToServers([ server ])
89 it('Should list video categories', async function () {
90 const res = await getVideoCategories(server.url)
92 const categories = res.body
93 expect(Object.keys(categories)).to.have.length.above(10)
95 expect(categories[11]).to.equal('News')
98 it('Should list video licences', async function () {
99 const res = await getVideoLicences(server.url)
101 const licences = res.body
102 expect(Object.keys(licences)).to.have.length.above(5)
104 expect(licences[3]).to.equal('Attribution - No Derivatives')
107 it('Should list video languages', async function () {
108 const res = await getVideoLanguages(server.url)
110 const languages = res.body
111 expect(Object.keys(languages)).to.have.length.above(5)
113 expect(languages[3]).to.equal('Mandarin')
116 it('Should list video privacies', async function () {
117 const res = await getVideoPrivacies(server.url)
119 const privacies = res.body
120 expect(Object.keys(privacies)).to.have.length.at.least(3)
122 expect(privacies[3]).to.equal('Private')
125 it('Should not have videos', async function () {
126 const res = await getVideosList(server.url)
128 expect(res.body.total).to.equal(0)
129 expect(res.body.data).to.be.an('array')
130 expect(res.body.data.length).to.equal(0)
133 it('Should upload the video', async function () {
134 const videoAttributes = {
135 name: 'my super name',
139 tags: [ 'tag1', 'tag2', 'tag3' ]
141 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
142 expect(res.body.video).to.not.be.undefined
143 expect(res.body.video.id).to.equal(1)
144 expect(res.body.video.uuid).to.have.length.above(5)
146 videoId = res.body.video.id
147 videoUUID = res.body.video.uuid
150 it('Should get and seed the uploaded video', async function () {
151 // Yes, this could be long
154 const res = await getVideosList(server.url)
156 expect(res.body.total).to.equal(1)
157 expect(res.body.data).to.be.an('array')
158 expect(res.body.data.length).to.equal(1)
160 const video = res.body.data[0]
161 await completeVideoCheck(server.url, video, getCheckAttributes)
164 it('Should get the video by UUID', async function () {
165 // Yes, this could be long
168 const res = await getVideo(server.url, videoUUID)
170 const video = res.body
171 await completeVideoCheck(server.url, video, getCheckAttributes)
174 it('Should have the views updated', async function () {
175 await viewVideo(server.url, videoId)
176 await viewVideo(server.url, videoId)
177 await viewVideo(server.url, videoId)
179 const res = await getVideo(server.url, videoId)
181 const video = res.body
182 expect(video.views).to.equal(3)
185 it('Should search the video by name', async function () {
186 const res = await searchVideo(server.url, 'my')
188 expect(res.body.total).to.equal(1)
189 expect(res.body.data).to.be.an('array')
190 expect(res.body.data.length).to.equal(1)
192 const video = res.body.data[0]
193 await completeVideoCheck(server.url, video, getCheckAttributes)
196 // Not implemented yet
197 // it('Should search the video by serverHost', async function () {
198 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
200 // expect(res.body.total).to.equal(1)
201 // expect(res.body.data).to.be.an('array')
202 // expect(res.body.data.length).to.equal(1)
204 // const video = res.body.data[0]
205 // expect(video.name).to.equal('my super name')
206 // expect(video.description).to.equal('my super description')
207 // expect(video.serverHost).to.equal('localhost:9001')
208 // expect(video.author).to.equal('root')
209 // expect(video.isLocal).to.be.true
210 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
211 // expect(dateIsValid(video.createdAt)).to.be.true
212 // expect(dateIsValid(video.updatedAt)).to.be.true
214 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
215 // expect(test).to.equal(true)
222 // Not implemented yet
223 // it('Should search the video by tag', async function () {
224 // const res = await searchVideo(server.url, 'tag1')
226 // expect(res.body.total).to.equal(1)
227 // expect(res.body.data).to.be.an('array')
228 // expect(res.body.data.length).to.equal(1)
230 // const video = res.body.data[0]
231 // expect(video.name).to.equal('my super name')
232 // expect(video.category).to.equal(2)
233 // expect(video.categoryLabel).to.equal('Films')
234 // expect(video.licence).to.equal(6)
235 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
236 // expect(video.language).to.equal(3)
237 // expect(video.languageLabel).to.equal('Mandarin')
238 // expect(video.nsfw).to.be.ok
239 // expect(video.description).to.equal('my super description')
240 // expect(video.serverHost).to.equal('localhost:9001')
241 // expect(video.accountName).to.equal('root')
242 // expect(video.isLocal).to.be.true
243 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
244 // expect(dateIsValid(video.createdAt)).to.be.true
245 // expect(dateIsValid(video.updatedAt)).to.be.true
247 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
248 // expect(test).to.equal(true)
251 it('Should not find a search by name', async function () {
252 const res = await searchVideo(server.url, 'hello')
254 expect(res.body.total).to.equal(0)
255 expect(res.body.data).to.be.an('array')
256 expect(res.body.data.length).to.equal(0)
259 // Not implemented yet
260 // it('Should not find a search by author', async function () {
261 // const res = await searchVideo(server.url, 'hello')
263 // expect(res.body.total).to.equal(0)
264 // expect(res.body.data).to.be.an('array')
265 // expect(res.body.data.length).to.equal(0)
268 // Not implemented yet
269 // it('Should not find a search by tag', async function () {
270 // const res = await searchVideo(server.url, 'hello')
272 // expect(res.body.total).to.equal(0)
273 // expect(res.body.data).to.be.an('array')
274 // expect(res.body.data.length).to.equal(0)
277 it('Should remove the video', async function () {
278 await removeVideo(server.url, server.accessToken, videoId)
280 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'videos'))
281 expect(files1).to.have.lengthOf(0)
283 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'thumbnails'))
284 expect(files2).to.have.lengthOf(0)
287 it('Should not have videos', async function () {
288 const res = await getVideosList(server.url)
290 expect(res.body.total).to.equal(0)
291 expect(res.body.data).to.be.an('array')
292 expect(res.body.data).to.have.lengthOf(0)
295 it('Should upload 6 videos', async function () {
299 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
300 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
303 const tasks: Promise<any>[] = []
304 for (const video of videos) {
305 const videoAttributes = {
306 name: video + ' name',
307 description: video + ' description',
312 tags: [ 'tag1', 'tag2', 'tag3' ],
316 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
320 await Promise.all(tasks)
323 it('Should have the correct durations', async function () {
324 const res = await getVideosList(server.url)
326 expect(res.body.total).to.equal(6)
327 const videos = res.body.data
328 expect(videos).to.be.an('array')
329 expect(videos).to.have.lengthOf(6)
331 const videosByName = keyBy<{ duration: number }>(videos, 'name')
332 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
333 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
334 expect(videosByName['video_short.webm name'].duration).to.equal(5)
335 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
336 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
337 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
340 it('Should have the correct thumbnails', async function () {
341 const res = await getVideosList(server.url)
343 const videos = res.body.data
345 videosListBase = videos
347 for (const video of videos) {
348 const videoName = video.name.replace(' name', '')
349 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
351 expect(test).to.equal(true)
355 it('Should list only the two first videos', async function () {
356 const res = await getVideosListPagination(server.url, 0, 2, 'name')
358 const videos = res.body.data
359 expect(res.body.total).to.equal(6)
360 expect(videos.length).to.equal(2)
361 expect(videos[0].name).to.equal(videosListBase[0].name)
362 expect(videos[1].name).to.equal(videosListBase[1].name)
365 it('Should list only the next three videos', async function () {
366 const res = await getVideosListPagination(server.url, 2, 3, 'name')
368 const videos = res.body.data
369 expect(res.body.total).to.equal(6)
370 expect(videos.length).to.equal(3)
371 expect(videos[0].name).to.equal(videosListBase[2].name)
372 expect(videos[1].name).to.equal(videosListBase[3].name)
373 expect(videos[2].name).to.equal(videosListBase[4].name)
376 it('Should list the last video', async function () {
377 const res = await getVideosListPagination(server.url, 5, 6, 'name')
379 const videos = res.body.data
380 expect(res.body.total).to.equal(6)
381 expect(videos.length).to.equal(1)
382 expect(videos[0].name).to.equal(videosListBase[5].name)
385 it('Should search the first video', async function () {
386 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
388 const videos = res.body.data
389 expect(res.body.total).to.equal(4)
390 expect(videos.length).to.equal(1)
391 expect(videos[0].name).to.equal('video_short1.webm name')
394 it('Should search the last two videos', async function () {
395 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
397 const videos = res.body.data
398 expect(res.body.total).to.equal(4)
399 expect(videos.length).to.equal(2)
400 expect(videos[0].name).to.equal('video_short3.webm name')
401 expect(videos[1].name).to.equal('video_short.webm name')
404 it('Should search all the webm videos', async function () {
405 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
407 const videos = res.body.data
408 expect(res.body.total).to.equal(4)
409 expect(videos.length).to.equal(4)
412 // Not implemented yet
413 // it('Should search all the root author videos', async function () {
414 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
416 // const videos = res.body.data
417 // expect(res.body.total).to.equal(6)
418 // expect(videos.length).to.equal(6)
421 // Not implemented yet
422 // it('Should search all the 9001 port videos', async function () {
423 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
425 // const videos = res.body.data
426 // expect(res.body.total).to.equal(6)
427 // expect(videos.length).to.equal(6)
433 // it('Should search all the localhost videos', async function () {
434 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
436 // const videos = res.body.data
437 // expect(res.body.total).to.equal(6)
438 // expect(videos.length).to.equal(6)
444 it('Should list and sort by name in descending order', async function () {
445 const res = await getVideosListSort(server.url, '-name')
447 const videos = res.body.data
448 expect(res.body.total).to.equal(6)
449 expect(videos.length).to.equal(6)
450 expect(videos[0].name).to.equal('video_short.webm name')
451 expect(videos[1].name).to.equal('video_short.ogv name')
452 expect(videos[2].name).to.equal('video_short.mp4 name')
453 expect(videos[3].name).to.equal('video_short3.webm name')
454 expect(videos[4].name).to.equal('video_short2.webm name')
455 expect(videos[5].name).to.equal('video_short1.webm name')
458 it('Should search and sort by name in ascending order', async function () {
459 const res = await searchVideoWithSort(server.url, 'webm', 'name')
461 const videos = res.body.data
462 expect(res.body.total).to.equal(4)
463 expect(videos.length).to.equal(4)
465 expect(videos[0].name).to.equal('video_short1.webm name')
466 expect(videos[1].name).to.equal('video_short2.webm name')
467 expect(videos[2].name).to.equal('video_short3.webm name')
468 expect(videos[3].name).to.equal('video_short.webm name')
470 videoId = videos[2].id
473 it('Should update a video', async function () {
475 name: 'my super video updated',
480 description: 'my super description updated',
481 commentsEnabled: false,
482 tags: [ 'tagup1', 'tagup2' ]
484 await updateVideo(server.url, server.accessToken, videoId, attributes)
487 it('Should have the video updated', async function () {
490 const res = await getVideo(server.url, videoId)
491 const video = res.body
493 await completeVideoCheck(server.url, video, updateCheckAttributes)
496 it('Should update only the tags of a video', async function () {
498 tags: [ 'supertag', 'tag1', 'tag2' ]
500 await updateVideo(server.url, server.accessToken, videoId, attributes)
502 const res = await getVideo(server.url, videoId)
503 const video = res.body
505 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
508 it('Should update only the description of a video', async function () {
510 description: 'hello everybody'
512 await updateVideo(server.url, server.accessToken, videoId, attributes)
514 const res = await getVideo(server.url, videoId)
515 const video = res.body
517 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
520 it('Should like a video', async function () {
521 await rateVideo(server.url, server.accessToken, videoId, 'like')
523 const res = await getVideo(server.url, videoId)
524 const video = res.body
526 expect(video.likes).to.equal(1)
527 expect(video.dislikes).to.equal(0)
530 it('Should dislike the same video', async function () {
531 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
533 const res = await getVideo(server.url, videoId)
534 const video = res.body
536 expect(video.likes).to.equal(0)
537 expect(video.dislikes).to.equal(1)
540 after(async function () {
541 killallServers([ server ])
543 // Keep the logs if the test failed