aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/video-channels.ts
blob: 95b202e2f678f8140a07002b4e09056f1e8b56fc (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
137
138
139
140
141
/* tslint:disable:no-unused-expression */

import { keyBy } from 'lodash'
import { join } from 'path'
import 'mocha'
import * as chai from 'chai'
const expect = chai.expect

import {
  ServerInfo,
  flushTests,
  runServer,
  setAccessTokensToServers,
  killallServers,
  getMyUserInformation,
  getVideoChannelsList,
  addVideoChannel,
  getAuthorVideoChannelsList,
  updateVideoChannel,
  deleteVideoChannel,
  getVideoChannel
} from '../utils'
import { User } from '../../../shared'

describe('Test a video channels', function () {
  let server: ServerInfo
  let userInfo: User
  let videoChannelId: number

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

    await flushTests()

    server = await runServer(1)

    await setAccessTokensToServers([ server ])
  })

  it('Should have one video channel (created with root)', async () => {
    const res = await getVideoChannelsList(server.url, 0, 2)

    expect(res.body.total).to.equal(1)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data).to.have.lengthOf(1)
  })

  it('Should create another video channel', async () => {
    const videoChannel = {
      name: 'second video channel',
      description: 'super video channel description'
    }
    await addVideoChannel(server.url, server.accessToken, videoChannel)
  })

  it('Should have two video channels when getting my information', async () => {
    const res = await getMyUserInformation(server.url, server.accessToken)
    userInfo = res.body

    expect(userInfo.videoChannels).to.be.an('array')
    expect(userInfo.videoChannels).to.have.lengthOf(2)

    const videoChannels = userInfo.videoChannels
    expect(videoChannels[0].name).to.equal('Default root channel')
    expect(videoChannels[1].name).to.equal('second video channel')
    expect(videoChannels[1].description).to.equal('super video channel description')
  })

  it('Should have two video channels when getting author channels', async () => {
    const res = await getAuthorVideoChannelsList(server.url, userInfo.author.uuid)

    expect(res.body.total).to.equal(2)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data).to.have.lengthOf(2)

    const videoChannels = res.body.data
    expect(videoChannels[0].name).to.equal('Default root channel')
    expect(videoChannels[1].name).to.equal('second video channel')
    expect(videoChannels[1].description).to.equal('super video channel description')

    videoChannelId = videoChannels[1].id
  })

  it('Should list video channels', async () => {
    const res = await getVideoChannelsList(server.url, 1, 1, '-name')

    expect(res.body.total).to.equal(2)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data).to.have.lengthOf(1)
    expect(res.body.data[0].name).to.equal('Default root channel')
  })

  it('Should update video channel', async () => {
    const videoChannelAttributes = {
      name: 'video channel updated',
      description: 'video channel description updated'
    }

    await updateVideoChannel(server.url, server.accessToken, videoChannelId, videoChannelAttributes)
  })

  it('Should have video channel updated', async () => {
    const res = await getVideoChannelsList(server.url, 0, 1, '-name')

    expect(res.body.total).to.equal(2)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data).to.have.lengthOf(1)
    expect(res.body.data[0].name).to.equal('video channel updated')
    expect(res.body.data[0].description).to.equal('video channel description updated')
  })

  it('Should get video channel', async () => {
    const res = await getVideoChannel(server.url, videoChannelId)

    const videoChannel = res.body
    expect(videoChannel.name).to.equal('video channel updated')
    expect(videoChannel.description).to.equal('video channel description updated')
  })

  it('Should delete video channel', async () => {
    await deleteVideoChannel(server.url, server.accessToken, videoChannelId)
  })

  it('Should have video channel deleted', async () => {
    const res = await getVideoChannelsList(server.url, 0, 10)

    expect(res.body.total).to.equal(1)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data).to.have.lengthOf(1)
    expect(res.body.data[0].name).to.equal('Default root channel')
  })

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

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