aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/videos-overview.ts
blob: b3ab9e070e8582aaabce7aa1de4ec0718f85fdef (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import * as chai from 'chai'
import {
  addAccountToAccountBlocklist,
  cleanupTests,
  flushAndRunServer,
  generateUserAccessToken,
  ServerInfo,
  setAccessTokensToServers,
  uploadVideo,
  wait
} from '@shared/extra-utils'
import { VideosOverview } from '@shared/models'

const expect = chai.expect

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

  function testOverviewCount (overview: VideosOverview, expected: number) {
    expect(overview.tags).to.have.lengthOf(expected)
    expect(overview.categories).to.have.lengthOf(expected)
    expect(overview.channels).to.have.lengthOf(expected)
  }

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

    server = await flushAndRunServer(1)

    await setAccessTokensToServers([ server ])
  })

  it('Should send empty overview', async function () {
    const body = await server.overviewsCommand.getVideos({ page: 1 })

    testOverviewCount(body, 0)
  })

  it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
    this.timeout(30000)

    await wait(3000)

    await uploadVideo(server.url, server.accessToken, {
      name: 'video 0',
      category: 3,
      tags: [ 'coucou1', 'coucou2' ]
    })

    const body = await server.overviewsCommand.getVideos({ page: 1 })

    testOverviewCount(body, 0)
  })

  it('Should upload another video and include all videos in the overview', async function () {
    this.timeout(30000)

    {
      for (let i = 1; i < 6; i++) {
        await uploadVideo(server.url, server.accessToken, {
          name: 'video ' + i,
          category: 3,
          tags: [ 'coucou1', 'coucou2' ]
        })
      }

      await wait(3000)
    }

    {
      const body = await server.overviewsCommand.getVideos({ page: 1 })

      testOverviewCount(body, 1)
    }

    {
      const overview = await server.overviewsCommand.getVideos({ page: 2 })

      expect(overview.tags).to.have.lengthOf(1)
      expect(overview.categories).to.have.lengthOf(0)
      expect(overview.channels).to.have.lengthOf(0)
    }
  })

  it('Should have the correct overview', async function () {
    const overview1 = await server.overviewsCommand.getVideos({ page: 1 })
    const overview2 = await server.overviewsCommand.getVideos({ page: 2 })

    for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
      expect(arr).to.have.lengthOf(1)

      const obj = arr[0]

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

    const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
    expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
    expect(tags.find(t => t === 'coucou2')).to.not.be.undefined

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

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

  it('Should hide muted accounts', async function () {
    const token = await generateUserAccessToken(server, 'choco')

    await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)

    {
      const body = await server.overviewsCommand.getVideos({ page: 1 })

      testOverviewCount(body, 1)
    }

    {
      const body = await server.overviewsCommand.getVideos({ page: 1, token })

      testOverviewCount(body, 0)
    }
  })

  after(async function () {
    await cleanupTests([ server ])
  })
})