]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-channels.ts
Remove unused actor uuid field
[github/Chocobozzz/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, Video, VideoChannel } from '../../../../shared/index'
6 import {
7 cleanupTests,
8 createUser,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 getVideoChannelVideos,
12 testImage,
13 updateVideo,
14 updateVideoChannelAvatar,
15 uploadVideo,
16 userLogin
17 } from '../../../../shared/extra-utils'
18 import {
19 addVideoChannel,
20 deleteVideoChannel,
21 getAccountVideoChannelsList,
22 getMyUserInformation,
23 getVideoChannel,
24 getVideoChannelsList,
25 ServerInfo,
26 setAccessTokensToServers,
27 updateVideoChannel
28 } from '../../../../shared/extra-utils/index'
29 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
30
31 const expect = chai.expect
32
33 describe('Test video channels', function () {
34 let servers: ServerInfo[]
35 let userInfo: User
36 let firstVideoChannelId: number
37 let secondVideoChannelId: number
38 let videoUUID: string
39
40 before(async function () {
41 this.timeout(60000)
42
43 servers = await flushAndRunMultipleServers(2)
44
45 await setAccessTokensToServers(servers)
46 await doubleFollow(servers[0], servers[1])
47
48 {
49 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
50 const user: User = res.body
51
52 firstVideoChannelId = user.videoChannels[0].id
53 }
54
55 await waitJobs(servers)
56 })
57
58 it('Should have one video channel (created with root)', async () => {
59 const res = await getVideoChannelsList(servers[0].url, 0, 2)
60
61 expect(res.body.total).to.equal(1)
62 expect(res.body.data).to.be.an('array')
63 expect(res.body.data).to.have.lengthOf(1)
64 })
65
66 it('Should create another video channel', async function () {
67 this.timeout(10000)
68
69 {
70 const videoChannel = {
71 name: 'second_video_channel',
72 displayName: 'second video channel',
73 description: 'super video channel description',
74 support: 'super video channel support text'
75 }
76 const res = await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel)
77 secondVideoChannelId = res.body.videoChannel.id
78 }
79
80 // The channel is 1 is propagated to servers 2
81 {
82 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name', channelId: secondVideoChannelId })
83 videoUUID = res.body.video.uuid
84 }
85
86 await waitJobs(servers)
87 })
88
89 it('Should have two video channels when getting my information', async () => {
90 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
91 userInfo = res.body
92
93 expect(userInfo.videoChannels).to.be.an('array')
94 expect(userInfo.videoChannels).to.have.lengthOf(2)
95
96 const videoChannels = userInfo.videoChannels
97 expect(videoChannels[0].name).to.equal('root_channel')
98 expect(videoChannels[0].displayName).to.equal('Main root channel')
99
100 expect(videoChannels[1].name).to.equal('second_video_channel')
101 expect(videoChannels[1].displayName).to.equal('second video channel')
102 expect(videoChannels[1].description).to.equal('super video channel description')
103 expect(videoChannels[1].support).to.equal('super video channel support text')
104 })
105
106 it('Should have two video channels when getting account channels on server 1', async function () {
107 const res = await getAccountVideoChannelsList({
108 url: servers[ 0 ].url,
109 accountName: userInfo.account.name + '@' + userInfo.account.host
110 })
111
112 expect(res.body.total).to.equal(2)
113 expect(res.body.data).to.be.an('array')
114 expect(res.body.data).to.have.lengthOf(2)
115
116 const videoChannels = res.body.data
117 expect(videoChannels[0].name).to.equal('root_channel')
118 expect(videoChannels[0].displayName).to.equal('Main root channel')
119
120 expect(videoChannels[1].name).to.equal('second_video_channel')
121 expect(videoChannels[1].displayName).to.equal('second video channel')
122 expect(videoChannels[1].description).to.equal('super video channel description')
123 expect(videoChannels[1].support).to.equal('super video channel support text')
124 })
125
126 it('Should paginate and sort account channels', async function () {
127 {
128 const res = await getAccountVideoChannelsList({
129 url: servers[ 0 ].url,
130 accountName: userInfo.account.name + '@' + userInfo.account.host,
131 start: 0,
132 count: 1,
133 sort: 'createdAt'
134 })
135
136 expect(res.body.total).to.equal(2)
137 expect(res.body.data).to.have.lengthOf(1)
138
139 const videoChannel: VideoChannel = res.body.data[ 0 ]
140 expect(videoChannel.name).to.equal('root_channel')
141 }
142
143 {
144 const res = await getAccountVideoChannelsList({
145 url: servers[ 0 ].url,
146 accountName: userInfo.account.name + '@' + userInfo.account.host,
147 start: 0,
148 count: 1,
149 sort: '-createdAt'
150 })
151
152 expect(res.body.total).to.equal(2)
153 expect(res.body.data).to.have.lengthOf(1)
154
155 const videoChannel: VideoChannel = res.body.data[ 0 ]
156 expect(videoChannel.name).to.equal('second_video_channel')
157 }
158
159 {
160 const res = await getAccountVideoChannelsList({
161 url: servers[ 0 ].url,
162 accountName: userInfo.account.name + '@' + userInfo.account.host,
163 start: 1,
164 count: 1,
165 sort: '-createdAt'
166 })
167
168 expect(res.body.total).to.equal(2)
169 expect(res.body.data).to.have.lengthOf(1)
170
171 const videoChannel: VideoChannel = res.body.data[ 0 ]
172 expect(videoChannel.name).to.equal('root_channel')
173 }
174 })
175
176 it('Should have one video channel when getting account channels on server 2', async function () {
177 const res = await getAccountVideoChannelsList({
178 url: servers[ 1 ].url,
179 accountName: userInfo.account.name + '@' + userInfo.account.host
180 })
181
182 expect(res.body.total).to.equal(1)
183 expect(res.body.data).to.be.an('array')
184 expect(res.body.data).to.have.lengthOf(1)
185
186 const videoChannels = res.body.data
187 expect(videoChannels[0].name).to.equal('second_video_channel')
188 expect(videoChannels[0].displayName).to.equal('second video channel')
189 expect(videoChannels[0].description).to.equal('super video channel description')
190 expect(videoChannels[0].support).to.equal('super video channel support text')
191 })
192
193 it('Should list video channels', async function () {
194 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
195
196 expect(res.body.total).to.equal(2)
197 expect(res.body.data).to.be.an('array')
198 expect(res.body.data).to.have.lengthOf(1)
199 expect(res.body.data[0].name).to.equal('root_channel')
200 expect(res.body.data[0].displayName).to.equal('Main root channel')
201 })
202
203 it('Should update video channel', async function () {
204 this.timeout(5000)
205
206 const videoChannelAttributes = {
207 displayName: 'video channel updated',
208 description: 'video channel description updated',
209 support: 'video channel support text updated'
210 }
211
212 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
213
214 await waitJobs(servers)
215 })
216
217 it('Should have video channel updated', async function () {
218 for (const server of servers) {
219 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
220
221 expect(res.body.total).to.equal(2)
222 expect(res.body.data).to.be.an('array')
223 expect(res.body.data).to.have.lengthOf(1)
224 expect(res.body.data[0].name).to.equal('second_video_channel')
225 expect(res.body.data[0].displayName).to.equal('video channel updated')
226 expect(res.body.data[0].description).to.equal('video channel description updated')
227 expect(res.body.data[0].support).to.equal('video channel support text updated')
228 }
229 })
230
231 it('Should update video channel avatar', async function () {
232 this.timeout(5000)
233
234 const fixture = 'avatar.png'
235
236 await updateVideoChannelAvatar({
237 url: servers[0].url,
238 accessToken: servers[0].accessToken,
239 videoChannelName: 'second_video_channel',
240 fixture
241 })
242
243 await waitJobs(servers)
244 })
245
246 it('Should have video channel avatar updated', async function () {
247 for (const server of servers) {
248 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
249
250 const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId)
251
252 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
253 }
254 })
255
256 it('Should get video channel', async function () {
257 const res = await getVideoChannel(servers[0].url, 'second_video_channel')
258
259 const videoChannel = res.body
260 expect(videoChannel.name).to.equal('second_video_channel')
261 expect(videoChannel.displayName).to.equal('video channel updated')
262 expect(videoChannel.description).to.equal('video channel description updated')
263 expect(videoChannel.support).to.equal('video channel support text updated')
264 })
265
266 it('Should list the second video channel videos', async function () {
267 this.timeout(10000)
268
269 for (const server of servers) {
270 const channelURI = 'second_video_channel@localhost:' + servers[0].port
271 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
272 expect(res1.body.total).to.equal(1)
273 expect(res1.body.data).to.be.an('array')
274 expect(res1.body.data).to.have.lengthOf(1)
275 expect(res1.body.data[0].name).to.equal('my video name')
276 }
277 })
278
279 it('Should change the video channel of a video', async function () {
280 this.timeout(10000)
281
282 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
283
284 await waitJobs(servers)
285 })
286
287 it('Should list the first video channel videos', async function () {
288 this.timeout(10000)
289
290 for (const server of servers) {
291 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
292 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
293 expect(res1.body.total).to.equal(0)
294
295 const channelURI = 'root_channel@localhost:' + servers[0].port
296 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
297 expect(res2.body.total).to.equal(1)
298
299 const videos: Video[] = res2.body.data
300 expect(videos).to.be.an('array')
301 expect(videos).to.have.lengthOf(1)
302 expect(videos[0].name).to.equal('my video name')
303 }
304 })
305
306 it('Should delete video channel', async function () {
307 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
308 })
309
310 it('Should have video channel deleted', async function () {
311 const res = await getVideoChannelsList(servers[0].url, 0, 10)
312
313 expect(res.body.total).to.equal(1)
314 expect(res.body.data).to.be.an('array')
315 expect(res.body.data).to.have.lengthOf(1)
316 expect(res.body.data[0].displayName).to.equal('Main root channel')
317 })
318
319 it('Should create the main channel with an uuid if there is a conflict', async function () {
320 {
321 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
322 await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel)
323 }
324
325 {
326 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' })
327 const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' })
328
329 const res = await getMyUserInformation(servers[ 0 ].url, accessToken)
330 const videoChannel = res.body.videoChannels[ 0 ]
331 expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)
332 }
333 })
334
335 after(async function () {
336 await cleanupTests(servers)
337 })
338 })