videos-overview.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import { flushTests, killallServers, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils'
  5. import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews'
  6. import { VideosOverview } from '../../../../shared/models/overviews'
  7. const expect = chai.expect
  8. describe('Test a videos overview', function () {
  9. let server: ServerInfo = null
  10. before(async function () {
  11. this.timeout(30000)
  12. server = await flushAndRunServer(1)
  13. await setAccessTokensToServers([ server ])
  14. })
  15. it('Should send empty overview', async function () {
  16. const res = await getVideosOverview(server.url)
  17. const overview: VideosOverview = res.body
  18. expect(overview.tags).to.have.lengthOf(0)
  19. expect(overview.categories).to.have.lengthOf(0)
  20. expect(overview.channels).to.have.lengthOf(0)
  21. })
  22. it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
  23. this.timeout(15000)
  24. for (let i = 0; i < 5; i++) {
  25. await uploadVideo(server.url, server.accessToken, {
  26. name: 'video ' + i,
  27. category: 3,
  28. tags: [ 'coucou1', 'coucou2' ]
  29. })
  30. }
  31. const res = await getVideosOverview(server.url)
  32. const overview: VideosOverview = res.body
  33. expect(overview.tags).to.have.lengthOf(0)
  34. expect(overview.categories).to.have.lengthOf(0)
  35. expect(overview.channels).to.have.lengthOf(0)
  36. })
  37. it('Should upload another video and include all videos in the overview', async function () {
  38. await uploadVideo(server.url, server.accessToken, {
  39. name: 'video 5',
  40. category: 3,
  41. tags: [ 'coucou1', 'coucou2' ]
  42. })
  43. const res = await getVideosOverview(server.url)
  44. const overview: VideosOverview = res.body
  45. expect(overview.tags).to.have.lengthOf(2)
  46. expect(overview.categories).to.have.lengthOf(1)
  47. expect(overview.channels).to.have.lengthOf(1)
  48. })
  49. it('Should have the correct overview', async function () {
  50. const res = await getVideosOverview(server.url)
  51. const overview: VideosOverview = res.body
  52. for (const attr of [ 'tags', 'categories', 'channels' ]) {
  53. const obj = overview[attr][0]
  54. expect(obj.videos).to.have.lengthOf(6)
  55. expect(obj.videos[0].name).to.equal('video 5')
  56. expect(obj.videos[1].name).to.equal('video 4')
  57. expect(obj.videos[2].name).to.equal('video 3')
  58. expect(obj.videos[3].name).to.equal('video 2')
  59. expect(obj.videos[4].name).to.equal('video 1')
  60. expect(obj.videos[5].name).to.equal('video 0')
  61. }
  62. expect(overview.tags.find(t => t.tag === 'coucou1')).to.not.be.undefined
  63. expect(overview.tags.find(t => t.tag === 'coucou2')).to.not.be.undefined
  64. expect(overview.categories[0].category.id).to.equal(3)
  65. expect(overview.channels[0].channel.name).to.equal('root_channel')
  66. })
  67. after(function () {
  68. killallServers([ server ])
  69. })
  70. })