]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-channels.ts
Video channel API routes refractor
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-channels.ts
CommitLineData
5f04dd2f
C
1/* tslint:disable:no-unused-expression */
2
5f04dd2f 3import * as chai from 'chai'
2422c46b
C
4import 'mocha'
5import { User } from '../../../../shared/index'
6b738c7a 6import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, uploadVideo, wait } from '../../utils'
5f04dd2f 7import {
2422c46b
C
8 addVideoChannel,
9 deleteVideoChannel,
5f04dd2f 10 flushTests,
2422c46b 11 getAccountVideoChannelsList,
5f04dd2f 12 getMyUserInformation,
2422c46b 13 getVideoChannel,
5f04dd2f 14 getVideoChannelsList,
2422c46b
C
15 killallServers,
16 ServerInfo,
17 setAccessTokensToServers,
18 updateVideoChannel
c5d31dba 19} from '../../utils/index'
48dce1c9 20import { getAccountsList } from '../../utils/users/accounts'
5f04dd2f 21
2422c46b
C
22const expect = chai.expect
23
24describe('Test video channels', function () {
25 let servers: ServerInfo[]
5f04dd2f 26 let userInfo: User
6b738c7a 27 let accountUUID: string
5f04dd2f 28 let videoChannelId: number
6b738c7a 29 let videoChannelUUID: string
5f04dd2f
C
30
31 before(async function () {
e212f887 32 this.timeout(30000)
5f04dd2f
C
33
34 await flushTests()
35
2422c46b
C
36 servers = await flushAndRunMultipleServers(2)
37
38 await setAccessTokensToServers(servers)
39 await doubleFollow(servers[0], servers[1])
5f04dd2f 40
48dce1c9 41 {
6b738c7a
C
42 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
43 const user: User = res.body
44 accountUUID = user.account.uuid
48dce1c9
C
45 }
46
2422c46b 47 await wait(5000)
5f04dd2f
C
48 })
49
50 it('Should have one video channel (created with root)', async () => {
2422c46b 51 const res = await getVideoChannelsList(servers[0].url, 0, 2)
5f04dd2f
C
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
2422c46b
C
58 it('Should create another video channel', async function () {
59 this.timeout(10000)
60
5f04dd2f
C
61 const videoChannel = {
62 name: 'second video channel',
2422c46b
C
63 description: 'super video channel description',
64 support: 'super video channel support text'
5f04dd2f 65 }
6b738c7a 66 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannel)
2422c46b 67 videoChannelId = res.body.videoChannel.id
6b738c7a 68 videoChannelUUID = res.body.videoChannel.uuid
2422c46b
C
69
70 // The channel is 1 is propagated to servers 2
6b738c7a 71 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name', channelId: videoChannelId })
2422c46b
C
72
73 await wait(3000)
5f04dd2f
C
74 })
75
76 it('Should have two video channels when getting my information', async () => {
2422c46b 77 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
5f04dd2f
C
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
7bc29171
C
84 expect(videoChannels[0].displayName).to.equal('Default root channel')
85 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 86 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b 87 expect(videoChannels[1].support).to.equal('super video channel support text')
5f04dd2f
C
88 })
89
2422c46b
C
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)
5f04dd2f
C
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
7bc29171
C
97 expect(videoChannels[0].displayName).to.equal('Default root channel')
98 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 99 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b
C
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)
5f04dd2f 108
2422c46b
C
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')
5f04dd2f
C
113 })
114
2422c46b
C
115 it('Should list video channels', async function () {
116 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
5f04dd2f
C
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)
7bc29171 121 expect(res.body.data[0].displayName).to.equal('Default root channel')
5f04dd2f
C
122 })
123
2422c46b
C
124 it('Should update video channel', async function () {
125 this.timeout(5000)
126
5f04dd2f
C
127 const videoChannelAttributes = {
128 name: 'video channel updated',
2422c46b
C
129 description: 'video channel description updated',
130 support: 'video channel support text updated'
5f04dd2f
C
131 }
132
6b738c7a 133 await updateVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannelId, videoChannelAttributes)
2422c46b
C
134
135 await wait(3000)
5f04dd2f
C
136 })
137
2422c46b
C
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')
5f04dd2f 141
2422c46b
C
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 }
5f04dd2f
C
149 })
150
2422c46b 151 it('Should get video channel', async function () {
6b738c7a 152 const res = await getVideoChannel(servers[0].url, accountUUID, videoChannelId)
5f04dd2f
C
153
154 const videoChannel = res.body
7bc29171 155 expect(videoChannel.displayName).to.equal('video channel updated')
5f04dd2f 156 expect(videoChannel.description).to.equal('video channel description updated')
2422c46b 157 expect(videoChannel.support).to.equal('video channel support text updated')
5f04dd2f
C
158 })
159
6b738c7a
C
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, accountUUID, 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
2422c46b 172 it('Should delete video channel', async function () {
6b738c7a 173 await deleteVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannelId)
5f04dd2f
C
174 })
175
2422c46b
C
176 it('Should have video channel deleted', async function () {
177 const res = await getVideoChannelsList(servers[0].url, 0, 10)
5f04dd2f
C
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)
7bc29171 182 expect(res.body.data[0].displayName).to.equal('Default root channel')
5f04dd2f
C
183 })
184
185 after(async function () {
2422c46b 186 killallServers(servers)
5f04dd2f
C
187
188 // Keep the logs if the test failed
189 if (this['ok']) {
190 await flushTests()
191 }
192 })
193})