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'
9 completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies,
10 getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, readdirPromise, removeVideo, runServer, searchVideo,
11 searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo
14 const expect = chai.expect
16 describe('Test a single server', function () {
17 let server: ServerInfo = null
20 let videosListBase: any[] = null
22 const getCheckAttributes = {
23 name: 'my super name',
28 description: 'my super description',
29 host: 'localhost:9001',
33 tags: [ 'tag1', 'tag2', 'tag3' ],
34 privacy: VideoPrivacy.PUBLIC,
35 commentsEnabled: true,
37 name: 'Default root channel',
41 fixture: 'video_short.webm',
50 const updateCheckAttributes = {
51 name: 'my super video updated',
56 description: 'my super description updated',
57 host: 'localhost:9001',
60 tags: [ 'tagup1', 'tagup2' ],
61 privacy: VideoPrivacy.PUBLIC,
63 commentsEnabled: false,
65 name: 'Default root channel',
69 fixture: 'video_short3.webm',
78 before(async function () {
83 server = await runServer(1)
85 await setAccessTokensToServers([ server ])
88 it('Should list video categories', async function () {
89 const res = await getVideoCategories(server.url)
91 const categories = res.body
92 expect(Object.keys(categories)).to.have.length.above(10)
94 expect(categories[11]).to.equal('News')
97 it('Should list video licences', async function () {
98 const res = await getVideoLicences(server.url)
100 const licences = res.body
101 expect(Object.keys(licences)).to.have.length.above(5)
103 expect(licences[3]).to.equal('Attribution - No Derivatives')
106 it('Should list video languages', async function () {
107 const res = await getVideoLanguages(server.url)
109 const languages = res.body
110 expect(Object.keys(languages)).to.have.length.above(5)
112 expect(languages[3]).to.equal('Mandarin')
115 it('Should list video privacies', async function () {
116 const res = await getVideoPrivacies(server.url)
118 const privacies = res.body
119 expect(Object.keys(privacies)).to.have.length.at.least(3)
121 expect(privacies[3]).to.equal('Private')
124 it('Should not have videos', async function () {
125 const res = await getVideosList(server.url)
127 expect(res.body.total).to.equal(0)
128 expect(res.body.data).to.be.an('array')
129 expect(res.body.data.length).to.equal(0)
132 it('Should upload the video', async function () {
133 const videoAttributes = {
134 name: 'my super name',
138 tags: [ 'tag1', 'tag2', 'tag3' ]
140 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
141 expect(res.body.video).to.not.be.undefined
142 expect(res.body.video.id).to.equal(1)
143 expect(res.body.video.uuid).to.have.length.above(5)
145 videoId = res.body.video.id
146 videoUUID = res.body.video.uuid
149 it('Should get and seed the uploaded video', async function () {
150 // Yes, this could be long
153 const res = await getVideosList(server.url)
155 expect(res.body.total).to.equal(1)
156 expect(res.body.data).to.be.an('array')
157 expect(res.body.data.length).to.equal(1)
159 const video = res.body.data[0]
160 await completeVideoCheck(server.url, video, getCheckAttributes)
163 it('Should get the video by UUID', async function () {
164 // Yes, this could be long
167 const res = await getVideo(server.url, videoUUID)
169 const video = res.body
170 await completeVideoCheck(server.url, video, getCheckAttributes)
173 it('Should have the views updated', async function () {
174 await viewVideo(server.url, videoId)
175 await viewVideo(server.url, videoId)
176 await viewVideo(server.url, videoId)
178 const res = await getVideo(server.url, videoId)
180 const video = res.body
181 expect(video.views).to.equal(3)
184 it('Should search the video by name', async function () {
185 const res = await searchVideo(server.url, 'my')
187 expect(res.body.total).to.equal(1)
188 expect(res.body.data).to.be.an('array')
189 expect(res.body.data.length).to.equal(1)
191 const video = res.body.data[0]
192 await completeVideoCheck(server.url, video, getCheckAttributes)
195 // Not implemented yet
196 // it('Should search the video by serverHost', async function () {
197 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
199 // expect(res.body.total).to.equal(1)
200 // expect(res.body.data).to.be.an('array')
201 // expect(res.body.data.length).to.equal(1)
203 // const video = res.body.data[0]
204 // expect(video.name).to.equal('my super name')
205 // expect(video.description).to.equal('my super description')
206 // expect(video.serverHost).to.equal('localhost:9001')
207 // expect(video.author).to.equal('root')
208 // expect(video.isLocal).to.be.true
209 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
210 // expect(dateIsValid(video.createdAt)).to.be.true
211 // expect(dateIsValid(video.updatedAt)).to.be.true
213 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
214 // expect(test).to.equal(true)
221 // Not implemented yet
222 // it('Should search the video by tag', async function () {
223 // const res = await searchVideo(server.url, 'tag1')
225 // expect(res.body.total).to.equal(1)
226 // expect(res.body.data).to.be.an('array')
227 // expect(res.body.data.length).to.equal(1)
229 // const video = res.body.data[0]
230 // expect(video.name).to.equal('my super name')
231 // expect(video.category).to.equal(2)
232 // expect(video.categoryLabel).to.equal('Films')
233 // expect(video.licence).to.equal(6)
234 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
235 // expect(video.language).to.equal(3)
236 // expect(video.languageLabel).to.equal('Mandarin')
237 // expect(video.nsfw).to.be.ok
238 // expect(video.description).to.equal('my super description')
239 // expect(video.serverHost).to.equal('localhost:9001')
240 // expect(video.accountName).to.equal('root')
241 // expect(video.isLocal).to.be.true
242 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
243 // expect(dateIsValid(video.createdAt)).to.be.true
244 // expect(dateIsValid(video.updatedAt)).to.be.true
246 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
247 // expect(test).to.equal(true)
250 it('Should not find a search by name', async function () {
251 const res = await searchVideo(server.url, 'hello')
253 expect(res.body.total).to.equal(0)
254 expect(res.body.data).to.be.an('array')
255 expect(res.body.data.length).to.equal(0)
258 // Not implemented yet
259 // it('Should not find a search by author', async function () {
260 // const res = await searchVideo(server.url, 'hello')
262 // expect(res.body.total).to.equal(0)
263 // expect(res.body.data).to.be.an('array')
264 // expect(res.body.data.length).to.equal(0)
267 // Not implemented yet
268 // it('Should not find a search by tag', async function () {
269 // const res = await searchVideo(server.url, 'hello')
271 // expect(res.body.total).to.equal(0)
272 // expect(res.body.data).to.be.an('array')
273 // expect(res.body.data.length).to.equal(0)
276 it('Should remove the video', async function () {
277 await removeVideo(server.url, server.accessToken, videoId)
279 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'videos'))
280 expect(files1).to.have.lengthOf(0)
282 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'thumbnails'))
283 expect(files2).to.have.lengthOf(0)
286 it('Should not have videos', async function () {
287 const res = await getVideosList(server.url)
289 expect(res.body.total).to.equal(0)
290 expect(res.body.data).to.be.an('array')
291 expect(res.body.data).to.have.lengthOf(0)
294 it('Should upload 6 videos', async function () {
298 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
299 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
302 const tasks: Promise<any>[] = []
303 for (const video of videos) {
304 const videoAttributes = {
305 name: video + ' name',
306 description: video + ' description',
311 tags: [ 'tag1', 'tag2', 'tag3' ],
315 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
319 await Promise.all(tasks)
322 it('Should have the correct durations', async function () {
323 const res = await getVideosList(server.url)
325 expect(res.body.total).to.equal(6)
326 const videos = res.body.data
327 expect(videos).to.be.an('array')
328 expect(videos).to.have.lengthOf(6)
330 const videosByName = keyBy<{ duration: number }>(videos, 'name')
331 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
332 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
333 expect(videosByName['video_short.webm name'].duration).to.equal(5)
334 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
335 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
336 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
339 it('Should have the correct thumbnails', async function () {
340 const res = await getVideosList(server.url)
342 const videos = res.body.data
344 videosListBase = videos
346 for (const video of videos) {
347 const videoName = video.name.replace(' name', '')
348 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
350 expect(test).to.equal(true)
354 it('Should list only the two first videos', async function () {
355 const res = await getVideosListPagination(server.url, 0, 2, 'name')
357 const videos = res.body.data
358 expect(res.body.total).to.equal(6)
359 expect(videos.length).to.equal(2)
360 expect(videos[0].name).to.equal(videosListBase[0].name)
361 expect(videos[1].name).to.equal(videosListBase[1].name)
364 it('Should list only the next three videos', async function () {
365 const res = await getVideosListPagination(server.url, 2, 3, 'name')
367 const videos = res.body.data
368 expect(res.body.total).to.equal(6)
369 expect(videos.length).to.equal(3)
370 expect(videos[0].name).to.equal(videosListBase[2].name)
371 expect(videos[1].name).to.equal(videosListBase[3].name)
372 expect(videos[2].name).to.equal(videosListBase[4].name)
375 it('Should list the last video', async function () {
376 const res = await getVideosListPagination(server.url, 5, 6, 'name')
378 const videos = res.body.data
379 expect(res.body.total).to.equal(6)
380 expect(videos.length).to.equal(1)
381 expect(videos[0].name).to.equal(videosListBase[5].name)
384 it('Should search the first video', async function () {
385 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
387 const videos = res.body.data
388 expect(res.body.total).to.equal(4)
389 expect(videos.length).to.equal(1)
390 expect(videos[0].name).to.equal('video_short1.webm name')
393 it('Should search the last two videos', async function () {
394 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
396 const videos = res.body.data
397 expect(res.body.total).to.equal(4)
398 expect(videos.length).to.equal(2)
399 expect(videos[0].name).to.equal('video_short3.webm name')
400 expect(videos[1].name).to.equal('video_short.webm name')
403 it('Should search all the webm videos', async function () {
404 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
406 const videos = res.body.data
407 expect(res.body.total).to.equal(4)
408 expect(videos.length).to.equal(4)
411 // Not implemented yet
412 // it('Should search all the root author videos', async function () {
413 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
415 // const videos = res.body.data
416 // expect(res.body.total).to.equal(6)
417 // expect(videos.length).to.equal(6)
420 // Not implemented yet
421 // it('Should search all the 9001 port videos', async function () {
422 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
424 // const videos = res.body.data
425 // expect(res.body.total).to.equal(6)
426 // expect(videos.length).to.equal(6)
432 // it('Should search all the localhost videos', async function () {
433 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
435 // const videos = res.body.data
436 // expect(res.body.total).to.equal(6)
437 // expect(videos.length).to.equal(6)
443 it('Should list and sort by name in descending order', async function () {
444 const res = await getVideosListSort(server.url, '-name')
446 const videos = res.body.data
447 expect(res.body.total).to.equal(6)
448 expect(videos.length).to.equal(6)
449 expect(videos[0].name).to.equal('video_short.webm name')
450 expect(videos[1].name).to.equal('video_short.ogv name')
451 expect(videos[2].name).to.equal('video_short.mp4 name')
452 expect(videos[3].name).to.equal('video_short3.webm name')
453 expect(videos[4].name).to.equal('video_short2.webm name')
454 expect(videos[5].name).to.equal('video_short1.webm name')
457 it('Should search and sort by name in ascending order', async function () {
458 const res = await searchVideoWithSort(server.url, 'webm', 'name')
460 const videos = res.body.data
461 expect(res.body.total).to.equal(4)
462 expect(videos.length).to.equal(4)
464 expect(videos[0].name).to.equal('video_short1.webm name')
465 expect(videos[1].name).to.equal('video_short2.webm name')
466 expect(videos[2].name).to.equal('video_short3.webm name')
467 expect(videos[3].name).to.equal('video_short.webm name')
469 videoId = videos[2].id
472 it('Should update a video', async function () {
474 name: 'my super video updated',
479 description: 'my super description updated',
480 commentsEnabled: false,
481 tags: [ 'tagup1', 'tagup2' ]
483 await updateVideo(server.url, server.accessToken, videoId, attributes)
486 it('Should have the video updated', async function () {
489 const res = await getVideo(server.url, videoId)
490 const video = res.body
492 await completeVideoCheck(server.url, video, updateCheckAttributes)
495 it('Should update only the tags of a video', async function () {
497 tags: [ 'supertag', 'tag1', 'tag2' ]
499 await updateVideo(server.url, server.accessToken, videoId, attributes)
501 const res = await getVideo(server.url, videoId)
502 const video = res.body
504 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
507 it('Should update only the description of a video', async function () {
509 description: 'hello everybody'
511 await updateVideo(server.url, server.accessToken, videoId, attributes)
513 const res = await getVideo(server.url, videoId)
514 const video = res.body
516 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
519 it('Should like a video', async function () {
520 await rateVideo(server.url, server.accessToken, videoId, 'like')
522 const res = await getVideo(server.url, videoId)
523 const video = res.body
525 expect(video.likes).to.equal(1)
526 expect(video.dislikes).to.equal(0)
529 it('Should dislike the same video', async function () {
530 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
532 const res = await getVideo(server.url, videoId)
533 const video = res.body
535 expect(video.likes).to.equal(0)
536 expect(video.dislikes).to.equal(1)
539 after(async function () {
540 killallServers([ server ])
542 // Keep the logs if the test failed