aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/videos-overview.ts
blob: 1514d1bda07992c9a1fc3fe20619d2777d434609 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* tslint:disable:no-unused-expression */

import * as chai from 'chai'
import 'mocha'
import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils'
import { getVideosOverview } from '../../utils/overviews/overviews'
import { VideosOverview } from '../../../../shared/models/overviews'

const expect = chai.expect

describe('Test a videos overview', function () {
  let server: ServerInfo = null

  before(async function () {
    this.timeout(30000)

    await flushTests()

    server = await runServer(1)

    await setAccessTokensToServers([ server ])
  })

  it('Should send empty overview', async function () {
    const res = await getVideosOverview(server.url)

    const overview: VideosOverview = res.body
    expect(overview.tags).to.have.lengthOf(0)
    expect(overview.categories).to.have.lengthOf(0)
    expect(overview.channels).to.have.lengthOf(0)
  })

  it('Should upload 3 videos in a specific category, tag and channel but not include them in overview', async function () {
    for (let i = 0; i < 3; i++) {
      await uploadVideo(server.url, server.accessToken, {
        name: 'video ' + i,
        category: 3,
        tags: [ 'coucou1', 'coucou2' ]
      })
    }

    const res = await getVideosOverview(server.url)

    const overview: VideosOverview = res.body
    expect(overview.tags).to.have.lengthOf(0)
    expect(overview.categories).to.have.lengthOf(0)
    expect(overview.channels).to.have.lengthOf(0)
  })

  it('Should upload another video and include all videos in the overview', async function () {
    await uploadVideo(server.url, server.accessToken, {
      name: 'video 3',
      category: 3,
      tags: [ 'coucou1', 'coucou2' ]
    })

    const res = await getVideosOverview(server.url)

    const overview: VideosOverview = res.body
    expect(overview.tags).to.have.lengthOf(2)
    expect(overview.categories).to.have.lengthOf(1)
    expect(overview.channels).to.have.lengthOf(1)
  })

  it('Should have the correct overview', async function () {
    const res = await getVideosOverview(server.url)

    const overview: VideosOverview = res.body

    for (const attr of [ 'tags', 'categories', 'channels' ]) {
      const obj = overview[attr][0]

      expect(obj.videos).to.have.lengthOf(4)
      expect(obj.videos[0].name).to.equal('video 3')
      expect(obj.videos[1].name).to.equal('video 2')
      expect(obj.videos[2].name).to.equal('video 1')
      expect(obj.videos[3].name).to.equal('video 0')
    }

    expect(overview.tags.find(t => t.tag === 'coucou1')).to.not.be.undefined
    expect(overview.tags.find(t => t.tag === 'coucou2')).to.not.be.undefined

    expect(overview.categories[0].category.id).to.equal(3)

    expect(overview.channels[0].channel.name).to.equal('root_channel')
  })

  after(async function () {
    killallServers([ server ])

    // Keep the logs if the test failed
    if (this['ok']) {
      await flushTests()
    }
  })
})