aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/video-channels.ts')
-rw-r--r--server/tests/api/videos/video-channels.ts352
1 files changed, 136 insertions, 216 deletions
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 865098777..c25754eb6 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -6,48 +6,28 @@ import { basename } from 'path'
6import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' 6import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
7import { 7import {
8 cleanupTests, 8 cleanupTests,
9 createUser, 9 createMultipleServers,
10 deleteVideoChannelImage,
11 doubleFollow, 10 doubleFollow,
12 flushAndRunMultipleServers, 11 PeerTubeServer,
13 getActorImage, 12 setAccessTokensToServers,
14 getVideo,
15 getVideoChannel,
16 getVideoChannelVideos,
17 setDefaultVideoChannel, 13 setDefaultVideoChannel,
18 testFileExistsOrNot, 14 testFileExistsOrNot,
19 testImage, 15 testImage,
20 updateVideo, 16 wait,
21 updateVideoChannelImage, 17 waitJobs
22 uploadVideo, 18} from '@shared/extra-utils'
23 userLogin, 19import { User, VideoChannel } from '@shared/models'
24 wait
25} from '../../../../shared/extra-utils'
26import {
27 addVideoChannel,
28 deleteVideoChannel,
29 getAccountVideoChannelsList,
30 getMyUserInformation,
31 getVideoChannelsList,
32 ServerInfo,
33 setAccessTokensToServers,
34 updateVideoChannel,
35 viewVideo
36} from '../../../../shared/extra-utils/index'
37import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
38import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
39 20
40const expect = chai.expect 21const expect = chai.expect
41 22
42async function findChannel (server: ServerInfo, channelId: number) { 23async function findChannel (server: PeerTubeServer, channelId: number) {
43 const res = await getVideoChannelsList(server.url, 0, 5, '-name') 24 const body = await server.channels.list({ sort: '-name' })
44 const videoChannel = res.body.data.find(c => c.id === channelId)
45 25
46 return videoChannel as VideoChannel 26 return body.data.find(c => c.id === channelId)
47} 27}
48 28
49describe('Test video channels', function () { 29describe('Test video channels', function () {
50 let servers: ServerInfo[] 30 let servers: PeerTubeServer[]
51 let userInfo: User 31 let userInfo: User
52 let secondVideoChannelId: number 32 let secondVideoChannelId: number
53 let totoChannel: number 33 let totoChannel: number
@@ -60,7 +40,7 @@ describe('Test video channels', function () {
60 before(async function () { 40 before(async function () {
61 this.timeout(60000) 41 this.timeout(60000)
62 42
63 servers = await flushAndRunMultipleServers(2) 43 servers = await createMultipleServers(2)
64 44
65 await setAccessTokensToServers(servers) 45 await setAccessTokensToServers(servers)
66 await setDefaultVideoChannel(servers) 46 await setDefaultVideoChannel(servers)
@@ -69,11 +49,11 @@ describe('Test video channels', function () {
69 }) 49 })
70 50
71 it('Should have one video channel (created with root)', async () => { 51 it('Should have one video channel (created with root)', async () => {
72 const res = await getVideoChannelsList(servers[0].url, 0, 2) 52 const body = await servers[0].channels.list({ start: 0, count: 2 })
73 53
74 expect(res.body.total).to.equal(1) 54 expect(body.total).to.equal(1)
75 expect(res.body.data).to.be.an('array') 55 expect(body.data).to.be.an('array')
76 expect(res.body.data).to.have.lengthOf(1) 56 expect(body.data).to.have.lengthOf(1)
77 }) 57 })
78 58
79 it('Should create another video channel', async function () { 59 it('Should create another video channel', async function () {
@@ -86,23 +66,22 @@ describe('Test video channels', function () {
86 description: 'super video channel description', 66 description: 'super video channel description',
87 support: 'super video channel support text' 67 support: 'super video channel support text'
88 } 68 }
89 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) 69 const created = await servers[0].channels.create({ attributes: videoChannel })
90 secondVideoChannelId = res.body.videoChannel.id 70 secondVideoChannelId = created.id
91 } 71 }
92 72
93 // The channel is 1 is propagated to servers 2 73 // The channel is 1 is propagated to servers 2
94 { 74 {
95 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } 75 const attributes = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
96 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg) 76 const { uuid } = await servers[0].videos.upload({ attributes })
97 videoUUID = res.body.video.uuid 77 videoUUID = uuid
98 } 78 }
99 79
100 await waitJobs(servers) 80 await waitJobs(servers)
101 }) 81 })
102 82
103 it('Should have two video channels when getting my information', async () => { 83 it('Should have two video channels when getting my information', async () => {
104 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) 84 userInfo = await servers[0].users.getMyInfo()
105 userInfo = res.body
106 85
107 expect(userInfo.videoChannels).to.be.an('array') 86 expect(userInfo.videoChannels).to.be.an('array')
108 expect(userInfo.videoChannels).to.have.lengthOf(2) 87 expect(userInfo.videoChannels).to.have.lengthOf(2)
@@ -120,16 +99,14 @@ describe('Test video channels', function () {
120 }) 99 })
121 100
122 it('Should have two video channels when getting account channels on server 1', async function () { 101 it('Should have two video channels when getting account channels on server 1', async function () {
123 const res = await getAccountVideoChannelsList({ 102 const body = await servers[0].channels.listByAccount({ accountName })
124 url: servers[0].url, 103 expect(body.total).to.equal(2)
125 accountName 104
126 }) 105 const videoChannels = body.data
127 106
128 expect(res.body.total).to.equal(2) 107 expect(videoChannels).to.be.an('array')
129 expect(res.body.data).to.be.an('array') 108 expect(videoChannels).to.have.lengthOf(2)
130 expect(res.body.data).to.have.lengthOf(2)
131 109
132 const videoChannels = res.body.data
133 expect(videoChannels[0].name).to.equal('root_channel') 110 expect(videoChannels[0].name).to.equal('root_channel')
134 expect(videoChannels[0].displayName).to.equal('Main root channel') 111 expect(videoChannels[0].displayName).to.equal('Main root channel')
135 112
@@ -141,79 +118,69 @@ describe('Test video channels', function () {
141 118
142 it('Should paginate and sort account channels', async function () { 119 it('Should paginate and sort account channels', async function () {
143 { 120 {
144 const res = await getAccountVideoChannelsList({ 121 const body = await servers[0].channels.listByAccount({
145 url: servers[0].url,
146 accountName, 122 accountName,
147 start: 0, 123 start: 0,
148 count: 1, 124 count: 1,
149 sort: 'createdAt' 125 sort: 'createdAt'
150 }) 126 })
151 127
152 expect(res.body.total).to.equal(2) 128 expect(body.total).to.equal(2)
153 expect(res.body.data).to.have.lengthOf(1) 129 expect(body.data).to.have.lengthOf(1)
154 130
155 const videoChannel: VideoChannel = res.body.data[0] 131 const videoChannel: VideoChannel = body.data[0]
156 expect(videoChannel.name).to.equal('root_channel') 132 expect(videoChannel.name).to.equal('root_channel')
157 } 133 }
158 134
159 { 135 {
160 const res = await getAccountVideoChannelsList({ 136 const body = await servers[0].channels.listByAccount({
161 url: servers[0].url,
162 accountName, 137 accountName,
163 start: 0, 138 start: 0,
164 count: 1, 139 count: 1,
165 sort: '-createdAt' 140 sort: '-createdAt'
166 }) 141 })
167 142
168 expect(res.body.total).to.equal(2) 143 expect(body.total).to.equal(2)
169 expect(res.body.data).to.have.lengthOf(1) 144 expect(body.data).to.have.lengthOf(1)
170 145 expect(body.data[0].name).to.equal('second_video_channel')
171 const videoChannel: VideoChannel = res.body.data[0]
172 expect(videoChannel.name).to.equal('second_video_channel')
173 } 146 }
174 147
175 { 148 {
176 const res = await getAccountVideoChannelsList({ 149 const body = await servers[0].channels.listByAccount({
177 url: servers[0].url,
178 accountName, 150 accountName,
179 start: 1, 151 start: 1,
180 count: 1, 152 count: 1,
181 sort: '-createdAt' 153 sort: '-createdAt'
182 }) 154 })
183 155
184 expect(res.body.total).to.equal(2) 156 expect(body.total).to.equal(2)
185 expect(res.body.data).to.have.lengthOf(1) 157 expect(body.data).to.have.lengthOf(1)
186 158 expect(body.data[0].name).to.equal('root_channel')
187 const videoChannel: VideoChannel = res.body.data[0]
188 expect(videoChannel.name).to.equal('root_channel')
189 } 159 }
190 }) 160 })
191 161
192 it('Should have one video channel when getting account channels on server 2', async function () { 162 it('Should have one video channel when getting account channels on server 2', async function () {
193 const res = await getAccountVideoChannelsList({ 163 const body = await servers[1].channels.listByAccount({ accountName })
194 url: servers[1].url,
195 accountName
196 })
197 164
198 expect(res.body.total).to.equal(1) 165 expect(body.total).to.equal(1)
199 expect(res.body.data).to.be.an('array') 166 expect(body.data).to.be.an('array')
200 expect(res.body.data).to.have.lengthOf(1) 167 expect(body.data).to.have.lengthOf(1)
201 168
202 const videoChannels = res.body.data 169 const videoChannel = body.data[0]
203 expect(videoChannels[0].name).to.equal('second_video_channel') 170 expect(videoChannel.name).to.equal('second_video_channel')
204 expect(videoChannels[0].displayName).to.equal('second video channel') 171 expect(videoChannel.displayName).to.equal('second video channel')
205 expect(videoChannels[0].description).to.equal('super video channel description') 172 expect(videoChannel.description).to.equal('super video channel description')
206 expect(videoChannels[0].support).to.equal('super video channel support text') 173 expect(videoChannel.support).to.equal('super video channel support text')
207 }) 174 })
208 175
209 it('Should list video channels', async function () { 176 it('Should list video channels', async function () {
210 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name') 177 const body = await servers[0].channels.list({ start: 1, count: 1, sort: '-name' })
211 178
212 expect(res.body.total).to.equal(2) 179 expect(body.total).to.equal(2)
213 expect(res.body.data).to.be.an('array') 180 expect(body.data).to.be.an('array')
214 expect(res.body.data).to.have.lengthOf(1) 181 expect(body.data).to.have.lengthOf(1)
215 expect(res.body.data[0].name).to.equal('root_channel') 182 expect(body.data[0].name).to.equal('root_channel')
216 expect(res.body.data[0].displayName).to.equal('Main root channel') 183 expect(body.data[0].displayName).to.equal('Main root channel')
217 }) 184 })
218 185
219 it('Should update video channel', async function () { 186 it('Should update video channel', async function () {
@@ -225,30 +192,29 @@ describe('Test video channels', function () {
225 support: 'support updated' 192 support: 'support updated'
226 } 193 }
227 194
228 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) 195 await servers[0].channels.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes })
229 196
230 await waitJobs(servers) 197 await waitJobs(servers)
231 }) 198 })
232 199
233 it('Should have video channel updated', async function () { 200 it('Should have video channel updated', async function () {
234 for (const server of servers) { 201 for (const server of servers) {
235 const res = await getVideoChannelsList(server.url, 0, 1, '-name') 202 const body = await server.channels.list({ start: 0, count: 1, sort: '-name' })
236 203
237 expect(res.body.total).to.equal(2) 204 expect(body.total).to.equal(2)
238 expect(res.body.data).to.be.an('array') 205 expect(body.data).to.be.an('array')
239 expect(res.body.data).to.have.lengthOf(1) 206 expect(body.data).to.have.lengthOf(1)
240 expect(res.body.data[0].name).to.equal('second_video_channel') 207
241 expect(res.body.data[0].displayName).to.equal('video channel updated') 208 expect(body.data[0].name).to.equal('second_video_channel')
242 expect(res.body.data[0].description).to.equal('video channel description updated') 209 expect(body.data[0].displayName).to.equal('video channel updated')
243 expect(res.body.data[0].support).to.equal('support updated') 210 expect(body.data[0].description).to.equal('video channel description updated')
211 expect(body.data[0].support).to.equal('support updated')
244 } 212 }
245 }) 213 })
246 214
247 it('Should not have updated the video support field', async function () { 215 it('Should not have updated the video support field', async function () {
248 for (const server of servers) { 216 for (const server of servers) {
249 const res = await getVideo(server.url, videoUUID) 217 const video = await server.videos.get({ id: videoUUID })
250 const video: VideoDetails = res.body
251
252 expect(video.support).to.equal('video support field') 218 expect(video.support).to.equal('video support field')
253 } 219 }
254 }) 220 })
@@ -261,14 +227,12 @@ describe('Test video channels', function () {
261 bulkVideosSupportUpdate: true 227 bulkVideosSupportUpdate: true
262 } 228 }
263 229
264 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) 230 await servers[0].channels.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes })
265 231
266 await waitJobs(servers) 232 await waitJobs(servers)
267 233
268 for (const server of servers) { 234 for (const server of servers) {
269 const res = await getVideo(server.url, videoUUID) 235 const video = await server.videos.get({ id: videoUUID })
270 const video: VideoDetails = res.body
271
272 expect(video.support).to.equal(videoChannelAttributes.support) 236 expect(video.support).to.equal(videoChannelAttributes.support)
273 } 237 }
274 }) 238 })
@@ -278,10 +242,8 @@ describe('Test video channels', function () {
278 242
279 const fixture = 'avatar.png' 243 const fixture = 'avatar.png'
280 244
281 await updateVideoChannelImage({ 245 await servers[0].channels.updateImage({
282 url: servers[0].url, 246 channelName: 'second_video_channel',
283 accessToken: servers[0].accessToken,
284 videoChannelName: 'second_video_channel',
285 fixture, 247 fixture,
286 type: 'avatar' 248 type: 'avatar'
287 }) 249 })
@@ -295,7 +257,7 @@ describe('Test video channels', function () {
295 await testImage(server.url, 'avatar-resized', avatarPaths[server.port], '.png') 257 await testImage(server.url, 'avatar-resized', avatarPaths[server.port], '.png')
296 await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true) 258 await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true)
297 259
298 const row = await getActorImage(server.internalServerNumber, basename(avatarPaths[server.port])) 260 const row = await server.sql.getActorImage(basename(avatarPaths[server.port]))
299 expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height) 261 expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height)
300 expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width) 262 expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width)
301 } 263 }
@@ -306,10 +268,8 @@ describe('Test video channels', function () {
306 268
307 const fixture = 'banner.jpg' 269 const fixture = 'banner.jpg'
308 270
309 await updateVideoChannelImage({ 271 await servers[0].channels.updateImage({
310 url: servers[0].url, 272 channelName: 'second_video_channel',
311 accessToken: servers[0].accessToken,
312 videoChannelName: 'second_video_channel',
313 fixture, 273 fixture,
314 type: 'banner' 274 type: 'banner'
315 }) 275 })
@@ -317,14 +277,13 @@ describe('Test video channels', function () {
317 await waitJobs(servers) 277 await waitJobs(servers)
318 278
319 for (const server of servers) { 279 for (const server of servers) {
320 const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host) 280 const videoChannel = await server.channels.get({ channelName: 'second_video_channel@' + servers[0].host })
321 const videoChannel = res.body
322 281
323 bannerPaths[server.port] = videoChannel.banner.path 282 bannerPaths[server.port] = videoChannel.banner.path
324 await testImage(server.url, 'banner-resized', bannerPaths[server.port]) 283 await testImage(server.url, 'banner-resized', bannerPaths[server.port])
325 await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true) 284 await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true)
326 285
327 const row = await getActorImage(server.internalServerNumber, basename(bannerPaths[server.port])) 286 const row = await server.sql.getActorImage(basename(bannerPaths[server.port]))
328 expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height) 287 expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height)
329 expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width) 288 expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width)
330 } 289 }
@@ -333,12 +292,7 @@ describe('Test video channels', function () {
333 it('Should delete the video channel avatar', async function () { 292 it('Should delete the video channel avatar', async function () {
334 this.timeout(15000) 293 this.timeout(15000)
335 294
336 await deleteVideoChannelImage({ 295 await servers[0].channels.deleteImage({ channelName: 'second_video_channel', type: 'avatar' })
337 url: servers[0].url,
338 accessToken: servers[0].accessToken,
339 videoChannelName: 'second_video_channel',
340 type: 'avatar'
341 })
342 296
343 await waitJobs(servers) 297 await waitJobs(servers)
344 298
@@ -353,12 +307,7 @@ describe('Test video channels', function () {
353 it('Should delete the video channel banner', async function () { 307 it('Should delete the video channel banner', async function () {
354 this.timeout(15000) 308 this.timeout(15000)
355 309
356 await deleteVideoChannelImage({ 310 await servers[0].channels.deleteImage({ channelName: 'second_video_channel', type: 'banner' })
357 url: servers[0].url,
358 accessToken: servers[0].accessToken,
359 videoChannelName: 'second_video_channel',
360 type: 'banner'
361 })
362 311
363 await waitJobs(servers) 312 await waitJobs(servers)
364 313
@@ -375,18 +324,19 @@ describe('Test video channels', function () {
375 324
376 for (const server of servers) { 325 for (const server of servers) {
377 const channelURI = 'second_video_channel@localhost:' + servers[0].port 326 const channelURI = 'second_video_channel@localhost:' + servers[0].port
378 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) 327 const { total, data } = await server.videos.listByChannel({ handle: channelURI })
379 expect(res1.body.total).to.equal(1) 328
380 expect(res1.body.data).to.be.an('array') 329 expect(total).to.equal(1)
381 expect(res1.body.data).to.have.lengthOf(1) 330 expect(data).to.be.an('array')
382 expect(res1.body.data[0].name).to.equal('my video name') 331 expect(data).to.have.lengthOf(1)
332 expect(data[0].name).to.equal('my video name')
383 } 333 }
384 }) 334 })
385 335
386 it('Should change the video channel of a video', async function () { 336 it('Should change the video channel of a video', async function () {
387 this.timeout(10000) 337 this.timeout(10000)
388 338
389 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: servers[0].videoChannel.id }) 339 await servers[0].videos.update({ id: videoUUID, attributes: { channelId: servers[0].store.channel.id } })
390 340
391 await waitJobs(servers) 341 await waitJobs(servers)
392 }) 342 })
@@ -395,47 +345,50 @@ describe('Test video channels', function () {
395 this.timeout(10000) 345 this.timeout(10000)
396 346
397 for (const server of servers) { 347 for (const server of servers) {
398 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port 348 {
399 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) 349 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
400 expect(res1.body.total).to.equal(0) 350 const { total } = await server.videos.listByChannel({ handle: secondChannelURI })
401 351 expect(total).to.equal(0)
402 const channelURI = 'root_channel@localhost:' + servers[0].port 352 }
403 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) 353
404 expect(res2.body.total).to.equal(1) 354 {
405 355 const channelURI = 'root_channel@localhost:' + servers[0].port
406 const videos: Video[] = res2.body.data 356 const { total, data } = await server.videos.listByChannel({ handle: channelURI })
407 expect(videos).to.be.an('array') 357 expect(total).to.equal(1)
408 expect(videos).to.have.lengthOf(1) 358
409 expect(videos[0].name).to.equal('my video name') 359 expect(data).to.be.an('array')
360 expect(data).to.have.lengthOf(1)
361 expect(data[0].name).to.equal('my video name')
362 }
410 } 363 }
411 }) 364 })
412 365
413 it('Should delete video channel', async function () { 366 it('Should delete video channel', async function () {
414 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel') 367 await servers[0].channels.delete({ channelName: 'second_video_channel' })
415 }) 368 })
416 369
417 it('Should have video channel deleted', async function () { 370 it('Should have video channel deleted', async function () {
418 const res = await getVideoChannelsList(servers[0].url, 0, 10) 371 const body = await servers[0].channels.list({ start: 0, count: 10 })
419 372
420 expect(res.body.total).to.equal(1) 373 expect(body.total).to.equal(1)
421 expect(res.body.data).to.be.an('array') 374 expect(body.data).to.be.an('array')
422 expect(res.body.data).to.have.lengthOf(1) 375 expect(body.data).to.have.lengthOf(1)
423 expect(res.body.data[0].displayName).to.equal('Main root channel') 376 expect(body.data[0].displayName).to.equal('Main root channel')
424 }) 377 })
425 378
426 it('Should create the main channel with an uuid if there is a conflict', async function () { 379 it('Should create the main channel with an uuid if there is a conflict', async function () {
427 { 380 {
428 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } 381 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
429 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) 382 const created = await servers[0].channels.create({ attributes: videoChannel })
430 totoChannel = res.body.videoChannel.id 383 totoChannel = created.id
431 } 384 }
432 385
433 { 386 {
434 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) 387 await servers[0].users.create({ username: 'toto', password: 'password' })
435 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' }) 388 const accessToken = await servers[0].login.getAccessToken({ username: 'toto', password: 'password' })
436 389
437 const res = await getMyUserInformation(servers[0].url, accessToken) 390 const { videoChannels } = await servers[0].users.getMyInfo({ token: accessToken })
438 const videoChannel = res.body.videoChannels[0] 391 const videoChannel = videoChannels[0]
439 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}/) 392 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}/)
440 } 393 }
441 }) 394 })
@@ -444,15 +397,9 @@ describe('Test video channels', function () {
444 this.timeout(10000) 397 this.timeout(10000)
445 398
446 { 399 {
447 const res = await getAccountVideoChannelsList({ 400 const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true })
448 url: servers[0].url,
449 accountName,
450 withStats: true
451 })
452
453 const channels: VideoChannel[] = res.body.data
454 401
455 for (const channel of channels) { 402 for (const channel of data) {
456 expect(channel).to.haveOwnProperty('viewsPerDay') 403 expect(channel).to.haveOwnProperty('viewsPerDay')
457 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today 404 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
458 405
@@ -464,33 +411,24 @@ describe('Test video channels', function () {
464 } 411 }
465 412
466 { 413 {
467 // video has been posted on channel servers[0].videoChannel.id since last update 414 // video has been posted on channel servers[0].store.videoChannel.id since last update
468 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') 415 await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' })
469 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') 416 await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' })
470 417
471 // Wait the repeatable job 418 // Wait the repeatable job
472 await wait(8000) 419 await wait(8000)
473 420
474 const res = await getAccountVideoChannelsList({ 421 const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true })
475 url: servers[0].url, 422 const channelWithView = data.find(channel => channel.id === servers[0].store.channel.id)
476 accountName,
477 withStats: true
478 })
479 const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === servers[0].videoChannel.id)
480 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) 423 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2)
481 } 424 }
482 }) 425 })
483 426
484 it('Should report correct videos count', async function () { 427 it('Should report correct videos count', async function () {
485 const res = await getAccountVideoChannelsList({ 428 const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true })
486 url: servers[0].url,
487 accountName,
488 withStats: true
489 })
490 const channels: VideoChannel[] = res.body.data
491 429
492 const totoChannel = channels.find(c => c.name === 'toto_channel') 430 const totoChannel = data.find(c => c.name === 'toto_channel')
493 const rootChannel = channels.find(c => c.name === 'root_channel') 431 const rootChannel = data.find(c => c.name === 'root_channel')
494 432
495 expect(rootChannel.videosCount).to.equal(1) 433 expect(rootChannel.videosCount).to.equal(1)
496 expect(totoChannel.videosCount).to.equal(0) 434 expect(totoChannel.videosCount).to.equal(0)
@@ -498,26 +436,18 @@ describe('Test video channels', function () {
498 436
499 it('Should search among account video channels', async function () { 437 it('Should search among account video channels', async function () {
500 { 438 {
501 const res = await getAccountVideoChannelsList({ 439 const body = await servers[0].channels.listByAccount({ accountName, search: 'root' })
502 url: servers[0].url, 440 expect(body.total).to.equal(1)
503 accountName,
504 search: 'root'
505 })
506 expect(res.body.total).to.equal(1)
507 441
508 const channels = res.body.data 442 const channels = body.data
509 expect(channels).to.have.lengthOf(1) 443 expect(channels).to.have.lengthOf(1)
510 } 444 }
511 445
512 { 446 {
513 const res = await getAccountVideoChannelsList({ 447 const body = await servers[0].channels.listByAccount({ accountName, search: 'does not exist' })
514 url: servers[0].url, 448 expect(body.total).to.equal(0)
515 accountName,
516 search: 'does not exist'
517 })
518 expect(res.body.total).to.equal(0)
519 449
520 const channels = res.body.data 450 const channels = body.data
521 expect(channels).to.have.lengthOf(0) 451 expect(channels).to.have.lengthOf(0)
522 } 452 }
523 }) 453 })
@@ -525,34 +455,24 @@ describe('Test video channels', function () {
525 it('Should list channels by updatedAt desc if a video has been uploaded', async function () { 455 it('Should list channels by updatedAt desc if a video has been uploaded', async function () {
526 this.timeout(30000) 456 this.timeout(30000)
527 457
528 await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: totoChannel }) 458 await servers[0].videos.upload({ attributes: { channelId: totoChannel } })
529 await waitJobs(servers) 459 await waitJobs(servers)
530 460
531 for (const server of servers) { 461 for (const server of servers) {
532 const res = await getAccountVideoChannelsList({ 462 const { data } = await server.channels.listByAccount({ accountName, sort: '-updatedAt' })
533 url: server.url,
534 accountName,
535 sort: '-updatedAt'
536 })
537 463
538 const channels: VideoChannel[] = res.body.data 464 expect(data[0].name).to.equal('toto_channel')
539 expect(channels[0].name).to.equal('toto_channel') 465 expect(data[1].name).to.equal('root_channel')
540 expect(channels[1].name).to.equal('root_channel')
541 } 466 }
542 467
543 await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: servers[0].videoChannel.id }) 468 await servers[0].videos.upload({ attributes: { channelId: servers[0].store.channel.id } })
544 await waitJobs(servers) 469 await waitJobs(servers)
545 470
546 for (const server of servers) { 471 for (const server of servers) {
547 const res = await getAccountVideoChannelsList({ 472 const { data } = await server.channels.listByAccount({ accountName, sort: '-updatedAt' })
548 url: server.url,
549 accountName,
550 sort: '-updatedAt'
551 })
552 473
553 const channels: VideoChannel[] = res.body.data 474 expect(data[0].name).to.equal('root_channel')
554 expect(channels[0].name).to.equal('root_channel') 475 expect(data[1].name).to.equal('toto_channel')
555 expect(channels[1].name).to.equal('toto_channel')
556 } 476 }
557 }) 477 })
558 478