Update video channel routes
[oweals/peertube.git] / server / tests / api / videos / video-channels.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { User } from '../../../../shared/index'
6 import { doubleFollow, flushAndRunMultipleServers, uploadVideo, wait } from '../../utils'
7 import {
8   addVideoChannel,
9   deleteVideoChannel,
10   flushTests,
11   getAccountVideoChannelsList,
12   getMyUserInformation,
13   getVideoChannel,
14   getVideoChannelsList,
15   killallServers,
16   ServerInfo,
17   setAccessTokensToServers,
18   updateVideoChannel
19 } from '../../utils/index'
20 import { getAccountsList } from '../../utils/users/accounts'
21
22 const expect = chai.expect
23
24 describe('Test video channels', function () {
25   let servers: ServerInfo[]
26   let userInfo: User
27   let accountId: number
28   let videoChannelId: number
29
30   before(async function () {
31     this.timeout(30000)
32
33     await flushTests()
34
35     servers = await flushAndRunMultipleServers(2)
36
37     await setAccessTokensToServers(servers)
38     await doubleFollow(servers[0], servers[1])
39
40     {
41       const res = await getAccountsList(servers[0].url)
42       accountId = res.body.data[0].id
43     }
44
45     await wait(5000)
46   })
47
48   it('Should have one video channel (created with root)', async () => {
49     const res = await getVideoChannelsList(servers[0].url, 0, 2)
50
51     expect(res.body.total).to.equal(1)
52     expect(res.body.data).to.be.an('array')
53     expect(res.body.data).to.have.lengthOf(1)
54   })
55
56   it('Should create another video channel', async function () {
57     this.timeout(10000)
58
59     const videoChannel = {
60       name: 'second video channel',
61       description: 'super video channel description',
62       support: 'super video channel support text'
63     }
64     const res = await addVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannel)
65     videoChannelId = res.body.videoChannel.id
66
67     // The channel is 1 is propagated to servers 2
68     await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: videoChannelId })
69
70     await wait(3000)
71   })
72
73   it('Should have two video channels when getting my information', async () => {
74     const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
75     userInfo = res.body
76
77     expect(userInfo.videoChannels).to.be.an('array')
78     expect(userInfo.videoChannels).to.have.lengthOf(2)
79
80     const videoChannels = userInfo.videoChannels
81     expect(videoChannels[0].displayName).to.equal('Default root channel')
82     expect(videoChannels[1].displayName).to.equal('second video channel')
83     expect(videoChannels[1].description).to.equal('super video channel description')
84     expect(videoChannels[1].support).to.equal('super video channel support text')
85   })
86
87   it('Should have two video channels when getting account channels on server 1', async function () {
88     const res = await getAccountVideoChannelsList(servers[0].url, userInfo.account.uuid)
89     expect(res.body.total).to.equal(2)
90     expect(res.body.data).to.be.an('array')
91     expect(res.body.data).to.have.lengthOf(2)
92
93     const videoChannels = res.body.data
94     expect(videoChannels[0].displayName).to.equal('Default root channel')
95     expect(videoChannels[1].displayName).to.equal('second video channel')
96     expect(videoChannels[1].description).to.equal('super video channel description')
97     expect(videoChannels[1].support).to.equal('super video channel support text')
98   })
99
100   it('Should have one video channel when getting account channels on server 2', async function () {
101     const res = await getAccountVideoChannelsList(servers[1].url, userInfo.account.uuid)
102     expect(res.body.total).to.equal(1)
103     expect(res.body.data).to.be.an('array')
104     expect(res.body.data).to.have.lengthOf(1)
105
106     const videoChannels = res.body.data
107     expect(videoChannels[0].displayName).to.equal('second video channel')
108     expect(videoChannels[0].description).to.equal('super video channel description')
109     expect(videoChannels[0].support).to.equal('super video channel support text')
110   })
111
112   it('Should list video channels', async function () {
113     const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
114
115     expect(res.body.total).to.equal(2)
116     expect(res.body.data).to.be.an('array')
117     expect(res.body.data).to.have.lengthOf(1)
118     expect(res.body.data[0].displayName).to.equal('Default root channel')
119   })
120
121   it('Should update video channel', async function () {
122     this.timeout(5000)
123
124     const videoChannelAttributes = {
125       name: 'video channel updated',
126       description: 'video channel description updated',
127       support: 'video channel support text updated'
128     }
129
130     await updateVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannelId, videoChannelAttributes)
131
132     await wait(3000)
133   })
134
135   it('Should have video channel updated', async function () {
136     for (const server of servers) {
137       const res = await getVideoChannelsList(server.url, 0, 1, '-name')
138
139       expect(res.body.total).to.equal(2)
140       expect(res.body.data).to.be.an('array')
141       expect(res.body.data).to.have.lengthOf(1)
142       expect(res.body.data[0].displayName).to.equal('video channel updated')
143       expect(res.body.data[0].description).to.equal('video channel description updated')
144       expect(res.body.data[0].support).to.equal('video channel support text updated')
145     }
146   })
147
148   it('Should get video channel', async function () {
149     const res = await getVideoChannel(servers[0].url, accountId, videoChannelId)
150
151     const videoChannel = res.body
152     expect(videoChannel.displayName).to.equal('video channel updated')
153     expect(videoChannel.description).to.equal('video channel description updated')
154     expect(videoChannel.support).to.equal('video channel support text updated')
155   })
156
157   it('Should delete video channel', async function () {
158     await deleteVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannelId)
159   })
160
161   it('Should have video channel deleted', async function () {
162     const res = await getVideoChannelsList(servers[0].url, 0, 10)
163
164     expect(res.body.total).to.equal(1)
165     expect(res.body.data).to.be.an('array')
166     expect(res.body.data).to.have.lengthOf(1)
167     expect(res.body.data[0].displayName).to.equal('Default root channel')
168   })
169
170   after(async function () {
171     killallServers(servers)
172
173     // Keep the logs if the test failed
174     if (this['ok']) {
175       await flushTests()
176     }
177   })
178 })