Update video-channel routes (again)
[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, getVideoChannelVideos, 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 accountUUID: string
28   let videoChannelId: number
29   let videoChannelUUID: string
30
31   before(async function () {
32     this.timeout(30000)
33
34     await flushTests()
35
36     servers = await flushAndRunMultipleServers(2)
37
38     await setAccessTokensToServers(servers)
39     await doubleFollow(servers[0], servers[1])
40
41     {
42       const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
43       const user: User = res.body
44       accountUUID = user.account.uuid
45     }
46
47     await wait(5000)
48   })
49
50   it('Should have one video channel (created with root)', async () => {
51     const res = await getVideoChannelsList(servers[0].url, 0, 2)
52
53     expect(res.body.total).to.equal(1)
54     expect(res.body.data).to.be.an('array')
55     expect(res.body.data).to.have.lengthOf(1)
56   })
57
58   it('Should create another video channel', async function () {
59     this.timeout(10000)
60
61     const videoChannel = {
62       name: 'second video channel',
63       description: 'super video channel description',
64       support: 'super video channel support text'
65     }
66     const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
67     videoChannelId = res.body.videoChannel.id
68     videoChannelUUID = res.body.videoChannel.uuid
69
70     // The channel is 1 is propagated to servers 2
71     await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name', channelId: videoChannelId })
72
73     await wait(3000)
74   })
75
76   it('Should have two video channels when getting my information', async () => {
77     const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
78     userInfo = res.body
79
80     expect(userInfo.videoChannels).to.be.an('array')
81     expect(userInfo.videoChannels).to.have.lengthOf(2)
82
83     const videoChannels = userInfo.videoChannels
84     expect(videoChannels[0].displayName).to.equal('Default root channel')
85     expect(videoChannels[1].displayName).to.equal('second video channel')
86     expect(videoChannels[1].description).to.equal('super video channel description')
87     expect(videoChannels[1].support).to.equal('super video channel support text')
88   })
89
90   it('Should have two video channels when getting account channels on server 1', async function () {
91     const res = await getAccountVideoChannelsList(servers[0].url, userInfo.account.uuid)
92     expect(res.body.total).to.equal(2)
93     expect(res.body.data).to.be.an('array')
94     expect(res.body.data).to.have.lengthOf(2)
95
96     const videoChannels = res.body.data
97     expect(videoChannels[0].displayName).to.equal('Default root channel')
98     expect(videoChannels[1].displayName).to.equal('second video channel')
99     expect(videoChannels[1].description).to.equal('super video channel description')
100     expect(videoChannels[1].support).to.equal('super video channel support text')
101   })
102
103   it('Should have one video channel when getting account channels on server 2', async function () {
104     const res = await getAccountVideoChannelsList(servers[1].url, userInfo.account.uuid)
105     expect(res.body.total).to.equal(1)
106     expect(res.body.data).to.be.an('array')
107     expect(res.body.data).to.have.lengthOf(1)
108
109     const videoChannels = res.body.data
110     expect(videoChannels[0].displayName).to.equal('second video channel')
111     expect(videoChannels[0].description).to.equal('super video channel description')
112     expect(videoChannels[0].support).to.equal('super video channel support text')
113   })
114
115   it('Should list video channels', async function () {
116     const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
117
118     expect(res.body.total).to.equal(2)
119     expect(res.body.data).to.be.an('array')
120     expect(res.body.data).to.have.lengthOf(1)
121     expect(res.body.data[0].displayName).to.equal('Default root channel')
122   })
123
124   it('Should update video channel', async function () {
125     this.timeout(5000)
126
127     const videoChannelAttributes = {
128       name: 'video channel updated',
129       description: 'video channel description updated',
130       support: 'video channel support text updated'
131     }
132
133     await updateVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId, videoChannelAttributes)
134
135     await wait(3000)
136   })
137
138   it('Should have video channel updated', async function () {
139     for (const server of servers) {
140       const res = await getVideoChannelsList(server.url, 0, 1, '-name')
141
142       expect(res.body.total).to.equal(2)
143       expect(res.body.data).to.be.an('array')
144       expect(res.body.data).to.have.lengthOf(1)
145       expect(res.body.data[0].displayName).to.equal('video channel updated')
146       expect(res.body.data[0].description).to.equal('video channel description updated')
147       expect(res.body.data[0].support).to.equal('video channel support text updated')
148     }
149   })
150
151   it('Should get video channel', async function () {
152     const res = await getVideoChannel(servers[0].url, videoChannelId)
153
154     const videoChannel = res.body
155     expect(videoChannel.displayName).to.equal('video channel updated')
156     expect(videoChannel.description).to.equal('video channel description updated')
157     expect(videoChannel.support).to.equal('video channel support text updated')
158   })
159
160   it('Should list the video channel videos', async function () {
161     this.timeout(10000)
162
163     for (const server of servers) {
164       const res = await getVideoChannelVideos(server.url, server.accessToken, videoChannelUUID, 0, 5)
165       expect(res.body.total).to.equal(1)
166       expect(res.body.data).to.be.an('array')
167       expect(res.body.data).to.have.lengthOf(1)
168       expect(res.body.data[0].name).to.equal('my video name')
169     }
170   })
171
172   it('Should delete video channel', async function () {
173     await deleteVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId)
174   })
175
176   it('Should have video channel deleted', async function () {
177     const res = await getVideoChannelsList(servers[0].url, 0, 10)
178
179     expect(res.body.total).to.equal(1)
180     expect(res.body.data).to.be.an('array')
181     expect(res.body.data).to.have.lengthOf(1)
182     expect(res.body.data[0].displayName).to.equal('Default root channel')
183   })
184
185   after(async function () {
186     killallServers(servers)
187
188     // Keep the logs if the test failed
189     if (this['ok']) {
190       await flushTests()
191     }
192   })
193 })