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