aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/videos
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/audio-only.ts29
-rw-r--r--server/tests/api/videos/multiple-servers.ts459
-rw-r--r--server/tests/api/videos/resumable-upload.ts48
-rw-r--r--server/tests/api/videos/single-server.ts286
-rw-r--r--server/tests/api/videos/video-captions.ts93
-rw-r--r--server/tests/api/videos/video-change-ownership.ts320
-rw-r--r--server/tests/api/videos/video-channels.ts352
-rw-r--r--server/tests/api/videos/video-comments.ts225
-rw-r--r--server/tests/api/videos/video-description.ts47
-rw-r--r--server/tests/api/videos/video-hls.ts101
-rw-r--r--server/tests/api/videos/video-imports.ts172
-rw-r--r--server/tests/api/videos/video-nsfw.ts226
-rw-r--r--server/tests/api/videos/video-playlist-thumbnails.ts144
-rw-r--r--server/tests/api/videos/video-playlists.ts727
-rw-r--r--server/tests/api/videos/video-privacy.ts157
-rw-r--r--server/tests/api/videos/video-schedule-update.ts77
-rw-r--r--server/tests/api/videos/video-transcoder.ts341
-rw-r--r--server/tests/api/videos/videos-filter.ts49
-rw-r--r--server/tests/api/videos/videos-history.ts139
-rw-r--r--server/tests/api/videos/videos-overview.ts97
-rw-r--r--server/tests/api/videos/videos-views-cleaner.ts47
21 files changed, 1772 insertions, 2364 deletions
diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts
index 7ddbd5cd9..15c3ae6d6 100644
--- a/server/tests/api/videos/audio-only.ts
+++ b/server/tests/api/videos/audio-only.ts
@@ -4,23 +4,12 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' 6import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils'
7import { 7import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
8 buildServerDirectory,
9 cleanupTests,
10 doubleFollow,
11 flushAndRunMultipleServers,
12 getVideo,
13 ServerInfo,
14 setAccessTokensToServers,
15 uploadVideo,
16 waitJobs
17} from '../../../../shared/extra-utils'
18import { VideoDetails } from '../../../../shared/models/videos'
19 8
20const expect = chai.expect 9const expect = chai.expect
21 10
22describe('Test audio only video transcoding', function () { 11describe('Test audio only video transcoding', function () {
23 let servers: ServerInfo[] = [] 12 let servers: PeerTubeServer[] = []
24 let videoUUID: string 13 let videoUUID: string
25 14
26 before(async function () { 15 before(async function () {
@@ -47,7 +36,7 @@ describe('Test audio only video transcoding', function () {
47 } 36 }
48 } 37 }
49 } 38 }
50 servers = await flushAndRunMultipleServers(2, configOverride) 39 servers = await createMultipleServers(2, configOverride)
51 40
52 // Get the access tokens 41 // Get the access tokens
53 await setAccessTokensToServers(servers) 42 await setAccessTokensToServers(servers)
@@ -59,15 +48,13 @@ describe('Test audio only video transcoding', function () {
59 it('Should upload a video and transcode it', async function () { 48 it('Should upload a video and transcode it', async function () {
60 this.timeout(120000) 49 this.timeout(120000)
61 50
62 const resUpload = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'audio only' }) 51 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'audio only' } })
63 videoUUID = resUpload.body.video.uuid 52 videoUUID = uuid
64 53
65 await waitJobs(servers) 54 await waitJobs(servers)
66 55
67 for (const server of servers) { 56 for (const server of servers) {
68 const res = await getVideo(server.url, videoUUID) 57 const video = await server.videos.get({ id: videoUUID })
69 const video: VideoDetails = res.body
70
71 expect(video.streamingPlaylists).to.have.lengthOf(1) 58 expect(video.streamingPlaylists).to.have.lengthOf(1)
72 59
73 for (const files of [ video.files, video.streamingPlaylists[0].files ]) { 60 for (const files of [ video.files, video.streamingPlaylists[0].files ]) {
@@ -81,8 +68,8 @@ describe('Test audio only video transcoding', function () {
81 68
82 it('0p transcoded video should not have video', async function () { 69 it('0p transcoded video should not have video', async function () {
83 const paths = [ 70 const paths = [
84 buildServerDirectory(servers[0], join('videos', videoUUID + '-0.mp4')), 71 servers[0].servers.buildDirectory(join('videos', videoUUID + '-0.mp4')),
85 buildServerDirectory(servers[0], join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) 72 servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4'))
86 ] 73 ]
87 74
88 for (const path of paths) { 75 for (const path of paths) {
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index a8c8a889b..d916abb09 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -3,49 +3,28 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import * as request from 'supertest' 5import * as request from 'supertest'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 6import {
8 addVideoChannel,
9 buildAbsoluteFixturePath, 7 buildAbsoluteFixturePath,
10 checkTmpIsEmpty, 8 checkTmpIsEmpty,
11 checkVideoFilesWereRemoved, 9 checkVideoFilesWereRemoved,
12 cleanupTests, 10 cleanupTests,
13 completeVideoCheck, 11 completeVideoCheck,
14 createUser, 12 createMultipleServers,
15 dateIsValid, 13 dateIsValid,
16 doubleFollow, 14 doubleFollow,
17 flushAndRunMultipleServers, 15 PeerTubeServer,
18 getLocalVideos,
19 getVideo,
20 getVideoChannelsList,
21 getVideosList,
22 rateVideo,
23 removeVideo,
24 ServerInfo,
25 setAccessTokensToServers, 16 setAccessTokensToServers,
26 testImage, 17 testImage,
27 updateVideo,
28 uploadVideo,
29 userLogin,
30 viewVideo,
31 wait, 18 wait,
19 waitJobs,
32 webtorrentAdd 20 webtorrentAdd
33} from '../../../../shared/extra-utils' 21} from '@shared/extra-utils'
34import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 22import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
35import {
36 addVideoCommentReply,
37 addVideoCommentThread,
38 deleteVideoComment,
39 findCommentId,
40 getVideoCommentThreads,
41 getVideoThreadComments
42} from '../../../../shared/extra-utils/videos/video-comments'
43import { VideoComment, VideoCommentThreadTree, VideoPrivacy } from '../../../../shared/models/videos'
44 23
45const expect = chai.expect 24const expect = chai.expect
46 25
47describe('Test multiple servers', function () { 26describe('Test multiple servers', function () {
48 let servers: ServerInfo[] = [] 27 let servers: PeerTubeServer[] = []
49 const toRemove = [] 28 const toRemove = []
50 let videoUUID = '' 29 let videoUUID = ''
51 let videoChannelId: number 30 let videoChannelId: number
@@ -53,7 +32,7 @@ describe('Test multiple servers', function () {
53 before(async function () { 32 before(async function () {
54 this.timeout(120000) 33 this.timeout(120000)
55 34
56 servers = await flushAndRunMultipleServers(3) 35 servers = await createMultipleServers(3)
57 36
58 // Get the access tokens 37 // Get the access tokens
59 await setAccessTokensToServers(servers) 38 await setAccessTokensToServers(servers)
@@ -64,9 +43,9 @@ describe('Test multiple servers', function () {
64 displayName: 'my channel', 43 displayName: 'my channel',
65 description: 'super channel' 44 description: 'super channel'
66 } 45 }
67 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) 46 await servers[0].channels.create({ attributes: videoChannel })
68 const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) 47 const { data } = await servers[0].channels.list({ start: 0, count: 1 })
69 videoChannelId = channelRes.body.data[0].id 48 videoChannelId = data[0].id
70 } 49 }
71 50
72 // Server 1 and server 2 follow each other 51 // Server 1 and server 2 follow each other
@@ -79,10 +58,9 @@ describe('Test multiple servers', function () {
79 58
80 it('Should not have videos for all servers', async function () { 59 it('Should not have videos for all servers', async function () {
81 for (const server of servers) { 60 for (const server of servers) {
82 const res = await getVideosList(server.url) 61 const { data } = await server.videos.list()
83 const videos = res.body.data 62 expect(data).to.be.an('array')
84 expect(videos).to.be.an('array') 63 expect(data.length).to.equal(0)
85 expect(videos.length).to.equal(0)
86 } 64 }
87 }) 65 })
88 66
@@ -90,7 +68,7 @@ describe('Test multiple servers', function () {
90 it('Should upload the video on server 1 and propagate on each server', async function () { 68 it('Should upload the video on server 1 and propagate on each server', async function () {
91 this.timeout(25000) 69 this.timeout(25000)
92 70
93 const videoAttributes = { 71 const attributes = {
94 name: 'my super name for server 1', 72 name: 'my super name for server 1',
95 category: 5, 73 category: 5,
96 licence: 4, 74 licence: 4,
@@ -103,7 +81,7 @@ describe('Test multiple servers', function () {
103 channelId: videoChannelId, 81 channelId: videoChannelId,
104 fixture: 'video_short1.webm' 82 fixture: 'video_short1.webm'
105 } 83 }
106 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 84 await servers[0].videos.upload({ attributes })
107 85
108 await waitJobs(servers) 86 await waitJobs(servers)
109 87
@@ -146,14 +124,13 @@ describe('Test multiple servers', function () {
146 ] 124 ]
147 } 125 }
148 126
149 const res = await getVideosList(server.url) 127 const { data } = await server.videos.list()
150 const videos = res.body.data 128 expect(data).to.be.an('array')
151 expect(videos).to.be.an('array') 129 expect(data.length).to.equal(1)
152 expect(videos.length).to.equal(1) 130 const video = data[0]
153 const video = videos[0]
154 131
155 await completeVideoCheck(server.url, video, checkAttributes) 132 await completeVideoCheck(server, video, checkAttributes)
156 publishedAt = video.publishedAt 133 publishedAt = video.publishedAt as string
157 } 134 }
158 }) 135 })
159 136
@@ -164,10 +141,10 @@ describe('Test multiple servers', function () {
164 username: 'user1', 141 username: 'user1',
165 password: 'super_password' 142 password: 'super_password'
166 } 143 }
167 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 144 await servers[1].users.create({ username: user.username, password: user.password })
168 const userAccessToken = await userLogin(servers[1], user) 145 const userAccessToken = await servers[1].login.getAccessToken(user)
169 146
170 const videoAttributes = { 147 const attributes = {
171 name: 'my super name for server 2', 148 name: 'my super name for server 2',
172 category: 4, 149 category: 4,
173 licence: 3, 150 licence: 3,
@@ -180,7 +157,7 @@ describe('Test multiple servers', function () {
180 thumbnailfile: 'thumbnail.jpg', 157 thumbnailfile: 'thumbnail.jpg',
181 previewfile: 'preview.jpg' 158 previewfile: 'preview.jpg'
182 } 159 }
183 await uploadVideo(servers[1].url, userAccessToken, videoAttributes, HttpStatusCode.OK_200, 'resumable') 160 await servers[1].videos.upload({ token: userAccessToken, attributes, mode: 'resumable' })
184 161
185 // Transcoding 162 // Transcoding
186 await waitJobs(servers) 163 await waitJobs(servers)
@@ -235,65 +212,67 @@ describe('Test multiple servers', function () {
235 previewfile: 'preview' 212 previewfile: 'preview'
236 } 213 }
237 214
238 const res = await getVideosList(server.url) 215 const { data } = await server.videos.list()
239 const videos = res.body.data 216 expect(data).to.be.an('array')
240 expect(videos).to.be.an('array') 217 expect(data.length).to.equal(2)
241 expect(videos.length).to.equal(2) 218 const video = data[1]
242 const video = videos[1]
243 219
244 await completeVideoCheck(server.url, video, checkAttributes) 220 await completeVideoCheck(server, video, checkAttributes)
245 } 221 }
246 }) 222 })
247 223
248 it('Should upload two videos on server 3 and propagate on each server', async function () { 224 it('Should upload two videos on server 3 and propagate on each server', async function () {
249 this.timeout(45000) 225 this.timeout(45000)
250 226
251 const videoAttributes1 = { 227 {
252 name: 'my super name for server 3', 228 const attributes = {
253 category: 6, 229 name: 'my super name for server 3',
254 licence: 5, 230 category: 6,
255 language: 'de', 231 licence: 5,
256 nsfw: true, 232 language: 'de',
257 description: 'my super description for server 3', 233 nsfw: true,
258 support: 'my super support text for server 3', 234 description: 'my super description for server 3',
259 tags: [ 'tag1p3' ], 235 support: 'my super support text for server 3',
260 fixture: 'video_short3.webm' 236 tags: [ 'tag1p3' ],
237 fixture: 'video_short3.webm'
238 }
239 await servers[2].videos.upload({ attributes })
261 } 240 }
262 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) 241
263 242 {
264 const videoAttributes2 = { 243 const attributes = {
265 name: 'my super name for server 3-2', 244 name: 'my super name for server 3-2',
266 category: 7, 245 category: 7,
267 licence: 6, 246 licence: 6,
268 language: 'ko', 247 language: 'ko',
269 nsfw: false, 248 nsfw: false,
270 description: 'my super description for server 3-2', 249 description: 'my super description for server 3-2',
271 support: 'my super support text for server 3-2', 250 support: 'my super support text for server 3-2',
272 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], 251 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
273 fixture: 'video_short.webm' 252 fixture: 'video_short.webm'
253 }
254 await servers[2].videos.upload({ attributes })
274 } 255 }
275 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
276 256
277 await waitJobs(servers) 257 await waitJobs(servers)
278 258
279 // All servers should have this video 259 // All servers should have this video
280 for (const server of servers) { 260 for (const server of servers) {
281 const isLocal = server.url === 'http://localhost:' + servers[2].port 261 const isLocal = server.url === 'http://localhost:' + servers[2].port
282 const res = await getVideosList(server.url) 262 const { data } = await server.videos.list()
283 263
284 const videos = res.body.data 264 expect(data).to.be.an('array')
285 expect(videos).to.be.an('array') 265 expect(data.length).to.equal(4)
286 expect(videos.length).to.equal(4)
287 266
288 // We not sure about the order of the two last uploads 267 // We not sure about the order of the two last uploads
289 let video1 = null 268 let video1 = null
290 let video2 = null 269 let video2 = null
291 if (videos[2].name === 'my super name for server 3') { 270 if (data[2].name === 'my super name for server 3') {
292 video1 = videos[2] 271 video1 = data[2]
293 video2 = videos[3] 272 video2 = data[3]
294 } else { 273 } else {
295 video1 = videos[3] 274 video1 = data[3]
296 video2 = videos[2] 275 video2 = data[2]
297 } 276 }
298 277
299 const checkAttributesVideo1 = { 278 const checkAttributesVideo1 = {
@@ -328,7 +307,7 @@ describe('Test multiple servers', function () {
328 } 307 }
329 ] 308 ]
330 } 309 }
331 await completeVideoCheck(server.url, video1, checkAttributesVideo1) 310 await completeVideoCheck(server, video1, checkAttributesVideo1)
332 311
333 const checkAttributesVideo2 = { 312 const checkAttributesVideo2 = {
334 name: 'my super name for server 3-2', 313 name: 'my super name for server 3-2',
@@ -362,38 +341,38 @@ describe('Test multiple servers', function () {
362 } 341 }
363 ] 342 ]
364 } 343 }
365 await completeVideoCheck(server.url, video2, checkAttributesVideo2) 344 await completeVideoCheck(server, video2, checkAttributesVideo2)
366 } 345 }
367 }) 346 })
368 }) 347 })
369 348
370 describe('It should list local videos', function () { 349 describe('It should list local videos', function () {
371 it('Should list only local videos on server 1', async function () { 350 it('Should list only local videos on server 1', async function () {
372 const { body } = await getLocalVideos(servers[0].url) 351 const { data, total } = await servers[0].videos.list({ filter: 'local' })
373 352
374 expect(body.total).to.equal(1) 353 expect(total).to.equal(1)
375 expect(body.data).to.be.an('array') 354 expect(data).to.be.an('array')
376 expect(body.data.length).to.equal(1) 355 expect(data.length).to.equal(1)
377 expect(body.data[0].name).to.equal('my super name for server 1') 356 expect(data[0].name).to.equal('my super name for server 1')
378 }) 357 })
379 358
380 it('Should list only local videos on server 2', async function () { 359 it('Should list only local videos on server 2', async function () {
381 const { body } = await getLocalVideos(servers[1].url) 360 const { data, total } = await servers[1].videos.list({ filter: 'local' })
382 361
383 expect(body.total).to.equal(1) 362 expect(total).to.equal(1)
384 expect(body.data).to.be.an('array') 363 expect(data).to.be.an('array')
385 expect(body.data.length).to.equal(1) 364 expect(data.length).to.equal(1)
386 expect(body.data[0].name).to.equal('my super name for server 2') 365 expect(data[0].name).to.equal('my super name for server 2')
387 }) 366 })
388 367
389 it('Should list only local videos on server 3', async function () { 368 it('Should list only local videos on server 3', async function () {
390 const { body } = await getLocalVideos(servers[2].url) 369 const { data, total } = await servers[2].videos.list({ filter: 'local' })
391 370
392 expect(body.total).to.equal(2) 371 expect(total).to.equal(2)
393 expect(body.data).to.be.an('array') 372 expect(data).to.be.an('array')
394 expect(body.data.length).to.equal(2) 373 expect(data.length).to.equal(2)
395 expect(body.data[0].name).to.equal('my super name for server 3') 374 expect(data[0].name).to.equal('my super name for server 3')
396 expect(body.data[1].name).to.equal('my super name for server 3-2') 375 expect(data[1].name).to.equal('my super name for server 3-2')
397 }) 376 })
398 }) 377 })
399 378
@@ -401,15 +380,13 @@ describe('Test multiple servers', function () {
401 it('Should add the file 1 by asking server 3', async function () { 380 it('Should add the file 1 by asking server 3', async function () {
402 this.timeout(10000) 381 this.timeout(10000)
403 382
404 const res = await getVideosList(servers[2].url) 383 const { data } = await servers[2].videos.list()
405
406 const video = res.body.data[0]
407 toRemove.push(res.body.data[2])
408 toRemove.push(res.body.data[3])
409 384
410 const res2 = await getVideo(servers[2].url, video.id) 385 const video = data[0]
411 const videoDetails = res2.body 386 toRemove.push(data[2])
387 toRemove.push(data[3])
412 388
389 const videoDetails = await servers[2].videos.get({ id: video.id })
413 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 390 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
414 expect(torrent.files).to.be.an('array') 391 expect(torrent.files).to.be.an('array')
415 expect(torrent.files.length).to.equal(1) 392 expect(torrent.files.length).to.equal(1)
@@ -419,11 +396,10 @@ describe('Test multiple servers', function () {
419 it('Should add the file 2 by asking server 1', async function () { 396 it('Should add the file 2 by asking server 1', async function () {
420 this.timeout(10000) 397 this.timeout(10000)
421 398
422 const res = await getVideosList(servers[0].url) 399 const { data } = await servers[0].videos.list()
423 400
424 const video = res.body.data[1] 401 const video = data[1]
425 const res2 = await getVideo(servers[0].url, video.id) 402 const videoDetails = await servers[0].videos.get({ id: video.id })
426 const videoDetails = res2.body
427 403
428 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 404 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
429 expect(torrent.files).to.be.an('array') 405 expect(torrent.files).to.be.an('array')
@@ -434,11 +410,10 @@ describe('Test multiple servers', function () {
434 it('Should add the file 3 by asking server 2', async function () { 410 it('Should add the file 3 by asking server 2', async function () {
435 this.timeout(10000) 411 this.timeout(10000)
436 412
437 const res = await getVideosList(servers[1].url) 413 const { data } = await servers[1].videos.list()
438 414
439 const video = res.body.data[2] 415 const video = data[2]
440 const res2 = await getVideo(servers[1].url, video.id) 416 const videoDetails = await servers[1].videos.get({ id: video.id })
441 const videoDetails = res2.body
442 417
443 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 418 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
444 expect(torrent.files).to.be.an('array') 419 expect(torrent.files).to.be.an('array')
@@ -449,11 +424,10 @@ describe('Test multiple servers', function () {
449 it('Should add the file 3-2 by asking server 1', async function () { 424 it('Should add the file 3-2 by asking server 1', async function () {
450 this.timeout(10000) 425 this.timeout(10000)
451 426
452 const res = await getVideosList(servers[0].url) 427 const { data } = await servers[0].videos.list()
453 428
454 const video = res.body.data[3] 429 const video = data[3]
455 const res2 = await getVideo(servers[0].url, video.id) 430 const videoDetails = await servers[0].videos.get({ id: video.id })
456 const videoDetails = res2.body
457 431
458 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) 432 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
459 expect(torrent.files).to.be.an('array') 433 expect(torrent.files).to.be.an('array')
@@ -464,11 +438,10 @@ describe('Test multiple servers', function () {
464 it('Should add the file 2 in 360p by asking server 1', async function () { 438 it('Should add the file 2 in 360p by asking server 1', async function () {
465 this.timeout(10000) 439 this.timeout(10000)
466 440
467 const res = await getVideosList(servers[0].url) 441 const { data } = await servers[0].videos.list()
468 442
469 const video = res.body.data.find(v => v.name === 'my super name for server 2') 443 const video = data.find(v => v.name === 'my super name for server 2')
470 const res2 = await getVideo(servers[0].url, video.id) 444 const videoDetails = await servers[0].videos.get({ id: video.id })
471 const videoDetails = res2.body
472 445
473 const file = videoDetails.files.find(f => f.resolution.id === 360) 446 const file = videoDetails.files.find(f => f.resolution.id === 360)
474 expect(file).not.to.be.undefined 447 expect(file).not.to.be.undefined
@@ -487,30 +460,36 @@ describe('Test multiple servers', function () {
487 let remoteVideosServer3 = [] 460 let remoteVideosServer3 = []
488 461
489 before(async function () { 462 before(async function () {
490 const res1 = await getVideosList(servers[0].url) 463 {
491 remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 464 const { data } = await servers[0].videos.list()
465 remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid)
466 }
492 467
493 const res2 = await getVideosList(servers[1].url) 468 {
494 remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 469 const { data } = await servers[1].videos.list()
470 remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid)
471 }
495 472
496 const res3 = await getVideosList(servers[2].url) 473 {
497 localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) 474 const { data } = await servers[2].videos.list()
498 remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 475 localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid)
476 remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid)
477 }
499 }) 478 })
500 479
501 it('Should view multiple videos on owned servers', async function () { 480 it('Should view multiple videos on owned servers', async function () {
502 this.timeout(30000) 481 this.timeout(30000)
503 482
504 await viewVideo(servers[2].url, localVideosServer3[0]) 483 await servers[2].videos.view({ id: localVideosServer3[0] })
505 await wait(1000) 484 await wait(1000)
506 485
507 await viewVideo(servers[2].url, localVideosServer3[0]) 486 await servers[2].videos.view({ id: localVideosServer3[0] })
508 await viewVideo(servers[2].url, localVideosServer3[1]) 487 await servers[2].videos.view({ id: localVideosServer3[1] })
509 488
510 await wait(1000) 489 await wait(1000)
511 490
512 await viewVideo(servers[2].url, localVideosServer3[0]) 491 await servers[2].videos.view({ id: localVideosServer3[0] })
513 await viewVideo(servers[2].url, localVideosServer3[0]) 492 await servers[2].videos.view({ id: localVideosServer3[0] })
514 493
515 await waitJobs(servers) 494 await waitJobs(servers)
516 495
@@ -520,11 +499,10 @@ describe('Test multiple servers', function () {
520 await waitJobs(servers) 499 await waitJobs(servers)
521 500
522 for (const server of servers) { 501 for (const server of servers) {
523 const res = await getVideosList(server.url) 502 const { data } = await server.videos.list()
524 503
525 const videos = res.body.data 504 const video0 = data.find(v => v.uuid === localVideosServer3[0])
526 const video0 = videos.find(v => v.uuid === localVideosServer3[0]) 505 const video1 = data.find(v => v.uuid === localVideosServer3[1])
527 const video1 = videos.find(v => v.uuid === localVideosServer3[1])
528 506
529 expect(video0.views).to.equal(3) 507 expect(video0.views).to.equal(3)
530 expect(video1.views).to.equal(1) 508 expect(video1.views).to.equal(1)
@@ -535,16 +513,16 @@ describe('Test multiple servers', function () {
535 this.timeout(45000) 513 this.timeout(45000)
536 514
537 const tasks: Promise<any>[] = [] 515 const tasks: Promise<any>[] = []
538 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) 516 tasks.push(servers[0].videos.view({ id: remoteVideosServer1[0] }))
539 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) 517 tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] }))
540 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) 518 tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] }))
541 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) 519 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[0] }))
542 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 520 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] }))
543 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 521 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] }))
544 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 522 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] }))
545 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 523 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] }))
546 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 524 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] }))
547 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 525 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] }))
548 526
549 await Promise.all(tasks) 527 await Promise.all(tasks)
550 528
@@ -558,18 +536,16 @@ describe('Test multiple servers', function () {
558 let baseVideos = null 536 let baseVideos = null
559 537
560 for (const server of servers) { 538 for (const server of servers) {
561 const res = await getVideosList(server.url) 539 const { data } = await server.videos.list()
562
563 const videos = res.body.data
564 540
565 // Initialize base videos for future comparisons 541 // Initialize base videos for future comparisons
566 if (baseVideos === null) { 542 if (baseVideos === null) {
567 baseVideos = videos 543 baseVideos = data
568 continue 544 continue
569 } 545 }
570 546
571 for (const baseVideo of baseVideos) { 547 for (const baseVideo of baseVideos) {
572 const sameVideo = videos.find(video => video.name === baseVideo.name) 548 const sameVideo = data.find(video => video.name === baseVideo.name)
573 expect(baseVideo.views).to.equal(sameVideo.views) 549 expect(baseVideo.views).to.equal(sameVideo.views)
574 } 550 }
575 } 551 }
@@ -578,35 +554,34 @@ describe('Test multiple servers', function () {
578 it('Should like and dislikes videos on different services', async function () { 554 it('Should like and dislikes videos on different services', async function () {
579 this.timeout(50000) 555 this.timeout(50000)
580 556
581 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') 557 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' })
582 await wait(500) 558 await wait(500)
583 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike') 559 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'dislike' })
584 await wait(500) 560 await wait(500)
585 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') 561 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' })
586 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like') 562 await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'like' })
587 await wait(500) 563 await wait(500)
588 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike') 564 await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'dislike' })
589 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike') 565 await servers[2].videos.rate({ id: remoteVideosServer3[1], rating: 'dislike' })
590 await wait(500) 566 await wait(500)
591 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') 567 await servers[2].videos.rate({ id: remoteVideosServer3[0], rating: 'like' })
592 568
593 await waitJobs(servers) 569 await waitJobs(servers)
594 await wait(5000) 570 await wait(5000)
571 await waitJobs(servers)
595 572
596 let baseVideos = null 573 let baseVideos = null
597 for (const server of servers) { 574 for (const server of servers) {
598 const res = await getVideosList(server.url) 575 const { data } = await server.videos.list()
599
600 const videos = res.body.data
601 576
602 // Initialize base videos for future comparisons 577 // Initialize base videos for future comparisons
603 if (baseVideos === null) { 578 if (baseVideos === null) {
604 baseVideos = videos 579 baseVideos = data
605 continue 580 continue
606 } 581 }
607 582
608 for (const baseVideo of baseVideos) { 583 for (const baseVideo of baseVideos) {
609 const sameVideo = videos.find(video => video.name === baseVideo.name) 584 const sameVideo = data.find(video => video.name === baseVideo.name)
610 expect(baseVideo.likes).to.equal(sameVideo.likes) 585 expect(baseVideo.likes).to.equal(sameVideo.likes)
611 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) 586 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
612 } 587 }
@@ -632,7 +607,7 @@ describe('Test multiple servers', function () {
632 previewfile: 'preview.jpg' 607 previewfile: 'preview.jpg'
633 } 608 }
634 609
635 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) 610 await servers[2].videos.update({ id: toRemove[0].id, attributes })
636 611
637 await waitJobs(servers) 612 await waitJobs(servers)
638 }) 613 })
@@ -641,10 +616,9 @@ describe('Test multiple servers', function () {
641 this.timeout(10000) 616 this.timeout(10000)
642 617
643 for (const server of servers) { 618 for (const server of servers) {
644 const res = await getVideosList(server.url) 619 const { data } = await server.videos.list()
645 620
646 const videos = res.body.data 621 const videoUpdated = data.find(video => video.name === 'my super video updated')
647 const videoUpdated = videos.find(video => video.name === 'my super video updated')
648 expect(!!videoUpdated).to.be.true 622 expect(!!videoUpdated).to.be.true
649 623
650 const isLocal = server.url === 'http://localhost:' + servers[2].port 624 const isLocal = server.url === 'http://localhost:' + servers[2].port
@@ -683,49 +657,46 @@ describe('Test multiple servers', function () {
683 thumbnailfile: 'thumbnail', 657 thumbnailfile: 'thumbnail',
684 previewfile: 'preview' 658 previewfile: 'preview'
685 } 659 }
686 await completeVideoCheck(server.url, videoUpdated, checkAttributes) 660 await completeVideoCheck(server, videoUpdated, checkAttributes)
687 } 661 }
688 }) 662 })
689 663
690 it('Should remove the videos 3 and 3-2 by asking server 3', async function () { 664 it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
691 this.timeout(10000) 665 this.timeout(10000)
692 666
693 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) 667 await servers[2].videos.remove({ id: toRemove[0].id })
694 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) 668 await servers[2].videos.remove({ id: toRemove[1].id })
695 669
696 await waitJobs(servers) 670 await waitJobs(servers)
697 }) 671 })
698 672
699 it('Should not have files of videos 3 and 3-2 on each server', async function () { 673 it('Should not have files of videos 3 and 3-2 on each server', async function () {
700 for (const server of servers) { 674 for (const server of servers) {
701 await checkVideoFilesWereRemoved(toRemove[0].uuid, server.internalServerNumber) 675 await checkVideoFilesWereRemoved(toRemove[0].uuid, server)
702 await checkVideoFilesWereRemoved(toRemove[1].uuid, server.internalServerNumber) 676 await checkVideoFilesWereRemoved(toRemove[1].uuid, server)
703 } 677 }
704 }) 678 })
705 679
706 it('Should have videos 1 and 3 on each server', async function () { 680 it('Should have videos 1 and 3 on each server', async function () {
707 for (const server of servers) { 681 for (const server of servers) {
708 const res = await getVideosList(server.url) 682 const { data } = await server.videos.list()
709 683
710 const videos = res.body.data 684 expect(data).to.be.an('array')
711 expect(videos).to.be.an('array') 685 expect(data.length).to.equal(2)
712 expect(videos.length).to.equal(2) 686 expect(data[0].name).not.to.equal(data[1].name)
713 expect(videos[0].name).not.to.equal(videos[1].name) 687 expect(data[0].name).not.to.equal(toRemove[0].name)
714 expect(videos[0].name).not.to.equal(toRemove[0].name) 688 expect(data[1].name).not.to.equal(toRemove[0].name)
715 expect(videos[1].name).not.to.equal(toRemove[0].name) 689 expect(data[0].name).not.to.equal(toRemove[1].name)
716 expect(videos[0].name).not.to.equal(toRemove[1].name) 690 expect(data[1].name).not.to.equal(toRemove[1].name)
717 expect(videos[1].name).not.to.equal(toRemove[1].name) 691
718 692 videoUUID = data.find(video => video.name === 'my super name for server 1').uuid
719 videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
720 } 693 }
721 }) 694 })
722 695
723 it('Should get the same video by UUID on each server', async function () { 696 it('Should get the same video by UUID on each server', async function () {
724 let baseVideo = null 697 let baseVideo = null
725 for (const server of servers) { 698 for (const server of servers) {
726 const res = await getVideo(server.url, videoUUID) 699 const video = await server.videos.get({ id: videoUUID })
727
728 const video = res.body
729 700
730 if (baseVideo === null) { 701 if (baseVideo === null) {
731 baseVideo = video 702 baseVideo = video
@@ -748,8 +719,7 @@ describe('Test multiple servers', function () {
748 719
749 it('Should get the preview from each server', async function () { 720 it('Should get the preview from each server', async function () {
750 for (const server of servers) { 721 for (const server of servers) {
751 const res = await getVideo(server.url, videoUUID) 722 const video = await server.videos.get({ id: videoUUID })
752 const video = res.body
753 723
754 await testImage(server.url, 'video_short1-preview.webm', video.previewPath) 724 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
755 } 725 }
@@ -764,36 +734,36 @@ describe('Test multiple servers', function () {
764 734
765 { 735 {
766 const text = 'my super first comment' 736 const text = 'my super first comment'
767 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, text) 737 await servers[0].comments.createThread({ videoId: videoUUID, text })
768 } 738 }
769 739
770 { 740 {
771 const text = 'my super second comment' 741 const text = 'my super second comment'
772 await addVideoCommentThread(servers[2].url, servers[2].accessToken, videoUUID, text) 742 await servers[2].comments.createThread({ videoId: videoUUID, text })
773 } 743 }
774 744
775 await waitJobs(servers) 745 await waitJobs(servers)
776 746
777 { 747 {
778 const threadId = await findCommentId(servers[1].url, videoUUID, 'my super first comment') 748 const threadId = await servers[1].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
779 749
780 const text = 'my super answer to thread 1' 750 const text = 'my super answer to thread 1'
781 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID, threadId, text) 751 await servers[1].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text })
782 } 752 }
783 753
784 await waitJobs(servers) 754 await waitJobs(servers)
785 755
786 { 756 {
787 const threadId = await findCommentId(servers[2].url, videoUUID, 'my super first comment') 757 const threadId = await servers[2].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
788 758
789 const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId) 759 const body = await servers[2].comments.getThread({ videoId: videoUUID, threadId })
790 const childCommentId = res2.body.children[0].comment.id 760 const childCommentId = body.children[0].comment.id
791 761
792 const text3 = 'my second answer to thread 1' 762 const text3 = 'my second answer to thread 1'
793 await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, threadId, text3) 763 await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 })
794 764
795 const text2 = 'my super answer to answer of thread 1' 765 const text2 = 'my super answer to answer of thread 1'
796 await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, childCommentId, text2) 766 await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 })
797 } 767 }
798 768
799 await waitJobs(servers) 769 await waitJobs(servers)
@@ -801,14 +771,14 @@ describe('Test multiple servers', function () {
801 771
802 it('Should have these threads', async function () { 772 it('Should have these threads', async function () {
803 for (const server of servers) { 773 for (const server of servers) {
804 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 774 const body = await server.comments.listThreads({ videoId: videoUUID })
805 775
806 expect(res.body.total).to.equal(2) 776 expect(body.total).to.equal(2)
807 expect(res.body.data).to.be.an('array') 777 expect(body.data).to.be.an('array')
808 expect(res.body.data).to.have.lengthOf(2) 778 expect(body.data).to.have.lengthOf(2)
809 779
810 { 780 {
811 const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment') 781 const comment = body.data.find(c => c.text === 'my super first comment')
812 expect(comment).to.not.be.undefined 782 expect(comment).to.not.be.undefined
813 expect(comment.inReplyToCommentId).to.be.null 783 expect(comment.inReplyToCommentId).to.be.null
814 expect(comment.account.name).to.equal('root') 784 expect(comment.account.name).to.equal('root')
@@ -819,7 +789,7 @@ describe('Test multiple servers', function () {
819 } 789 }
820 790
821 { 791 {
822 const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment') 792 const comment = body.data.find(c => c.text === 'my super second comment')
823 expect(comment).to.not.be.undefined 793 expect(comment).to.not.be.undefined
824 expect(comment.inReplyToCommentId).to.be.null 794 expect(comment.inReplyToCommentId).to.be.null
825 expect(comment.account.name).to.equal('root') 795 expect(comment.account.name).to.equal('root')
@@ -833,12 +803,11 @@ describe('Test multiple servers', function () {
833 803
834 it('Should have these comments', async function () { 804 it('Should have these comments', async function () {
835 for (const server of servers) { 805 for (const server of servers) {
836 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 806 const body = await server.comments.listThreads({ videoId: videoUUID })
837 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id 807 const threadId = body.data.find(c => c.text === 'my super first comment').id
838 808
839 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) 809 const tree = await server.comments.getThread({ videoId: videoUUID, threadId })
840 810
841 const tree: VideoCommentThreadTree = res2.body
842 expect(tree.comment.text).equal('my super first comment') 811 expect(tree.comment.text).equal('my super first comment')
843 expect(tree.comment.account.name).equal('root') 812 expect(tree.comment.account.name).equal('root')
844 expect(tree.comment.account.host).equal('localhost:' + servers[0].port) 813 expect(tree.comment.account.host).equal('localhost:' + servers[0].port)
@@ -867,19 +836,17 @@ describe('Test multiple servers', function () {
867 it('Should delete a reply', async function () { 836 it('Should delete a reply', async function () {
868 this.timeout(10000) 837 this.timeout(10000)
869 838
870 await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id) 839 await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id })
871 840
872 await waitJobs(servers) 841 await waitJobs(servers)
873 }) 842 })
874 843
875 it('Should have this comment marked as deleted', async function () { 844 it('Should have this comment marked as deleted', async function () {
876 for (const server of servers) { 845 for (const server of servers) {
877 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 846 const { data } = await server.comments.listThreads({ videoId: videoUUID })
878 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id 847 const threadId = data.find(c => c.text === 'my super first comment').id
879
880 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
881 848
882 const tree: VideoCommentThreadTree = res2.body 849 const tree = await server.comments.getThread({ videoId: videoUUID, threadId })
883 expect(tree.comment.text).equal('my super first comment') 850 expect(tree.comment.text).equal('my super first comment')
884 851
885 const firstChild = tree.children[0] 852 const firstChild = tree.children[0]
@@ -900,23 +867,23 @@ describe('Test multiple servers', function () {
900 it('Should delete the thread comments', async function () { 867 it('Should delete the thread comments', async function () {
901 this.timeout(10000) 868 this.timeout(10000)
902 869
903 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) 870 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
904 const threadId = res.body.data.find(c => c.text === 'my super first comment').id 871 const commentId = data.find(c => c.text === 'my super first comment').id
905 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 872 await servers[0].comments.delete({ videoId: videoUUID, commentId })
906 873
907 await waitJobs(servers) 874 await waitJobs(servers)
908 }) 875 })
909 876
910 it('Should have the threads marked as deleted on other servers too', async function () { 877 it('Should have the threads marked as deleted on other servers too', async function () {
911 for (const server of servers) { 878 for (const server of servers) {
912 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 879 const body = await server.comments.listThreads({ videoId: videoUUID })
913 880
914 expect(res.body.total).to.equal(2) 881 expect(body.total).to.equal(2)
915 expect(res.body.data).to.be.an('array') 882 expect(body.data).to.be.an('array')
916 expect(res.body.data).to.have.lengthOf(2) 883 expect(body.data).to.have.lengthOf(2)
917 884
918 { 885 {
919 const comment: VideoComment = res.body.data[0] 886 const comment = body.data[0]
920 expect(comment).to.not.be.undefined 887 expect(comment).to.not.be.undefined
921 expect(comment.inReplyToCommentId).to.be.null 888 expect(comment.inReplyToCommentId).to.be.null
922 expect(comment.account.name).to.equal('root') 889 expect(comment.account.name).to.equal('root')
@@ -927,7 +894,7 @@ describe('Test multiple servers', function () {
927 } 894 }
928 895
929 { 896 {
930 const deletedComment: VideoComment = res.body.data[1] 897 const deletedComment = body.data[1]
931 expect(deletedComment).to.not.be.undefined 898 expect(deletedComment).to.not.be.undefined
932 expect(deletedComment.isDeleted).to.be.true 899 expect(deletedComment.isDeleted).to.be.true
933 expect(deletedComment.deletedAt).to.not.be.null 900 expect(deletedComment.deletedAt).to.not.be.null
@@ -945,22 +912,22 @@ describe('Test multiple servers', function () {
945 it('Should delete a remote thread by the origin server', async function () { 912 it('Should delete a remote thread by the origin server', async function () {
946 this.timeout(5000) 913 this.timeout(5000)
947 914
948 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) 915 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
949 const threadId = res.body.data.find(c => c.text === 'my super second comment').id 916 const commentId = data.find(c => c.text === 'my super second comment').id
950 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 917 await servers[0].comments.delete({ videoId: videoUUID, commentId })
951 918
952 await waitJobs(servers) 919 await waitJobs(servers)
953 }) 920 })
954 921
955 it('Should have the threads marked as deleted on other servers too', async function () { 922 it('Should have the threads marked as deleted on other servers too', async function () {
956 for (const server of servers) { 923 for (const server of servers) {
957 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 924 const body = await server.comments.listThreads({ videoId: videoUUID })
958 925
959 expect(res.body.total).to.equal(2) 926 expect(body.total).to.equal(2)
960 expect(res.body.data).to.have.lengthOf(2) 927 expect(body.data).to.have.lengthOf(2)
961 928
962 { 929 {
963 const comment: VideoComment = res.body.data[0] 930 const comment = body.data[0]
964 expect(comment.text).to.equal('') 931 expect(comment.text).to.equal('')
965 expect(comment.isDeleted).to.be.true 932 expect(comment.isDeleted).to.be.true
966 expect(comment.createdAt).to.not.be.null 933 expect(comment.createdAt).to.not.be.null
@@ -970,7 +937,7 @@ describe('Test multiple servers', function () {
970 } 937 }
971 938
972 { 939 {
973 const comment: VideoComment = res.body.data[1] 940 const comment = body.data[1]
974 expect(comment.text).to.equal('') 941 expect(comment.text).to.equal('')
975 expect(comment.isDeleted).to.be.true 942 expect(comment.isDeleted).to.be.true
976 expect(comment.createdAt).to.not.be.null 943 expect(comment.createdAt).to.not.be.null
@@ -989,17 +956,17 @@ describe('Test multiple servers', function () {
989 downloadEnabled: false 956 downloadEnabled: false
990 } 957 }
991 958
992 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) 959 await servers[0].videos.update({ id: videoUUID, attributes })
993 960
994 await waitJobs(servers) 961 await waitJobs(servers)
995 962
996 for (const server of servers) { 963 for (const server of servers) {
997 const res = await getVideo(server.url, videoUUID) 964 const video = await server.videos.get({ id: videoUUID })
998 expect(res.body.commentsEnabled).to.be.false 965 expect(video.commentsEnabled).to.be.false
999 expect(res.body.downloadEnabled).to.be.false 966 expect(video.downloadEnabled).to.be.false
1000 967
1001 const text = 'my super forbidden comment' 968 const text = 'my super forbidden comment'
1002 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, HttpStatusCode.CONFLICT_409) 969 await server.comments.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
1003 } 970 }
1004 }) 971 })
1005 }) 972 })
@@ -1024,8 +991,8 @@ describe('Test multiple servers', function () {
1024 await waitJobs(servers) 991 await waitJobs(servers)
1025 992
1026 for (const server of servers) { 993 for (const server of servers) {
1027 const res = await getVideosList(server.url) 994 const { data } = await server.videos.list()
1028 const video = res.body.data.find(v => v.name === 'minimum parameters') 995 const video = data.find(v => v.name === 'minimum parameters')
1029 996
1030 const isLocal = server.url === 'http://localhost:' + servers[1].port 997 const isLocal = server.url === 'http://localhost:' + servers[1].port
1031 const checkAttributes = { 998 const checkAttributes = {
@@ -1072,7 +1039,7 @@ describe('Test multiple servers', function () {
1072 } 1039 }
1073 ] 1040 ]
1074 } 1041 }
1075 await completeVideoCheck(server.url, video, checkAttributes) 1042 await completeVideoCheck(server, video, checkAttributes)
1076 } 1043 }
1077 }) 1044 })
1078 }) 1045 })
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index 4fc3317df..13e47c85e 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -4,22 +4,15 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { pathExists, readdir, stat } from 'fs-extra' 5import { pathExists, readdir, stat } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { HttpStatusCode } from '@shared/core-utils'
8import { 7import {
9 buildAbsoluteFixturePath, 8 buildAbsoluteFixturePath,
10 buildServerDirectory,
11 cleanupTests, 9 cleanupTests,
12 flushAndRunServer, 10 createSingleServer,
13 getMyUserInformation, 11 PeerTubeServer,
14 prepareResumableUpload,
15 sendDebugCommand,
16 sendResumableChunks,
17 ServerInfo,
18 setAccessTokensToServers, 12 setAccessTokensToServers,
19 setDefaultVideoChannel, 13 setDefaultVideoChannel
20 updateUser
21} from '@shared/extra-utils' 14} from '@shared/extra-utils'
22import { MyUser, VideoPrivacy } from '@shared/models' 15import { HttpStatusCode, VideoPrivacy } from '@shared/models'
23 16
24const expect = chai.expect 17const expect = chai.expect
25 18
@@ -27,7 +20,7 @@ const expect = chai.expect
27 20
28describe('Test resumable upload', function () { 21describe('Test resumable upload', function () {
29 const defaultFixture = 'video_short.mp4' 22 const defaultFixture = 'video_short.mp4'
30 let server: ServerInfo 23 let server: PeerTubeServer
31 let rootId: number 24 let rootId: number
32 25
33 async function buildSize (fixture: string, size?: number) { 26 async function buildSize (fixture: string, size?: number) {
@@ -42,14 +35,14 @@ describe('Test resumable upload', function () {
42 35
43 const attributes = { 36 const attributes = {
44 name: 'video', 37 name: 'video',
45 channelId: server.videoChannel.id, 38 channelId: server.store.channel.id,
46 privacy: VideoPrivacy.PUBLIC, 39 privacy: VideoPrivacy.PUBLIC,
47 fixture: defaultFixture 40 fixture: defaultFixture
48 } 41 }
49 42
50 const mimetype = 'video/mp4' 43 const mimetype = 'video/mp4'
51 44
52 const res = await prepareResumableUpload({ url: server.url, token: server.accessToken, attributes, size, mimetype }) 45 const res = await server.videos.prepareResumableUpload({ attributes, size, mimetype })
53 46
54 return res.header['location'].split('?')[1] 47 return res.header['location'].split('?')[1]
55 } 48 }
@@ -67,15 +60,13 @@ describe('Test resumable upload', function () {
67 const size = await buildSize(defaultFixture, options.size) 60 const size = await buildSize(defaultFixture, options.size)
68 const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture) 61 const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture)
69 62
70 return sendResumableChunks({ 63 return server.videos.sendResumableChunks({
71 url: server.url,
72 token: server.accessToken,
73 pathUploadId, 64 pathUploadId,
74 videoFilePath: absoluteFilePath, 65 videoFilePath: absoluteFilePath,
75 size, 66 size,
76 contentLength, 67 contentLength,
77 contentRangeBuilder, 68 contentRangeBuilder,
78 specialStatus: expectedStatus 69 expectedStatus
79 }) 70 })
80 } 71 }
81 72
@@ -83,7 +74,7 @@ describe('Test resumable upload', function () {
83 const uploadId = uploadIdArg.replace(/^upload_id=/, '') 74 const uploadId = uploadIdArg.replace(/^upload_id=/, '')
84 75
85 const subPath = join('tmp', 'resumable-uploads', uploadId) 76 const subPath = join('tmp', 'resumable-uploads', uploadId)
86 const filePath = buildServerDirectory(server, subPath) 77 const filePath = server.servers.buildDirectory(subPath)
87 const exists = await pathExists(filePath) 78 const exists = await pathExists(filePath)
88 79
89 if (expectedSize === null) { 80 if (expectedSize === null) {
@@ -98,7 +89,7 @@ describe('Test resumable upload', function () {
98 89
99 async function countResumableUploads () { 90 async function countResumableUploads () {
100 const subPath = join('tmp', 'resumable-uploads') 91 const subPath = join('tmp', 'resumable-uploads')
101 const filePath = buildServerDirectory(server, subPath) 92 const filePath = server.servers.buildDirectory(subPath)
102 93
103 const files = await readdir(filePath) 94 const files = await readdir(filePath)
104 return files.length 95 return files.length
@@ -107,19 +98,14 @@ describe('Test resumable upload', function () {
107 before(async function () { 98 before(async function () {
108 this.timeout(30000) 99 this.timeout(30000)
109 100
110 server = await flushAndRunServer(1) 101 server = await createSingleServer(1)
111 await setAccessTokensToServers([ server ]) 102 await setAccessTokensToServers([ server ])
112 await setDefaultVideoChannel([ server ]) 103 await setDefaultVideoChannel([ server ])
113 104
114 const res = await getMyUserInformation(server.url, server.accessToken) 105 const body = await server.users.getMyInfo()
115 rootId = (res.body as MyUser).id 106 rootId = body.id
116 107
117 await updateUser({ 108 await server.users.update({ userId: rootId, videoQuota: 10_000_000 })
118 url: server.url,
119 userId: rootId,
120 accessToken: server.accessToken,
121 videoQuota: 10_000_000
122 })
123 }) 109 })
124 110
125 describe('Directory cleaning', function () { 111 describe('Directory cleaning', function () {
@@ -138,13 +124,13 @@ describe('Test resumable upload', function () {
138 }) 124 })
139 125
140 it('Should not delete recent uploads', async function () { 126 it('Should not delete recent uploads', async function () {
141 await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) 127 await server.debug.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } })
142 128
143 expect(await countResumableUploads()).to.equal(2) 129 expect(await countResumableUploads()).to.equal(2)
144 }) 130 })
145 131
146 it('Should delete old uploads', async function () { 132 it('Should delete old uploads', async function () {
147 await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) 133 await server.debug.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } })
148 134
149 expect(await countResumableUploads()).to.equal(0) 135 expect(await countResumableUploads()).to.equal(0)
150 }) 136 })
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index 1058a1e9c..c0535be09 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -2,43 +2,26 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { keyBy } from 'lodash'
6
7import { 5import {
8 checkVideoFilesWereRemoved, 6 checkVideoFilesWereRemoved,
9 cleanupTests, 7 cleanupTests,
10 completeVideoCheck, 8 completeVideoCheck,
11 flushAndRunServer, 9 createSingleServer,
12 getVideo, 10 PeerTubeServer,
13 getVideoCategories,
14 getVideoLanguages,
15 getVideoLicences,
16 getVideoPrivacies,
17 getVideosList,
18 getVideosListPagination,
19 getVideosListSort,
20 getVideosWithFilters,
21 rateVideo,
22 removeVideo,
23 ServerInfo,
24 setAccessTokensToServers, 11 setAccessTokensToServers,
25 testImage, 12 testImage,
26 updateVideo,
27 uploadVideo,
28 viewVideo,
29 wait 13 wait
30} from '../../../../shared/extra-utils' 14} from '@shared/extra-utils'
31import { VideoPrivacy } from '../../../../shared/models/videos' 15import { Video, VideoPrivacy } from '@shared/models'
32import { HttpStatusCode } from '@shared/core-utils'
33 16
34const expect = chai.expect 17const expect = chai.expect
35 18
36describe('Test a single server', function () { 19describe('Test a single server', function () {
37 20
38 function runSuite (mode: 'legacy' | 'resumable') { 21 function runSuite (mode: 'legacy' | 'resumable') {
39 let server: ServerInfo = null 22 let server: PeerTubeServer = null
40 let videoId = -1 23 let videoId: number | string
41 let videoId2 = -1 24 let videoId2: string
42 let videoUUID = '' 25 let videoUUID = ''
43 let videosListBase: any[] = null 26 let videosListBase: any[] = null
44 27
@@ -111,134 +94,122 @@ describe('Test a single server', function () {
111 before(async function () { 94 before(async function () {
112 this.timeout(30000) 95 this.timeout(30000)
113 96
114 server = await flushAndRunServer(1) 97 server = await createSingleServer(1)
115 98
116 await setAccessTokensToServers([ server ]) 99 await setAccessTokensToServers([ server ])
117 }) 100 })
118 101
119 it('Should list video categories', async function () { 102 it('Should list video categories', async function () {
120 const res = await getVideoCategories(server.url) 103 const categories = await server.videos.getCategories()
121
122 const categories = res.body
123 expect(Object.keys(categories)).to.have.length.above(10) 104 expect(Object.keys(categories)).to.have.length.above(10)
124 105
125 expect(categories[11]).to.equal('News & Politics') 106 expect(categories[11]).to.equal('News & Politics')
126 }) 107 })
127 108
128 it('Should list video licences', async function () { 109 it('Should list video licences', async function () {
129 const res = await getVideoLicences(server.url) 110 const licences = await server.videos.getLicences()
130
131 const licences = res.body
132 expect(Object.keys(licences)).to.have.length.above(5) 111 expect(Object.keys(licences)).to.have.length.above(5)
133 112
134 expect(licences[3]).to.equal('Attribution - No Derivatives') 113 expect(licences[3]).to.equal('Attribution - No Derivatives')
135 }) 114 })
136 115
137 it('Should list video languages', async function () { 116 it('Should list video languages', async function () {
138 const res = await getVideoLanguages(server.url) 117 const languages = await server.videos.getLanguages()
139
140 const languages = res.body
141 expect(Object.keys(languages)).to.have.length.above(5) 118 expect(Object.keys(languages)).to.have.length.above(5)
142 119
143 expect(languages['ru']).to.equal('Russian') 120 expect(languages['ru']).to.equal('Russian')
144 }) 121 })
145 122
146 it('Should list video privacies', async function () { 123 it('Should list video privacies', async function () {
147 const res = await getVideoPrivacies(server.url) 124 const privacies = await server.videos.getPrivacies()
148
149 const privacies = res.body
150 expect(Object.keys(privacies)).to.have.length.at.least(3) 125 expect(Object.keys(privacies)).to.have.length.at.least(3)
151 126
152 expect(privacies[3]).to.equal('Private') 127 expect(privacies[3]).to.equal('Private')
153 }) 128 })
154 129
155 it('Should not have videos', async function () { 130 it('Should not have videos', async function () {
156 const res = await getVideosList(server.url) 131 const { data, total } = await server.videos.list()
157 132
158 expect(res.body.total).to.equal(0) 133 expect(total).to.equal(0)
159 expect(res.body.data).to.be.an('array') 134 expect(data).to.be.an('array')
160 expect(res.body.data.length).to.equal(0) 135 expect(data.length).to.equal(0)
161 }) 136 })
162 137
163 it('Should upload the video', async function () { 138 it('Should upload the video', async function () {
164 this.timeout(10000) 139 this.timeout(10000)
165 140
166 const videoAttributes = { 141 const attributes = {
167 name: 'my super name', 142 name: 'my super name',
168 category: 2, 143 category: 2,
169 nsfw: true, 144 nsfw: true,
170 licence: 6, 145 licence: 6,
171 tags: [ 'tag1', 'tag2', 'tag3' ] 146 tags: [ 'tag1', 'tag2', 'tag3' ]
172 } 147 }
173 const res = await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) 148 const video = await server.videos.upload({ attributes, mode })
174 expect(res.body.video).to.not.be.undefined 149 expect(video).to.not.be.undefined
175 expect(res.body.video.id).to.equal(1) 150 expect(video.id).to.equal(1)
176 expect(res.body.video.uuid).to.have.length.above(5) 151 expect(video.uuid).to.have.length.above(5)
177 152
178 videoId = res.body.video.id 153 videoId = video.id
179 videoUUID = res.body.video.uuid 154 videoUUID = video.uuid
180 }) 155 })
181 156
182 it('Should get and seed the uploaded video', async function () { 157 it('Should get and seed the uploaded video', async function () {
183 this.timeout(5000) 158 this.timeout(5000)
184 159
185 const res = await getVideosList(server.url) 160 const { data, total } = await server.videos.list()
186 161
187 expect(res.body.total).to.equal(1) 162 expect(total).to.equal(1)
188 expect(res.body.data).to.be.an('array') 163 expect(data).to.be.an('array')
189 expect(res.body.data.length).to.equal(1) 164 expect(data.length).to.equal(1)
190 165
191 const video = res.body.data[0] 166 const video = data[0]
192 await completeVideoCheck(server.url, video, getCheckAttributes()) 167 await completeVideoCheck(server, video, getCheckAttributes())
193 }) 168 })
194 169
195 it('Should get the video by UUID', async function () { 170 it('Should get the video by UUID', async function () {
196 this.timeout(5000) 171 this.timeout(5000)
197 172
198 const res = await getVideo(server.url, videoUUID) 173 const video = await server.videos.get({ id: videoUUID })
199 174 await completeVideoCheck(server, video, getCheckAttributes())
200 const video = res.body
201 await completeVideoCheck(server.url, video, getCheckAttributes())
202 }) 175 })
203 176
204 it('Should have the views updated', async function () { 177 it('Should have the views updated', async function () {
205 this.timeout(20000) 178 this.timeout(20000)
206 179
207 await viewVideo(server.url, videoId) 180 await server.videos.view({ id: videoId })
208 await viewVideo(server.url, videoId) 181 await server.videos.view({ id: videoId })
209 await viewVideo(server.url, videoId) 182 await server.videos.view({ id: videoId })
210 183
211 await wait(1500) 184 await wait(1500)
212 185
213 await viewVideo(server.url, videoId) 186 await server.videos.view({ id: videoId })
214 await viewVideo(server.url, videoId) 187 await server.videos.view({ id: videoId })
215 188
216 await wait(1500) 189 await wait(1500)
217 190
218 await viewVideo(server.url, videoId) 191 await server.videos.view({ id: videoId })
219 await viewVideo(server.url, videoId) 192 await server.videos.view({ id: videoId })
220 193
221 // Wait the repeatable job 194 // Wait the repeatable job
222 await wait(8000) 195 await wait(8000)
223 196
224 const res = await getVideo(server.url, videoId) 197 const video = await server.videos.get({ id: videoId })
225
226 const video = res.body
227 expect(video.views).to.equal(3) 198 expect(video.views).to.equal(3)
228 }) 199 })
229 200
230 it('Should remove the video', async function () { 201 it('Should remove the video', async function () {
231 await removeVideo(server.url, server.accessToken, videoId) 202 await server.videos.remove({ id: videoId })
232 203
233 await checkVideoFilesWereRemoved(videoUUID, 1) 204 await checkVideoFilesWereRemoved(videoUUID, server)
234 }) 205 })
235 206
236 it('Should not have videos', async function () { 207 it('Should not have videos', async function () {
237 const res = await getVideosList(server.url) 208 const { total, data } = await server.videos.list()
238 209
239 expect(res.body.total).to.equal(0) 210 expect(total).to.equal(0)
240 expect(res.body.data).to.be.an('array') 211 expect(data).to.be.an('array')
241 expect(res.body.data).to.have.lengthOf(0) 212 expect(data).to.have.lengthOf(0)
242 }) 213 })
243 214
244 it('Should upload 6 videos', async function () { 215 it('Should upload 6 videos', async function () {
@@ -250,7 +221,7 @@ describe('Test a single server', function () {
250 ]) 221 ])
251 222
252 for (const video of videos) { 223 for (const video of videos) {
253 const videoAttributes = { 224 const attributes = {
254 name: video + ' name', 225 name: video + ' name',
255 description: video + ' description', 226 description: video + ' description',
256 category: 2, 227 category: 2,
@@ -261,19 +232,20 @@ describe('Test a single server', function () {
261 fixture: video 232 fixture: video
262 } 233 }
263 234
264 await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) 235 await server.videos.upload({ attributes, mode })
265 } 236 }
266 }) 237 })
267 238
268 it('Should have the correct durations', async function () { 239 it('Should have the correct durations', async function () {
269 const res = await getVideosList(server.url) 240 const { total, data } = await server.videos.list()
241
242 expect(total).to.equal(6)
243 expect(data).to.be.an('array')
244 expect(data).to.have.lengthOf(6)
270 245
271 expect(res.body.total).to.equal(6) 246 const videosByName: { [ name: string ]: Video } = {}
272 const videos = res.body.data 247 data.forEach(v => { videosByName[v.name] = v })
273 expect(videos).to.be.an('array')
274 expect(videos).to.have.lengthOf(6)
275 248
276 const videosByName = keyBy<{ duration: number }>(videos, 'name')
277 expect(videosByName['video_short.mp4 name'].duration).to.equal(5) 249 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
278 expect(videosByName['video_short.ogv name'].duration).to.equal(5) 250 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
279 expect(videosByName['video_short.webm name'].duration).to.equal(5) 251 expect(videosByName['video_short.webm name'].duration).to.equal(5)
@@ -283,96 +255,87 @@ describe('Test a single server', function () {
283 }) 255 })
284 256
285 it('Should have the correct thumbnails', async function () { 257 it('Should have the correct thumbnails', async function () {
286 const res = await getVideosList(server.url) 258 const { data } = await server.videos.list()
287 259
288 const videos = res.body.data
289 // For the next test 260 // For the next test
290 videosListBase = videos 261 videosListBase = data
291 262
292 for (const video of videos) { 263 for (const video of data) {
293 const videoName = video.name.replace(' name', '') 264 const videoName = video.name.replace(' name', '')
294 await testImage(server.url, videoName, video.thumbnailPath) 265 await testImage(server.url, videoName, video.thumbnailPath)
295 } 266 }
296 }) 267 })
297 268
298 it('Should list only the two first videos', async function () { 269 it('Should list only the two first videos', async function () {
299 const res = await getVideosListPagination(server.url, 0, 2, 'name') 270 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' })
300 271
301 const videos = res.body.data 272 expect(total).to.equal(6)
302 expect(res.body.total).to.equal(6) 273 expect(data.length).to.equal(2)
303 expect(videos.length).to.equal(2) 274 expect(data[0].name).to.equal(videosListBase[0].name)
304 expect(videos[0].name).to.equal(videosListBase[0].name) 275 expect(data[1].name).to.equal(videosListBase[1].name)
305 expect(videos[1].name).to.equal(videosListBase[1].name)
306 }) 276 })
307 277
308 it('Should list only the next three videos', async function () { 278 it('Should list only the next three videos', async function () {
309 const res = await getVideosListPagination(server.url, 2, 3, 'name') 279 const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' })
310 280
311 const videos = res.body.data 281 expect(total).to.equal(6)
312 expect(res.body.total).to.equal(6) 282 expect(data.length).to.equal(3)
313 expect(videos.length).to.equal(3) 283 expect(data[0].name).to.equal(videosListBase[2].name)
314 expect(videos[0].name).to.equal(videosListBase[2].name) 284 expect(data[1].name).to.equal(videosListBase[3].name)
315 expect(videos[1].name).to.equal(videosListBase[3].name) 285 expect(data[2].name).to.equal(videosListBase[4].name)
316 expect(videos[2].name).to.equal(videosListBase[4].name)
317 }) 286 })
318 287
319 it('Should list the last video', async function () { 288 it('Should list the last video', async function () {
320 const res = await getVideosListPagination(server.url, 5, 6, 'name') 289 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' })
321 290
322 const videos = res.body.data 291 expect(total).to.equal(6)
323 expect(res.body.total).to.equal(6) 292 expect(data.length).to.equal(1)
324 expect(videos.length).to.equal(1) 293 expect(data[0].name).to.equal(videosListBase[5].name)
325 expect(videos[0].name).to.equal(videosListBase[5].name)
326 }) 294 })
327 295
328 it('Should not have the total field', async function () { 296 it('Should not have the total field', async function () {
329 const res = await getVideosListPagination(server.url, 5, 6, 'name', true) 297 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true })
330 298
331 const videos = res.body.data 299 expect(total).to.not.exist
332 expect(res.body.total).to.not.exist 300 expect(data.length).to.equal(1)
333 expect(videos.length).to.equal(1) 301 expect(data[0].name).to.equal(videosListBase[5].name)
334 expect(videos[0].name).to.equal(videosListBase[5].name)
335 }) 302 })
336 303
337 it('Should list and sort by name in descending order', async function () { 304 it('Should list and sort by name in descending order', async function () {
338 const res = await getVideosListSort(server.url, '-name') 305 const { total, data } = await server.videos.list({ sort: '-name' })
339 306
340 const videos = res.body.data 307 expect(total).to.equal(6)
341 expect(res.body.total).to.equal(6) 308 expect(data.length).to.equal(6)
342 expect(videos.length).to.equal(6) 309 expect(data[0].name).to.equal('video_short.webm name')
343 expect(videos[0].name).to.equal('video_short.webm name') 310 expect(data[1].name).to.equal('video_short.ogv name')
344 expect(videos[1].name).to.equal('video_short.ogv name') 311 expect(data[2].name).to.equal('video_short.mp4 name')
345 expect(videos[2].name).to.equal('video_short.mp4 name') 312 expect(data[3].name).to.equal('video_short3.webm name')
346 expect(videos[3].name).to.equal('video_short3.webm name') 313 expect(data[4].name).to.equal('video_short2.webm name')
347 expect(videos[4].name).to.equal('video_short2.webm name') 314 expect(data[5].name).to.equal('video_short1.webm name')
348 expect(videos[5].name).to.equal('video_short1.webm name')
349 315
350 videoId = videos[3].uuid 316 videoId = data[3].uuid
351 videoId2 = videos[5].uuid 317 videoId2 = data[5].uuid
352 }) 318 })
353 319
354 it('Should list and sort by trending in descending order', async function () { 320 it('Should list and sort by trending in descending order', async function () {
355 const res = await getVideosListPagination(server.url, 0, 2, '-trending') 321 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' })
356 322
357 const videos = res.body.data 323 expect(total).to.equal(6)
358 expect(res.body.total).to.equal(6) 324 expect(data.length).to.equal(2)
359 expect(videos.length).to.equal(2)
360 }) 325 })
361 326
362 it('Should list and sort by hotness in descending order', async function () { 327 it('Should list and sort by hotness in descending order', async function () {
363 const res = await getVideosListPagination(server.url, 0, 2, '-hot') 328 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' })
364 329
365 const videos = res.body.data 330 expect(total).to.equal(6)
366 expect(res.body.total).to.equal(6) 331 expect(data.length).to.equal(2)
367 expect(videos.length).to.equal(2)
368 }) 332 })
369 333
370 it('Should list and sort by best in descending order', async function () { 334 it('Should list and sort by best in descending order', async function () {
371 const res = await getVideosListPagination(server.url, 0, 2, '-best') 335 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' })
372 336
373 const videos = res.body.data 337 expect(total).to.equal(6)
374 expect(res.body.total).to.equal(6) 338 expect(data.length).to.equal(2)
375 expect(videos.length).to.equal(2)
376 }) 339 })
377 340
378 it('Should update a video', async function () { 341 it('Should update a video', async function () {
@@ -387,67 +350,66 @@ describe('Test a single server', function () {
387 downloadEnabled: false, 350 downloadEnabled: false,
388 tags: [ 'tagup1', 'tagup2' ] 351 tags: [ 'tagup1', 'tagup2' ]
389 } 352 }
390 await updateVideo(server.url, server.accessToken, videoId, attributes) 353 await server.videos.update({ id: videoId, attributes })
391 }) 354 })
392 355
393 it('Should filter by tags and category', async function () { 356 it('Should filter by tags and category', async function () {
394 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) 357 {
395 expect(res1.body.total).to.equal(1) 358 const { data, total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
396 expect(res1.body.data[0].name).to.equal('my super video updated') 359 expect(total).to.equal(1)
360 expect(data[0].name).to.equal('my super video updated')
361 }
397 362
398 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) 363 {
399 expect(res2.body.total).to.equal(0) 364 const { total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
365 expect(total).to.equal(0)
366 }
400 }) 367 })
401 368
402 it('Should have the video updated', async function () { 369 it('Should have the video updated', async function () {
403 this.timeout(60000) 370 this.timeout(60000)
404 371
405 const res = await getVideo(server.url, videoId) 372 const video = await server.videos.get({ id: videoId })
406 const video = res.body
407 373
408 await completeVideoCheck(server.url, video, updateCheckAttributes()) 374 await completeVideoCheck(server, video, updateCheckAttributes())
409 }) 375 })
410 376
411 it('Should update only the tags of a video', async function () { 377 it('Should update only the tags of a video', async function () {
412 const attributes = { 378 const attributes = {
413 tags: [ 'supertag', 'tag1', 'tag2' ] 379 tags: [ 'supertag', 'tag1', 'tag2' ]
414 } 380 }
415 await updateVideo(server.url, server.accessToken, videoId, attributes) 381 await server.videos.update({ id: videoId, attributes })
416 382
417 const res = await getVideo(server.url, videoId) 383 const video = await server.videos.get({ id: videoId })
418 const video = res.body
419 384
420 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes)) 385 await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes))
421 }) 386 })
422 387
423 it('Should update only the description of a video', async function () { 388 it('Should update only the description of a video', async function () {
424 const attributes = { 389 const attributes = {
425 description: 'hello everybody' 390 description: 'hello everybody'
426 } 391 }
427 await updateVideo(server.url, server.accessToken, videoId, attributes) 392 await server.videos.update({ id: videoId, attributes })
428 393
429 const res = await getVideo(server.url, videoId) 394 const video = await server.videos.get({ id: videoId })
430 const video = res.body
431 395
432 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) 396 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
433 await completeVideoCheck(server.url, video, expectedAttributes) 397 await completeVideoCheck(server, video, expectedAttributes)
434 }) 398 })
435 399
436 it('Should like a video', async function () { 400 it('Should like a video', async function () {
437 await rateVideo(server.url, server.accessToken, videoId, 'like') 401 await server.videos.rate({ id: videoId, rating: 'like' })
438 402
439 const res = await getVideo(server.url, videoId) 403 const video = await server.videos.get({ id: videoId })
440 const video = res.body
441 404
442 expect(video.likes).to.equal(1) 405 expect(video.likes).to.equal(1)
443 expect(video.dislikes).to.equal(0) 406 expect(video.dislikes).to.equal(0)
444 }) 407 })
445 408
446 it('Should dislike the same video', async function () { 409 it('Should dislike the same video', async function () {
447 await rateVideo(server.url, server.accessToken, videoId, 'dislike') 410 await server.videos.rate({ id: videoId, rating: 'dislike' })
448 411
449 const res = await getVideo(server.url, videoId) 412 const video = await server.videos.get({ id: videoId })
450 const video = res.body
451 413
452 expect(video.likes).to.equal(0) 414 expect(video.likes).to.equal(0)
453 expect(video.dislikes).to.equal(1) 415 expect(video.dislikes).to.equal(1)
@@ -457,10 +419,10 @@ describe('Test a single server', function () {
457 { 419 {
458 const now = new Date() 420 const now = new Date()
459 const attributes = { originallyPublishedAt: now.toISOString() } 421 const attributes = { originallyPublishedAt: now.toISOString() }
460 await updateVideo(server.url, server.accessToken, videoId, attributes) 422 await server.videos.update({ id: videoId, attributes })
461 423
462 const res = await getVideosListSort(server.url, '-originallyPublishedAt') 424 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
463 const names = res.body.data.map(v => v.name) 425 const names = data.map(v => v.name)
464 426
465 expect(names[0]).to.equal('my super video updated') 427 expect(names[0]).to.equal('my super video updated')
466 expect(names[1]).to.equal('video_short2.webm name') 428 expect(names[1]).to.equal('video_short2.webm name')
@@ -473,10 +435,10 @@ describe('Test a single server', function () {
473 { 435 {
474 const now = new Date() 436 const now = new Date()
475 const attributes = { originallyPublishedAt: now.toISOString() } 437 const attributes = { originallyPublishedAt: now.toISOString() }
476 await updateVideo(server.url, server.accessToken, videoId2, attributes) 438 await server.videos.update({ id: videoId2, attributes })
477 439
478 const res = await getVideosListSort(server.url, '-originallyPublishedAt') 440 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
479 const names = res.body.data.map(v => v.name) 441 const names = data.map(v => v.name)
480 442
481 expect(names[0]).to.equal('video_short1.webm name') 443 expect(names[0]).to.equal('video_short1.webm name')
482 expect(names[1]).to.equal('my super video updated') 444 expect(names[1]).to.equal('my super video updated')
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index 14ecedfa6..4c8e28adf 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -1,72 +1,61 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 checkVideoFilesWereRemoved, 6 checkVideoFilesWereRemoved,
7 cleanupTests, 7 cleanupTests,
8 createMultipleServers,
8 doubleFollow, 9 doubleFollow,
9 flushAndRunMultipleServers, 10 PeerTubeServer,
10 removeVideo, 11 setAccessTokensToServers,
11 uploadVideo, 12 testCaptionFile,
12 wait 13 wait,
13} from '../../../../shared/extra-utils' 14 waitJobs
14import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' 15} from '@shared/extra-utils'
15import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
16import {
17 createVideoCaption,
18 deleteVideoCaption,
19 listVideoCaptions,
20 testCaptionFile
21} from '../../../../shared/extra-utils/videos/video-captions'
22import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
23 16
24const expect = chai.expect 17const expect = chai.expect
25 18
26describe('Test video captions', function () { 19describe('Test video captions', function () {
27 const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' 20 const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
28 21
29 let servers: ServerInfo[] 22 let servers: PeerTubeServer[]
30 let videoUUID: string 23 let videoUUID: string
31 24
32 before(async function () { 25 before(async function () {
33 this.timeout(60000) 26 this.timeout(60000)
34 27
35 servers = await flushAndRunMultipleServers(2) 28 servers = await createMultipleServers(2)
36 29
37 await setAccessTokensToServers(servers) 30 await setAccessTokensToServers(servers)
38 await doubleFollow(servers[0], servers[1]) 31 await doubleFollow(servers[0], servers[1])
39 32
40 await waitJobs(servers) 33 await waitJobs(servers)
41 34
42 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' }) 35 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video name' } })
43 videoUUID = res.body.video.uuid 36 videoUUID = uuid
44 37
45 await waitJobs(servers) 38 await waitJobs(servers)
46 }) 39 })
47 40
48 it('Should list the captions and return an empty list', async function () { 41 it('Should list the captions and return an empty list', async function () {
49 for (const server of servers) { 42 for (const server of servers) {
50 const res = await listVideoCaptions(server.url, videoUUID) 43 const body = await server.captions.list({ videoId: videoUUID })
51 expect(res.body.total).to.equal(0) 44 expect(body.total).to.equal(0)
52 expect(res.body.data).to.have.lengthOf(0) 45 expect(body.data).to.have.lengthOf(0)
53 } 46 }
54 }) 47 })
55 48
56 it('Should create two new captions', async function () { 49 it('Should create two new captions', async function () {
57 this.timeout(30000) 50 this.timeout(30000)
58 51
59 await createVideoCaption({ 52 await servers[0].captions.add({
60 url: servers[0].url,
61 accessToken: servers[0].accessToken,
62 language: 'ar', 53 language: 'ar',
63 videoId: videoUUID, 54 videoId: videoUUID,
64 fixture: 'subtitle-good1.vtt' 55 fixture: 'subtitle-good1.vtt'
65 }) 56 })
66 57
67 await createVideoCaption({ 58 await servers[0].captions.add({
68 url: servers[0].url,
69 accessToken: servers[0].accessToken,
70 language: 'zh', 59 language: 'zh',
71 videoId: videoUUID, 60 videoId: videoUUID,
72 fixture: 'subtitle-good2.vtt', 61 fixture: 'subtitle-good2.vtt',
@@ -78,17 +67,17 @@ describe('Test video captions', function () {
78 67
79 it('Should list these uploaded captions', async function () { 68 it('Should list these uploaded captions', async function () {
80 for (const server of servers) { 69 for (const server of servers) {
81 const res = await listVideoCaptions(server.url, videoUUID) 70 const body = await server.captions.list({ videoId: videoUUID })
82 expect(res.body.total).to.equal(2) 71 expect(body.total).to.equal(2)
83 expect(res.body.data).to.have.lengthOf(2) 72 expect(body.data).to.have.lengthOf(2)
84 73
85 const caption1: VideoCaption = res.body.data[0] 74 const caption1 = body.data[0]
86 expect(caption1.language.id).to.equal('ar') 75 expect(caption1.language.id).to.equal('ar')
87 expect(caption1.language.label).to.equal('Arabic') 76 expect(caption1.language.label).to.equal('Arabic')
88 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 77 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
89 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') 78 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
90 79
91 const caption2: VideoCaption = res.body.data[1] 80 const caption2 = body.data[1]
92 expect(caption2.language.id).to.equal('zh') 81 expect(caption2.language.id).to.equal('zh')
93 expect(caption2.language.label).to.equal('Chinese') 82 expect(caption2.language.label).to.equal('Chinese')
94 expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) 83 expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$'))
@@ -99,9 +88,7 @@ describe('Test video captions', function () {
99 it('Should replace an existing caption', async function () { 88 it('Should replace an existing caption', async function () {
100 this.timeout(30000) 89 this.timeout(30000)
101 90
102 await createVideoCaption({ 91 await servers[0].captions.add({
103 url: servers[0].url,
104 accessToken: servers[0].accessToken,
105 language: 'ar', 92 language: 'ar',
106 videoId: videoUUID, 93 videoId: videoUUID,
107 fixture: 'subtitle-good2.vtt' 94 fixture: 'subtitle-good2.vtt'
@@ -112,11 +99,11 @@ describe('Test video captions', function () {
112 99
113 it('Should have this caption updated', async function () { 100 it('Should have this caption updated', async function () {
114 for (const server of servers) { 101 for (const server of servers) {
115 const res = await listVideoCaptions(server.url, videoUUID) 102 const body = await server.captions.list({ videoId: videoUUID })
116 expect(res.body.total).to.equal(2) 103 expect(body.total).to.equal(2)
117 expect(res.body.data).to.have.lengthOf(2) 104 expect(body.data).to.have.lengthOf(2)
118 105
119 const caption1: VideoCaption = res.body.data[0] 106 const caption1 = body.data[0]
120 expect(caption1.language.id).to.equal('ar') 107 expect(caption1.language.id).to.equal('ar')
121 expect(caption1.language.label).to.equal('Arabic') 108 expect(caption1.language.label).to.equal('Arabic')
122 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 109 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
@@ -127,9 +114,7 @@ describe('Test video captions', function () {
127 it('Should replace an existing caption with a srt file and convert it', async function () { 114 it('Should replace an existing caption with a srt file and convert it', async function () {
128 this.timeout(30000) 115 this.timeout(30000)
129 116
130 await createVideoCaption({ 117 await servers[0].captions.add({
131 url: servers[0].url,
132 accessToken: servers[0].accessToken,
133 language: 'ar', 118 language: 'ar',
134 videoId: videoUUID, 119 videoId: videoUUID,
135 fixture: 'subtitle-good.srt' 120 fixture: 'subtitle-good.srt'
@@ -143,11 +128,11 @@ describe('Test video captions', function () {
143 128
144 it('Should have this caption updated and converted', async function () { 129 it('Should have this caption updated and converted', async function () {
145 for (const server of servers) { 130 for (const server of servers) {
146 const res = await listVideoCaptions(server.url, videoUUID) 131 const body = await server.captions.list({ videoId: videoUUID })
147 expect(res.body.total).to.equal(2) 132 expect(body.total).to.equal(2)
148 expect(res.body.data).to.have.lengthOf(2) 133 expect(body.data).to.have.lengthOf(2)
149 134
150 const caption1: VideoCaption = res.body.data[0] 135 const caption1 = body.data[0]
151 expect(caption1.language.id).to.equal('ar') 136 expect(caption1.language.id).to.equal('ar')
152 expect(caption1.language.label).to.equal('Arabic') 137 expect(caption1.language.label).to.equal('Arabic')
153 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 138 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
@@ -172,18 +157,18 @@ describe('Test video captions', function () {
172 it('Should remove one caption', async function () { 157 it('Should remove one caption', async function () {
173 this.timeout(30000) 158 this.timeout(30000)
174 159
175 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar') 160 await servers[0].captions.delete({ videoId: videoUUID, language: 'ar' })
176 161
177 await waitJobs(servers) 162 await waitJobs(servers)
178 }) 163 })
179 164
180 it('Should only list the caption that was not deleted', async function () { 165 it('Should only list the caption that was not deleted', async function () {
181 for (const server of servers) { 166 for (const server of servers) {
182 const res = await listVideoCaptions(server.url, videoUUID) 167 const body = await server.captions.list({ videoId: videoUUID })
183 expect(res.body.total).to.equal(1) 168 expect(body.total).to.equal(1)
184 expect(res.body.data).to.have.lengthOf(1) 169 expect(body.data).to.have.lengthOf(1)
185 170
186 const caption: VideoCaption = res.body.data[0] 171 const caption = body.data[0]
187 172
188 expect(caption.language.id).to.equal('zh') 173 expect(caption.language.id).to.equal('zh')
189 expect(caption.language.label).to.equal('Chinese') 174 expect(caption.language.label).to.equal('Chinese')
@@ -193,9 +178,9 @@ describe('Test video captions', function () {
193 }) 178 })
194 179
195 it('Should remove the video, and thus all video captions', async function () { 180 it('Should remove the video, and thus all video captions', async function () {
196 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) 181 await servers[0].videos.remove({ id: videoUUID })
197 182
198 await checkVideoFilesWereRemoved(videoUUID, 1) 183 await checkVideoFilesWereRemoved(videoUUID, servers[0])
199 }) 184 })
200 185
201 after(async function () { 186 after(async function () {
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index a3384851b..6ae6d3004 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -2,234 +2,212 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 5import {
7 acceptChangeOwnership, 6 ChangeOwnershipCommand,
8 changeVideoOwnership,
9 cleanupTests, 7 cleanupTests,
10 createLive, 8 createMultipleServers,
11 createUser, 9 createSingleServer,
12 doubleFollow, 10 doubleFollow,
13 flushAndRunMultipleServers, 11 PeerTubeServer,
14 flushAndRunServer,
15 getMyUserInformation,
16 getVideo,
17 getVideoChangeOwnershipList,
18 getVideosList,
19 refuseChangeOwnership,
20 ServerInfo,
21 setAccessTokensToServers, 12 setAccessTokensToServers,
22 setDefaultVideoChannel, 13 setDefaultVideoChannel,
23 updateCustomSubConfig, 14 waitJobs
24 uploadVideo, 15} from '@shared/extra-utils'
25 userLogin 16import { HttpStatusCode, VideoPrivacy } from '@shared/models'
26} from '../../../../shared/extra-utils'
27import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
28import { User } from '../../../../shared/models/users'
29import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
30 17
31const expect = chai.expect 18const expect = chai.expect
32 19
33describe('Test video change ownership - nominal', function () { 20describe('Test video change ownership - nominal', function () {
34 let servers: ServerInfo[] = [] 21 let servers: PeerTubeServer[] = []
35 const firstUser = { 22
36 username: 'first', 23 const firstUser = 'first'
37 password: 'My great password' 24 const secondUser = 'second'
38 } 25
39 const secondUser = { 26 let firstUserToken = ''
40 username: 'second',
41 password: 'My other password'
42 }
43
44 let firstUserAccessToken = ''
45 let firstUserChannelId: number 27 let firstUserChannelId: number
46 28
47 let secondUserAccessToken = '' 29 let secondUserToken = ''
48 let secondUserChannelId: number 30 let secondUserChannelId: number
49 31
50 let lastRequestChangeOwnershipId = '' 32 let lastRequestId: number
51 33
52 let liveId: number 34 let liveId: number
53 35
36 let command: ChangeOwnershipCommand
37
54 before(async function () { 38 before(async function () {
55 this.timeout(50000) 39 this.timeout(50000)
56 40
57 servers = await flushAndRunMultipleServers(2) 41 servers = await createMultipleServers(2)
58 await setAccessTokensToServers(servers) 42 await setAccessTokensToServers(servers)
59 await setDefaultVideoChannel(servers) 43 await setDefaultVideoChannel(servers)
60 44
61 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 45 await servers[0].config.updateCustomSubConfig({
62 transcoding: { 46 newConfig: {
63 enabled: false 47 transcoding: {
64 }, 48 enabled: false
65 live: { 49 },
66 enabled: true 50 live: {
51 enabled: true
52 }
67 } 53 }
68 }) 54 })
69 55
70 const videoQuota = 42000000 56 firstUserToken = await servers[0].users.generateUserAndToken(firstUser)
71 await createUser({ 57 secondUserToken = await servers[0].users.generateUserAndToken(secondUser)
72 url: servers[0].url,
73 accessToken: servers[0].accessToken,
74 username: firstUser.username,
75 password: firstUser.password,
76 videoQuota: videoQuota
77 })
78 await createUser({
79 url: servers[0].url,
80 accessToken: servers[0].accessToken,
81 username: secondUser.username,
82 password: secondUser.password,
83 videoQuota: videoQuota
84 })
85
86 firstUserAccessToken = await userLogin(servers[0], firstUser)
87 secondUserAccessToken = await userLogin(servers[0], secondUser)
88 58
89 { 59 {
90 const res = await getMyUserInformation(servers[0].url, firstUserAccessToken) 60 const { videoChannels } = await servers[0].users.getMyInfo({ token: firstUserToken })
91 const firstUserInformation: User = res.body 61 firstUserChannelId = videoChannels[0].id
92 firstUserChannelId = firstUserInformation.videoChannels[0].id
93 } 62 }
94 63
95 { 64 {
96 const res = await getMyUserInformation(servers[0].url, secondUserAccessToken) 65 const { videoChannels } = await servers[0].users.getMyInfo({ token: secondUserToken })
97 const secondUserInformation: User = res.body 66 secondUserChannelId = videoChannels[0].id
98 secondUserChannelId = secondUserInformation.videoChannels[0].id
99 } 67 }
100 68
101 { 69 {
102 const videoAttributes = { 70 const attributes = {
103 name: 'my super name', 71 name: 'my super name',
104 description: 'my super description' 72 description: 'my super description'
105 } 73 }
106 const res = await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes) 74 const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes })
107 75
108 const resVideo = await getVideo(servers[0].url, res.body.video.id) 76 servers[0].store.video = await servers[0].videos.get({ id })
109 servers[0].video = resVideo.body
110 } 77 }
111 78
112 { 79 {
113 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } 80 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
114 const res = await createLive(servers[0].url, firstUserAccessToken, attributes) 81 const video = await servers[0].live.create({ token: firstUserToken, fields: attributes })
115 82
116 liveId = res.body.video.id 83 liveId = video.id
117 } 84 }
118 85
86 command = servers[0].changeOwnership
87
119 await doubleFollow(servers[0], servers[1]) 88 await doubleFollow(servers[0], servers[1])
120 }) 89 })
121 90
122 it('Should not have video change ownership', async function () { 91 it('Should not have video change ownership', async function () {
123 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 92 {
93 const body = await command.list({ token: firstUserToken })
124 94
125 expect(resFirstUser.body.total).to.equal(0) 95 expect(body.total).to.equal(0)
126 expect(resFirstUser.body.data).to.be.an('array') 96 expect(body.data).to.be.an('array')
127 expect(resFirstUser.body.data.length).to.equal(0) 97 expect(body.data.length).to.equal(0)
98 }
128 99
129 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 100 {
101 const body = await command.list({ token: secondUserToken })
130 102
131 expect(resSecondUser.body.total).to.equal(0) 103 expect(body.total).to.equal(0)
132 expect(resSecondUser.body.data).to.be.an('array') 104 expect(body.data).to.be.an('array')
133 expect(resSecondUser.body.data.length).to.equal(0) 105 expect(body.data.length).to.equal(0)
106 }
134 }) 107 })
135 108
136 it('Should send a request to change ownership of a video', async function () { 109 it('Should send a request to change ownership of a video', async function () {
137 this.timeout(15000) 110 this.timeout(15000)
138 111
139 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 112 await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser })
140 }) 113 })
141 114
142 it('Should only return a request to change ownership for the second user', async function () { 115 it('Should only return a request to change ownership for the second user', async function () {
143 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 116 {
117 const body = await command.list({ token: firstUserToken })
144 118
145 expect(resFirstUser.body.total).to.equal(0) 119 expect(body.total).to.equal(0)
146 expect(resFirstUser.body.data).to.be.an('array') 120 expect(body.data).to.be.an('array')
147 expect(resFirstUser.body.data.length).to.equal(0) 121 expect(body.data.length).to.equal(0)
122 }
148 123
149 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 124 {
125 const body = await command.list({ token: secondUserToken })
150 126
151 expect(resSecondUser.body.total).to.equal(1) 127 expect(body.total).to.equal(1)
152 expect(resSecondUser.body.data).to.be.an('array') 128 expect(body.data).to.be.an('array')
153 expect(resSecondUser.body.data.length).to.equal(1) 129 expect(body.data.length).to.equal(1)
154 130
155 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 131 lastRequestId = body.data[0].id
132 }
156 }) 133 })
157 134
158 it('Should accept the same change ownership request without crashing', async function () { 135 it('Should accept the same change ownership request without crashing', async function () {
159 this.timeout(10000) 136 this.timeout(10000)
160 137
161 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 138 await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser })
162 }) 139 })
163 140
164 it('Should not create multiple change ownership requests while one is waiting', async function () { 141 it('Should not create multiple change ownership requests while one is waiting', async function () {
165 this.timeout(10000) 142 this.timeout(10000)
166 143
167 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 144 const body = await command.list({ token: secondUserToken })
168 145
169 expect(resSecondUser.body.total).to.equal(1) 146 expect(body.total).to.equal(1)
170 expect(resSecondUser.body.data).to.be.an('array') 147 expect(body.data).to.be.an('array')
171 expect(resSecondUser.body.data.length).to.equal(1) 148 expect(body.data.length).to.equal(1)
172 }) 149 })
173 150
174 it('Should not be possible to refuse the change of ownership from first user', async function () { 151 it('Should not be possible to refuse the change of ownership from first user', async function () {
175 this.timeout(10000) 152 this.timeout(10000)
176 153
177 await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403) 154 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
178 }) 155 })
179 156
180 it('Should be possible to refuse the change of ownership from second user', async function () { 157 it('Should be possible to refuse the change of ownership from second user', async function () {
181 this.timeout(10000) 158 this.timeout(10000)
182 159
183 await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId) 160 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
184 }) 161 })
185 162
186 it('Should send a new request to change ownership of a video', async function () { 163 it('Should send a new request to change ownership of a video', async function () {
187 this.timeout(15000) 164 this.timeout(15000)
188 165
189 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 166 await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser })
190 }) 167 })
191 168
192 it('Should return two requests to change ownership for the second user', async function () { 169 it('Should return two requests to change ownership for the second user', async function () {
193 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 170 {
171 const body = await command.list({ token: firstUserToken })
194 172
195 expect(resFirstUser.body.total).to.equal(0) 173 expect(body.total).to.equal(0)
196 expect(resFirstUser.body.data).to.be.an('array') 174 expect(body.data).to.be.an('array')
197 expect(resFirstUser.body.data.length).to.equal(0) 175 expect(body.data.length).to.equal(0)
176 }
198 177
199 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 178 {
179 const body = await command.list({ token: secondUserToken })
200 180
201 expect(resSecondUser.body.total).to.equal(2) 181 expect(body.total).to.equal(2)
202 expect(resSecondUser.body.data).to.be.an('array') 182 expect(body.data).to.be.an('array')
203 expect(resSecondUser.body.data.length).to.equal(2) 183 expect(body.data.length).to.equal(2)
204 184
205 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 185 lastRequestId = body.data[0].id
186 }
206 }) 187 })
207 188
208 it('Should not be possible to accept the change of ownership from first user', async function () { 189 it('Should not be possible to accept the change of ownership from first user', async function () {
209 this.timeout(10000) 190 this.timeout(10000)
210 191
211 await acceptChangeOwnership( 192 await command.accept({
212 servers[0].url, 193 token: firstUserToken,
213 firstUserAccessToken, 194 ownershipId: lastRequestId,
214 lastRequestChangeOwnershipId, 195 channelId: secondUserChannelId,
215 secondUserChannelId, 196 expectedStatus: HttpStatusCode.FORBIDDEN_403
216 HttpStatusCode.FORBIDDEN_403 197 })
217 )
218 }) 198 })
219 199
220 it('Should be possible to accept the change of ownership from second user', async function () { 200 it('Should be possible to accept the change of ownership from second user', async function () {
221 this.timeout(10000) 201 this.timeout(10000)
222 202
223 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) 203 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
224 204
225 await waitJobs(servers) 205 await waitJobs(servers)
226 }) 206 })
227 207
228 it('Should have the channel of the video updated', async function () { 208 it('Should have the channel of the video updated', async function () {
229 for (const server of servers) { 209 for (const server of servers) {
230 const res = await getVideo(server.url, servers[0].video.uuid) 210 const video = await server.videos.get({ id: servers[0].store.video.uuid })
231
232 const video: VideoDetails = res.body
233 211
234 expect(video.name).to.equal('my super name') 212 expect(video.name).to.equal('my super name')
235 expect(video.channel.displayName).to.equal('Main second channel') 213 expect(video.channel.displayName).to.equal('Main second channel')
@@ -240,27 +218,25 @@ describe('Test video change ownership - nominal', function () {
240 it('Should send a request to change ownership of a live', async function () { 218 it('Should send a request to change ownership of a live', async function () {
241 this.timeout(15000) 219 this.timeout(15000)
242 220
243 await changeVideoOwnership(servers[0].url, firstUserAccessToken, liveId, secondUser.username) 221 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
244 222
245 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 223 const body = await command.list({ token: secondUserToken })
246 224
247 expect(resSecondUser.body.total).to.equal(3) 225 expect(body.total).to.equal(3)
248 expect(resSecondUser.body.data.length).to.equal(3) 226 expect(body.data.length).to.equal(3)
249 227
250 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 228 lastRequestId = body.data[0].id
251 }) 229 })
252 230
253 it('Should accept a live ownership change', async function () { 231 it('Should accept a live ownership change', async function () {
254 this.timeout(20000) 232 this.timeout(20000)
255 233
256 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) 234 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
257 235
258 await waitJobs(servers) 236 await waitJobs(servers)
259 237
260 for (const server of servers) { 238 for (const server of servers) {
261 const res = await getVideo(server.url, servers[0].video.uuid) 239 const video = await server.videos.get({ id: servers[0].store.video.uuid })
262
263 const video: VideoDetails = res.body
264 240
265 expect(video.name).to.equal('my super name') 241 expect(video.name).to.equal('my super name')
266 expect(video.channel.displayName).to.equal('Main second channel') 242 expect(video.channel.displayName).to.equal('Main second channel')
@@ -274,99 +250,79 @@ describe('Test video change ownership - nominal', function () {
274}) 250})
275 251
276describe('Test video change ownership - quota too small', function () { 252describe('Test video change ownership - quota too small', function () {
277 let server: ServerInfo 253 let server: PeerTubeServer
278 const firstUser = { 254 const firstUser = 'first'
279 username: 'first', 255 const secondUser = 'second'
280 password: 'My great password' 256
281 } 257 let firstUserToken = ''
282 const secondUser = { 258 let secondUserToken = ''
283 username: 'second', 259 let lastRequestId: number
284 password: 'My other password'
285 }
286 let firstUserAccessToken = ''
287 let secondUserAccessToken = ''
288 let lastRequestChangeOwnershipId = ''
289 260
290 before(async function () { 261 before(async function () {
291 this.timeout(50000) 262 this.timeout(50000)
292 263
293 // Run one server 264 // Run one server
294 server = await flushAndRunServer(1) 265 server = await createSingleServer(1)
295 await setAccessTokensToServers([ server ]) 266 await setAccessTokensToServers([ server ])
296 267
297 const videoQuota = 42000000 268 await server.users.create({ username: secondUser, videoQuota: 10 })
298 const limitedVideoQuota = 10
299 await createUser({
300 url: server.url,
301 accessToken: server.accessToken,
302 username: firstUser.username,
303 password: firstUser.password,
304 videoQuota: videoQuota
305 })
306 await createUser({
307 url: server.url,
308 accessToken: server.accessToken,
309 username: secondUser.username,
310 password: secondUser.password,
311 videoQuota: limitedVideoQuota
312 })
313 269
314 firstUserAccessToken = await userLogin(server, firstUser) 270 firstUserToken = await server.users.generateUserAndToken(firstUser)
315 secondUserAccessToken = await userLogin(server, secondUser) 271 secondUserToken = await server.login.getAccessToken(secondUser)
316 272
317 // Upload some videos on the server 273 // Upload some videos on the server
318 const video1Attributes = { 274 const attributes = {
319 name: 'my super name', 275 name: 'my super name',
320 description: 'my super description' 276 description: 'my super description'
321 } 277 }
322 await uploadVideo(server.url, firstUserAccessToken, video1Attributes) 278 await server.videos.upload({ token: firstUserToken, attributes })
323 279
324 await waitJobs(server) 280 await waitJobs(server)
325 281
326 const res = await getVideosList(server.url) 282 const { data } = await server.videos.list()
327 const videos = res.body.data 283 expect(data.length).to.equal(1)
328
329 expect(videos.length).to.equal(1)
330 284
331 server.video = videos.find(video => video.name === 'my super name') 285 server.store.video = data.find(video => video.name === 'my super name')
332 }) 286 })
333 287
334 it('Should send a request to change ownership of a video', async function () { 288 it('Should send a request to change ownership of a video', async function () {
335 this.timeout(15000) 289 this.timeout(15000)
336 290
337 await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) 291 await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.video.id, username: secondUser })
338 }) 292 })
339 293
340 it('Should only return a request to change ownership for the second user', async function () { 294 it('Should only return a request to change ownership for the second user', async function () {
341 const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) 295 {
296 const body = await server.changeOwnership.list({ token: firstUserToken })
342 297
343 expect(resFirstUser.body.total).to.equal(0) 298 expect(body.total).to.equal(0)
344 expect(resFirstUser.body.data).to.be.an('array') 299 expect(body.data).to.be.an('array')
345 expect(resFirstUser.body.data.length).to.equal(0) 300 expect(body.data.length).to.equal(0)
301 }
346 302
347 const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) 303 {
304 const body = await server.changeOwnership.list({ token: secondUserToken })
348 305
349 expect(resSecondUser.body.total).to.equal(1) 306 expect(body.total).to.equal(1)
350 expect(resSecondUser.body.data).to.be.an('array') 307 expect(body.data).to.be.an('array')
351 expect(resSecondUser.body.data.length).to.equal(1) 308 expect(body.data.length).to.equal(1)
352 309
353 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 310 lastRequestId = body.data[0].id
311 }
354 }) 312 })
355 313
356 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { 314 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
357 this.timeout(10000) 315 this.timeout(10000)
358 316
359 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) 317 const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken })
360 const secondUserInformation: User = secondUserInformationResponse.body 318 const channelId = videoChannels[0].id
361 const channelId = secondUserInformation.videoChannels[0].id
362 319
363 await acceptChangeOwnership( 320 await server.changeOwnership.accept({
364 server.url, 321 token: secondUserToken,
365 secondUserAccessToken, 322 ownershipId: lastRequestId,
366 lastRequestChangeOwnershipId,
367 channelId, 323 channelId,
368 HttpStatusCode.PAYLOAD_TOO_LARGE_413 324 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
369 ) 325 })
370 }) 326 })
371 327
372 after(async function () { 328 after(async function () {
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
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index b6b002307..61ee54540 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -2,80 +2,62 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '@shared/models'
6import { cleanupTests, testImage } from '../../../../shared/extra-utils'
7import { 5import {
8 createUser, 6 cleanupTests,
7 CommentsCommand,
8 createSingleServer,
9 dateIsValid, 9 dateIsValid,
10 flushAndRunServer, 10 PeerTubeServer,
11 getAccessToken,
12 ServerInfo,
13 setAccessTokensToServers, 11 setAccessTokensToServers,
14 updateMyAvatar, 12 testImage
15 uploadVideo 13} from '@shared/extra-utils'
16} from '../../../../shared/extra-utils/index'
17import {
18 addVideoCommentReply,
19 addVideoCommentThread,
20 deleteVideoComment,
21 getAdminVideoComments,
22 getVideoCommentThreads,
23 getVideoThreadComments
24} from '../../../../shared/extra-utils/videos/video-comments'
25 14
26const expect = chai.expect 15const expect = chai.expect
27 16
28describe('Test video comments', function () { 17describe('Test video comments', function () {
29 let server: ServerInfo 18 let server: PeerTubeServer
30 let videoId 19 let videoId: number
31 let videoUUID 20 let videoUUID: string
32 let threadId 21 let threadId: number
33 let replyToDeleteId: number 22 let replyToDeleteId: number
34 23
35 let userAccessTokenServer1: string 24 let userAccessTokenServer1: string
36 25
26 let command: CommentsCommand
27
37 before(async function () { 28 before(async function () {
38 this.timeout(30000) 29 this.timeout(30000)
39 30
40 server = await flushAndRunServer(1) 31 server = await createSingleServer(1)
41 32
42 await setAccessTokensToServers([ server ]) 33 await setAccessTokensToServers([ server ])
43 34
44 const res = await uploadVideo(server.url, server.accessToken, {}) 35 const { id, uuid } = await server.videos.upload()
45 videoUUID = res.body.video.uuid 36 videoUUID = uuid
46 videoId = res.body.video.id 37 videoId = id
47 38
48 await updateMyAvatar({ 39 await server.users.updateMyAvatar({ fixture: 'avatar.png' })
49 url: server.url,
50 accessToken: server.accessToken,
51 fixture: 'avatar.png'
52 })
53 40
54 await createUser({ 41 userAccessTokenServer1 = await server.users.generateUserAndToken('user1')
55 url: server.url, 42
56 accessToken: server.accessToken, 43 command = server.comments
57 username: 'user1',
58 password: 'password'
59 })
60 userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password')
61 }) 44 })
62 45
63 describe('User comments', function () { 46 describe('User comments', function () {
64 47
65 it('Should not have threads on this video', async function () { 48 it('Should not have threads on this video', async function () {
66 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 49 const body = await command.listThreads({ videoId: videoUUID })
67 50
68 expect(res.body.total).to.equal(0) 51 expect(body.total).to.equal(0)
69 expect(res.body.totalNotDeletedComments).to.equal(0) 52 expect(body.totalNotDeletedComments).to.equal(0)
70 expect(res.body.data).to.be.an('array') 53 expect(body.data).to.be.an('array')
71 expect(res.body.data).to.have.lengthOf(0) 54 expect(body.data).to.have.lengthOf(0)
72 }) 55 })
73 56
74 it('Should create a thread in this video', async function () { 57 it('Should create a thread in this video', async function () {
75 const text = 'my super first comment' 58 const text = 'my super first comment'
76 59
77 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 60 const comment = await command.createThread({ videoId: videoUUID, text })
78 const comment = res.body.comment
79 61
80 expect(comment.inReplyToCommentId).to.be.null 62 expect(comment.inReplyToCommentId).to.be.null
81 expect(comment.text).equal('my super first comment') 63 expect(comment.text).equal('my super first comment')
@@ -91,14 +73,14 @@ describe('Test video comments', function () {
91 }) 73 })
92 74
93 it('Should list threads of this video', async function () { 75 it('Should list threads of this video', async function () {
94 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 76 const body = await command.listThreads({ videoId: videoUUID })
95 77
96 expect(res.body.total).to.equal(1) 78 expect(body.total).to.equal(1)
97 expect(res.body.totalNotDeletedComments).to.equal(1) 79 expect(body.totalNotDeletedComments).to.equal(1)
98 expect(res.body.data).to.be.an('array') 80 expect(body.data).to.be.an('array')
99 expect(res.body.data).to.have.lengthOf(1) 81 expect(body.data).to.have.lengthOf(1)
100 82
101 const comment: VideoComment = res.body.data[0] 83 const comment = body.data[0]
102 expect(comment.inReplyToCommentId).to.be.null 84 expect(comment.inReplyToCommentId).to.be.null
103 expect(comment.text).equal('my super first comment') 85 expect(comment.text).equal('my super first comment')
104 expect(comment.videoId).to.equal(videoId) 86 expect(comment.videoId).to.equal(videoId)
@@ -117,9 +99,9 @@ describe('Test video comments', function () {
117 }) 99 })
118 100
119 it('Should get all the thread created', async function () { 101 it('Should get all the thread created', async function () {
120 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 102 const body = await command.getThread({ videoId: videoUUID, threadId })
121 103
122 const rootComment = res.body.comment 104 const rootComment = body.comment
123 expect(rootComment.inReplyToCommentId).to.be.null 105 expect(rootComment.inReplyToCommentId).to.be.null
124 expect(rootComment.text).equal('my super first comment') 106 expect(rootComment.text).equal('my super first comment')
125 expect(rootComment.videoId).to.equal(videoId) 107 expect(rootComment.videoId).to.equal(videoId)
@@ -129,20 +111,19 @@ describe('Test video comments', function () {
129 111
130 it('Should create multiple replies in this thread', async function () { 112 it('Should create multiple replies in this thread', async function () {
131 const text1 = 'my super answer to thread 1' 113 const text1 = 'my super answer to thread 1'
132 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) 114 const created = await command.addReply({ videoId, toCommentId: threadId, text: text1 })
133 const childCommentId = childCommentRes.body.comment.id 115 const childCommentId = created.id
134 116
135 const text2 = 'my super answer to answer of thread 1' 117 const text2 = 'my super answer to answer of thread 1'
136 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) 118 await command.addReply({ videoId, toCommentId: childCommentId, text: text2 })
137 119
138 const text3 = 'my second answer to thread 1' 120 const text3 = 'my second answer to thread 1'
139 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) 121 await command.addReply({ videoId, toCommentId: threadId, text: text3 })
140 }) 122 })
141 123
142 it('Should get correctly the replies', async function () { 124 it('Should get correctly the replies', async function () {
143 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 125 const tree = await command.getThread({ videoId: videoUUID, threadId })
144 126
145 const tree: VideoCommentThreadTree = res.body
146 expect(tree.comment.text).equal('my super first comment') 127 expect(tree.comment.text).equal('my super first comment')
147 expect(tree.children).to.have.lengthOf(2) 128 expect(tree.children).to.have.lengthOf(2)
148 129
@@ -163,42 +144,41 @@ describe('Test video comments', function () {
163 144
164 it('Should create other threads', async function () { 145 it('Should create other threads', async function () {
165 const text1 = 'super thread 2' 146 const text1 = 'super thread 2'
166 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) 147 await command.createThread({ videoId: videoUUID, text: text1 })
167 148
168 const text2 = 'super thread 3' 149 const text2 = 'super thread 3'
169 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) 150 await command.createThread({ videoId: videoUUID, text: text2 })
170 }) 151 })
171 152
172 it('Should list the threads', async function () { 153 it('Should list the threads', async function () {
173 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 154 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
174 155
175 expect(res.body.total).to.equal(3) 156 expect(body.total).to.equal(3)
176 expect(res.body.totalNotDeletedComments).to.equal(6) 157 expect(body.totalNotDeletedComments).to.equal(6)
177 expect(res.body.data).to.be.an('array') 158 expect(body.data).to.be.an('array')
178 expect(res.body.data).to.have.lengthOf(3) 159 expect(body.data).to.have.lengthOf(3)
179 160
180 expect(res.body.data[0].text).to.equal('my super first comment') 161 expect(body.data[0].text).to.equal('my super first comment')
181 expect(res.body.data[0].totalReplies).to.equal(3) 162 expect(body.data[0].totalReplies).to.equal(3)
182 expect(res.body.data[1].text).to.equal('super thread 2') 163 expect(body.data[1].text).to.equal('super thread 2')
183 expect(res.body.data[1].totalReplies).to.equal(0) 164 expect(body.data[1].totalReplies).to.equal(0)
184 expect(res.body.data[2].text).to.equal('super thread 3') 165 expect(body.data[2].text).to.equal('super thread 3')
185 expect(res.body.data[2].totalReplies).to.equal(0) 166 expect(body.data[2].totalReplies).to.equal(0)
186 }) 167 })
187 168
188 it('Should delete a reply', async function () { 169 it('Should delete a reply', async function () {
189 await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId) 170 await command.delete({ videoId, commentId: replyToDeleteId })
190 171
191 { 172 {
192 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 173 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
193 174
194 expect(res.body.total).to.equal(3) 175 expect(body.total).to.equal(3)
195 expect(res.body.totalNotDeletedComments).to.equal(5) 176 expect(body.totalNotDeletedComments).to.equal(5)
196 } 177 }
197 178
198 { 179 {
199 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 180 const tree = await command.getThread({ videoId: videoUUID, threadId })
200 181
201 const tree: VideoCommentThreadTree = res.body
202 expect(tree.comment.text).equal('my super first comment') 182 expect(tree.comment.text).equal('my super first comment')
203 expect(tree.children).to.have.lengthOf(2) 183 expect(tree.children).to.have.lengthOf(2)
204 184
@@ -220,99 +200,88 @@ describe('Test video comments', function () {
220 }) 200 })
221 201
222 it('Should delete a complete thread', async function () { 202 it('Should delete a complete thread', async function () {
223 await deleteVideoComment(server.url, server.accessToken, videoId, threadId) 203 await command.delete({ videoId, commentId: threadId })
224 204
225 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 205 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
226 expect(res.body.total).to.equal(3) 206 expect(body.total).to.equal(3)
227 expect(res.body.data).to.be.an('array') 207 expect(body.data).to.be.an('array')
228 expect(res.body.data).to.have.lengthOf(3) 208 expect(body.data).to.have.lengthOf(3)
229 209
230 expect(res.body.data[0].text).to.equal('') 210 expect(body.data[0].text).to.equal('')
231 expect(res.body.data[0].isDeleted).to.be.true 211 expect(body.data[0].isDeleted).to.be.true
232 expect(res.body.data[0].deletedAt).to.not.be.null 212 expect(body.data[0].deletedAt).to.not.be.null
233 expect(res.body.data[0].account).to.be.null 213 expect(body.data[0].account).to.be.null
234 expect(res.body.data[0].totalReplies).to.equal(2) 214 expect(body.data[0].totalReplies).to.equal(2)
235 expect(res.body.data[1].text).to.equal('super thread 2') 215 expect(body.data[1].text).to.equal('super thread 2')
236 expect(res.body.data[1].totalReplies).to.equal(0) 216 expect(body.data[1].totalReplies).to.equal(0)
237 expect(res.body.data[2].text).to.equal('super thread 3') 217 expect(body.data[2].text).to.equal('super thread 3')
238 expect(res.body.data[2].totalReplies).to.equal(0) 218 expect(body.data[2].totalReplies).to.equal(0)
239 }) 219 })
240 220
241 it('Should count replies from the video author correctly', async function () { 221 it('Should count replies from the video author correctly', async function () {
242 const text = 'my super first comment' 222 await command.createThread({ videoId: videoUUID, text: 'my super first comment' })
243 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 223
244 let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 224 const { data } = await command.listThreads({ videoId: videoUUID })
245 const comment: VideoComment = res.body.data[0] 225 const threadId2 = data[0].threadId
246 const threadId2 = comment.threadId
247 226
248 const text2 = 'a first answer to thread 4 by a third party' 227 const text2 = 'a first answer to thread 4 by a third party'
249 await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2) 228 await command.addReply({ token: userAccessTokenServer1, videoId, toCommentId: threadId2, text: text2 })
250 229
251 const text3 = 'my second answer to thread 4' 230 const text3 = 'my second answer to thread 4'
252 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3) 231 await command.addReply({ videoId, toCommentId: threadId2, text: text3 })
253 232
254 res = await getVideoThreadComments(server.url, videoUUID, threadId2) 233 const tree = await command.getThread({ videoId: videoUUID, threadId: threadId2 })
255 const tree: VideoCommentThreadTree = res.body
256 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1) 234 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1)
257 }) 235 })
258 }) 236 })
259 237
260 describe('All instance comments', function () { 238 describe('All instance comments', function () {
261 async function getComments (options: any = {}) {
262 const res = await getAdminVideoComments(Object.assign({
263 url: server.url,
264 token: server.accessToken,
265 start: 0,
266 count: 10
267 }, options))
268
269 return { comments: res.body.data as VideoCommentAdmin[], total: res.body.total as number }
270 }
271 239
272 it('Should list instance comments as admin', async function () { 240 it('Should list instance comments as admin', async function () {
273 const { comments } = await getComments({ start: 0, count: 1 }) 241 const { data } = await command.listForAdmin({ start: 0, count: 1 })
274 242
275 expect(comments[0].text).to.equal('my second answer to thread 4') 243 expect(data[0].text).to.equal('my second answer to thread 4')
276 }) 244 })
277 245
278 it('Should filter instance comments by isLocal', async function () { 246 it('Should filter instance comments by isLocal', async function () {
279 const { total, comments } = await getComments({ isLocal: false }) 247 const { total, data } = await command.listForAdmin({ isLocal: false })
280 248
281 expect(comments).to.have.lengthOf(0) 249 expect(data).to.have.lengthOf(0)
282 expect(total).to.equal(0) 250 expect(total).to.equal(0)
283 }) 251 })
284 252
285 it('Should search instance comments by account', async function () { 253 it('Should search instance comments by account', async function () {
286 const { total, comments } = await getComments({ searchAccount: 'user' }) 254 const { total, data } = await command.listForAdmin({ searchAccount: 'user' })
287 255
288 expect(comments).to.have.lengthOf(1) 256 expect(data).to.have.lengthOf(1)
289 expect(total).to.equal(1) 257 expect(total).to.equal(1)
290 258
291 expect(comments[0].text).to.equal('a first answer to thread 4 by a third party') 259 expect(data[0].text).to.equal('a first answer to thread 4 by a third party')
292 }) 260 })
293 261
294 it('Should search instance comments by video', async function () { 262 it('Should search instance comments by video', async function () {
295 { 263 {
296 const { total, comments } = await getComments({ searchVideo: 'video' }) 264 const { total, data } = await command.listForAdmin({ searchVideo: 'video' })
297 265
298 expect(comments).to.have.lengthOf(7) 266 expect(data).to.have.lengthOf(7)
299 expect(total).to.equal(7) 267 expect(total).to.equal(7)
300 } 268 }
301 269
302 { 270 {
303 const { total, comments } = await getComments({ searchVideo: 'hello' }) 271 const { total, data } = await command.listForAdmin({ searchVideo: 'hello' })
304 272
305 expect(comments).to.have.lengthOf(0) 273 expect(data).to.have.lengthOf(0)
306 expect(total).to.equal(0) 274 expect(total).to.equal(0)
307 } 275 }
308 }) 276 })
309 277
310 it('Should search instance comments', async function () { 278 it('Should search instance comments', async function () {
311 const { total, comments } = await getComments({ search: 'super thread 3' }) 279 const { total, data } = await command.listForAdmin({ search: 'super thread 3' })
312 280
313 expect(comments).to.have.lengthOf(1)
314 expect(total).to.equal(1) 281 expect(total).to.equal(1)
315 expect(comments[0].text).to.equal('super thread 3') 282
283 expect(data).to.have.lengthOf(1)
284 expect(data[0].text).to.equal('super thread 3')
316 }) 285 })
317 }) 286 })
318 287
diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts
index b8e98e45f..d22b4ed96 100644
--- a/server/tests/api/videos/video-description.ts
+++ b/server/tests/api/videos/video-description.ts
@@ -1,25 +1,13 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { 4import * as chai from 'chai'
6 cleanupTests, 5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
7 flushAndRunMultipleServers,
8 getVideo,
9 getVideoDescription,
10 getVideosList,
11 ServerInfo,
12 setAccessTokensToServers,
13 updateVideo,
14 uploadVideo
15} from '../../../../shared/extra-utils/index'
16import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
17import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18 6
19const expect = chai.expect 7const expect = chai.expect
20 8
21describe('Test video description', function () { 9describe('Test video description', function () {
22 let servers: ServerInfo[] = [] 10 let servers: PeerTubeServer[] = []
23 let videoUUID = '' 11 let videoUUID = ''
24 let videoId: number 12 let videoId: number
25 const longDescription = 'my super description for server 1'.repeat(50) 13 const longDescription = 'my super description for server 1'.repeat(50)
@@ -28,7 +16,7 @@ describe('Test video description', function () {
28 this.timeout(40000) 16 this.timeout(40000)
29 17
30 // Run servers 18 // Run servers
31 servers = await flushAndRunMultipleServers(2) 19 servers = await createMultipleServers(2)
32 20
33 // Get the access tokens 21 // Get the access tokens
34 await setAccessTokensToServers(servers) 22 await setAccessTokensToServers(servers)
@@ -43,20 +31,19 @@ describe('Test video description', function () {
43 const attributes = { 31 const attributes = {
44 description: longDescription 32 description: longDescription
45 } 33 }
46 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 34 await servers[0].videos.upload({ attributes })
47 35
48 await waitJobs(servers) 36 await waitJobs(servers)
49 37
50 const res = await getVideosList(servers[0].url) 38 const { data } = await servers[0].videos.list()
51 39
52 videoId = res.body.data[0].id 40 videoId = data[0].id
53 videoUUID = res.body.data[0].uuid 41 videoUUID = data[0].uuid
54 }) 42 })
55 43
56 it('Should have a truncated description on each server', async function () { 44 it('Should have a truncated description on each server', async function () {
57 for (const server of servers) { 45 for (const server of servers) {
58 const res = await getVideo(server.url, videoUUID) 46 const video = await server.videos.get({ id: videoUUID })
59 const video = res.body
60 47
61 // 30 characters * 6 -> 240 characters 48 // 30 characters * 6 -> 240 characters
62 const truncatedDescription = 'my super description for server 1'.repeat(7) + 49 const truncatedDescription = 'my super description for server 1'.repeat(7) +
@@ -68,11 +55,10 @@ describe('Test video description', function () {
68 55
69 it('Should fetch long description on each server', async function () { 56 it('Should fetch long description on each server', async function () {
70 for (const server of servers) { 57 for (const server of servers) {
71 const res = await getVideo(server.url, videoUUID) 58 const video = await server.videos.get({ id: videoUUID })
72 const video = res.body
73 59
74 const res2 = await getVideoDescription(server.url, video.descriptionPath) 60 const { description } = await server.videos.getDescription({ descriptionPath: video.descriptionPath })
75 expect(res2.body.description).to.equal(longDescription) 61 expect(description).to.equal(longDescription)
76 } 62 }
77 }) 63 })
78 64
@@ -82,20 +68,19 @@ describe('Test video description', function () {
82 const attributes = { 68 const attributes = {
83 description: 'short description' 69 description: 'short description'
84 } 70 }
85 await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes) 71 await servers[0].videos.update({ id: videoId, attributes })
86 72
87 await waitJobs(servers) 73 await waitJobs(servers)
88 }) 74 })
89 75
90 it('Should have a small description on each server', async function () { 76 it('Should have a small description on each server', async function () {
91 for (const server of servers) { 77 for (const server of servers) {
92 const res = await getVideo(server.url, videoUUID) 78 const video = await server.videos.get({ id: videoUUID })
93 const video = res.body
94 79
95 expect(video.description).to.equal('short description') 80 expect(video.description).to.equal('short description')
96 81
97 const res2 = await getVideoDescription(server.url, video.descriptionPath) 82 const { description } = await server.videos.getDescription({ descriptionPath: video.descriptionPath })
98 expect(res2.body.description).to.equal('short description') 83 expect(description).to.equal('short description')
99 } 84 }
100 }) 85 })
101 86
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts
index 03ac3f321..7845f7334 100644
--- a/server/tests/api/videos/video-hls.ts
+++ b/server/tests/api/videos/video-hls.ts
@@ -9,31 +9,22 @@ import {
9 checkSegmentHash, 9 checkSegmentHash,
10 checkTmpIsEmpty, 10 checkTmpIsEmpty,
11 cleanupTests, 11 cleanupTests,
12 createMultipleServers,
12 doubleFollow, 13 doubleFollow,
13 flushAndRunMultipleServers,
14 getPlaylist,
15 getVideo,
16 makeRawRequest, 14 makeRawRequest,
17 removeVideo, 15 PeerTubeServer,
18 ServerInfo,
19 setAccessTokensToServers, 16 setAccessTokensToServers,
20 updateCustomSubConfig,
21 updateVideo,
22 uploadVideo,
23 waitJobs, 17 waitJobs,
24 webtorrentAdd 18 webtorrentAdd
25} from '../../../../shared/extra-utils' 19} from '@shared/extra-utils'
26import { VideoDetails } from '../../../../shared/models/videos' 20import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models'
27import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
28import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' 21import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
29import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
30 22
31const expect = chai.expect 23const expect = chai.expect
32 24
33async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { 25async function checkHlsPlaylist (servers: PeerTubeServer[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) {
34 for (const server of servers) { 26 for (const server of servers) {
35 const resVideoDetails = await getVideo(server.url, videoUUID) 27 const videoDetails = await server.videos.get({ id: videoUUID })
36 const videoDetails: VideoDetails = resVideoDetails.body
37 const baseUrl = `http://${videoDetails.account.host}` 28 const baseUrl = `http://${videoDetails.account.host}`
38 29
39 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) 30 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
@@ -68,10 +59,9 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn
68 } 59 }
69 60
70 { 61 {
71 await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions) 62 await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions })
72 63
73 const res = await getPlaylist(hlsPlaylist.playlistUrl) 64 const masterPlaylist = await server.streamingPlaylists.get({ url: hlsPlaylist.playlistUrl })
74 const masterPlaylist = res.text
75 65
76 for (const resolution of resolutions) { 66 for (const resolution of resolutions) {
77 expect(masterPlaylist).to.contain(`${resolution}.m3u8`) 67 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
@@ -81,9 +71,10 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn
81 71
82 { 72 {
83 for (const resolution of resolutions) { 73 for (const resolution of resolutions) {
84 const res = await getPlaylist(`${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) 74 const subPlaylist = await server.streamingPlaylists.get({
75 url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`
76 })
85 77
86 const subPlaylist = res.text
87 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) 78 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
88 } 79 }
89 } 80 }
@@ -92,23 +83,31 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn
92 const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls' 83 const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls'
93 84
94 for (const resolution of resolutions) { 85 for (const resolution of resolutions) {
95 await checkSegmentHash(baseUrlAndPath, baseUrlAndPath, videoUUID, resolution, hlsPlaylist) 86 await checkSegmentHash({
87 server,
88 baseUrlPlaylist: baseUrlAndPath,
89 baseUrlSegment: baseUrlAndPath,
90 videoUUID,
91 resolution,
92 hlsPlaylist
93 })
96 } 94 }
97 } 95 }
98 } 96 }
99} 97}
100 98
101describe('Test HLS videos', function () { 99describe('Test HLS videos', function () {
102 let servers: ServerInfo[] = [] 100 let servers: PeerTubeServer[] = []
103 let videoUUID = '' 101 let videoUUID = ''
104 let videoAudioUUID = '' 102 let videoAudioUUID = ''
105 103
106 function runTestSuite (hlsOnly: boolean) { 104 function runTestSuite (hlsOnly: boolean) {
105
107 it('Should upload a video and transcode it to HLS', async function () { 106 it('Should upload a video and transcode it to HLS', async function () {
108 this.timeout(120000) 107 this.timeout(120000)
109 108
110 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) 109 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
111 videoUUID = res.body.video.uuid 110 videoUUID = uuid
112 111
113 await waitJobs(servers) 112 await waitJobs(servers)
114 113
@@ -118,8 +117,8 @@ describe('Test HLS videos', function () {
118 it('Should upload an audio file and transcode it to HLS', async function () { 117 it('Should upload an audio file and transcode it to HLS', async function () {
119 this.timeout(120000) 118 this.timeout(120000)
120 119
121 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) 120 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
122 videoAudioUUID = res.body.video.uuid 121 videoAudioUUID = uuid
123 122
124 await waitJobs(servers) 123 await waitJobs(servers)
125 124
@@ -129,7 +128,7 @@ describe('Test HLS videos', function () {
129 it('Should update the video', async function () { 128 it('Should update the video', async function () {
130 this.timeout(10000) 129 this.timeout(10000)
131 130
132 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' }) 131 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video 1 updated' } })
133 132
134 await waitJobs(servers) 133 await waitJobs(servers)
135 134
@@ -139,14 +138,14 @@ describe('Test HLS videos', function () {
139 it('Should delete videos', async function () { 138 it('Should delete videos', async function () {
140 this.timeout(10000) 139 this.timeout(10000)
141 140
142 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) 141 await servers[0].videos.remove({ id: videoUUID })
143 await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) 142 await servers[0].videos.remove({ id: videoAudioUUID })
144 143
145 await waitJobs(servers) 144 await waitJobs(servers)
146 145
147 for (const server of servers) { 146 for (const server of servers) {
148 await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) 147 await server.videos.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
149 await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) 148 await server.videos.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
150 } 149 }
151 }) 150 })
152 151
@@ -176,7 +175,7 @@ describe('Test HLS videos', function () {
176 } 175 }
177 } 176 }
178 } 177 }
179 servers = await flushAndRunMultipleServers(2, configOverride) 178 servers = await createMultipleServers(2, configOverride)
180 179
181 // Get the access tokens 180 // Get the access tokens
182 await setAccessTokensToServers(servers) 181 await setAccessTokensToServers(servers)
@@ -192,24 +191,26 @@ describe('Test HLS videos', function () {
192 describe('With only HLS enabled', function () { 191 describe('With only HLS enabled', function () {
193 192
194 before(async function () { 193 before(async function () {
195 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 194 await servers[0].config.updateCustomSubConfig({
196 transcoding: { 195 newConfig: {
197 enabled: true, 196 transcoding: {
198 allowAudioFiles: true, 197 enabled: true,
199 resolutions: { 198 allowAudioFiles: true,
200 '240p': true, 199 resolutions: {
201 '360p': true, 200 '240p': true,
202 '480p': true, 201 '360p': true,
203 '720p': true, 202 '480p': true,
204 '1080p': true, 203 '720p': true,
205 '1440p': true, 204 '1080p': true,
206 '2160p': true 205 '1440p': true,
207 }, 206 '2160p': true
208 hls: { 207 },
209 enabled: true 208 hls: {
210 }, 209 enabled: true
211 webtorrent: { 210 },
212 enabled: false 211 webtorrent: {
212 enabled: false
213 }
213 } 214 }
214 } 215 }
215 }) 216 })
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index 80834ca86..2eac130d2 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -3,43 +3,30 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 areHttpImportTestsDisabled,
6 cleanupTests, 7 cleanupTests,
8 createMultipleServers,
7 doubleFollow, 9 doubleFollow,
8 flushAndRunMultipleServers, 10 FIXTURE_URLS,
9 getMyUserInformation, 11 PeerTubeServer,
10 getMyVideos,
11 getVideo,
12 getVideosList,
13 immutableAssign,
14 listVideoCaptions,
15 ServerInfo,
16 setAccessTokensToServers, 12 setAccessTokensToServers,
17 testCaptionFile, 13 testCaptionFile,
18 updateCustomSubConfig 14 testImage,
19} from '../../../../shared/extra-utils' 15 waitJobs
20import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' 16} from '@shared/extra-utils'
21import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 17import { VideoPrivacy, VideoResolution } from '@shared/models'
22import {
23 getMagnetURI,
24 getMyVideoImports,
25 getYoutubeHDRVideoUrl,
26 getYoutubeVideoUrl,
27 importVideo
28} from '../../../../shared/extra-utils/videos/video-imports'
29import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos'
30 18
31const expect = chai.expect 19const expect = chai.expect
32 20
33describe('Test video imports', function () { 21describe('Test video imports', function () {
34 let servers: ServerInfo[] = [] 22 let servers: PeerTubeServer[] = []
35 let channelIdServer1: number 23 let channelIdServer1: number
36 let channelIdServer2: number 24 let channelIdServer2: number
37 25
38 if (areHttpImportTestsDisabled()) return 26 if (areHttpImportTestsDisabled()) return
39 27
40 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { 28 async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) {
41 const resHttp = await getVideo(url, idHttp) 29 const videoHttp = await server.videos.get({ id: idHttp })
42 const videoHttp: VideoDetails = resHttp.body
43 30
44 expect(videoHttp.name).to.equal('small video - youtube') 31 expect(videoHttp.name).to.equal('small video - youtube')
45 // FIXME: youtube-dl seems broken 32 // FIXME: youtube-dl seems broken
@@ -56,10 +43,8 @@ describe('Test video imports', function () {
56 expect(originallyPublishedAt.getMonth()).to.equal(0) 43 expect(originallyPublishedAt.getMonth()).to.equal(0)
57 expect(originallyPublishedAt.getFullYear()).to.equal(2019) 44 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
58 45
59 const resMagnet = await getVideo(url, idMagnet) 46 const videoMagnet = await server.videos.get({ id: idMagnet })
60 const videoMagnet: VideoDetails = resMagnet.body 47 const videoTorrent = await server.videos.get({ id: idTorrent })
61 const resTorrent = await getVideo(url, idTorrent)
62 const videoTorrent: VideoDetails = resTorrent.body
63 48
64 for (const video of [ videoMagnet, videoTorrent ]) { 49 for (const video of [ videoMagnet, videoTorrent ]) {
65 expect(video.category.label).to.equal('Misc') 50 expect(video.category.label).to.equal('Misc')
@@ -74,13 +59,12 @@ describe('Test video imports', function () {
74 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') 59 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
75 expect(videoMagnet.name).to.contain('super peertube2 video') 60 expect(videoMagnet.name).to.contain('super peertube2 video')
76 61
77 const resCaptions = await listVideoCaptions(url, idHttp) 62 const bodyCaptions = await server.captions.list({ videoId: idHttp })
78 expect(resCaptions.body.total).to.equal(2) 63 expect(bodyCaptions.total).to.equal(2)
79 } 64 }
80 65
81 async function checkVideoServer2 (url: string, id: number | string) { 66 async function checkVideoServer2 (server: PeerTubeServer, id: number | string) {
82 const res = await getVideo(url, id) 67 const video = await server.videos.get({ id })
83 const video: VideoDetails = res.body
84 68
85 expect(video.name).to.equal('my super name') 69 expect(video.name).to.equal('my super name')
86 expect(video.category.label).to.equal('Entertainment') 70 expect(video.category.label).to.equal('Entertainment')
@@ -92,26 +76,26 @@ describe('Test video imports', function () {
92 76
93 expect(video.files).to.have.lengthOf(1) 77 expect(video.files).to.have.lengthOf(1)
94 78
95 const resCaptions = await listVideoCaptions(url, id) 79 const bodyCaptions = await server.captions.list({ videoId: id })
96 expect(resCaptions.body.total).to.equal(2) 80 expect(bodyCaptions.total).to.equal(2)
97 } 81 }
98 82
99 before(async function () { 83 before(async function () {
100 this.timeout(30_000) 84 this.timeout(30_000)
101 85
102 // Run servers 86 // Run servers
103 servers = await flushAndRunMultipleServers(2) 87 servers = await createMultipleServers(2)
104 88
105 await setAccessTokensToServers(servers) 89 await setAccessTokensToServers(servers)
106 90
107 { 91 {
108 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) 92 const { videoChannels } = await servers[0].users.getMyInfo()
109 channelIdServer1 = res.body.videoChannels[0].id 93 channelIdServer1 = videoChannels[0].id
110 } 94 }
111 95
112 { 96 {
113 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) 97 const { videoChannels } = await servers[1].users.getMyInfo()
114 channelIdServer2 = res.body.videoChannels[0].id 98 channelIdServer2 = videoChannels[0].id
115 } 99 }
116 100
117 await doubleFollow(servers[0], servers[1]) 101 await doubleFollow(servers[0], servers[1])
@@ -126,18 +110,18 @@ describe('Test video imports', function () {
126 } 110 }
127 111
128 { 112 {
129 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) 113 const attributes = { ...baseAttributes, targetUrl: FIXTURE_URLS.youtube }
130 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 114 const { video } = await servers[0].imports.importVideo({ attributes })
131 expect(res.body.video.name).to.equal('small video - youtube') 115 expect(video.name).to.equal('small video - youtube')
132 116
133 expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) 117 expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`))
134 expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) 118 expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`))
135 119
136 await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) 120 await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath)
137 await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) 121 await testImage(servers[0].url, 'video_import_preview', video.previewPath)
138 122
139 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) 123 const bodyCaptions = await servers[0].captions.list({ videoId: video.id })
140 const videoCaptions: VideoCaption[] = resCaptions.body.data 124 const videoCaptions = bodyCaptions.data
141 expect(videoCaptions).to.have.lengthOf(2) 125 expect(videoCaptions).to.have.lengthOf(2)
142 126
143 const enCaption = videoCaptions.find(caption => caption.language.id === 'en') 127 const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
@@ -176,52 +160,52 @@ Ajouter un sous-titre est vraiment facile`)
176 } 160 }
177 161
178 { 162 {
179 const attributes = immutableAssign(baseAttributes, { 163 const attributes = {
180 magnetUri: getMagnetURI(), 164 ...baseAttributes,
165 magnetUri: FIXTURE_URLS.magnet,
181 description: 'this is a super torrent description', 166 description: 'this is a super torrent description',
182 tags: [ 'tag_torrent1', 'tag_torrent2' ] 167 tags: [ 'tag_torrent1', 'tag_torrent2' ]
183 }) 168 }
184 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 169 const { video } = await servers[0].imports.importVideo({ attributes })
185 expect(res.body.video.name).to.equal('super peertube2 video') 170 expect(video.name).to.equal('super peertube2 video')
186 } 171 }
187 172
188 { 173 {
189 const attributes = immutableAssign(baseAttributes, { 174 const attributes = {
175 ...baseAttributes,
190 torrentfile: 'video-720p.torrent' as any, 176 torrentfile: 'video-720p.torrent' as any,
191 description: 'this is a super torrent description', 177 description: 'this is a super torrent description',
192 tags: [ 'tag_torrent1', 'tag_torrent2' ] 178 tags: [ 'tag_torrent1', 'tag_torrent2' ]
193 }) 179 }
194 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 180 const { video } = await servers[0].imports.importVideo({ attributes })
195 expect(res.body.video.name).to.equal('你好 世界 720p.mp4') 181 expect(video.name).to.equal('你好 世界 720p.mp4')
196 } 182 }
197 }) 183 })
198 184
199 it('Should list the videos to import in my videos on server 1', async function () { 185 it('Should list the videos to import in my videos on server 1', async function () {
200 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt') 186 const { total, data } = await servers[0].videos.listMyVideos({ sort: 'createdAt' })
201 187
202 expect(res.body.total).to.equal(3) 188 expect(total).to.equal(3)
203 189
204 const videos = res.body.data 190 expect(data).to.have.lengthOf(3)
205 expect(videos).to.have.lengthOf(3) 191 expect(data[0].name).to.equal('small video - youtube')
206 expect(videos[0].name).to.equal('small video - youtube') 192 expect(data[1].name).to.equal('super peertube2 video')
207 expect(videos[1].name).to.equal('super peertube2 video') 193 expect(data[2].name).to.equal('你好 世界 720p.mp4')
208 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
209 }) 194 })
210 195
211 it('Should list the videos to import in my imports on server 1', async function () { 196 it('Should list the videos to import in my imports on server 1', async function () {
212 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt') 197 const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ sort: '-createdAt' })
198 expect(total).to.equal(3)
213 199
214 expect(res.body.total).to.equal(3)
215 const videoImports: VideoImport[] = res.body.data
216 expect(videoImports).to.have.lengthOf(3) 200 expect(videoImports).to.have.lengthOf(3)
217 201
218 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl()) 202 expect(videoImports[2].targetUrl).to.equal(FIXTURE_URLS.youtube)
219 expect(videoImports[2].magnetUri).to.be.null 203 expect(videoImports[2].magnetUri).to.be.null
220 expect(videoImports[2].torrentName).to.be.null 204 expect(videoImports[2].torrentName).to.be.null
221 expect(videoImports[2].video.name).to.equal('small video - youtube') 205 expect(videoImports[2].video.name).to.equal('small video - youtube')
222 206
223 expect(videoImports[1].targetUrl).to.be.null 207 expect(videoImports[1].targetUrl).to.be.null
224 expect(videoImports[1].magnetUri).to.equal(getMagnetURI()) 208 expect(videoImports[1].magnetUri).to.equal(FIXTURE_URLS.magnet)
225 expect(videoImports[1].torrentName).to.be.null 209 expect(videoImports[1].torrentName).to.be.null
226 expect(videoImports[1].video.name).to.equal('super peertube2 video') 210 expect(videoImports[1].video.name).to.equal('super peertube2 video')
227 211
@@ -237,12 +221,12 @@ Ajouter un sous-titre est vraiment facile`)
237 await waitJobs(servers) 221 await waitJobs(servers)
238 222
239 for (const server of servers) { 223 for (const server of servers) {
240 const res = await getVideosList(server.url) 224 const { total, data } = await server.videos.list()
241 expect(res.body.total).to.equal(3) 225 expect(total).to.equal(3)
242 expect(res.body.data).to.have.lengthOf(3) 226 expect(data).to.have.lengthOf(3)
243 227
244 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data 228 const [ videoHttp, videoMagnet, videoTorrent ] = data
245 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) 229 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
246 } 230 }
247 }) 231 })
248 232
@@ -250,7 +234,7 @@ Ajouter un sous-titre est vraiment facile`)
250 this.timeout(60_000) 234 this.timeout(60_000)
251 235
252 const attributes = { 236 const attributes = {
253 targetUrl: getYoutubeVideoUrl(), 237 targetUrl: FIXTURE_URLS.youtube,
254 channelId: channelIdServer2, 238 channelId: channelIdServer2,
255 privacy: VideoPrivacy.PUBLIC, 239 privacy: VideoPrivacy.PUBLIC,
256 category: 10, 240 category: 10,
@@ -260,8 +244,8 @@ Ajouter un sous-titre est vraiment facile`)
260 description: 'my super description', 244 description: 'my super description',
261 tags: [ 'supertag1', 'supertag2' ] 245 tags: [ 'supertag1', 'supertag2' ]
262 } 246 }
263 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 247 const { video } = await servers[1].imports.importVideo({ attributes })
264 expect(res.body.video.name).to.equal('my super name') 248 expect(video.name).to.equal('my super name')
265 }) 249 })
266 250
267 it('Should have the videos listed on the two instances', async function () { 251 it('Should have the videos listed on the two instances', async function () {
@@ -270,14 +254,14 @@ Ajouter un sous-titre est vraiment facile`)
270 await waitJobs(servers) 254 await waitJobs(servers)
271 255
272 for (const server of servers) { 256 for (const server of servers) {
273 const res = await getVideosList(server.url) 257 const { total, data } = await server.videos.list()
274 expect(res.body.total).to.equal(4) 258 expect(total).to.equal(4)
275 expect(res.body.data).to.have.lengthOf(4) 259 expect(data).to.have.lengthOf(4)
276 260
277 await checkVideoServer2(server.url, res.body.data[0].uuid) 261 await checkVideoServer2(server, data[0].uuid)
278 262
279 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data 263 const [ , videoHttp, videoMagnet, videoTorrent ] = data
280 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) 264 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
281 } 265 }
282 }) 266 })
283 267
@@ -286,18 +270,17 @@ Ajouter un sous-titre est vraiment facile`)
286 270
287 const attributes = { 271 const attributes = {
288 name: 'transcoded video', 272 name: 'transcoded video',
289 magnetUri: getMagnetURI(), 273 magnetUri: FIXTURE_URLS.magnet,
290 channelId: channelIdServer2, 274 channelId: channelIdServer2,
291 privacy: VideoPrivacy.PUBLIC 275 privacy: VideoPrivacy.PUBLIC
292 } 276 }
293 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 277 const { video } = await servers[1].imports.importVideo({ attributes })
294 const videoUUID = res.body.video.uuid 278 const videoUUID = video.uuid
295 279
296 await waitJobs(servers) 280 await waitJobs(servers)
297 281
298 for (const server of servers) { 282 for (const server of servers) {
299 const res = await getVideo(server.url, videoUUID) 283 const video = await server.videos.get({ id: videoUUID })
300 const video: VideoDetails = res.body
301 284
302 expect(video.name).to.equal('transcoded video') 285 expect(video.name).to.equal('transcoded video')
303 expect(video.files).to.have.lengthOf(4) 286 expect(video.files).to.have.lengthOf(4)
@@ -333,22 +316,21 @@ Ajouter un sous-titre est vraiment facile`)
333 } 316 }
334 } 317 }
335 } 318 }
336 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 319 await servers[0].config.updateCustomSubConfig({ newConfig: config })
337 320
338 const attributes = { 321 const attributes = {
339 name: 'hdr video', 322 name: 'hdr video',
340 targetUrl: getYoutubeHDRVideoUrl(), 323 targetUrl: FIXTURE_URLS.youtubeHDR,
341 channelId: channelIdServer1, 324 channelId: channelIdServer1,
342 privacy: VideoPrivacy.PUBLIC 325 privacy: VideoPrivacy.PUBLIC
343 } 326 }
344 const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes) 327 const { video: videoImported } = await servers[0].imports.importVideo({ attributes })
345 const videoUUID = res1.body.video.uuid 328 const videoUUID = videoImported.uuid
346 329
347 await waitJobs(servers) 330 await waitJobs(servers)
348 331
349 // test resolution 332 // test resolution
350 const res2 = await getVideo(servers[0].url, videoUUID) 333 const video = await servers[0].videos.get({ id: videoUUID })
351 const video: VideoDetails = res2.body
352 expect(video.name).to.equal('hdr video') 334 expect(video.name).to.equal('hdr video')
353 const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) 335 const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id }))
354 expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P) 336 expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P)
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index b16b484b9..b5d183d62 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -1,117 +1,96 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index' 4import * as chai from 'chai'
6import { userLogin } from '../../../../shared/extra-utils/users/login' 5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
7import { createUser } from '../../../../shared/extra-utils/users/users' 6import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models'
8import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
9import {
10 flushAndRunServer,
11 getAccountVideos,
12 getConfig,
13 getCustomConfig,
14 getMyUserInformation,
15 getVideoChannelVideos,
16 getVideosListWithToken,
17 searchVideo,
18 searchVideoWithToken,
19 updateCustomConfig,
20 updateMyUser
21} from '../../../../shared/extra-utils'
22import { ServerConfig, VideosOverview } from '../../../../shared/models'
23import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
24import { User } from '../../../../shared/models/users'
25import { getVideosOverview, getVideosOverviewWithToken } from '@shared/extra-utils/overviews/overviews'
26 7
27const expect = chai.expect 8const expect = chai.expect
28 9
29function createOverviewRes (res: any) { 10function createOverviewRes (overview: VideosOverview) {
30 const overview = res.body as VideosOverview
31
32 const videos = overview.categories[0].videos 11 const videos = overview.categories[0].videos
33 return { body: { data: videos, total: videos.length } } 12 return { data: videos, total: videos.length }
34} 13}
35 14
36describe('Test video NSFW policy', function () { 15describe('Test video NSFW policy', function () {
37 let server: ServerInfo 16 let server: PeerTubeServer
38 let userAccessToken: string 17 let userAccessToken: string
39 let customConfig: CustomConfig 18 let customConfig: CustomConfig
40 19
41 function getVideosFunctions (token?: string, query = {}) { 20 async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) {
42 return getMyUserInformation(server.url, server.accessToken) 21 const user = await server.users.getMyInfo()
43 .then(res => { 22
44 const user: User = res.body 23 const channelName = user.videoChannels[0].name
45 const videoChannelName = user.videoChannels[0].name 24 const accountName = user.account.name + '@' + user.account.host
46 const accountName = user.account.name + '@' + user.account.host 25
47 const hasQuery = Object.keys(query).length !== 0 26 const hasQuery = Object.keys(query).length !== 0
48 let promises: Promise<any>[] 27 let promises: Promise<ResultList<Video>>[]
49 28
50 if (token) { 29 if (token) {
51 promises = [ 30 promises = [
52 getVideosListWithToken(server.url, token, query), 31 server.search.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }),
53 searchVideoWithToken(server.url, 'n', token, query), 32 server.videos.listWithToken({ token, ...query }),
54 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), 33 server.videos.listByAccount({ token, handle: accountName, ...query }),
55 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) 34 server.videos.listByChannel({ token, handle: channelName, ...query })
56 ] 35 ]
57 36
58 // Overviews do not support video filters 37 // Overviews do not support video filters
59 if (!hasQuery) { 38 if (!hasQuery) {
60 promises.push(getVideosOverviewWithToken(server.url, 1, token).then(res => createOverviewRes(res))) 39 const p = server.overviews.getVideos({ page: 1, token })
61 } 40 .then(res => createOverviewRes(res))
62 41 promises.push(p)
63 return Promise.all(promises) 42 }
64 } 43
65 44 return Promise.all(promises)
66 promises = [ 45 }
67 getVideosList(server.url), 46
68 searchVideo(server.url, 'n'), 47 promises = [
69 getAccountVideos(server.url, undefined, accountName, 0, 5), 48 server.search.searchVideos({ search: 'n', sort: '-publishedAt' }),
70 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) 49 server.videos.list(),
71 ] 50 server.videos.listByAccount({ token: null, handle: accountName }),
72 51 server.videos.listByChannel({ token: null, handle: channelName })
73 // Overviews do not support video filters 52 ]
74 if (!hasQuery) { 53
75 promises.push(getVideosOverview(server.url, 1).then(res => createOverviewRes(res))) 54 // Overviews do not support video filters
76 } 55 if (!hasQuery) {
77 56 const p = server.overviews.getVideos({ page: 1 })
78 return Promise.all(promises) 57 .then(res => createOverviewRes(res))
79 }) 58 promises.push(p)
59 }
60
61 return Promise.all(promises)
80 } 62 }
81 63
82 before(async function () { 64 before(async function () {
83 this.timeout(50000) 65 this.timeout(50000)
84 server = await flushAndRunServer(1) 66 server = await createSingleServer(1)
85 67
86 // Get the access tokens 68 // Get the access tokens
87 await setAccessTokensToServers([ server ]) 69 await setAccessTokensToServers([ server ])
88 70
89 { 71 {
90 const attributes = { name: 'nsfw', nsfw: true, category: 1 } 72 const attributes = { name: 'nsfw', nsfw: true, category: 1 }
91 await uploadVideo(server.url, server.accessToken, attributes) 73 await server.videos.upload({ attributes })
92 } 74 }
93 75
94 { 76 {
95 const attributes = { name: 'normal', nsfw: false, category: 1 } 77 const attributes = { name: 'normal', nsfw: false, category: 1 }
96 await uploadVideo(server.url, server.accessToken, attributes) 78 await server.videos.upload({ attributes })
97 } 79 }
98 80
99 { 81 customConfig = await server.config.getCustomConfig()
100 const res = await getCustomConfig(server.url, server.accessToken)
101 customConfig = res.body
102 }
103 }) 82 })
104 83
105 describe('Instance default NSFW policy', function () { 84 describe('Instance default NSFW policy', function () {
85
106 it('Should display NSFW videos with display default NSFW policy', async function () { 86 it('Should display NSFW videos with display default NSFW policy', async function () {
107 const resConfig = await getConfig(server.url) 87 const serverConfig = await server.config.getConfig()
108 const serverConfig: ServerConfig = resConfig.body
109 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') 88 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
110 89
111 for (const res of await getVideosFunctions()) { 90 for (const body of await getVideosFunctions()) {
112 expect(res.body.total).to.equal(2) 91 expect(body.total).to.equal(2)
113 92
114 const videos = res.body.data 93 const videos = body.data
115 expect(videos).to.have.lengthOf(2) 94 expect(videos).to.have.lengthOf(2)
116 expect(videos[0].name).to.equal('normal') 95 expect(videos[0].name).to.equal('normal')
117 expect(videos[1].name).to.equal('nsfw') 96 expect(videos[1].name).to.equal('nsfw')
@@ -120,16 +99,15 @@ describe('Test video NSFW policy', function () {
120 99
121 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () { 100 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
122 customConfig.instance.defaultNSFWPolicy = 'do_not_list' 101 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
123 await updateCustomConfig(server.url, server.accessToken, customConfig) 102 await server.config.updateCustomConfig({ newCustomConfig: customConfig })
124 103
125 const resConfig = await getConfig(server.url) 104 const serverConfig = await server.config.getConfig()
126 const serverConfig: ServerConfig = resConfig.body
127 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') 105 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
128 106
129 for (const res of await getVideosFunctions()) { 107 for (const body of await getVideosFunctions()) {
130 expect(res.body.total).to.equal(1) 108 expect(body.total).to.equal(1)
131 109
132 const videos = res.body.data 110 const videos = body.data
133 expect(videos).to.have.lengthOf(1) 111 expect(videos).to.have.lengthOf(1)
134 expect(videos[0].name).to.equal('normal') 112 expect(videos[0].name).to.equal('normal')
135 } 113 }
@@ -137,16 +115,15 @@ describe('Test video NSFW policy', function () {
137 115
138 it('Should display NSFW videos with blur default NSFW policy', async function () { 116 it('Should display NSFW videos with blur default NSFW policy', async function () {
139 customConfig.instance.defaultNSFWPolicy = 'blur' 117 customConfig.instance.defaultNSFWPolicy = 'blur'
140 await updateCustomConfig(server.url, server.accessToken, customConfig) 118 await server.config.updateCustomConfig({ newCustomConfig: customConfig })
141 119
142 const resConfig = await getConfig(server.url) 120 const serverConfig = await server.config.getConfig()
143 const serverConfig: ServerConfig = resConfig.body
144 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') 121 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
145 122
146 for (const res of await getVideosFunctions()) { 123 for (const body of await getVideosFunctions()) {
147 expect(res.body.total).to.equal(2) 124 expect(body.total).to.equal(2)
148 125
149 const videos = res.body.data 126 const videos = body.data
150 expect(videos).to.have.lengthOf(2) 127 expect(videos).to.have.lengthOf(2)
151 expect(videos[0].name).to.equal('normal') 128 expect(videos[0].name).to.equal('normal')
152 expect(videos[1].name).to.equal('nsfw') 129 expect(videos[1].name).to.equal('nsfw')
@@ -159,24 +136,22 @@ describe('Test video NSFW policy', function () {
159 it('Should create a user having the default nsfw policy', async function () { 136 it('Should create a user having the default nsfw policy', async function () {
160 const username = 'user1' 137 const username = 'user1'
161 const password = 'my super password' 138 const password = 'my super password'
162 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 139 await server.users.create({ username: username, password: password })
163
164 userAccessToken = await userLogin(server, { username, password })
165 140
166 const res = await getMyUserInformation(server.url, userAccessToken) 141 userAccessToken = await server.login.getAccessToken({ username, password })
167 const user = res.body
168 142
143 const user = await server.users.getMyInfo({ token: userAccessToken })
169 expect(user.nsfwPolicy).to.equal('blur') 144 expect(user.nsfwPolicy).to.equal('blur')
170 }) 145 })
171 146
172 it('Should display NSFW videos with blur user NSFW policy', async function () { 147 it('Should display NSFW videos with blur user NSFW policy', async function () {
173 customConfig.instance.defaultNSFWPolicy = 'do_not_list' 148 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
174 await updateCustomConfig(server.url, server.accessToken, customConfig) 149 await server.config.updateCustomConfig({ newCustomConfig: customConfig })
175 150
176 for (const res of await getVideosFunctions(userAccessToken)) { 151 for (const body of await getVideosFunctions(userAccessToken)) {
177 expect(res.body.total).to.equal(2) 152 expect(body.total).to.equal(2)
178 153
179 const videos = res.body.data 154 const videos = body.data
180 expect(videos).to.have.lengthOf(2) 155 expect(videos).to.have.lengthOf(2)
181 expect(videos[0].name).to.equal('normal') 156 expect(videos[0].name).to.equal('normal')
182 expect(videos[1].name).to.equal('nsfw') 157 expect(videos[1].name).to.equal('nsfw')
@@ -184,16 +159,12 @@ describe('Test video NSFW policy', function () {
184 }) 159 })
185 160
186 it('Should display NSFW videos with display user NSFW policy', async function () { 161 it('Should display NSFW videos with display user NSFW policy', async function () {
187 await updateMyUser({ 162 await server.users.updateMe({ nsfwPolicy: 'display' })
188 url: server.url,
189 accessToken: server.accessToken,
190 nsfwPolicy: 'display'
191 })
192 163
193 for (const res of await getVideosFunctions(server.accessToken)) { 164 for (const body of await getVideosFunctions(server.accessToken)) {
194 expect(res.body.total).to.equal(2) 165 expect(body.total).to.equal(2)
195 166
196 const videos = res.body.data 167 const videos = body.data
197 expect(videos).to.have.lengthOf(2) 168 expect(videos).to.have.lengthOf(2)
198 expect(videos[0].name).to.equal('normal') 169 expect(videos[0].name).to.equal('normal')
199 expect(videos[1].name).to.equal('nsfw') 170 expect(videos[1].name).to.equal('nsfw')
@@ -201,56 +172,51 @@ describe('Test video NSFW policy', function () {
201 }) 172 })
202 173
203 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { 174 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
204 await updateMyUser({ 175 await server.users.updateMe({ nsfwPolicy: 'do_not_list' })
205 url: server.url,
206 accessToken: server.accessToken,
207 nsfwPolicy: 'do_not_list'
208 })
209 176
210 for (const res of await getVideosFunctions(server.accessToken)) { 177 for (const body of await getVideosFunctions(server.accessToken)) {
211 expect(res.body.total).to.equal(1) 178 expect(body.total).to.equal(1)
212 179
213 const videos = res.body.data 180 const videos = body.data
214 expect(videos).to.have.lengthOf(1) 181 expect(videos).to.have.lengthOf(1)
215 expect(videos[0].name).to.equal('normal') 182 expect(videos[0].name).to.equal('normal')
216 } 183 }
217 }) 184 })
218 185
219 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () { 186 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
220 const res = await getMyVideos(server.url, server.accessToken, 0, 5) 187 const { total, data } = await server.videos.listMyVideos()
221 expect(res.body.total).to.equal(2) 188 expect(total).to.equal(2)
222 189
223 const videos = res.body.data 190 expect(data).to.have.lengthOf(2)
224 expect(videos).to.have.lengthOf(2) 191 expect(data[0].name).to.equal('normal')
225 expect(videos[0].name).to.equal('normal') 192 expect(data[1].name).to.equal('nsfw')
226 expect(videos[1].name).to.equal('nsfw')
227 }) 193 })
228 194
229 it('Should display NSFW videos when the nsfw param === true', async function () { 195 it('Should display NSFW videos when the nsfw param === true', async function () {
230 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) { 196 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) {
231 expect(res.body.total).to.equal(1) 197 expect(body.total).to.equal(1)
232 198
233 const videos = res.body.data 199 const videos = body.data
234 expect(videos).to.have.lengthOf(1) 200 expect(videos).to.have.lengthOf(1)
235 expect(videos[0].name).to.equal('nsfw') 201 expect(videos[0].name).to.equal('nsfw')
236 } 202 }
237 }) 203 })
238 204
239 it('Should hide NSFW videos when the nsfw param === true', async function () { 205 it('Should hide NSFW videos when the nsfw param === true', async function () {
240 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) { 206 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) {
241 expect(res.body.total).to.equal(1) 207 expect(body.total).to.equal(1)
242 208
243 const videos = res.body.data 209 const videos = body.data
244 expect(videos).to.have.lengthOf(1) 210 expect(videos).to.have.lengthOf(1)
245 expect(videos[0].name).to.equal('normal') 211 expect(videos[0].name).to.equal('normal')
246 } 212 }
247 }) 213 })
248 214
249 it('Should display both videos when the nsfw param === both', async function () { 215 it('Should display both videos when the nsfw param === both', async function () {
250 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) { 216 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
251 expect(res.body.total).to.equal(2) 217 expect(body.total).to.equal(2)
252 218
253 const videos = res.body.data 219 const videos = body.data
254 expect(videos).to.have.lengthOf(2) 220 expect(videos).to.have.lengthOf(2)
255 expect(videos[0].name).to.equal('normal') 221 expect(videos[0].name).to.equal('normal')
256 expect(videos[1].name).to.equal('nsfw') 222 expect(videos[1].name).to.equal('nsfw')
diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts
index a93a0b7de..f0b2ca169 100644
--- a/server/tests/api/videos/video-playlist-thumbnails.ts
+++ b/server/tests/api/videos/video-playlist-thumbnails.ts
@@ -1,21 +1,15 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 addVideoInPlaylist,
7 cleanupTests, 6 cleanupTests,
8 createVideoPlaylist, 7 createMultipleServers,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunMultipleServers, 9 PeerTubeServer,
11 getVideoPlaylistsList,
12 removeVideoFromPlaylist,
13 reorderVideosPlaylist,
14 ServerInfo,
15 setAccessTokensToServers, 10 setAccessTokensToServers,
16 setDefaultVideoChannel, 11 setDefaultVideoChannel,
17 testImage, 12 testImage,
18 uploadVideoAndGetId,
19 waitJobs 13 waitJobs
20} from '../../../../shared/extra-utils' 14} from '../../../../shared/extra-utils'
21import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 15import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
@@ -23,10 +17,10 @@ import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/
23const expect = chai.expect 17const expect = chai.expect
24 18
25describe('Playlist thumbnail', function () { 19describe('Playlist thumbnail', function () {
26 let servers: ServerInfo[] = [] 20 let servers: PeerTubeServer[] = []
27 21
28 let playlistWithoutThumbnail: number 22 let playlistWithoutThumbnailId: number
29 let playlistWithThumbnail: number 23 let playlistWithThumbnailId: number
30 24
31 let withThumbnailE1: number 25 let withThumbnailE1: number
32 let withThumbnailE2: number 26 let withThumbnailE2: number
@@ -36,22 +30,22 @@ describe('Playlist thumbnail', function () {
36 let video1: number 30 let video1: number
37 let video2: number 31 let video2: number
38 32
39 async function getPlaylistWithoutThumbnail (server: ServerInfo) { 33 async function getPlaylistWithoutThumbnail (server: PeerTubeServer) {
40 const res = await getVideoPlaylistsList(server.url, 0, 10) 34 const body = await server.playlists.list({ start: 0, count: 10 })
41 35
42 return res.body.data.find(p => p.displayName === 'playlist without thumbnail') 36 return body.data.find(p => p.displayName === 'playlist without thumbnail')
43 } 37 }
44 38
45 async function getPlaylistWithThumbnail (server: ServerInfo) { 39 async function getPlaylistWithThumbnail (server: PeerTubeServer) {
46 const res = await getVideoPlaylistsList(server.url, 0, 10) 40 const body = await server.playlists.list({ start: 0, count: 10 })
47 41
48 return res.body.data.find(p => p.displayName === 'playlist with thumbnail') 42 return body.data.find(p => p.displayName === 'playlist with thumbnail')
49 } 43 }
50 44
51 before(async function () { 45 before(async function () {
52 this.timeout(120000) 46 this.timeout(120000)
53 47
54 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } }) 48 servers = await createMultipleServers(2, { transcoding: { enabled: false } })
55 49
56 // Get the access tokens 50 // Get the access tokens
57 await setAccessTokensToServers(servers) 51 await setAccessTokensToServers(servers)
@@ -60,8 +54,8 @@ describe('Playlist thumbnail', function () {
60 // Server 1 and server 2 follow each other 54 // Server 1 and server 2 follow each other
61 await doubleFollow(servers[0], servers[1]) 55 await doubleFollow(servers[0], servers[1])
62 56
63 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id 57 video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id
64 video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id 58 video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id
65 59
66 await waitJobs(servers) 60 await waitJobs(servers)
67 }) 61 })
@@ -69,24 +63,20 @@ describe('Playlist thumbnail', function () {
69 it('Should automatically update the thumbnail when adding an element', async function () { 63 it('Should automatically update the thumbnail when adding an element', async function () {
70 this.timeout(30000) 64 this.timeout(30000)
71 65
72 const res = await createVideoPlaylist({ 66 const created = await servers[1].playlists.create({
73 url: servers[1].url, 67 attributes: {
74 token: servers[1].accessToken,
75 playlistAttrs: {
76 displayName: 'playlist without thumbnail', 68 displayName: 'playlist without thumbnail',
77 privacy: VideoPlaylistPrivacy.PUBLIC, 69 privacy: VideoPlaylistPrivacy.PUBLIC,
78 videoChannelId: servers[1].videoChannel.id 70 videoChannelId: servers[1].store.channel.id
79 } 71 }
80 }) 72 })
81 playlistWithoutThumbnail = res.body.videoPlaylist.id 73 playlistWithoutThumbnailId = created.id
82 74
83 const res2 = await addVideoInPlaylist({ 75 const added = await servers[1].playlists.addElement({
84 url: servers[1].url, 76 playlistId: playlistWithoutThumbnailId,
85 token: servers[1].accessToken, 77 attributes: { videoId: video1 }
86 playlistId: playlistWithoutThumbnail,
87 elementAttrs: { videoId: video1 }
88 }) 78 })
89 withoutThumbnailE1 = res2.body.videoPlaylistElement.id 79 withoutThumbnailE1 = added.id
90 80
91 await waitJobs(servers) 81 await waitJobs(servers)
92 82
@@ -99,25 +89,21 @@ describe('Playlist thumbnail', function () {
99 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () { 89 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
100 this.timeout(30000) 90 this.timeout(30000)
101 91
102 const res = await createVideoPlaylist({ 92 const created = await servers[1].playlists.create({
103 url: servers[1].url, 93 attributes: {
104 token: servers[1].accessToken,
105 playlistAttrs: {
106 displayName: 'playlist with thumbnail', 94 displayName: 'playlist with thumbnail',
107 privacy: VideoPlaylistPrivacy.PUBLIC, 95 privacy: VideoPlaylistPrivacy.PUBLIC,
108 videoChannelId: servers[1].videoChannel.id, 96 videoChannelId: servers[1].store.channel.id,
109 thumbnailfile: 'thumbnail.jpg' 97 thumbnailfile: 'thumbnail.jpg'
110 } 98 }
111 }) 99 })
112 playlistWithThumbnail = res.body.videoPlaylist.id 100 playlistWithThumbnailId = created.id
113 101
114 const res2 = await addVideoInPlaylist({ 102 const added = await servers[1].playlists.addElement({
115 url: servers[1].url, 103 playlistId: playlistWithThumbnailId,
116 token: servers[1].accessToken, 104 attributes: { videoId: video1 }
117 playlistId: playlistWithThumbnail,
118 elementAttrs: { videoId: video1 }
119 }) 105 })
120 withThumbnailE1 = res2.body.videoPlaylistElement.id 106 withThumbnailE1 = added.id
121 107
122 await waitJobs(servers) 108 await waitJobs(servers)
123 109
@@ -130,19 +116,15 @@ describe('Playlist thumbnail', function () {
130 it('Should automatically update the thumbnail when moving the first element', async function () { 116 it('Should automatically update the thumbnail when moving the first element', async function () {
131 this.timeout(30000) 117 this.timeout(30000)
132 118
133 const res = await addVideoInPlaylist({ 119 const added = await servers[1].playlists.addElement({
134 url: servers[1].url, 120 playlistId: playlistWithoutThumbnailId,
135 token: servers[1].accessToken, 121 attributes: { videoId: video2 }
136 playlistId: playlistWithoutThumbnail,
137 elementAttrs: { videoId: video2 }
138 }) 122 })
139 withoutThumbnailE2 = res.body.videoPlaylistElement.id 123 withoutThumbnailE2 = added.id
140 124
141 await reorderVideosPlaylist({ 125 await servers[1].playlists.reorderElements({
142 url: servers[1].url, 126 playlistId: playlistWithoutThumbnailId,
143 token: servers[1].accessToken, 127 attributes: {
144 playlistId: playlistWithoutThumbnail,
145 elementAttrs: {
146 startPosition: 1, 128 startPosition: 1,
147 insertAfterPosition: 2 129 insertAfterPosition: 2
148 } 130 }
@@ -159,19 +141,15 @@ describe('Playlist thumbnail', function () {
159 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () { 141 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
160 this.timeout(30000) 142 this.timeout(30000)
161 143
162 const res = await addVideoInPlaylist({ 144 const added = await servers[1].playlists.addElement({
163 url: servers[1].url, 145 playlistId: playlistWithThumbnailId,
164 token: servers[1].accessToken, 146 attributes: { videoId: video2 }
165 playlistId: playlistWithThumbnail,
166 elementAttrs: { videoId: video2 }
167 }) 147 })
168 withThumbnailE2 = res.body.videoPlaylistElement.id 148 withThumbnailE2 = added.id
169 149
170 await reorderVideosPlaylist({ 150 await servers[1].playlists.reorderElements({
171 url: servers[1].url, 151 playlistId: playlistWithThumbnailId,
172 token: servers[1].accessToken, 152 attributes: {
173 playlistId: playlistWithThumbnail,
174 elementAttrs: {
175 startPosition: 1, 153 startPosition: 1,
176 insertAfterPosition: 2 154 insertAfterPosition: 2
177 } 155 }
@@ -188,11 +166,9 @@ describe('Playlist thumbnail', function () {
188 it('Should automatically update the thumbnail when deleting the first element', async function () { 166 it('Should automatically update the thumbnail when deleting the first element', async function () {
189 this.timeout(30000) 167 this.timeout(30000)
190 168
191 await removeVideoFromPlaylist({ 169 await servers[1].playlists.removeElement({
192 url: servers[1].url, 170 playlistId: playlistWithoutThumbnailId,
193 token: servers[1].accessToken, 171 elementId: withoutThumbnailE1
194 playlistId: playlistWithoutThumbnail,
195 playlistElementId: withoutThumbnailE1
196 }) 172 })
197 173
198 await waitJobs(servers) 174 await waitJobs(servers)
@@ -206,11 +182,9 @@ describe('Playlist thumbnail', function () {
206 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () { 182 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
207 this.timeout(30000) 183 this.timeout(30000)
208 184
209 await removeVideoFromPlaylist({ 185 await servers[1].playlists.removeElement({
210 url: servers[1].url, 186 playlistId: playlistWithThumbnailId,
211 token: servers[1].accessToken, 187 elementId: withThumbnailE1
212 playlistId: playlistWithThumbnail,
213 playlistElementId: withThumbnailE1
214 }) 188 })
215 189
216 await waitJobs(servers) 190 await waitJobs(servers)
@@ -224,11 +198,9 @@ describe('Playlist thumbnail', function () {
224 it('Should the thumbnail when we delete the last element', async function () { 198 it('Should the thumbnail when we delete the last element', async function () {
225 this.timeout(30000) 199 this.timeout(30000)
226 200
227 await removeVideoFromPlaylist({ 201 await servers[1].playlists.removeElement({
228 url: servers[1].url, 202 playlistId: playlistWithoutThumbnailId,
229 token: servers[1].accessToken, 203 elementId: withoutThumbnailE2
230 playlistId: playlistWithoutThumbnail,
231 playlistElementId: withoutThumbnailE2
232 }) 204 })
233 205
234 await waitJobs(servers) 206 await waitJobs(servers)
@@ -242,11 +214,9 @@ describe('Playlist thumbnail', function () {
242 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () { 214 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
243 this.timeout(30000) 215 this.timeout(30000)
244 216
245 await removeVideoFromPlaylist({ 217 await servers[1].playlists.removeElement({
246 url: servers[1].url, 218 playlistId: playlistWithThumbnailId,
247 token: servers[1].accessToken, 219 elementId: withThumbnailE2
248 playlistId: playlistWithThumbnail,
249 playlistElementId: withThumbnailE2
250 }) 220 })
251 221
252 await waitJobs(servers) 222 await waitJobs(servers)
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index da8de054b..f42aee2ff 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -2,71 +2,33 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 5import {
7 addVideoChannel,
8 addVideoInPlaylist,
9 addVideoToBlacklist,
10 checkPlaylistFilesWereRemoved, 6 checkPlaylistFilesWereRemoved,
11 cleanupTests, 7 cleanupTests,
12 createUser, 8 createMultipleServers,
13 createVideoPlaylist,
14 deleteVideoChannel,
15 deleteVideoPlaylist,
16 doubleFollow, 9 doubleFollow,
17 doVideosExistInMyPlaylist, 10 PeerTubeServer,
18 flushAndRunMultipleServers, 11 PlaylistsCommand,
19 generateUserAccessToken,
20 getAccessToken,
21 getAccountPlaylistsList,
22 getAccountPlaylistsListWithToken,
23 getMyUserInformation,
24 getPlaylistVideos,
25 getVideoChannelPlaylistsList,
26 getVideoPlaylist,
27 getVideoPlaylistPrivacies,
28 getVideoPlaylistsList,
29 getVideoPlaylistWithToken,
30 removeUser,
31 removeVideoFromBlacklist,
32 removeVideoFromPlaylist,
33 reorderVideosPlaylist,
34 ServerInfo,
35 setAccessTokensToServers, 12 setAccessTokensToServers,
36 setDefaultVideoChannel, 13 setDefaultVideoChannel,
37 testImage, 14 testImage,
38 unfollow,
39 updateVideo,
40 updateVideoPlaylist,
41 updateVideoPlaylistElement,
42 uploadVideo,
43 uploadVideoAndGetId,
44 userLogin,
45 wait, 15 wait,
46 waitJobs 16 waitJobs
47} from '../../../../shared/extra-utils' 17} from '@shared/extra-utils'
48import { 18import {
49 addAccountToAccountBlocklist, 19 HttpStatusCode,
50 addAccountToServerBlocklist, 20 VideoPlaylist,
51 addServerToAccountBlocklist, 21 VideoPlaylistCreateResult,
52 addServerToServerBlocklist, 22 VideoPlaylistElementType,
53 removeAccountFromAccountBlocklist, 23 VideoPlaylistPrivacy,
54 removeAccountFromServerBlocklist, 24 VideoPlaylistType,
55 removeServerFromAccountBlocklist, 25 VideoPrivacy
56 removeServerFromServerBlocklist 26} from '@shared/models'
57} from '../../../../shared/extra-utils/users/blocklist'
58import { User } from '../../../../shared/models/users'
59import { VideoPlaylistCreateResult, VideoPrivacy } from '../../../../shared/models/videos'
60import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
61import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../../shared/models/videos/playlist/video-playlist-element.model'
62import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
63import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
64import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
65 27
66const expect = chai.expect 28const expect = chai.expect
67 29
68async function checkPlaylistElementType ( 30async function checkPlaylistElementType (
69 servers: ServerInfo[], 31 servers: PeerTubeServer[],
70 playlistId: string, 32 playlistId: string,
71 type: VideoPlaylistElementType, 33 type: VideoPlaylistElementType,
72 position: number, 34 position: number,
@@ -74,10 +36,10 @@ async function checkPlaylistElementType (
74 total: number 36 total: number
75) { 37) {
76 for (const server of servers) { 38 for (const server of servers) {
77 const res = await getPlaylistVideos(server.url, server.accessToken, playlistId, 0, 10) 39 const body = await server.playlists.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 })
78 expect(res.body.total).to.equal(total) 40 expect(body.total).to.equal(total)
79 41
80 const videoElement: VideoPlaylistElement = res.body.data.find((e: VideoPlaylistElement) => e.position === position) 42 const videoElement = body.data.find(e => e.position === position)
81 expect(videoElement.type).to.equal(type, 'On server ' + server.url) 43 expect(videoElement.type).to.equal(type, 'On server ' + server.url)
82 44
83 if (type === VideoPlaylistElementType.REGULAR) { 45 if (type === VideoPlaylistElementType.REGULAR) {
@@ -90,11 +52,11 @@ async function checkPlaylistElementType (
90} 52}
91 53
92describe('Test video playlists', function () { 54describe('Test video playlists', function () {
93 let servers: ServerInfo[] = [] 55 let servers: PeerTubeServer[] = []
94 56
95 let playlistServer2Id1: number 57 let playlistServer2Id1: number
96 let playlistServer2Id2: number 58 let playlistServer2Id2: number
97 let playlistServer2UUID2: number 59 let playlistServer2UUID2: string
98 60
99 let playlistServer1Id: number 61 let playlistServer1Id: number
100 let playlistServer1UUID: string 62 let playlistServer1UUID: string
@@ -106,12 +68,14 @@ describe('Test video playlists', function () {
106 68
107 let nsfwVideoServer1: number 69 let nsfwVideoServer1: number
108 70
109 let userAccessTokenServer1: string 71 let userTokenServer1: string
72
73 let commands: PlaylistsCommand[]
110 74
111 before(async function () { 75 before(async function () {
112 this.timeout(120000) 76 this.timeout(120000)
113 77
114 servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } }) 78 servers = await createMultipleServers(3, { transcoding: { enabled: false } })
115 79
116 // Get the access tokens 80 // Get the access tokens
117 await setAccessTokensToServers(servers) 81 await setAccessTokensToServers(servers)
@@ -122,86 +86,78 @@ describe('Test video playlists', function () {
122 // Server 1 and server 3 follow each other 86 // Server 1 and server 3 follow each other
123 await doubleFollow(servers[0], servers[2]) 87 await doubleFollow(servers[0], servers[2])
124 88
89 commands = servers.map(s => s.playlists)
90
125 { 91 {
126 servers[0].videos = [] 92 servers[0].store.videos = []
127 servers[1].videos = [] 93 servers[1].store.videos = []
128 servers[2].videos = [] 94 servers[2].store.videos = []
129 95
130 for (const server of servers) { 96 for (const server of servers) {
131 for (let i = 0; i < 7; i++) { 97 for (let i = 0; i < 7; i++) {
132 const name = `video ${i} server ${server.serverNumber}` 98 const name = `video ${i} server ${server.serverNumber}`
133 const resVideo = await uploadVideo(server.url, server.accessToken, { name, nsfw: false }) 99 const video = await server.videos.upload({ attributes: { name, nsfw: false } })
134 100
135 server.videos.push(resVideo.body.video) 101 server.store.videos.push(video)
136 } 102 }
137 } 103 }
138 } 104 }
139 105
140 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id 106 nsfwVideoServer1 = (await servers[0].videos.quickUpload({ name: 'NSFW video', nsfw: true })).id
141 107
142 { 108 userTokenServer1 = await servers[0].users.generateUserAndToken('user1')
143 await createUser({
144 url: servers[0].url,
145 accessToken: servers[0].accessToken,
146 username: 'user1',
147 password: 'password'
148 })
149 userAccessTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password')
150 }
151 109
152 await waitJobs(servers) 110 await waitJobs(servers)
153 }) 111 })
154 112
155 describe('Get default playlists', function () { 113 describe('Get default playlists', function () {
114
156 it('Should list video playlist privacies', async function () { 115 it('Should list video playlist privacies', async function () {
157 const res = await getVideoPlaylistPrivacies(servers[0].url) 116 const privacies = await commands[0].getPrivacies()
158 117
159 const privacies = res.body
160 expect(Object.keys(privacies)).to.have.length.at.least(3) 118 expect(Object.keys(privacies)).to.have.length.at.least(3)
161
162 expect(privacies[3]).to.equal('Private') 119 expect(privacies[3]).to.equal('Private')
163 }) 120 })
164 121
165 it('Should list watch later playlist', async function () { 122 it('Should list watch later playlist', async function () {
166 const url = servers[0].url 123 const token = servers[0].accessToken
167 const accessToken = servers[0].accessToken
168 124
169 { 125 {
170 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER) 126 const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.WATCH_LATER })
171 127
172 expect(res.body.total).to.equal(1) 128 expect(body.total).to.equal(1)
173 expect(res.body.data).to.have.lengthOf(1) 129 expect(body.data).to.have.lengthOf(1)
174 130
175 const playlist: VideoPlaylist = res.body.data[0] 131 const playlist = body.data[0]
176 expect(playlist.displayName).to.equal('Watch later') 132 expect(playlist.displayName).to.equal('Watch later')
177 expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER) 133 expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER)
178 expect(playlist.type.label).to.equal('Watch later') 134 expect(playlist.type.label).to.equal('Watch later')
179 } 135 }
180 136
181 { 137 {
182 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR) 138 const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.REGULAR })
183 139
184 expect(res.body.total).to.equal(0) 140 expect(body.total).to.equal(0)
185 expect(res.body.data).to.have.lengthOf(0) 141 expect(body.data).to.have.lengthOf(0)
186 } 142 }
187 143
188 { 144 {
189 const res = await getAccountPlaylistsList(url, 'root', 0, 5) 145 const body = await commands[0].listByAccount({ handle: 'root' })
190 expect(res.body.total).to.equal(0) 146 expect(body.total).to.equal(0)
191 expect(res.body.data).to.have.lengthOf(0) 147 expect(body.data).to.have.lengthOf(0)
192 } 148 }
193 }) 149 })
194 150
195 it('Should get private playlist for a classic user', async function () { 151 it('Should get private playlist for a classic user', async function () {
196 const token = await generateUserAccessToken(servers[0], 'toto') 152 const token = await servers[0].users.generateUserAndToken('toto')
197 153
198 const res = await getAccountPlaylistsListWithToken(servers[0].url, token, 'toto', 0, 5) 154 const body = await commands[0].listByAccount({ token, handle: 'toto' })
199 155
200 expect(res.body.total).to.equal(1) 156 expect(body.total).to.equal(1)
201 expect(res.body.data).to.have.lengthOf(1) 157 expect(body.data).to.have.lengthOf(1)
202 158
203 const playlistId = res.body.data[0].id 159 const playlistId = body.data[0].id
204 await getPlaylistVideos(servers[0].url, token, playlistId, 0, 5) 160 await commands[0].listVideos({ token, playlistId })
205 }) 161 })
206 }) 162 })
207 163
@@ -210,15 +166,13 @@ describe('Test video playlists', function () {
210 it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () { 166 it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
211 this.timeout(30000) 167 this.timeout(30000)
212 168
213 await createVideoPlaylist({ 169 await commands[0].create({
214 url: servers[0].url, 170 attributes: {
215 token: servers[0].accessToken,
216 playlistAttrs: {
217 displayName: 'my super playlist', 171 displayName: 'my super playlist',
218 privacy: VideoPlaylistPrivacy.PUBLIC, 172 privacy: VideoPlaylistPrivacy.PUBLIC,
219 description: 'my super description', 173 description: 'my super description',
220 thumbnailfile: 'thumbnail.jpg', 174 thumbnailfile: 'thumbnail.jpg',
221 videoChannelId: servers[0].videoChannel.id 175 videoChannelId: servers[0].store.channel.id
222 } 176 }
223 }) 177 })
224 178
@@ -227,14 +181,13 @@ describe('Test video playlists', function () {
227 await wait(3000) 181 await wait(3000)
228 182
229 for (const server of servers) { 183 for (const server of servers) {
230 const res = await getVideoPlaylistsList(server.url, 0, 5) 184 const body = await server.playlists.list({ start: 0, count: 5 })
231 expect(res.body.total).to.equal(1) 185 expect(body.total).to.equal(1)
232 expect(res.body.data).to.have.lengthOf(1) 186 expect(body.data).to.have.lengthOf(1)
233 187
234 const playlistFromList = res.body.data[0] as VideoPlaylist 188 const playlistFromList = body.data[0]
235 189
236 const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid) 190 const playlistFromGet = await server.playlists.get({ playlistId: playlistFromList.uuid })
237 const playlistFromGet = res2.body as VideoPlaylist
238 191
239 for (const playlist of [ playlistFromGet, playlistFromList ]) { 192 for (const playlist of [ playlistFromGet, playlistFromList ]) {
240 expect(playlist.id).to.be.a('number') 193 expect(playlist.id).to.be.a('number')
@@ -264,46 +217,38 @@ describe('Test video playlists', function () {
264 this.timeout(30000) 217 this.timeout(30000)
265 218
266 { 219 {
267 const res = await createVideoPlaylist({ 220 const playlist = await servers[1].playlists.create({
268 url: servers[1].url, 221 attributes: {
269 token: servers[1].accessToken,
270 playlistAttrs: {
271 displayName: 'playlist 2', 222 displayName: 'playlist 2',
272 privacy: VideoPlaylistPrivacy.PUBLIC, 223 privacy: VideoPlaylistPrivacy.PUBLIC,
273 videoChannelId: servers[1].videoChannel.id 224 videoChannelId: servers[1].store.channel.id
274 } 225 }
275 }) 226 })
276 playlistServer2Id1 = res.body.videoPlaylist.id 227 playlistServer2Id1 = playlist.id
277 } 228 }
278 229
279 { 230 {
280 const res = await createVideoPlaylist({ 231 const playlist = await servers[1].playlists.create({
281 url: servers[1].url, 232 attributes: {
282 token: servers[1].accessToken,
283 playlistAttrs: {
284 displayName: 'playlist 3', 233 displayName: 'playlist 3',
285 privacy: VideoPlaylistPrivacy.PUBLIC, 234 privacy: VideoPlaylistPrivacy.PUBLIC,
286 thumbnailfile: 'thumbnail.jpg', 235 thumbnailfile: 'thumbnail.jpg',
287 videoChannelId: servers[1].videoChannel.id 236 videoChannelId: servers[1].store.channel.id
288 } 237 }
289 }) 238 })
290 239
291 playlistServer2Id2 = res.body.videoPlaylist.id 240 playlistServer2Id2 = playlist.id
292 playlistServer2UUID2 = res.body.videoPlaylist.uuid 241 playlistServer2UUID2 = playlist.uuid
293 } 242 }
294 243
295 for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) { 244 for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) {
296 await addVideoInPlaylist({ 245 await servers[1].playlists.addElement({
297 url: servers[1].url,
298 token: servers[1].accessToken,
299 playlistId: id, 246 playlistId: id,
300 elementAttrs: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 } 247 attributes: { videoId: servers[1].store.videos[0].id, startTimestamp: 1, stopTimestamp: 2 }
301 }) 248 })
302 await addVideoInPlaylist({ 249 await servers[1].playlists.addElement({
303 url: servers[1].url,
304 token: servers[1].accessToken,
305 playlistId: id, 250 playlistId: id,
306 elementAttrs: { videoId: servers[1].videos[1].id } 251 attributes: { videoId: servers[1].store.videos[1].id }
307 }) 252 })
308 } 253 }
309 254
@@ -311,20 +256,20 @@ describe('Test video playlists', function () {
311 await wait(3000) 256 await wait(3000)
312 257
313 for (const server of [ servers[0], servers[1] ]) { 258 for (const server of [ servers[0], servers[1] ]) {
314 const res = await getVideoPlaylistsList(server.url, 0, 5) 259 const body = await server.playlists.list({ start: 0, count: 5 })
315 260
316 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2') 261 const playlist2 = body.data.find(p => p.displayName === 'playlist 2')
317 expect(playlist2).to.not.be.undefined 262 expect(playlist2).to.not.be.undefined
318 await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath) 263 await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath)
319 264
320 const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3') 265 const playlist3 = body.data.find(p => p.displayName === 'playlist 3')
321 expect(playlist3).to.not.be.undefined 266 expect(playlist3).to.not.be.undefined
322 await testImage(server.url, 'thumbnail', playlist3.thumbnailPath) 267 await testImage(server.url, 'thumbnail', playlist3.thumbnailPath)
323 } 268 }
324 269
325 const res = await getVideoPlaylistsList(servers[2].url, 0, 5) 270 const body = await servers[2].playlists.list({ start: 0, count: 5 })
326 expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined 271 expect(body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined
327 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined 272 expect(body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined
328 }) 273 })
329 274
330 it('Should have the playlist on server 3 after a new follow', async function () { 275 it('Should have the playlist on server 3 after a new follow', async function () {
@@ -333,13 +278,13 @@ describe('Test video playlists', function () {
333 // Server 2 and server 3 follow each other 278 // Server 2 and server 3 follow each other
334 await doubleFollow(servers[1], servers[2]) 279 await doubleFollow(servers[1], servers[2])
335 280
336 const res = await getVideoPlaylistsList(servers[2].url, 0, 5) 281 const body = await servers[2].playlists.list({ start: 0, count: 5 })
337 282
338 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2') 283 const playlist2 = body.data.find(p => p.displayName === 'playlist 2')
339 expect(playlist2).to.not.be.undefined 284 expect(playlist2).to.not.be.undefined
340 await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath) 285 await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath)
341 286
342 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined 287 expect(body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
343 }) 288 })
344 }) 289 })
345 290
@@ -349,22 +294,20 @@ describe('Test video playlists', function () {
349 this.timeout(30000) 294 this.timeout(30000)
350 295
351 { 296 {
352 const res = await getVideoPlaylistsList(servers[2].url, 1, 2, 'createdAt') 297 const body = await servers[2].playlists.list({ start: 1, count: 2, sort: 'createdAt' })
353 298 expect(body.total).to.equal(3)
354 expect(res.body.total).to.equal(3)
355 299
356 const data: VideoPlaylist[] = res.body.data 300 const data = body.data
357 expect(data).to.have.lengthOf(2) 301 expect(data).to.have.lengthOf(2)
358 expect(data[0].displayName).to.equal('playlist 2') 302 expect(data[0].displayName).to.equal('playlist 2')
359 expect(data[1].displayName).to.equal('playlist 3') 303 expect(data[1].displayName).to.equal('playlist 3')
360 } 304 }
361 305
362 { 306 {
363 const res = await getVideoPlaylistsList(servers[2].url, 1, 2, '-createdAt') 307 const body = await servers[2].playlists.list({ start: 1, count: 2, sort: '-createdAt' })
308 expect(body.total).to.equal(3)
364 309
365 expect(res.body.total).to.equal(3) 310 const data = body.data
366
367 const data: VideoPlaylist[] = res.body.data
368 expect(data).to.have.lengthOf(2) 311 expect(data).to.have.lengthOf(2)
369 expect(data[0].displayName).to.equal('playlist 2') 312 expect(data[0].displayName).to.equal('playlist 2')
370 expect(data[1].displayName).to.equal('my super playlist') 313 expect(data[1].displayName).to.equal('my super playlist')
@@ -375,11 +318,10 @@ describe('Test video playlists', function () {
375 this.timeout(30000) 318 this.timeout(30000)
376 319
377 { 320 {
378 const res = await getVideoChannelPlaylistsList(servers[0].url, 'root_channel', 0, 2, '-createdAt') 321 const body = await commands[0].listByChannel({ handle: 'root_channel', start: 0, count: 2, sort: '-createdAt' })
379 322 expect(body.total).to.equal(1)
380 expect(res.body.total).to.equal(1)
381 323
382 const data: VideoPlaylist[] = res.body.data 324 const data = body.data
383 expect(data).to.have.lengthOf(1) 325 expect(data).to.have.lengthOf(1)
384 expect(data[0].displayName).to.equal('my super playlist') 326 expect(data[0].displayName).to.equal('my super playlist')
385 } 327 }
@@ -389,41 +331,37 @@ describe('Test video playlists', function () {
389 this.timeout(30000) 331 this.timeout(30000)
390 332
391 { 333 {
392 const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, '-createdAt') 334 const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' })
335 expect(body.total).to.equal(2)
393 336
394 expect(res.body.total).to.equal(2) 337 const data = body.data
395
396 const data: VideoPlaylist[] = res.body.data
397 expect(data).to.have.lengthOf(1) 338 expect(data).to.have.lengthOf(1)
398 expect(data[0].displayName).to.equal('playlist 2') 339 expect(data[0].displayName).to.equal('playlist 2')
399 } 340 }
400 341
401 { 342 {
402 const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, 'createdAt') 343 const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' })
403 344 expect(body.total).to.equal(2)
404 expect(res.body.total).to.equal(2)
405 345
406 const data: VideoPlaylist[] = res.body.data 346 const data = body.data
407 expect(data).to.have.lengthOf(1) 347 expect(data).to.have.lengthOf(1)
408 expect(data[0].displayName).to.equal('playlist 3') 348 expect(data[0].displayName).to.equal('playlist 3')
409 } 349 }
410 350
411 { 351 {
412 const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '3') 352 const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' })
353 expect(body.total).to.equal(1)
413 354
414 expect(res.body.total).to.equal(1) 355 const data = body.data
415
416 const data: VideoPlaylist[] = res.body.data
417 expect(data).to.have.lengthOf(1) 356 expect(data).to.have.lengthOf(1)
418 expect(data[0].displayName).to.equal('playlist 3') 357 expect(data[0].displayName).to.equal('playlist 3')
419 } 358 }
420 359
421 { 360 {
422 const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '4') 361 const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' })
423 362 expect(body.total).to.equal(0)
424 expect(res.body.total).to.equal(0)
425 363
426 const data: VideoPlaylist[] = res.body.data 364 const data = body.data
427 expect(data).to.have.lengthOf(0) 365 expect(data).to.have.lengthOf(0)
428 } 366 }
429 }) 367 })
@@ -437,28 +375,22 @@ describe('Test video playlists', function () {
437 this.timeout(30000) 375 this.timeout(30000)
438 376
439 { 377 {
440 const res = await createVideoPlaylist({ 378 unlistedPlaylist = await servers[1].playlists.create({
441 url: servers[1].url, 379 attributes: {
442 token: servers[1].accessToken,
443 playlistAttrs: {
444 displayName: 'playlist unlisted', 380 displayName: 'playlist unlisted',
445 privacy: VideoPlaylistPrivacy.UNLISTED, 381 privacy: VideoPlaylistPrivacy.UNLISTED,
446 videoChannelId: servers[1].videoChannel.id 382 videoChannelId: servers[1].store.channel.id
447 } 383 }
448 }) 384 })
449 unlistedPlaylist = res.body.videoPlaylist
450 } 385 }
451 386
452 { 387 {
453 const res = await createVideoPlaylist({ 388 privatePlaylist = await servers[1].playlists.create({
454 url: servers[1].url, 389 attributes: {
455 token: servers[1].accessToken,
456 playlistAttrs: {
457 displayName: 'playlist private', 390 displayName: 'playlist private',
458 privacy: VideoPlaylistPrivacy.PRIVATE 391 privacy: VideoPlaylistPrivacy.PRIVATE
459 } 392 }
460 }) 393 })
461 privatePlaylist = res.body.videoPlaylist
462 } 394 }
463 395
464 await waitJobs(servers) 396 await waitJobs(servers)
@@ -468,15 +400,15 @@ describe('Test video playlists', function () {
468 it('Should not list unlisted or private playlists', async function () { 400 it('Should not list unlisted or private playlists', async function () {
469 for (const server of servers) { 401 for (const server of servers) {
470 const results = [ 402 const results = [
471 await getAccountPlaylistsList(server.url, 'root@localhost:' + servers[1].port, 0, 5, '-createdAt'), 403 await server.playlists.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }),
472 await getVideoPlaylistsList(server.url, 0, 2, '-createdAt') 404 await server.playlists.list({ start: 0, count: 2, sort: '-createdAt' })
473 ] 405 ]
474 406
475 expect(results[0].body.total).to.equal(2) 407 expect(results[0].total).to.equal(2)
476 expect(results[1].body.total).to.equal(3) 408 expect(results[1].total).to.equal(3)
477 409
478 for (const res of results) { 410 for (const body of results) {
479 const data: VideoPlaylist[] = res.body.data 411 const data = body.data
480 expect(data).to.have.lengthOf(2) 412 expect(data).to.have.lengthOf(2)
481 expect(data[0].displayName).to.equal('playlist 3') 413 expect(data[0].displayName).to.equal('playlist 3')
482 expect(data[1].displayName).to.equal('playlist 2') 414 expect(data[1].displayName).to.equal('playlist 2')
@@ -485,23 +417,23 @@ describe('Test video playlists', function () {
485 }) 417 })
486 418
487 it('Should not get unlisted playlist using only the id', async function () { 419 it('Should not get unlisted playlist using only the id', async function () {
488 await getVideoPlaylist(servers[1].url, unlistedPlaylist.id, 404) 420 await servers[1].playlists.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 })
489 }) 421 })
490 422
491 it('Should get unlisted plyaylist using uuid or shortUUID', async function () { 423 it('Should get unlisted plyaylist using uuid or shortUUID', async function () {
492 await getVideoPlaylist(servers[1].url, unlistedPlaylist.uuid) 424 await servers[1].playlists.get({ playlistId: unlistedPlaylist.uuid })
493 await getVideoPlaylist(servers[1].url, unlistedPlaylist.shortUUID) 425 await servers[1].playlists.get({ playlistId: unlistedPlaylist.shortUUID })
494 }) 426 })
495 427
496 it('Should not get private playlist without token', async function () { 428 it('Should not get private playlist without token', async function () {
497 for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { 429 for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) {
498 await getVideoPlaylist(servers[1].url, id, 401) 430 await servers[1].playlists.get({ playlistId: id, expectedStatus: 401 })
499 } 431 }
500 }) 432 })
501 433
502 it('Should get private playlist with a token', async function () { 434 it('Should get private playlist with a token', async function () {
503 for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { 435 for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) {
504 await getVideoPlaylistWithToken(servers[1].url, servers[1].accessToken, id) 436 await servers[1].playlists.get({ token: servers[1].accessToken, playlistId: id })
505 } 437 }
506 }) 438 })
507 }) 439 })
@@ -511,15 +443,13 @@ describe('Test video playlists', function () {
511 it('Should update a playlist', async function () { 443 it('Should update a playlist', async function () {
512 this.timeout(30000) 444 this.timeout(30000)
513 445
514 await updateVideoPlaylist({ 446 await servers[1].playlists.update({
515 url: servers[1].url, 447 attributes: {
516 token: servers[1].accessToken,
517 playlistAttrs: {
518 displayName: 'playlist 3 updated', 448 displayName: 'playlist 3 updated',
519 description: 'description updated', 449 description: 'description updated',
520 privacy: VideoPlaylistPrivacy.UNLISTED, 450 privacy: VideoPlaylistPrivacy.UNLISTED,
521 thumbnailfile: 'thumbnail.jpg', 451 thumbnailfile: 'thumbnail.jpg',
522 videoChannelId: servers[1].videoChannel.id 452 videoChannelId: servers[1].store.channel.id
523 }, 453 },
524 playlistId: playlistServer2Id2 454 playlistId: playlistServer2Id2
525 }) 455 })
@@ -527,8 +457,7 @@ describe('Test video playlists', function () {
527 await waitJobs(servers) 457 await waitJobs(servers)
528 458
529 for (const server of servers) { 459 for (const server of servers) {
530 const res = await getVideoPlaylist(server.url, playlistServer2UUID2) 460 const playlist = await server.playlists.get({ playlistId: playlistServer2UUID2 })
531 const playlist: VideoPlaylist = res.body
532 461
533 expect(playlist.displayName).to.equal('playlist 3 updated') 462 expect(playlist.displayName).to.equal('playlist 3 updated')
534 expect(playlist.description).to.equal('description updated') 463 expect(playlist.description).to.equal('description updated')
@@ -554,39 +483,37 @@ describe('Test video playlists', function () {
554 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () { 483 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
555 this.timeout(30000) 484 this.timeout(30000)
556 485
557 const addVideo = (elementAttrs: any) => { 486 const addVideo = (attributes: any) => {
558 return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs }) 487 return commands[0].addElement({ playlistId: playlistServer1Id, attributes })
559 } 488 }
560 489
561 const res = await createVideoPlaylist({ 490 const playlist = await commands[0].create({
562 url: servers[0].url, 491 attributes: {
563 token: servers[0].accessToken,
564 playlistAttrs: {
565 displayName: 'playlist 4', 492 displayName: 'playlist 4',
566 privacy: VideoPlaylistPrivacy.PUBLIC, 493 privacy: VideoPlaylistPrivacy.PUBLIC,
567 videoChannelId: servers[0].videoChannel.id 494 videoChannelId: servers[0].store.channel.id
568 } 495 }
569 }) 496 })
570 497
571 playlistServer1Id = res.body.videoPlaylist.id 498 playlistServer1Id = playlist.id
572 playlistServer1UUID = res.body.videoPlaylist.uuid 499 playlistServer1UUID = playlist.uuid
573 500
574 await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) 501 await addVideo({ videoId: servers[0].store.videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 })
575 await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 }) 502 await addVideo({ videoId: servers[2].store.videos[1].uuid, startTimestamp: 35 })
576 await addVideo({ videoId: servers[2].videos[2].uuid }) 503 await addVideo({ videoId: servers[2].store.videos[2].uuid })
577 { 504 {
578 const res = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 }) 505 const element = await addVideo({ videoId: servers[0].store.videos[3].uuid, stopTimestamp: 35 })
579 playlistElementServer1Video4 = res.body.videoPlaylistElement.id 506 playlistElementServer1Video4 = element.id
580 } 507 }
581 508
582 { 509 {
583 const res = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) 510 const element = await addVideo({ videoId: servers[0].store.videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 })
584 playlistElementServer1Video5 = res.body.videoPlaylistElement.id 511 playlistElementServer1Video5 = element.id
585 } 512 }
586 513
587 { 514 {
588 const res = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 }) 515 const element = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 })
589 playlistElementNSFW = res.body.videoPlaylistElement.id 516 playlistElementNSFW = element.id
590 517
591 await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 4 }) 518 await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 4 })
592 await addVideo({ videoId: nsfwVideoServer1 }) 519 await addVideo({ videoId: nsfwVideoServer1 })
@@ -599,64 +526,68 @@ describe('Test video playlists', function () {
599 this.timeout(30000) 526 this.timeout(30000)
600 527
601 for (const server of servers) { 528 for (const server of servers) {
602 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) 529 {
603 530 const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
604 expect(res.body.total).to.equal(8) 531
605 532 expect(body.total).to.equal(8)
606 const videoElements: VideoPlaylistElement[] = res.body.data 533
607 expect(videoElements).to.have.lengthOf(8) 534 const videoElements = body.data
608 535 expect(videoElements).to.have.lengthOf(8)
609 expect(videoElements[0].video.name).to.equal('video 0 server 1') 536
610 expect(videoElements[0].position).to.equal(1) 537 expect(videoElements[0].video.name).to.equal('video 0 server 1')
611 expect(videoElements[0].startTimestamp).to.equal(15) 538 expect(videoElements[0].position).to.equal(1)
612 expect(videoElements[0].stopTimestamp).to.equal(28) 539 expect(videoElements[0].startTimestamp).to.equal(15)
613 540 expect(videoElements[0].stopTimestamp).to.equal(28)
614 expect(videoElements[1].video.name).to.equal('video 1 server 3') 541
615 expect(videoElements[1].position).to.equal(2) 542 expect(videoElements[1].video.name).to.equal('video 1 server 3')
616 expect(videoElements[1].startTimestamp).to.equal(35) 543 expect(videoElements[1].position).to.equal(2)
617 expect(videoElements[1].stopTimestamp).to.be.null 544 expect(videoElements[1].startTimestamp).to.equal(35)
618 545 expect(videoElements[1].stopTimestamp).to.be.null
619 expect(videoElements[2].video.name).to.equal('video 2 server 3') 546
620 expect(videoElements[2].position).to.equal(3) 547 expect(videoElements[2].video.name).to.equal('video 2 server 3')
621 expect(videoElements[2].startTimestamp).to.be.null 548 expect(videoElements[2].position).to.equal(3)
622 expect(videoElements[2].stopTimestamp).to.be.null 549 expect(videoElements[2].startTimestamp).to.be.null
623 550 expect(videoElements[2].stopTimestamp).to.be.null
624 expect(videoElements[3].video.name).to.equal('video 3 server 1') 551
625 expect(videoElements[3].position).to.equal(4) 552 expect(videoElements[3].video.name).to.equal('video 3 server 1')
626 expect(videoElements[3].startTimestamp).to.be.null 553 expect(videoElements[3].position).to.equal(4)
627 expect(videoElements[3].stopTimestamp).to.equal(35) 554 expect(videoElements[3].startTimestamp).to.be.null
628 555 expect(videoElements[3].stopTimestamp).to.equal(35)
629 expect(videoElements[4].video.name).to.equal('video 4 server 1') 556
630 expect(videoElements[4].position).to.equal(5) 557 expect(videoElements[4].video.name).to.equal('video 4 server 1')
631 expect(videoElements[4].startTimestamp).to.equal(45) 558 expect(videoElements[4].position).to.equal(5)
632 expect(videoElements[4].stopTimestamp).to.equal(60) 559 expect(videoElements[4].startTimestamp).to.equal(45)
633 560 expect(videoElements[4].stopTimestamp).to.equal(60)
634 expect(videoElements[5].video.name).to.equal('NSFW video') 561
635 expect(videoElements[5].position).to.equal(6) 562 expect(videoElements[5].video.name).to.equal('NSFW video')
636 expect(videoElements[5].startTimestamp).to.equal(5) 563 expect(videoElements[5].position).to.equal(6)
637 expect(videoElements[5].stopTimestamp).to.be.null 564 expect(videoElements[5].startTimestamp).to.equal(5)
638 565 expect(videoElements[5].stopTimestamp).to.be.null
639 expect(videoElements[6].video.name).to.equal('NSFW video') 566
640 expect(videoElements[6].position).to.equal(7) 567 expect(videoElements[6].video.name).to.equal('NSFW video')
641 expect(videoElements[6].startTimestamp).to.equal(4) 568 expect(videoElements[6].position).to.equal(7)
642 expect(videoElements[6].stopTimestamp).to.be.null 569 expect(videoElements[6].startTimestamp).to.equal(4)
643 570 expect(videoElements[6].stopTimestamp).to.be.null
644 expect(videoElements[7].video.name).to.equal('NSFW video') 571
645 expect(videoElements[7].position).to.equal(8) 572 expect(videoElements[7].video.name).to.equal('NSFW video')
646 expect(videoElements[7].startTimestamp).to.be.null 573 expect(videoElements[7].position).to.equal(8)
647 expect(videoElements[7].stopTimestamp).to.be.null 574 expect(videoElements[7].startTimestamp).to.be.null
648 575 expect(videoElements[7].stopTimestamp).to.be.null
649 const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2) 576 }
650 expect(res3.body.data).to.have.lengthOf(2) 577
578 {
579 const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 })
580 expect(body.data).to.have.lengthOf(2)
581 }
651 } 582 }
652 }) 583 })
653 }) 584 })
654 585
655 describe('Element type', function () { 586 describe('Element type', function () {
656 let groupUser1: ServerInfo[] 587 let groupUser1: PeerTubeServer[]
657 let groupWithoutToken1: ServerInfo[] 588 let groupWithoutToken1: PeerTubeServer[]
658 let group1: ServerInfo[] 589 let group1: PeerTubeServer[]
659 let group2: ServerInfo[] 590 let group2: PeerTubeServer[]
660 591
661 let video1: string 592 let video1: string
662 let video2: string 593 let video2: string
@@ -665,31 +596,30 @@ describe('Test video playlists', function () {
665 before(async function () { 596 before(async function () {
666 this.timeout(60000) 597 this.timeout(60000)
667 598
668 groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ] 599 groupUser1 = [ Object.assign({}, servers[0], { accessToken: userTokenServer1 }) ]
669 groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ] 600 groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ]
670 group1 = [ servers[0] ] 601 group1 = [ servers[0] ]
671 group2 = [ servers[1], servers[2] ] 602 group2 = [ servers[1], servers[2] ]
672 603
673 const res = await createVideoPlaylist({ 604 const playlist = await commands[0].create({
674 url: servers[0].url, 605 token: userTokenServer1,
675 token: userAccessTokenServer1, 606 attributes: {
676 playlistAttrs: {
677 displayName: 'playlist 56', 607 displayName: 'playlist 56',
678 privacy: VideoPlaylistPrivacy.PUBLIC, 608 privacy: VideoPlaylistPrivacy.PUBLIC,
679 videoChannelId: servers[0].videoChannel.id 609 videoChannelId: servers[0].store.channel.id
680 } 610 }
681 }) 611 })
682 612
683 const playlistServer1Id2 = res.body.videoPlaylist.id 613 const playlistServer1Id2 = playlist.id
684 playlistServer1UUID2 = res.body.videoPlaylist.uuid 614 playlistServer1UUID2 = playlist.uuid
685 615
686 const addVideo = (elementAttrs: any) => { 616 const addVideo = (attributes: any) => {
687 return addVideoInPlaylist({ url: servers[0].url, token: userAccessTokenServer1, playlistId: playlistServer1Id2, elementAttrs }) 617 return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes })
688 } 618 }
689 619
690 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userAccessTokenServer1 })).uuid 620 video1 = (await servers[0].videos.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid
691 video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid 621 video2 = (await servers[1].videos.quickUpload({ name: 'video 90' })).uuid
692 video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid 622 video3 = (await servers[0].videos.quickUpload({ name: 'video 91', nsfw: true })).uuid
693 623
694 await waitJobs(servers) 624 await waitJobs(servers)
695 625
@@ -707,7 +637,7 @@ describe('Test video playlists', function () {
707 const position = 1 637 const position = 1
708 638
709 { 639 {
710 await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE }) 640 await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } })
711 await waitJobs(servers) 641 await waitJobs(servers)
712 642
713 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 643 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
@@ -717,7 +647,7 @@ describe('Test video playlists', function () {
717 } 647 }
718 648
719 { 649 {
720 await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC }) 650 await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } })
721 await waitJobs(servers) 651 await waitJobs(servers)
722 652
723 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 653 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
@@ -735,7 +665,7 @@ describe('Test video playlists', function () {
735 const position = 1 665 const position = 1
736 666
737 { 667 {
738 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video1, 'reason', true) 668 await servers[0].blacklist.add({ videoId: video1, reason: 'reason', unfederate: true })
739 await waitJobs(servers) 669 await waitJobs(servers)
740 670
741 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 671 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
@@ -745,7 +675,7 @@ describe('Test video playlists', function () {
745 } 675 }
746 676
747 { 677 {
748 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video1) 678 await servers[0].blacklist.remove({ videoId: video1 })
749 await waitJobs(servers) 679 await waitJobs(servers)
750 680
751 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 681 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
@@ -759,56 +689,58 @@ describe('Test video playlists', function () {
759 it('Should update the element type if the account or server of the video is blocked', async function () { 689 it('Should update the element type if the account or server of the video is blocked', async function () {
760 this.timeout(90000) 690 this.timeout(90000)
761 691
692 const command = servers[0].blocklist
693
762 const name = 'video 90' 694 const name = 'video 90'
763 const position = 2 695 const position = 2
764 696
765 { 697 {
766 await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) 698 await command.addToMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port })
767 await waitJobs(servers) 699 await waitJobs(servers)
768 700
769 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) 701 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
770 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 702 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
771 703
772 await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) 704 await command.removeFromMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port })
773 await waitJobs(servers) 705 await waitJobs(servers)
774 706
775 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 707 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
776 } 708 }
777 709
778 { 710 {
779 await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) 711 await command.addToMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port })
780 await waitJobs(servers) 712 await waitJobs(servers)
781 713
782 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) 714 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
783 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 715 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
784 716
785 await removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) 717 await command.removeFromMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port })
786 await waitJobs(servers) 718 await waitJobs(servers)
787 719
788 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 720 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
789 } 721 }
790 722
791 { 723 {
792 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) 724 await command.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
793 await waitJobs(servers) 725 await waitJobs(servers)
794 726
795 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) 727 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
796 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 728 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
797 729
798 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) 730 await command.removeFromServerBlocklist({ account: 'root@localhost:' + servers[1].port })
799 await waitJobs(servers) 731 await waitJobs(servers)
800 732
801 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 733 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
802 } 734 }
803 735
804 { 736 {
805 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) 737 await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
806 await waitJobs(servers) 738 await waitJobs(servers)
807 739
808 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) 740 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
809 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 741 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
810 742
811 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) 743 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
812 await waitJobs(servers) 744 await waitJobs(servers)
813 745
814 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 746 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
@@ -816,10 +748,10 @@ describe('Test video playlists', function () {
816 }) 748 })
817 749
818 it('Should hide the video if it is NSFW', async function () { 750 it('Should hide the video if it is NSFW', async function () {
819 const res = await getPlaylistVideos(servers[0].url, userAccessTokenServer1, playlistServer1UUID2, 0, 10, { nsfw: false }) 751 const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } })
820 expect(res.body.total).to.equal(3) 752 expect(body.total).to.equal(3)
821 753
822 const elements: VideoPlaylistElement[] = res.body.data 754 const elements = body.data
823 const element = elements.find(e => e.position === 3) 755 const element = elements.find(e => e.position === 3)
824 756
825 expect(element).to.exist 757 expect(element).to.exist
@@ -835,11 +767,9 @@ describe('Test video playlists', function () {
835 this.timeout(30000) 767 this.timeout(30000)
836 768
837 { 769 {
838 await reorderVideosPlaylist({ 770 await commands[0].reorderElements({
839 url: servers[0].url,
840 token: servers[0].accessToken,
841 playlistId: playlistServer1Id, 771 playlistId: playlistServer1Id,
842 elementAttrs: { 772 attributes: {
843 startPosition: 2, 773 startPosition: 2,
844 insertAfterPosition: 3 774 insertAfterPosition: 3
845 } 775 }
@@ -848,8 +778,8 @@ describe('Test video playlists', function () {
848 await waitJobs(servers) 778 await waitJobs(servers)
849 779
850 for (const server of servers) { 780 for (const server of servers) {
851 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) 781 const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
852 const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) 782 const names = body.data.map(v => v.video.name)
853 783
854 expect(names).to.deep.equal([ 784 expect(names).to.deep.equal([
855 'video 0 server 1', 785 'video 0 server 1',
@@ -865,11 +795,9 @@ describe('Test video playlists', function () {
865 } 795 }
866 796
867 { 797 {
868 await reorderVideosPlaylist({ 798 await commands[0].reorderElements({
869 url: servers[0].url,
870 token: servers[0].accessToken,
871 playlistId: playlistServer1Id, 799 playlistId: playlistServer1Id,
872 elementAttrs: { 800 attributes: {
873 startPosition: 1, 801 startPosition: 1,
874 reorderLength: 3, 802 reorderLength: 3,
875 insertAfterPosition: 4 803 insertAfterPosition: 4
@@ -879,8 +807,8 @@ describe('Test video playlists', function () {
879 await waitJobs(servers) 807 await waitJobs(servers)
880 808
881 for (const server of servers) { 809 for (const server of servers) {
882 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) 810 const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
883 const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) 811 const names = body.data.map(v => v.video.name)
884 812
885 expect(names).to.deep.equal([ 813 expect(names).to.deep.equal([
886 'video 3 server 1', 814 'video 3 server 1',
@@ -896,11 +824,9 @@ describe('Test video playlists', function () {
896 } 824 }
897 825
898 { 826 {
899 await reorderVideosPlaylist({ 827 await commands[0].reorderElements({
900 url: servers[0].url,
901 token: servers[0].accessToken,
902 playlistId: playlistServer1Id, 828 playlistId: playlistServer1Id,
903 elementAttrs: { 829 attributes: {
904 startPosition: 6, 830 startPosition: 6,
905 insertAfterPosition: 3 831 insertAfterPosition: 3
906 } 832 }
@@ -909,8 +835,7 @@ describe('Test video playlists', function () {
909 await waitJobs(servers) 835 await waitJobs(servers)
910 836
911 for (const server of servers) { 837 for (const server of servers) {
912 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) 838 const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
913 const elements: VideoPlaylistElement[] = res.body.data
914 const names = elements.map(v => v.video.name) 839 const names = elements.map(v => v.video.name)
915 840
916 expect(names).to.deep.equal([ 841 expect(names).to.deep.equal([
@@ -934,22 +859,18 @@ describe('Test video playlists', function () {
934 it('Should update startTimestamp/endTimestamp of some elements', async function () { 859 it('Should update startTimestamp/endTimestamp of some elements', async function () {
935 this.timeout(30000) 860 this.timeout(30000)
936 861
937 await updateVideoPlaylistElement({ 862 await commands[0].updateElement({
938 url: servers[0].url,
939 token: servers[0].accessToken,
940 playlistId: playlistServer1Id, 863 playlistId: playlistServer1Id,
941 playlistElementId: playlistElementServer1Video4, 864 elementId: playlistElementServer1Video4,
942 elementAttrs: { 865 attributes: {
943 startTimestamp: 1 866 startTimestamp: 1
944 } 867 }
945 }) 868 })
946 869
947 await updateVideoPlaylistElement({ 870 await commands[0].updateElement({
948 url: servers[0].url,
949 token: servers[0].accessToken,
950 playlistId: playlistServer1Id, 871 playlistId: playlistServer1Id,
951 playlistElementId: playlistElementServer1Video5, 872 elementId: playlistElementServer1Video5,
952 elementAttrs: { 873 attributes: {
953 stopTimestamp: null 874 stopTimestamp: null
954 } 875 }
955 }) 876 })
@@ -957,8 +878,7 @@ describe('Test video playlists', function () {
957 await waitJobs(servers) 878 await waitJobs(servers)
958 879
959 for (const server of servers) { 880 for (const server of servers) {
960 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) 881 const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
961 const elements: VideoPlaylistElement[] = res.body.data
962 882
963 expect(elements[0].video.name).to.equal('video 3 server 1') 883 expect(elements[0].video.name).to.equal('video 3 server 1')
964 expect(elements[0].position).to.equal(1) 884 expect(elements[0].position).to.equal(1)
@@ -974,17 +894,16 @@ describe('Test video playlists', function () {
974 894
975 it('Should check videos existence in my playlist', async function () { 895 it('Should check videos existence in my playlist', async function () {
976 const videoIds = [ 896 const videoIds = [
977 servers[0].videos[0].id, 897 servers[0].store.videos[0].id,
978 42000, 898 42000,
979 servers[0].videos[3].id, 899 servers[0].store.videos[3].id,
980 43000, 900 43000,
981 servers[0].videos[4].id 901 servers[0].store.videos[4].id
982 ] 902 ]
983 const res = await doVideosExistInMyPlaylist(servers[0].url, servers[0].accessToken, videoIds) 903 const obj = await commands[0].videosExist({ videoIds })
984 const obj = res.body as VideoExistInPlaylist
985 904
986 { 905 {
987 const elem = obj[servers[0].videos[0].id] 906 const elem = obj[servers[0].store.videos[0].id]
988 expect(elem).to.have.lengthOf(1) 907 expect(elem).to.have.lengthOf(1)
989 expect(elem[0].playlistElementId).to.exist 908 expect(elem[0].playlistElementId).to.exist
990 expect(elem[0].playlistId).to.equal(playlistServer1Id) 909 expect(elem[0].playlistId).to.equal(playlistServer1Id)
@@ -993,7 +912,7 @@ describe('Test video playlists', function () {
993 } 912 }
994 913
995 { 914 {
996 const elem = obj[servers[0].videos[3].id] 915 const elem = obj[servers[0].store.videos[3].id]
997 expect(elem).to.have.lengthOf(1) 916 expect(elem).to.have.lengthOf(1)
998 expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4) 917 expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4)
999 expect(elem[0].playlistId).to.equal(playlistServer1Id) 918 expect(elem[0].playlistId).to.equal(playlistServer1Id)
@@ -1002,7 +921,7 @@ describe('Test video playlists', function () {
1002 } 921 }
1003 922
1004 { 923 {
1005 const elem = obj[servers[0].videos[4].id] 924 const elem = obj[servers[0].store.videos[4].id]
1006 expect(elem).to.have.lengthOf(1) 925 expect(elem).to.have.lengthOf(1)
1007 expect(elem[0].playlistId).to.equal(playlistServer1Id) 926 expect(elem[0].playlistId).to.equal(playlistServer1Id)
1008 expect(elem[0].startTimestamp).to.equal(45) 927 expect(elem[0].startTimestamp).to.equal(45)
@@ -1015,42 +934,29 @@ describe('Test video playlists', function () {
1015 934
1016 it('Should automatically update updatedAt field of playlists', async function () { 935 it('Should automatically update updatedAt field of playlists', async function () {
1017 const server = servers[1] 936 const server = servers[1]
1018 const videoId = servers[1].videos[5].id 937 const videoId = servers[1].store.videos[5].id
1019 938
1020 async function getPlaylistNames () { 939 async function getPlaylistNames () {
1021 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt') 940 const { data } = await server.playlists.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' })
1022 941
1023 return (res.body.data as VideoPlaylist[]).map(p => p.displayName) 942 return data.map(p => p.displayName)
1024 } 943 }
1025 944
1026 const elementAttrs = { videoId } 945 const attributes = { videoId }
1027 const res1 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs }) 946 const element1 = await server.playlists.addElement({ playlistId: playlistServer2Id1, attributes })
1028 const res2 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs }) 947 const element2 = await server.playlists.addElement({ playlistId: playlistServer2Id2, attributes })
1029
1030 const element1 = res1.body.videoPlaylistElement.id
1031 const element2 = res2.body.videoPlaylistElement.id
1032 948
1033 const names1 = await getPlaylistNames() 949 const names1 = await getPlaylistNames()
1034 expect(names1[0]).to.equal('playlist 3 updated') 950 expect(names1[0]).to.equal('playlist 3 updated')
1035 expect(names1[1]).to.equal('playlist 2') 951 expect(names1[1]).to.equal('playlist 2')
1036 952
1037 await removeVideoFromPlaylist({ 953 await server.playlists.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id })
1038 url: server.url,
1039 token: server.accessToken,
1040 playlistId: playlistServer2Id1,
1041 playlistElementId: element1
1042 })
1043 954
1044 const names2 = await getPlaylistNames() 955 const names2 = await getPlaylistNames()
1045 expect(names2[0]).to.equal('playlist 2') 956 expect(names2[0]).to.equal('playlist 2')
1046 expect(names2[1]).to.equal('playlist 3 updated') 957 expect(names2[1]).to.equal('playlist 3 updated')
1047 958
1048 await removeVideoFromPlaylist({ 959 await server.playlists.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id })
1049 url: server.url,
1050 token: server.accessToken,
1051 playlistId: playlistServer2Id2,
1052 playlistElementId: element2
1053 })
1054 960
1055 const names3 = await getPlaylistNames() 961 const names3 = await getPlaylistNames()
1056 expect(names3[0]).to.equal('playlist 3 updated') 962 expect(names3[0]).to.equal('playlist 3 updated')
@@ -1060,28 +966,16 @@ describe('Test video playlists', function () {
1060 it('Should delete some elements', async function () { 966 it('Should delete some elements', async function () {
1061 this.timeout(30000) 967 this.timeout(30000)
1062 968
1063 await removeVideoFromPlaylist({ 969 await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementServer1Video4 })
1064 url: servers[0].url, 970 await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementNSFW })
1065 token: servers[0].accessToken,
1066 playlistId: playlistServer1Id,
1067 playlistElementId: playlistElementServer1Video4
1068 })
1069
1070 await removeVideoFromPlaylist({
1071 url: servers[0].url,
1072 token: servers[0].accessToken,
1073 playlistId: playlistServer1Id,
1074 playlistElementId: playlistElementNSFW
1075 })
1076 971
1077 await waitJobs(servers) 972 await waitJobs(servers)
1078 973
1079 for (const server of servers) { 974 for (const server of servers) {
1080 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) 975 const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 })
976 expect(body.total).to.equal(6)
1081 977
1082 expect(res.body.total).to.equal(6) 978 const elements = body.data
1083
1084 const elements: VideoPlaylistElement[] = res.body.data
1085 expect(elements).to.have.lengthOf(6) 979 expect(elements).to.have.lengthOf(6)
1086 980
1087 expect(elements[0].video.name).to.equal('video 0 server 1') 981 expect(elements[0].video.name).to.equal('video 0 server 1')
@@ -1107,34 +1001,31 @@ describe('Test video playlists', function () {
1107 it('Should be able to create a public playlist, and set it to private', async function () { 1001 it('Should be able to create a public playlist, and set it to private', async function () {
1108 this.timeout(30000) 1002 this.timeout(30000)
1109 1003
1110 const res = await createVideoPlaylist({ 1004 const videoPlaylistIds = await commands[0].create({
1111 url: servers[0].url, 1005 attributes: {
1112 token: servers[0].accessToken,
1113 playlistAttrs: {
1114 displayName: 'my super public playlist', 1006 displayName: 'my super public playlist',
1115 privacy: VideoPlaylistPrivacy.PUBLIC, 1007 privacy: VideoPlaylistPrivacy.PUBLIC,
1116 videoChannelId: servers[0].videoChannel.id 1008 videoChannelId: servers[0].store.channel.id
1117 } 1009 }
1118 }) 1010 })
1119 const videoPlaylistIds = res.body.videoPlaylist
1120 1011
1121 await waitJobs(servers) 1012 await waitJobs(servers)
1122 1013
1123 for (const server of servers) { 1014 for (const server of servers) {
1124 await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.OK_200) 1015 await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 })
1125 } 1016 }
1126 1017
1127 const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE } 1018 const attributes = { privacy: VideoPlaylistPrivacy.PRIVATE }
1128 await updateVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: videoPlaylistIds.id, playlistAttrs }) 1019 await commands[0].update({ playlistId: videoPlaylistIds.id, attributes })
1129 1020
1130 await waitJobs(servers) 1021 await waitJobs(servers)
1131 1022
1132 for (const server of [ servers[1], servers[2] ]) { 1023 for (const server of [ servers[1], servers[2] ]) {
1133 await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.NOT_FOUND_404) 1024 await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
1134 } 1025 }
1135 await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, HttpStatusCode.UNAUTHORIZED_401)
1136 1026
1137 await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, HttpStatusCode.OK_200) 1027 await commands[0].get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
1028 await commands[0].get({ token: servers[0].accessToken, playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 })
1138 }) 1029 })
1139 }) 1030 })
1140 1031
@@ -1143,12 +1034,12 @@ describe('Test video playlists', function () {
1143 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () { 1034 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
1144 this.timeout(30000) 1035 this.timeout(30000)
1145 1036
1146 await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id) 1037 await commands[0].delete({ playlistId: playlistServer1Id })
1147 1038
1148 await waitJobs(servers) 1039 await waitJobs(servers)
1149 1040
1150 for (const server of servers) { 1041 for (const server of servers) {
1151 await getVideoPlaylist(server.url, playlistServer1UUID, HttpStatusCode.NOT_FOUND_404) 1042 await server.playlists.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
1152 } 1043 }
1153 }) 1044 })
1154 1045
@@ -1163,75 +1054,61 @@ describe('Test video playlists', function () {
1163 it('Should unfollow servers 1 and 2 and hide their playlists', async function () { 1054 it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
1164 this.timeout(30000) 1055 this.timeout(30000)
1165 1056
1166 const finder = data => data.find(p => p.displayName === 'my super playlist') 1057 const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'my super playlist')
1167 1058
1168 { 1059 {
1169 const res = await getVideoPlaylistsList(servers[2].url, 0, 5) 1060 const body = await servers[2].playlists.list({ start: 0, count: 5 })
1170 expect(res.body.total).to.equal(3) 1061 expect(body.total).to.equal(3)
1171 expect(finder(res.body.data)).to.not.be.undefined 1062
1063 expect(finder(body.data)).to.not.be.undefined
1172 } 1064 }
1173 1065
1174 await unfollow(servers[2].url, servers[2].accessToken, servers[0]) 1066 await servers[2].follows.unfollow({ target: servers[0] })
1175 1067
1176 { 1068 {
1177 const res = await getVideoPlaylistsList(servers[2].url, 0, 5) 1069 const body = await servers[2].playlists.list({ start: 0, count: 5 })
1178 expect(res.body.total).to.equal(1) 1070 expect(body.total).to.equal(1)
1179 1071
1180 expect(finder(res.body.data)).to.be.undefined 1072 expect(finder(body.data)).to.be.undefined
1181 } 1073 }
1182 }) 1074 })
1183 1075
1184 it('Should delete a channel and put the associated playlist in private mode', async function () { 1076 it('Should delete a channel and put the associated playlist in private mode', async function () {
1185 this.timeout(30000) 1077 this.timeout(30000)
1186 1078
1187 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' }) 1079 const channel = await servers[0].channels.create({ attributes: { name: 'super_channel', displayName: 'super channel' } })
1188 const videoChannelId = res.body.videoChannel.id
1189 1080
1190 const res2 = await createVideoPlaylist({ 1081 const playlistCreated = await commands[0].create({
1191 url: servers[0].url, 1082 attributes: {
1192 token: servers[0].accessToken,
1193 playlistAttrs: {
1194 displayName: 'channel playlist', 1083 displayName: 'channel playlist',
1195 privacy: VideoPlaylistPrivacy.PUBLIC, 1084 privacy: VideoPlaylistPrivacy.PUBLIC,
1196 videoChannelId 1085 videoChannelId: channel.id
1197 } 1086 }
1198 }) 1087 })
1199 const videoPlaylistUUID = res2.body.videoPlaylist.uuid
1200 1088
1201 await waitJobs(servers) 1089 await waitJobs(servers)
1202 1090
1203 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel') 1091 await servers[0].channels.delete({ channelName: 'super_channel' })
1204 1092
1205 await waitJobs(servers) 1093 await waitJobs(servers)
1206 1094
1207 const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID) 1095 const body = await commands[0].get({ token: servers[0].accessToken, playlistId: playlistCreated.uuid })
1208 expect(res3.body.displayName).to.equal('channel playlist') 1096 expect(body.displayName).to.equal('channel playlist')
1209 expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) 1097 expect(body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
1210 1098
1211 await getVideoPlaylist(servers[1].url, videoPlaylistUUID, HttpStatusCode.NOT_FOUND_404) 1099 await servers[1].playlists.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
1212 }) 1100 })
1213 1101
1214 it('Should delete an account and delete its playlists', async function () { 1102 it('Should delete an account and delete its playlists', async function () {
1215 this.timeout(30000) 1103 this.timeout(30000)
1216 1104
1217 const user = { username: 'user_1', password: 'password' } 1105 const { userId, token } = await servers[0].users.generate('user_1')
1218 const res = await createUser({
1219 url: servers[0].url,
1220 accessToken: servers[0].accessToken,
1221 username: user.username,
1222 password: user.password
1223 })
1224
1225 const userId = res.body.user.id
1226 const userAccessToken = await userLogin(servers[0], user)
1227 1106
1228 const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) 1107 const { videoChannels } = await servers[0].users.getMyInfo({ token })
1229 const userChannel = (resChannel.body as User).videoChannels[0] 1108 const userChannel = videoChannels[0]
1230 1109
1231 await createVideoPlaylist({ 1110 await commands[0].create({
1232 url: servers[0].url, 1111 attributes: {
1233 token: userAccessToken,
1234 playlistAttrs: {
1235 displayName: 'playlist to be deleted', 1112 displayName: 'playlist to be deleted',
1236 privacy: VideoPlaylistPrivacy.PUBLIC, 1113 privacy: VideoPlaylistPrivacy.PUBLIC,
1237 videoChannelId: userChannel.id 1114 videoChannelId: userChannel.id
@@ -1240,22 +1117,24 @@ describe('Test video playlists', function () {
1240 1117
1241 await waitJobs(servers) 1118 await waitJobs(servers)
1242 1119
1243 const finder = data => data.find(p => p.displayName === 'playlist to be deleted') 1120 const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'playlist to be deleted')
1244 1121
1245 { 1122 {
1246 for (const server of [ servers[0], servers[1] ]) { 1123 for (const server of [ servers[0], servers[1] ]) {
1247 const res = await getVideoPlaylistsList(server.url, 0, 15) 1124 const body = await server.playlists.list({ start: 0, count: 15 })
1248 expect(finder(res.body.data)).to.not.be.undefined 1125
1126 expect(finder(body.data)).to.not.be.undefined
1249 } 1127 }
1250 } 1128 }
1251 1129
1252 await removeUser(servers[0].url, userId, servers[0].accessToken) 1130 await servers[0].users.remove({ userId })
1253 await waitJobs(servers) 1131 await waitJobs(servers)
1254 1132
1255 { 1133 {
1256 for (const server of [ servers[0], servers[1] ]) { 1134 for (const server of [ servers[0], servers[1] ]) {
1257 const res = await getVideoPlaylistsList(server.url, 0, 15) 1135 const body = await server.playlists.list({ start: 0, count: 15 })
1258 expect(finder(res.body.data)).to.be.undefined 1136
1137 expect(finder(body.data)).to.be.undefined
1259 } 1138 }
1260 } 1139 }
1261 }) 1140 })
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index 950aeb7cf..b51b3bcdd 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -2,28 +2,13 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 5import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6import { Video, VideoCreateResult } from '@shared/models' 6import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
7import {
8 cleanupTests,
9 flushAndRunServer,
10 getVideosList,
11 getVideosListWithToken,
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo
15} from '../../../../shared/extra-utils/index'
16import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
17import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18import { userLogin } from '../../../../shared/extra-utils/users/login'
19import { createUser } from '../../../../shared/extra-utils/users/users'
20import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
21import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
22 7
23const expect = chai.expect 8const expect = chai.expect
24 9
25describe('Test video privacy', function () { 10describe('Test video privacy', function () {
26 const servers: ServerInfo[] = [] 11 const servers: PeerTubeServer[] = []
27 let anotherUserToken: string 12 let anotherUserToken: string
28 13
29 let privateVideoId: number 14 let privateVideoId: number
@@ -49,8 +34,8 @@ describe('Test video privacy', function () {
49 this.timeout(50000) 34 this.timeout(50000)
50 35
51 // Run servers 36 // Run servers
52 servers.push(await flushAndRunServer(1, dontFederateUnlistedConfig)) 37 servers.push(await createSingleServer(1, dontFederateUnlistedConfig))
53 servers.push(await flushAndRunServer(2)) 38 servers.push(await createSingleServer(2))
54 39
55 // Get the access tokens 40 // Get the access tokens
56 await setAccessTokensToServers(servers) 41 await setAccessTokensToServers(servers)
@@ -66,55 +51,53 @@ describe('Test video privacy', function () {
66 51
67 for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { 52 for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) {
68 const attributes = { privacy } 53 const attributes = { privacy }
69 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 54 await servers[0].videos.upload({ attributes })
70 } 55 }
71 56
72 await waitJobs(servers) 57 await waitJobs(servers)
73 }) 58 })
74 59
75 it('Should not have these private and internal videos on server 2', async function () { 60 it('Should not have these private and internal videos on server 2', async function () {
76 const res = await getVideosList(servers[1].url) 61 const { total, data } = await servers[1].videos.list()
77 62
78 expect(res.body.total).to.equal(0) 63 expect(total).to.equal(0)
79 expect(res.body.data).to.have.lengthOf(0) 64 expect(data).to.have.lengthOf(0)
80 }) 65 })
81 66
82 it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () { 67 it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () {
83 const res = await getVideosList(servers[0].url) 68 const { total, data } = await servers[0].videos.list()
84 69
85 expect(res.body.total).to.equal(0) 70 expect(total).to.equal(0)
86 expect(res.body.data).to.have.lengthOf(0) 71 expect(data).to.have.lengthOf(0)
87 }) 72 })
88 73
89 it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () { 74 it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () {
90 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 75 const { total, data } = await servers[0].videos.listWithToken()
91 76
92 expect(res.body.total).to.equal(1) 77 expect(total).to.equal(1)
93 expect(res.body.data).to.have.lengthOf(1) 78 expect(data).to.have.lengthOf(1)
94 79
95 expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) 80 expect(data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL)
96 }) 81 })
97 82
98 it('Should list my (private and internal) videos', async function () { 83 it('Should list my (private and internal) videos', async function () {
99 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10) 84 const { total, data } = await servers[0].videos.listMyVideos()
100 85
101 expect(res.body.total).to.equal(2) 86 expect(total).to.equal(2)
102 expect(res.body.data).to.have.lengthOf(2) 87 expect(data).to.have.lengthOf(2)
103 88
104 const videos: Video[] = res.body.data 89 const privateVideo = data.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
105
106 const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
107 privateVideoId = privateVideo.id 90 privateVideoId = privateVideo.id
108 privateVideoUUID = privateVideo.uuid 91 privateVideoUUID = privateVideo.uuid
109 92
110 const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL) 93 const internalVideo = data.find(v => v.privacy.id === VideoPrivacy.INTERNAL)
111 internalVideoId = internalVideo.id 94 internalVideoId = internalVideo.id
112 internalVideoUUID = internalVideo.uuid 95 internalVideoUUID = internalVideo.uuid
113 }) 96 })
114 97
115 it('Should not be able to watch the private/internal video with non authenticated user', async function () { 98 it('Should not be able to watch the private/internal video with non authenticated user', async function () {
116 await getVideo(servers[0].url, privateVideoUUID, HttpStatusCode.UNAUTHORIZED_401) 99 await servers[0].videos.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
117 await getVideo(servers[0].url, internalVideoUUID, HttpStatusCode.UNAUTHORIZED_401) 100 await servers[0].videos.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
118 }) 101 })
119 102
120 it('Should not be able to watch the private video with another user', async function () { 103 it('Should not be able to watch the private video with another user', async function () {
@@ -124,18 +107,23 @@ describe('Test video privacy', function () {
124 username: 'hello', 107 username: 'hello',
125 password: 'super password' 108 password: 'super password'
126 } 109 }
127 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 110 await servers[0].users.create({ username: user.username, password: user.password })
111
112 anotherUserToken = await servers[0].login.getAccessToken(user)
128 113
129 anotherUserToken = await userLogin(servers[0], user) 114 await servers[0].videos.getWithToken({
130 await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) 115 token: anotherUserToken,
116 id: privateVideoUUID,
117 expectedStatus: HttpStatusCode.FORBIDDEN_403
118 })
131 }) 119 })
132 120
133 it('Should be able to watch the internal video with another user', async function () { 121 it('Should be able to watch the internal video with another user', async function () {
134 await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, HttpStatusCode.OK_200) 122 await servers[0].videos.getWithToken({ token: anotherUserToken, id: internalVideoUUID })
135 }) 123 })
136 124
137 it('Should be able to watch the private video with the correct user', async function () { 125 it('Should be able to watch the private video with the correct user', async function () {
138 await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, HttpStatusCode.OK_200) 126 await servers[0].videos.getWithToken({ id: privateVideoUUID })
139 }) 127 })
140 }) 128 })
141 129
@@ -148,7 +136,7 @@ describe('Test video privacy', function () {
148 name: 'unlisted video', 136 name: 'unlisted video',
149 privacy: VideoPrivacy.UNLISTED 137 privacy: VideoPrivacy.UNLISTED
150 } 138 }
151 await uploadVideo(servers[1].url, servers[1].accessToken, attributes) 139 await servers[1].videos.upload({ attributes })
152 140
153 // Server 2 has transcoding enabled 141 // Server 2 has transcoding enabled
154 await waitJobs(servers) 142 await waitJobs(servers)
@@ -156,32 +144,32 @@ describe('Test video privacy', function () {
156 144
157 it('Should not have this unlisted video listed on server 1 and 2', async function () { 145 it('Should not have this unlisted video listed on server 1 and 2', async function () {
158 for (const server of servers) { 146 for (const server of servers) {
159 const res = await getVideosList(server.url) 147 const { total, data } = await server.videos.list()
160 148
161 expect(res.body.total).to.equal(0) 149 expect(total).to.equal(0)
162 expect(res.body.data).to.have.lengthOf(0) 150 expect(data).to.have.lengthOf(0)
163 } 151 }
164 }) 152 })
165 153
166 it('Should list my (unlisted) videos', async function () { 154 it('Should list my (unlisted) videos', async function () {
167 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) 155 const { total, data } = await servers[1].videos.listMyVideos()
168 156
169 expect(res.body.total).to.equal(1) 157 expect(total).to.equal(1)
170 expect(res.body.data).to.have.lengthOf(1) 158 expect(data).to.have.lengthOf(1)
171 159
172 unlistedVideo = res.body.data[0] 160 unlistedVideo = data[0]
173 }) 161 })
174 162
175 it('Should not be able to get this unlisted video using its id', async function () { 163 it('Should not be able to get this unlisted video using its id', async function () {
176 await getVideo(servers[1].url, unlistedVideo.id, 404) 164 await servers[1].videos.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
177 }) 165 })
178 166
179 it('Should be able to get this unlisted video using its uuid/shortUUID', async function () { 167 it('Should be able to get this unlisted video using its uuid/shortUUID', async function () {
180 for (const server of servers) { 168 for (const server of servers) {
181 for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) { 169 for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) {
182 const res = await getVideo(server.url, id) 170 const video = await server.videos.get({ id })
183 171
184 expect(res.body.name).to.equal('unlisted video') 172 expect(video.name).to.equal('unlisted video')
185 } 173 }
186 } 174 }
187 }) 175 })
@@ -193,28 +181,28 @@ describe('Test video privacy', function () {
193 name: 'unlisted video', 181 name: 'unlisted video',
194 privacy: VideoPrivacy.UNLISTED 182 privacy: VideoPrivacy.UNLISTED
195 } 183 }
196 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 184 await servers[0].videos.upload({ attributes })
197 185
198 await waitJobs(servers) 186 await waitJobs(servers)
199 }) 187 })
200 188
201 it('Should list my new unlisted video', async function () { 189 it('Should list my new unlisted video', async function () {
202 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 3) 190 const { total, data } = await servers[0].videos.listMyVideos()
203 191
204 expect(res.body.total).to.equal(3) 192 expect(total).to.equal(3)
205 expect(res.body.data).to.have.lengthOf(3) 193 expect(data).to.have.lengthOf(3)
206 194
207 nonFederatedUnlistedVideoUUID = res.body.data[0].uuid 195 nonFederatedUnlistedVideoUUID = data[0].uuid
208 }) 196 })
209 197
210 it('Should be able to get non-federated unlisted video from origin', async function () { 198 it('Should be able to get non-federated unlisted video from origin', async function () {
211 const res = await getVideo(servers[0].url, nonFederatedUnlistedVideoUUID) 199 const video = await servers[0].videos.get({ id: nonFederatedUnlistedVideoUUID })
212 200
213 expect(res.body.name).to.equal('unlisted video') 201 expect(video.name).to.equal('unlisted video')
214 }) 202 })
215 203
216 it('Should not be able to get non-federated unlisted video from federated server', async function () { 204 it('Should not be able to get non-federated unlisted video from federated server', async function () {
217 await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, HttpStatusCode.NOT_FOUND_404) 205 await servers[1].videos.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
218 }) 206 })
219 }) 207 })
220 208
@@ -226,20 +214,20 @@ describe('Test video privacy', function () {
226 now = Date.now() 214 now = Date.now()
227 215
228 { 216 {
229 const attribute = { 217 const attributes = {
230 name: 'private video becomes public', 218 name: 'private video becomes public',
231 privacy: VideoPrivacy.PUBLIC 219 privacy: VideoPrivacy.PUBLIC
232 } 220 }
233 221
234 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) 222 await servers[0].videos.update({ id: privateVideoId, attributes })
235 } 223 }
236 224
237 { 225 {
238 const attribute = { 226 const attributes = {
239 name: 'internal video becomes public', 227 name: 'internal video becomes public',
240 privacy: VideoPrivacy.PUBLIC 228 privacy: VideoPrivacy.PUBLIC
241 } 229 }
242 await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, attribute) 230 await servers[0].videos.update({ id: internalVideoId, attributes })
243 } 231 }
244 232
245 await waitJobs(servers) 233 await waitJobs(servers)
@@ -247,13 +235,12 @@ describe('Test video privacy', function () {
247 235
248 it('Should have this new public video listed on server 1 and 2', async function () { 236 it('Should have this new public video listed on server 1 and 2', async function () {
249 for (const server of servers) { 237 for (const server of servers) {
250 const res = await getVideosList(server.url) 238 const { total, data } = await server.videos.list()
251 expect(res.body.total).to.equal(2) 239 expect(total).to.equal(2)
252 expect(res.body.data).to.have.lengthOf(2) 240 expect(data).to.have.lengthOf(2)
253 241
254 const videos: Video[] = res.body.data 242 const privateVideo = data.find(v => v.name === 'private video becomes public')
255 const privateVideo = videos.find(v => v.name === 'private video becomes public') 243 const internalVideo = data.find(v => v.name === 'internal video becomes public')
256 const internalVideo = videos.find(v => v.name === 'internal video becomes public')
257 244
258 expect(privateVideo).to.not.be.undefined 245 expect(privateVideo).to.not.be.undefined
259 expect(internalVideo).to.not.be.undefined 246 expect(internalVideo).to.not.be.undefined
@@ -270,27 +257,25 @@ describe('Test video privacy', function () {
270 it('Should set these videos as private and internal', async function () { 257 it('Should set these videos as private and internal', async function () {
271 this.timeout(10000) 258 this.timeout(10000)
272 259
273 await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE }) 260 await servers[0].videos.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } })
274 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL }) 261 await servers[0].videos.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } })
275 262
276 await waitJobs(servers) 263 await waitJobs(servers)
277 264
278 for (const server of servers) { 265 for (const server of servers) {
279 const res = await getVideosList(server.url) 266 const { total, data } = await server.videos.list()
280 267
281 expect(res.body.total).to.equal(0) 268 expect(total).to.equal(0)
282 expect(res.body.data).to.have.lengthOf(0) 269 expect(data).to.have.lengthOf(0)
283 } 270 }
284 271
285 { 272 {
286 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) 273 const { total, data } = await servers[0].videos.listMyVideos()
287 const videos = res.body.data 274 expect(total).to.equal(3)
288 275 expect(data).to.have.lengthOf(3)
289 expect(res.body.total).to.equal(3)
290 expect(videos).to.have.lengthOf(3)
291 276
292 const privateVideo = videos.find(v => v.name === 'private video becomes public') 277 const privateVideo = data.find(v => v.name === 'private video becomes public')
293 const internalVideo = videos.find(v => v.name === 'internal video becomes public') 278 const internalVideo = data.find(v => v.name === 'internal video becomes public')
294 279
295 expect(privateVideo).to.not.be.undefined 280 expect(privateVideo).to.not.be.undefined
296 expect(internalVideo).to.not.be.undefined 281 expect(internalVideo).to.not.be.undefined
diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts
index 204f43611..3f7738784 100644
--- a/server/tests/api/videos/video-schedule-update.ts
+++ b/server/tests/api/videos/video-schedule-update.ts
@@ -1,22 +1,17 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { VideoPrivacy } from '../../../../shared/models/videos' 4import * as chai from 'chai'
6import { 5import {
7 cleanupTests, 6 cleanupTests,
7 createMultipleServers,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 PeerTubeServer,
10 getMyVideos,
11 getVideosList,
12 getVideoWithToken,
13 ServerInfo,
14 setAccessTokensToServers, 10 setAccessTokensToServers,
15 updateVideo, 11 wait,
16 uploadVideo, 12 waitJobs
17 wait 13} from '@shared/extra-utils'
18} from '../../../../shared/extra-utils' 14import { VideoPrivacy } from '@shared/models'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20 15
21const expect = chai.expect 16const expect = chai.expect
22 17
@@ -28,14 +23,14 @@ function in10Seconds () {
28} 23}
29 24
30describe('Test video update scheduler', function () { 25describe('Test video update scheduler', function () {
31 let servers: ServerInfo[] = [] 26 let servers: PeerTubeServer[] = []
32 let video2UUID: string 27 let video2UUID: string
33 28
34 before(async function () { 29 before(async function () {
35 this.timeout(30000) 30 this.timeout(30000)
36 31
37 // Run servers 32 // Run servers
38 servers = await flushAndRunMultipleServers(2) 33 servers = await createMultipleServers(2)
39 34
40 await setAccessTokensToServers(servers) 35 await setAccessTokensToServers(servers)
41 36
@@ -45,35 +40,34 @@ describe('Test video update scheduler', function () {
45 it('Should upload a video and schedule an update in 10 seconds', async function () { 40 it('Should upload a video and schedule an update in 10 seconds', async function () {
46 this.timeout(10000) 41 this.timeout(10000)
47 42
48 const videoAttributes = { 43 const attributes = {
49 name: 'video 1', 44 name: 'video 1',
50 privacy: VideoPrivacy.PRIVATE, 45 privacy: VideoPrivacy.PRIVATE,
51 scheduleUpdate: { 46 scheduleUpdate: {
52 updateAt: in10Seconds().toISOString(), 47 updateAt: in10Seconds().toISOString(),
53 privacy: VideoPrivacy.PUBLIC 48 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
54 } 49 }
55 } 50 }
56 51
57 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 52 await servers[0].videos.upload({ attributes })
58 53
59 await waitJobs(servers) 54 await waitJobs(servers)
60 }) 55 })
61 56
62 it('Should not list the video (in privacy mode)', async function () { 57 it('Should not list the video (in privacy mode)', async function () {
63 for (const server of servers) { 58 for (const server of servers) {
64 const res = await getVideosList(server.url) 59 const { total } = await server.videos.list()
65 60
66 expect(res.body.total).to.equal(0) 61 expect(total).to.equal(0)
67 } 62 }
68 }) 63 })
69 64
70 it('Should have my scheduled video in my account videos', async function () { 65 it('Should have my scheduled video in my account videos', async function () {
71 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) 66 const { total, data } = await servers[0].videos.listMyVideos()
72 expect(res.body.total).to.equal(1) 67 expect(total).to.equal(1)
73 68
74 const videoFromList = res.body.data[0] 69 const videoFromList = data[0]
75 const res2 = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoFromList.uuid) 70 const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid })
76 const videoFromGet = res2.body
77 71
78 for (const video of [ videoFromList, videoFromGet ]) { 72 for (const video of [ videoFromList, videoFromGet ]) {
79 expect(video.name).to.equal('video 1') 73 expect(video.name).to.equal('video 1')
@@ -90,23 +84,23 @@ describe('Test video update scheduler', function () {
90 await waitJobs(servers) 84 await waitJobs(servers)
91 85
92 for (const server of servers) { 86 for (const server of servers) {
93 const res = await getVideosList(server.url) 87 const { total, data } = await server.videos.list()
94 88
95 expect(res.body.total).to.equal(1) 89 expect(total).to.equal(1)
96 expect(res.body.data[0].name).to.equal('video 1') 90 expect(data[0].name).to.equal('video 1')
97 } 91 }
98 }) 92 })
99 93
100 it('Should upload a video without scheduling an update', async function () { 94 it('Should upload a video without scheduling an update', async function () {
101 this.timeout(10000) 95 this.timeout(10000)
102 96
103 const videoAttributes = { 97 const attributes = {
104 name: 'video 2', 98 name: 'video 2',
105 privacy: VideoPrivacy.PRIVATE 99 privacy: VideoPrivacy.PRIVATE
106 } 100 }
107 101
108 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 102 const { uuid } = await servers[0].videos.upload({ attributes })
109 video2UUID = res.body.video.uuid 103 video2UUID = uuid
110 104
111 await waitJobs(servers) 105 await waitJobs(servers)
112 }) 106 })
@@ -114,31 +108,31 @@ describe('Test video update scheduler', function () {
114 it('Should update a video by scheduling an update', async function () { 108 it('Should update a video by scheduling an update', async function () {
115 this.timeout(10000) 109 this.timeout(10000)
116 110
117 const videoAttributes = { 111 const attributes = {
118 name: 'video 2 updated', 112 name: 'video 2 updated',
119 scheduleUpdate: { 113 scheduleUpdate: {
120 updateAt: in10Seconds().toISOString(), 114 updateAt: in10Seconds().toISOString(),
121 privacy: VideoPrivacy.PUBLIC 115 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
122 } 116 }
123 } 117 }
124 118
125 await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes) 119 await servers[0].videos.update({ id: video2UUID, attributes })
126 await waitJobs(servers) 120 await waitJobs(servers)
127 }) 121 })
128 122
129 it('Should not display the updated video', async function () { 123 it('Should not display the updated video', async function () {
130 for (const server of servers) { 124 for (const server of servers) {
131 const res = await getVideosList(server.url) 125 const { total } = await server.videos.list()
132 126
133 expect(res.body.total).to.equal(1) 127 expect(total).to.equal(1)
134 } 128 }
135 }) 129 })
136 130
137 it('Should have my scheduled updated video in my account videos', async function () { 131 it('Should have my scheduled updated video in my account videos', async function () {
138 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) 132 const { total, data } = await servers[0].videos.listMyVideos()
139 expect(res.body.total).to.equal(2) 133 expect(total).to.equal(2)
140 134
141 const video = res.body.data.find(v => v.uuid === video2UUID) 135 const video = data.find(v => v.uuid === video2UUID)
142 expect(video).not.to.be.undefined 136 expect(video).not.to.be.undefined
143 137
144 expect(video.name).to.equal('video 2 updated') 138 expect(video.name).to.equal('video 2 updated')
@@ -155,11 +149,10 @@ describe('Test video update scheduler', function () {
155 await waitJobs(servers) 149 await waitJobs(servers)
156 150
157 for (const server of servers) { 151 for (const server of servers) {
158 const res = await getVideosList(server.url) 152 const { total, data } = await server.videos.list()
159 153 expect(total).to.equal(2)
160 expect(res.body.total).to.equal(2)
161 154
162 const video = res.body.data.find(v => v.uuid === video2UUID) 155 const video = data.find(v => v.uuid === video2UUID)
163 expect(video).not.to.be.undefined 156 expect(video).not.to.be.undefined
164 expect(video.name).to.equal('video 2 updated') 157 expect(video.name).to.equal('video 2 updated')
165 } 158 }
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index ea5ffd239..e4892bb24 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -2,36 +2,23 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfprobeData } from 'fluent-ffmpeg'
6import { omit } from 'lodash' 5import { omit } from 'lodash'
7import { join } from 'path' 6import { join } from 'path'
8import { Job } from '@shared/models'
9import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
10import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
11import { 7import {
12 buildAbsoluteFixturePath, 8 buildAbsoluteFixturePath,
13 buildServerDirectory,
14 cleanupTests, 9 cleanupTests,
10 createMultipleServers,
15 doubleFollow, 11 doubleFollow,
16 flushAndRunMultipleServers,
17 generateHighBitrateVideo, 12 generateHighBitrateVideo,
18 generateVideoWithFramerate, 13 generateVideoWithFramerate,
19 getJobsListPaginationAndSort,
20 getMyVideos,
21 getServerFileSize,
22 getVideo,
23 getVideoFileMetadataUrl,
24 getVideosList,
25 makeGetRequest, 14 makeGetRequest,
26 ServerInfo, 15 PeerTubeServer,
27 setAccessTokensToServers, 16 setAccessTokensToServers,
28 updateCustomSubConfig,
29 uploadVideo,
30 uploadVideoAndGetId,
31 waitJobs, 17 waitJobs,
32 webtorrentAdd 18 webtorrentAdd
33} from '../../../../shared/extra-utils' 19} from '@shared/extra-utils'
34import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' 20import { getMaxBitrate, HttpStatusCode, VideoResolution, VideoState } from '@shared/models'
21import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
35import { 22import {
36 canDoQuickTranscode, 23 canDoQuickTranscode,
37 getAudioStream, 24 getAudioStream,
@@ -43,37 +30,39 @@ import {
43 30
44const expect = chai.expect 31const expect = chai.expect
45 32
46function updateConfigForTranscoding (server: ServerInfo) { 33function updateConfigForTranscoding (server: PeerTubeServer) {
47 return updateCustomSubConfig(server.url, server.accessToken, { 34 return server.config.updateCustomSubConfig({
48 transcoding: { 35 newConfig: {
49 enabled: true, 36 transcoding: {
50 allowAdditionalExtensions: true, 37 enabled: true,
51 allowAudioFiles: true, 38 allowAdditionalExtensions: true,
52 hls: { enabled: true }, 39 allowAudioFiles: true,
53 webtorrent: { enabled: true }, 40 hls: { enabled: true },
54 resolutions: { 41 webtorrent: { enabled: true },
55 '0p': false, 42 resolutions: {
56 '240p': true, 43 '0p': false,
57 '360p': true, 44 '240p': true,
58 '480p': true, 45 '360p': true,
59 '720p': true, 46 '480p': true,
60 '1080p': true, 47 '720p': true,
61 '1440p': true, 48 '1080p': true,
62 '2160p': true 49 '1440p': true,
50 '2160p': true
51 }
63 } 52 }
64 } 53 }
65 }) 54 })
66} 55}
67 56
68describe('Test video transcoding', function () { 57describe('Test video transcoding', function () {
69 let servers: ServerInfo[] = [] 58 let servers: PeerTubeServer[] = []
70 let video4k: string 59 let video4k: string
71 60
72 before(async function () { 61 before(async function () {
73 this.timeout(30_000) 62 this.timeout(30_000)
74 63
75 // Run servers 64 // Run servers
76 servers = await flushAndRunMultipleServers(2) 65 servers = await createMultipleServers(2)
77 66
78 await setAccessTokensToServers(servers) 67 await setAccessTokensToServers(servers)
79 68
@@ -87,21 +76,20 @@ describe('Test video transcoding', function () {
87 it('Should not transcode video on server 1', async function () { 76 it('Should not transcode video on server 1', async function () {
88 this.timeout(60_000) 77 this.timeout(60_000)
89 78
90 const videoAttributes = { 79 const attributes = {
91 name: 'my super name for server 1', 80 name: 'my super name for server 1',
92 description: 'my super description for server 1', 81 description: 'my super description for server 1',
93 fixture: 'video_short.webm' 82 fixture: 'video_short.webm'
94 } 83 }
95 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 84 await servers[0].videos.upload({ attributes })
96 85
97 await waitJobs(servers) 86 await waitJobs(servers)
98 87
99 for (const server of servers) { 88 for (const server of servers) {
100 const res = await getVideosList(server.url) 89 const { data } = await server.videos.list()
101 const video = res.body.data[0] 90 const video = data[0]
102 91
103 const res2 = await getVideo(server.url, video.id) 92 const videoDetails = await server.videos.get({ id: video.id })
104 const videoDetails = res2.body
105 expect(videoDetails.files).to.have.lengthOf(1) 93 expect(videoDetails.files).to.have.lengthOf(1)
106 94
107 const magnetUri = videoDetails.files[0].magnetUri 95 const magnetUri = videoDetails.files[0].magnetUri
@@ -117,21 +105,20 @@ describe('Test video transcoding', function () {
117 it('Should transcode video on server 2', async function () { 105 it('Should transcode video on server 2', async function () {
118 this.timeout(120_000) 106 this.timeout(120_000)
119 107
120 const videoAttributes = { 108 const attributes = {
121 name: 'my super name for server 2', 109 name: 'my super name for server 2',
122 description: 'my super description for server 2', 110 description: 'my super description for server 2',
123 fixture: 'video_short.webm' 111 fixture: 'video_short.webm'
124 } 112 }
125 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 113 await servers[1].videos.upload({ attributes })
126 114
127 await waitJobs(servers) 115 await waitJobs(servers)
128 116
129 for (const server of servers) { 117 for (const server of servers) {
130 const res = await getVideosList(server.url) 118 const { data } = await server.videos.list()
131 119
132 const video = res.body.data.find(v => v.name === videoAttributes.name) 120 const video = data.find(v => v.name === attributes.name)
133 const res2 = await getVideo(server.url, video.id) 121 const videoDetails = await server.videos.get({ id: video.id })
134 const videoDetails = res2.body
135 122
136 expect(videoDetails.files).to.have.lengthOf(4) 123 expect(videoDetails.files).to.have.lengthOf(4)
137 124
@@ -150,47 +137,50 @@ describe('Test video transcoding', function () {
150 137
151 { 138 {
152 // Upload the video, but wait transcoding 139 // Upload the video, but wait transcoding
153 const videoAttributes = { 140 const attributes = {
154 name: 'waiting video', 141 name: 'waiting video',
155 fixture: 'video_short1.webm', 142 fixture: 'video_short1.webm',
156 waitTranscoding: true 143 waitTranscoding: true
157 } 144 }
158 const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 145 const { uuid } = await servers[1].videos.upload({ attributes })
159 const videoId = resVideo.body.video.uuid 146 const videoId = uuid
160 147
161 // Should be in transcode state 148 // Should be in transcode state
162 const { body } = await getVideo(servers[1].url, videoId) 149 const body = await servers[1].videos.get({ id: videoId })
163 expect(body.name).to.equal('waiting video') 150 expect(body.name).to.equal('waiting video')
164 expect(body.state.id).to.equal(VideoState.TO_TRANSCODE) 151 expect(body.state.id).to.equal(VideoState.TO_TRANSCODE)
165 expect(body.state.label).to.equal('To transcode') 152 expect(body.state.label).to.equal('To transcode')
166 expect(body.waitTranscoding).to.be.true 153 expect(body.waitTranscoding).to.be.true
167 154
168 // Should have my video 155 {
169 const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10) 156 // Should have my video
170 const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name) 157 const { data } = await servers[1].videos.listMyVideos()
171 expect(videoToFindInMine).not.to.be.undefined 158 const videoToFindInMine = data.find(v => v.name === attributes.name)
172 expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) 159 expect(videoToFindInMine).not.to.be.undefined
173 expect(videoToFindInMine.state.label).to.equal('To transcode') 160 expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE)
174 expect(videoToFindInMine.waitTranscoding).to.be.true 161 expect(videoToFindInMine.state.label).to.equal('To transcode')
162 expect(videoToFindInMine.waitTranscoding).to.be.true
163 }
175 164
176 // Should not list this video 165 {
177 const resVideos = await getVideosList(servers[1].url) 166 // Should not list this video
178 const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name) 167 const { data } = await servers[1].videos.list()
179 expect(videoToFindInList).to.be.undefined 168 const videoToFindInList = data.find(v => v.name === attributes.name)
169 expect(videoToFindInList).to.be.undefined
170 }
180 171
181 // Server 1 should not have the video yet 172 // Server 1 should not have the video yet
182 await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404) 173 await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
183 } 174 }
184 175
185 await waitJobs(servers) 176 await waitJobs(servers)
186 177
187 for (const server of servers) { 178 for (const server of servers) {
188 const res = await getVideosList(server.url) 179 const { data } = await server.videos.list()
189 const videoToFind = res.body.data.find(v => v.name === 'waiting video') 180 const videoToFind = data.find(v => v.name === 'waiting video')
190 expect(videoToFind).not.to.be.undefined 181 expect(videoToFind).not.to.be.undefined
191 182
192 const res2 = await getVideo(server.url, videoToFind.id) 183 const videoDetails = await server.videos.get({ id: videoToFind.id })
193 const videoDetails: VideoDetails = res2.body
194 184
195 expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) 185 expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED)
196 expect(videoDetails.state.label).to.equal('Published') 186 expect(videoDetails.state.label).to.equal('Published')
@@ -211,22 +201,20 @@ describe('Test video transcoding', function () {
211 } 201 }
212 202
213 for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { 203 for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) {
214 const videoAttributes = { 204 const attributes = {
215 name: fixture, 205 name: fixture,
216 fixture 206 fixture
217 } 207 }
218 208
219 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 209 await servers[1].videos.upload({ attributes })
220 210
221 await waitJobs(servers) 211 await waitJobs(servers)
222 212
223 for (const server of servers) { 213 for (const server of servers) {
224 const res = await getVideosList(server.url) 214 const { data } = await server.videos.list()
225
226 const video = res.body.data.find(v => v.name === videoAttributes.name)
227 const res2 = await getVideo(server.url, video.id)
228 const videoDetails = res2.body
229 215
216 const video = data.find(v => v.name === attributes.name)
217 const videoDetails = await server.videos.get({ id: video.id })
230 expect(videoDetails.files).to.have.lengthOf(4) 218 expect(videoDetails.files).to.have.lengthOf(4)
231 219
232 const magnetUri = videoDetails.files[0].magnetUri 220 const magnetUri = videoDetails.files[0].magnetUri
@@ -238,22 +226,20 @@ describe('Test video transcoding', function () {
238 it('Should transcode a 4k video', async function () { 226 it('Should transcode a 4k video', async function () {
239 this.timeout(200_000) 227 this.timeout(200_000)
240 228
241 const videoAttributes = { 229 const attributes = {
242 name: '4k video', 230 name: '4k video',
243 fixture: 'video_short_4k.mp4' 231 fixture: 'video_short_4k.mp4'
244 } 232 }
245 233
246 const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 234 const { uuid } = await servers[1].videos.upload({ attributes })
247 video4k = resUpload.body.video.uuid 235 video4k = uuid
248 236
249 await waitJobs(servers) 237 await waitJobs(servers)
250 238
251 const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] 239 const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ]
252 240
253 for (const server of servers) { 241 for (const server of servers) {
254 const res = await getVideo(server.url, video4k) 242 const videoDetails = await server.videos.get({ id: video4k })
255 const videoDetails: VideoDetails = res.body
256
257 expect(videoDetails.files).to.have.lengthOf(resolutions.length) 243 expect(videoDetails.files).to.have.lengthOf(resolutions.length)
258 244
259 for (const r of resolutions) { 245 for (const r of resolutions) {
@@ -269,24 +255,23 @@ describe('Test video transcoding', function () {
269 it('Should transcode high bit rate mp3 to proper bit rate', async function () { 255 it('Should transcode high bit rate mp3 to proper bit rate', async function () {
270 this.timeout(60_000) 256 this.timeout(60_000)
271 257
272 const videoAttributes = { 258 const attributes = {
273 name: 'mp3_256k', 259 name: 'mp3_256k',
274 fixture: 'video_short_mp3_256k.mp4' 260 fixture: 'video_short_mp3_256k.mp4'
275 } 261 }
276 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 262 await servers[1].videos.upload({ attributes })
277 263
278 await waitJobs(servers) 264 await waitJobs(servers)
279 265
280 for (const server of servers) { 266 for (const server of servers) {
281 const res = await getVideosList(server.url) 267 const { data } = await server.videos.list()
282 268
283 const video = res.body.data.find(v => v.name === videoAttributes.name) 269 const video = data.find(v => v.name === attributes.name)
284 const res2 = await getVideo(server.url, video.id) 270 const videoDetails = await server.videos.get({ id: video.id })
285 const videoDetails: VideoDetails = res2.body
286 271
287 expect(videoDetails.files).to.have.lengthOf(4) 272 expect(videoDetails.files).to.have.lengthOf(4)
288 273
289 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) 274 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
290 const probe = await getAudioStream(path) 275 const probe = await getAudioStream(path)
291 276
292 if (probe.audioStream) { 277 if (probe.audioStream) {
@@ -301,23 +286,22 @@ describe('Test video transcoding', function () {
301 it('Should transcode video with no audio and have no audio itself', async function () { 286 it('Should transcode video with no audio and have no audio itself', async function () {
302 this.timeout(60_000) 287 this.timeout(60_000)
303 288
304 const videoAttributes = { 289 const attributes = {
305 name: 'no_audio', 290 name: 'no_audio',
306 fixture: 'video_short_no_audio.mp4' 291 fixture: 'video_short_no_audio.mp4'
307 } 292 }
308 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 293 await servers[1].videos.upload({ attributes })
309 294
310 await waitJobs(servers) 295 await waitJobs(servers)
311 296
312 for (const server of servers) { 297 for (const server of servers) {
313 const res = await getVideosList(server.url) 298 const { data } = await server.videos.list()
314 299
315 const video = res.body.data.find(v => v.name === videoAttributes.name) 300 const video = data.find(v => v.name === attributes.name)
316 const res2 = await getVideo(server.url, video.id) 301 const videoDetails = await server.videos.get({ id: video.id })
317 const videoDetails: VideoDetails = res2.body
318 302
319 expect(videoDetails.files).to.have.lengthOf(4) 303 expect(videoDetails.files).to.have.lengthOf(4)
320 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) 304 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
321 const probe = await getAudioStream(path) 305 const probe = await getAudioStream(path)
322 expect(probe).to.not.have.property('audioStream') 306 expect(probe).to.not.have.property('audioStream')
323 } 307 }
@@ -326,26 +310,25 @@ describe('Test video transcoding', function () {
326 it('Should leave the audio untouched, but properly transcode the video', async function () { 310 it('Should leave the audio untouched, but properly transcode the video', async function () {
327 this.timeout(60_000) 311 this.timeout(60_000)
328 312
329 const videoAttributes = { 313 const attributes = {
330 name: 'untouched_audio', 314 name: 'untouched_audio',
331 fixture: 'video_short.mp4' 315 fixture: 'video_short.mp4'
332 } 316 }
333 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 317 await servers[1].videos.upload({ attributes })
334 318
335 await waitJobs(servers) 319 await waitJobs(servers)
336 320
337 for (const server of servers) { 321 for (const server of servers) {
338 const res = await getVideosList(server.url) 322 const { data } = await server.videos.list()
339 323
340 const video = res.body.data.find(v => v.name === videoAttributes.name) 324 const video = data.find(v => v.name === attributes.name)
341 const res2 = await getVideo(server.url, video.id) 325 const videoDetails = await server.videos.get({ id: video.id })
342 const videoDetails: VideoDetails = res2.body
343 326
344 expect(videoDetails.files).to.have.lengthOf(4) 327 expect(videoDetails.files).to.have.lengthOf(4)
345 328
346 const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) 329 const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
347 const fixtureVideoProbe = await getAudioStream(fixturePath) 330 const fixtureVideoProbe = await getAudioStream(fixturePath)
348 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) 331 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
349 332
350 const videoProbe = await getAudioStream(path) 333 const videoProbe = await getAudioStream(path)
351 334
@@ -364,19 +347,21 @@ describe('Test video transcoding', function () {
364 function runSuite (mode: 'legacy' | 'resumable') { 347 function runSuite (mode: 'legacy' | 'resumable') {
365 348
366 before(async function () { 349 before(async function () {
367 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { 350 await servers[1].config.updateCustomSubConfig({
368 transcoding: { 351 newConfig: {
369 hls: { enabled: true }, 352 transcoding: {
370 webtorrent: { enabled: true }, 353 hls: { enabled: true },
371 resolutions: { 354 webtorrent: { enabled: true },
372 '0p': false, 355 resolutions: {
373 '240p': false, 356 '0p': false,
374 '360p': false, 357 '240p': false,
375 '480p': false, 358 '360p': false,
376 '720p': false, 359 '480p': false,
377 '1080p': false, 360 '720p': false,
378 '1440p': false, 361 '1080p': false,
379 '2160p': false 362 '1440p': false,
363 '2160p': false
364 }
380 } 365 }
381 } 366 }
382 }) 367 })
@@ -385,22 +370,21 @@ describe('Test video transcoding', function () {
385 it('Should merge an audio file with the preview file', async function () { 370 it('Should merge an audio file with the preview file', async function () {
386 this.timeout(60_000) 371 this.timeout(60_000)
387 372
388 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } 373 const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
389 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) 374 await servers[1].videos.upload({ attributes, mode })
390 375
391 await waitJobs(servers) 376 await waitJobs(servers)
392 377
393 for (const server of servers) { 378 for (const server of servers) {
394 const res = await getVideosList(server.url) 379 const { data } = await server.videos.list()
395 380
396 const video = res.body.data.find(v => v.name === 'audio_with_preview') 381 const video = data.find(v => v.name === 'audio_with_preview')
397 const res2 = await getVideo(server.url, video.id) 382 const videoDetails = await server.videos.get({ id: video.id })
398 const videoDetails: VideoDetails = res2.body
399 383
400 expect(videoDetails.files).to.have.lengthOf(1) 384 expect(videoDetails.files).to.have.lengthOf(1)
401 385
402 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) 386 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 })
403 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) 387 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 })
404 388
405 const magnetUri = videoDetails.files[0].magnetUri 389 const magnetUri = videoDetails.files[0].magnetUri
406 expect(magnetUri).to.contain('.mp4') 390 expect(magnetUri).to.contain('.mp4')
@@ -410,22 +394,21 @@ describe('Test video transcoding', function () {
410 it('Should upload an audio file and choose a default background image', async function () { 394 it('Should upload an audio file and choose a default background image', async function () {
411 this.timeout(60_000) 395 this.timeout(60_000)
412 396
413 const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } 397 const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' }
414 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) 398 await servers[1].videos.upload({ attributes, mode })
415 399
416 await waitJobs(servers) 400 await waitJobs(servers)
417 401
418 for (const server of servers) { 402 for (const server of servers) {
419 const res = await getVideosList(server.url) 403 const { data } = await server.videos.list()
420 404
421 const video = res.body.data.find(v => v.name === 'audio_without_preview') 405 const video = data.find(v => v.name === 'audio_without_preview')
422 const res2 = await getVideo(server.url, video.id) 406 const videoDetails = await server.videos.get({ id: video.id })
423 const videoDetails = res2.body
424 407
425 expect(videoDetails.files).to.have.lengthOf(1) 408 expect(videoDetails.files).to.have.lengthOf(1)
426 409
427 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) 410 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 })
428 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) 411 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 })
429 412
430 const magnetUri = videoDetails.files[0].magnetUri 413 const magnetUri = videoDetails.files[0].magnetUri
431 expect(magnetUri).to.contain('.mp4') 414 expect(magnetUri).to.contain('.mp4')
@@ -435,26 +418,27 @@ describe('Test video transcoding', function () {
435 it('Should upload an audio file and create an audio version only', async function () { 418 it('Should upload an audio file and create an audio version only', async function () {
436 this.timeout(60_000) 419 this.timeout(60_000)
437 420
438 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { 421 await servers[1].config.updateCustomSubConfig({
439 transcoding: { 422 newConfig: {
440 hls: { enabled: true }, 423 transcoding: {
441 webtorrent: { enabled: true }, 424 hls: { enabled: true },
442 resolutions: { 425 webtorrent: { enabled: true },
443 '0p': true, 426 resolutions: {
444 '240p': false, 427 '0p': true,
445 '360p': false 428 '240p': false,
429 '360p': false
430 }
446 } 431 }
447 } 432 }
448 }) 433 })
449 434
450 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } 435 const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
451 const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) 436 const { id } = await servers[1].videos.upload({ attributes, mode })
452 437
453 await waitJobs(servers) 438 await waitJobs(servers)
454 439
455 for (const server of servers) { 440 for (const server of servers) {
456 const res2 = await getVideo(server.url, resVideo.body.video.id) 441 const videoDetails = await server.videos.get({ id })
457 const videoDetails: VideoDetails = res2.body
458 442
459 for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { 443 for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
460 expect(files).to.have.lengthOf(2) 444 expect(files).to.have.lengthOf(2)
@@ -480,21 +464,20 @@ describe('Test video transcoding', function () {
480 it('Should transcode a 60 FPS video', async function () { 464 it('Should transcode a 60 FPS video', async function () {
481 this.timeout(60_000) 465 this.timeout(60_000)
482 466
483 const videoAttributes = { 467 const attributes = {
484 name: 'my super 30fps name for server 2', 468 name: 'my super 30fps name for server 2',
485 description: 'my super 30fps description for server 2', 469 description: 'my super 30fps description for server 2',
486 fixture: '60fps_720p_small.mp4' 470 fixture: '60fps_720p_small.mp4'
487 } 471 }
488 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 472 await servers[1].videos.upload({ attributes })
489 473
490 await waitJobs(servers) 474 await waitJobs(servers)
491 475
492 for (const server of servers) { 476 for (const server of servers) {
493 const res = await getVideosList(server.url) 477 const { data } = await server.videos.list()
494 478
495 const video = res.body.data.find(v => v.name === videoAttributes.name) 479 const video = data.find(v => v.name === attributes.name)
496 const res2 = await getVideo(server.url, video.id) 480 const videoDetails = await server.videos.get({ id: video.id })
497 const videoDetails: VideoDetails = res2.body
498 481
499 expect(videoDetails.files).to.have.lengthOf(4) 482 expect(videoDetails.files).to.have.lengthOf(4)
500 expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) 483 expect(videoDetails.files[0].fps).to.be.above(58).and.below(62)
@@ -503,13 +486,13 @@ describe('Test video transcoding', function () {
503 expect(videoDetails.files[3].fps).to.be.below(31) 486 expect(videoDetails.files[3].fps).to.be.below(31)
504 487
505 for (const resolution of [ '240', '360', '480' ]) { 488 for (const resolution of [ '240', '360', '480' ]) {
506 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) 489 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
507 const fps = await getVideoFileFPS(path) 490 const fps = await getVideoFileFPS(path)
508 491
509 expect(fps).to.be.below(31) 492 expect(fps).to.be.below(31)
510 } 493 }
511 494
512 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) 495 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4'))
513 const fps = await getVideoFileFPS(path) 496 const fps = await getVideoFileFPS(path)
514 497
515 expect(fps).to.be.above(58).and.below(62) 498 expect(fps).to.be.above(58).and.below(62)
@@ -528,29 +511,29 @@ describe('Test video transcoding', function () {
528 expect(fps).to.be.equal(59) 511 expect(fps).to.be.equal(59)
529 } 512 }
530 513
531 const videoAttributes = { 514 const attributes = {
532 name: '59fps video', 515 name: '59fps video',
533 description: '59fps video', 516 description: '59fps video',
534 fixture: tempFixturePath 517 fixture: tempFixturePath
535 } 518 }
536 519
537 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 520 await servers[1].videos.upload({ attributes })
538 521
539 await waitJobs(servers) 522 await waitJobs(servers)
540 523
541 for (const server of servers) { 524 for (const server of servers) {
542 const res = await getVideosList(server.url) 525 const { data } = await server.videos.list()
543 526
544 const video = res.body.data.find(v => v.name === videoAttributes.name) 527 const video = data.find(v => v.name === attributes.name)
545 528
546 { 529 {
547 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) 530 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
548 const fps = await getVideoFileFPS(path) 531 const fps = await getVideoFileFPS(path)
549 expect(fps).to.be.equal(25) 532 expect(fps).to.be.equal(25)
550 } 533 }
551 534
552 { 535 {
553 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) 536 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4'))
554 const fps = await getVideoFileFPS(path) 537 const fps = await getVideoFileFPS(path)
555 expect(fps).to.be.equal(59) 538 expect(fps).to.be.equal(59)
556 } 539 }
@@ -571,23 +554,23 @@ describe('Test video transcoding', function () {
571 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) 554 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
572 } 555 }
573 556
574 const videoAttributes = { 557 const attributes = {
575 name: 'high bitrate video', 558 name: 'high bitrate video',
576 description: 'high bitrate video', 559 description: 'high bitrate video',
577 fixture: tempFixturePath 560 fixture: tempFixturePath
578 } 561 }
579 562
580 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 563 await servers[1].videos.upload({ attributes })
581 564
582 await waitJobs(servers) 565 await waitJobs(servers)
583 566
584 for (const server of servers) { 567 for (const server of servers) {
585 const res = await getVideosList(server.url) 568 const { data } = await server.videos.list()
586 569
587 const video = res.body.data.find(v => v.name === videoAttributes.name) 570 const video = data.find(v => v.name === attributes.name)
588 571
589 for (const resolution of [ '240', '360', '480', '720', '1080' ]) { 572 for (const resolution of [ '240', '360', '480', '720', '1080' ]) {
590 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) 573 const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
591 574
592 const bitrate = await getVideoFileBitrate(path) 575 const bitrate = await getVideoFileBitrate(path)
593 const fps = await getVideoFileFPS(path) 576 const fps = await getVideoFileFPS(path)
@@ -602,7 +585,7 @@ describe('Test video transcoding', function () {
602 it('Should not transcode to an higher bitrate than the original file', async function () { 585 it('Should not transcode to an higher bitrate than the original file', async function () {
603 this.timeout(160_000) 586 this.timeout(160_000)
604 587
605 const config = { 588 const newConfig = {
606 transcoding: { 589 transcoding: {
607 enabled: true, 590 enabled: true,
608 resolutions: { 591 resolutions: {
@@ -618,22 +601,21 @@ describe('Test video transcoding', function () {
618 hls: { enabled: true } 601 hls: { enabled: true }
619 } 602 }
620 } 603 }
621 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) 604 await servers[1].config.updateCustomSubConfig({ newConfig })
622 605
623 const videoAttributes = { 606 const attributes = {
624 name: 'low bitrate', 607 name: 'low bitrate',
625 fixture: 'low-bitrate.mp4' 608 fixture: 'low-bitrate.mp4'
626 } 609 }
627 610
628 const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 611 const { uuid } = await servers[1].videos.upload({ attributes })
629 const videoUUID = resUpload.body.video.uuid
630 612
631 await waitJobs(servers) 613 await waitJobs(servers)
632 614
633 const resolutions = [ 240, 360, 480, 720, 1080 ] 615 const resolutions = [ 240, 360, 480, 720, 1080 ]
634 for (const r of resolutions) { 616 for (const r of resolutions) {
635 const path = `videos/${videoUUID}-${r}.mp4` 617 const path = `videos/${uuid}-${r}.mp4`
636 const size = await getServerFileSize(servers[1], path) 618 const size = await servers[1].servers.getServerFileSize(path)
637 expect(size, `${path} not below ${60_000}`).to.be.below(60_000) 619 expect(size, `${path} not below ${60_000}`).to.be.below(60_000)
638 } 620 }
639 }) 621 })
@@ -644,11 +626,11 @@ describe('Test video transcoding', function () {
644 it('Should provide valid ffprobe data', async function () { 626 it('Should provide valid ffprobe data', async function () {
645 this.timeout(160_000) 627 this.timeout(160_000)
646 628
647 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid 629 const videoUUID = (await servers[1].videos.quickUpload({ name: 'ffprobe data' })).uuid
648 await waitJobs(servers) 630 await waitJobs(servers)
649 631
650 { 632 {
651 const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4')) 633 const path = servers[1].servers.buildDirectory(join('videos', videoUUID + '-240.mp4'))
652 const metadata = await getMetadataFromFile(path) 634 const metadata = await getMetadataFromFile(path)
653 635
654 // expected format properties 636 // expected format properties
@@ -678,8 +660,7 @@ describe('Test video transcoding', function () {
678 } 660 }
679 661
680 for (const server of servers) { 662 for (const server of servers) {
681 const res2 = await getVideo(server.url, videoUUID) 663 const videoDetails = await server.videos.get({ id: videoUUID })
682 const videoDetails: VideoDetails = res2.body
683 664
684 const videoFiles = videoDetails.files 665 const videoFiles = videoDetails.files
685 .concat(videoDetails.streamingPlaylists[0].files) 666 .concat(videoDetails.streamingPlaylists[0].files)
@@ -691,8 +672,7 @@ describe('Test video transcoding', function () {
691 expect(file.metadataUrl).to.contain(servers[1].url) 672 expect(file.metadataUrl).to.contain(servers[1].url)
692 expect(file.metadataUrl).to.contain(videoUUID) 673 expect(file.metadataUrl).to.contain(videoUUID)
693 674
694 const res3 = await getVideoFileMetadataUrl(file.metadataUrl) 675 const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl })
695 const metadata: FfprobeData = res3.body
696 expect(metadata).to.have.nested.property('format.size') 676 expect(metadata).to.have.nested.property('format.size')
697 } 677 }
698 } 678 }
@@ -709,17 +689,14 @@ describe('Test video transcoding', function () {
709 describe('Transcoding job queue', function () { 689 describe('Transcoding job queue', function () {
710 690
711 it('Should have the appropriate priorities for transcoding jobs', async function () { 691 it('Should have the appropriate priorities for transcoding jobs', async function () {
712 const res = await getJobsListPaginationAndSort({ 692 const body = await servers[1].jobs.getJobsList({
713 url: servers[1].url,
714 accessToken: servers[1].accessToken,
715 start: 0, 693 start: 0,
716 count: 100, 694 count: 100,
717 sort: '-createdAt', 695 sort: '-createdAt',
718 jobType: 'video-transcoding' 696 jobType: 'video-transcoding'
719 }) 697 })
720 698
721 const jobs = res.body.data as Job[] 699 const jobs = body.data
722
723 const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) 700 const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k)
724 701
725 expect(transcodingJobs).to.have.lengthOf(14) 702 expect(transcodingJobs).to.have.lengthOf(14)
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
index 7428b82c5..2306807bf 100644
--- a/server/tests/api/videos/videos-filter.ts
+++ b/server/tests/api/videos/videos-filter.ts
@@ -1,25 +1,18 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import { expect } from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser, 7 createMultipleServers,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers,
10 makeGetRequest, 9 makeGetRequest,
11 ServerInfo, 10 PeerTubeServer,
12 setAccessTokensToServers, 11 setAccessTokensToServers
13 uploadVideo, 12} from '@shared/extra-utils'
14 userLogin 13import { HttpStatusCode, UserRole, Video, VideoPrivacy } from '@shared/models'
15} from '../../../../shared/extra-utils' 14
16import { Video, VideoPrivacy } from '../../../../shared/models/videos' 15async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) {
17import { UserRole } from '../../../../shared/models/users'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19
20const expect = chai.expect
21
22async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
23 const paths = [ 16 const paths = [
24 '/api/v1/video-channels/root_channel/videos', 17 '/api/v1/video-channels/root_channel/videos',
25 '/api/v1/accounts/root/videos', 18 '/api/v1/accounts/root/videos',
@@ -38,7 +31,7 @@ async function getVideosNames (server: ServerInfo, token: string, filter: string
38 sort: 'createdAt', 31 sort: 'createdAt',
39 filter 32 filter
40 }, 33 },
41 statusCodeExpected 34 expectedStatus
42 }) 35 })
43 36
44 videosResults.push(res.body.data.map(v => v.name)) 37 videosResults.push(res.body.data.map(v => v.name))
@@ -48,42 +41,32 @@ async function getVideosNames (server: ServerInfo, token: string, filter: string
48} 41}
49 42
50describe('Test videos filter', function () { 43describe('Test videos filter', function () {
51 let servers: ServerInfo[] 44 let servers: PeerTubeServer[]
52 45
53 // --------------------------------------------------------------- 46 // ---------------------------------------------------------------
54 47
55 before(async function () { 48 before(async function () {
56 this.timeout(160000) 49 this.timeout(160000)
57 50
58 servers = await flushAndRunMultipleServers(2) 51 servers = await createMultipleServers(2)
59 52
60 await setAccessTokensToServers(servers) 53 await setAccessTokensToServers(servers)
61 54
62 for (const server of servers) { 55 for (const server of servers) {
63 const moderator = { username: 'moderator', password: 'my super password' } 56 const moderator = { username: 'moderator', password: 'my super password' }
64 await createUser( 57 await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
65 { 58 server['moderatorAccessToken'] = await server.login.getAccessToken(moderator)
66 url: server.url,
67 accessToken: server.accessToken,
68 username: moderator.username,
69 password: moderator.password,
70 videoQuota: undefined,
71 videoQuotaDaily: undefined,
72 role: UserRole.MODERATOR
73 }
74 )
75 server['moderatorAccessToken'] = await userLogin(server, moderator)
76 59
77 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) 60 await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } })
78 61
79 { 62 {
80 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED } 63 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
81 await uploadVideo(server.url, server.accessToken, attributes) 64 await server.videos.upload({ attributes })
82 } 65 }
83 66
84 { 67 {
85 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } 68 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
86 await uploadVideo(server.url, server.accessToken, attributes) 69 await server.videos.upload({ attributes })
87 } 70 }
88 } 71 }
89 72
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index b25cff879..e4bc0bb3a 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -1,74 +1,66 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser, 7 createSingleServer,
8 flushAndRunServer, 8 HistoryCommand,
9 getVideosListWithToken,
10 getVideoWithToken,
11 killallServers, 9 killallServers,
12 reRunServer, 10 PeerTubeServer,
13 searchVideoWithToken,
14 ServerInfo,
15 setAccessTokensToServers, 11 setAccessTokensToServers,
16 updateMyUser,
17 uploadVideo,
18 userLogin,
19 wait 12 wait
20} from '../../../../shared/extra-utils' 13} from '@shared/extra-utils'
21import { Video, VideoDetails } from '../../../../shared/models/videos' 14import { HttpStatusCode, Video } from '@shared/models'
22import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
24 15
25const expect = chai.expect 16const expect = chai.expect
26 17
27describe('Test videos history', function () { 18describe('Test videos history', function () {
28 let server: ServerInfo = null 19 let server: PeerTubeServer = null
29 let video1UUID: string 20 let video1UUID: string
30 let video2UUID: string 21 let video2UUID: string
31 let video3UUID: string 22 let video3UUID: string
32 let video3WatchedDate: Date 23 let video3WatchedDate: Date
33 let userAccessToken: string 24 let userAccessToken: string
25 let command: HistoryCommand
34 26
35 before(async function () { 27 before(async function () {
36 this.timeout(30000) 28 this.timeout(30000)
37 29
38 server = await flushAndRunServer(1) 30 server = await createSingleServer(1)
39 31
40 await setAccessTokensToServers([ server ]) 32 await setAccessTokensToServers([ server ])
41 33
34 command = server.history
35
42 { 36 {
43 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) 37 const { uuid } = await server.videos.upload({ attributes: { name: 'video 1' } })
44 video1UUID = res.body.video.uuid 38 video1UUID = uuid
45 } 39 }
46 40
47 { 41 {
48 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) 42 const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } })
49 video2UUID = res.body.video.uuid 43 video2UUID = uuid
50 } 44 }
51 45
52 { 46 {
53 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) 47 const { uuid } = await server.videos.upload({ attributes: { name: 'video 3' } })
54 video3UUID = res.body.video.uuid 48 video3UUID = uuid
55 } 49 }
56 50
57 const user = { 51 const user = {
58 username: 'user_1', 52 username: 'user_1',
59 password: 'super password' 53 password: 'super password'
60 } 54 }
61 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 55 await server.users.create({ username: user.username, password: user.password })
62 userAccessToken = await userLogin(server, user) 56 userAccessToken = await server.login.getAccessToken(user)
63 }) 57 })
64 58
65 it('Should get videos, without watching history', async function () { 59 it('Should get videos, without watching history', async function () {
66 const res = await getVideosListWithToken(server.url, server.accessToken) 60 const { data } = await server.videos.listWithToken()
67 const videos: Video[] = res.body.data
68 61
69 for (const video of videos) { 62 for (const video of data) {
70 const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id) 63 const videoDetails = await server.videos.getWithToken({ id: video.id })
71 const videoDetails: VideoDetails = resDetail.body
72 64
73 expect(video.userHistory).to.be.undefined 65 expect(video.userHistory).to.be.undefined
74 expect(videoDetails.userHistory).to.be.undefined 66 expect(videoDetails.userHistory).to.be.undefined
@@ -76,21 +68,21 @@ describe('Test videos history', function () {
76 }) 68 })
77 69
78 it('Should watch the first and second video', async function () { 70 it('Should watch the first and second video', async function () {
79 await userWatchVideo(server.url, server.accessToken, video2UUID, 8) 71 await command.wathVideo({ videoId: video2UUID, currentTime: 8 })
80 await userWatchVideo(server.url, server.accessToken, video1UUID, 3) 72 await command.wathVideo({ videoId: video1UUID, currentTime: 3 })
81 }) 73 })
82 74
83 it('Should return the correct history when listing, searching and getting videos', async function () { 75 it('Should return the correct history when listing, searching and getting videos', async function () {
84 const videosOfVideos: Video[][] = [] 76 const videosOfVideos: Video[][] = []
85 77
86 { 78 {
87 const res = await getVideosListWithToken(server.url, server.accessToken) 79 const { data } = await server.videos.listWithToken()
88 videosOfVideos.push(res.body.data) 80 videosOfVideos.push(data)
89 } 81 }
90 82
91 { 83 {
92 const res = await searchVideoWithToken(server.url, 'video', server.accessToken) 84 const body = await server.search.searchVideos({ token: server.accessToken, search: 'video' })
93 videosOfVideos.push(res.body.data) 85 videosOfVideos.push(body.data)
94 } 86 }
95 87
96 for (const videos of videosOfVideos) { 88 for (const videos of videosOfVideos) {
@@ -108,24 +100,21 @@ describe('Test videos history', function () {
108 } 100 }
109 101
110 { 102 {
111 const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID) 103 const videoDetails = await server.videos.getWithToken({ id: video1UUID })
112 const videoDetails: VideoDetails = resDetail.body
113 104
114 expect(videoDetails.userHistory).to.not.be.undefined 105 expect(videoDetails.userHistory).to.not.be.undefined
115 expect(videoDetails.userHistory.currentTime).to.equal(3) 106 expect(videoDetails.userHistory.currentTime).to.equal(3)
116 } 107 }
117 108
118 { 109 {
119 const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID) 110 const videoDetails = await server.videos.getWithToken({ id: video2UUID })
120 const videoDetails: VideoDetails = resDetail.body
121 111
122 expect(videoDetails.userHistory).to.not.be.undefined 112 expect(videoDetails.userHistory).to.not.be.undefined
123 expect(videoDetails.userHistory.currentTime).to.equal(8) 113 expect(videoDetails.userHistory.currentTime).to.equal(8)
124 } 114 }
125 115
126 { 116 {
127 const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID) 117 const videoDetails = await server.videos.getWithToken({ id: video3UUID })
128 const videoDetails: VideoDetails = resDetail.body
129 118
130 expect(videoDetails.userHistory).to.be.undefined 119 expect(videoDetails.userHistory).to.be.undefined
131 } 120 }
@@ -133,71 +122,64 @@ describe('Test videos history', function () {
133 122
134 it('Should have these videos when listing my history', async function () { 123 it('Should have these videos when listing my history', async function () {
135 video3WatchedDate = new Date() 124 video3WatchedDate = new Date()
136 await userWatchVideo(server.url, server.accessToken, video3UUID, 2) 125 await command.wathVideo({ videoId: video3UUID, currentTime: 2 })
137 126
138 const res = await listMyVideosHistory(server.url, server.accessToken) 127 const body = await command.list()
139 128
140 expect(res.body.total).to.equal(3) 129 expect(body.total).to.equal(3)
141 130
142 const videos: Video[] = res.body.data 131 const videos = body.data
143 expect(videos[0].name).to.equal('video 3') 132 expect(videos[0].name).to.equal('video 3')
144 expect(videos[1].name).to.equal('video 1') 133 expect(videos[1].name).to.equal('video 1')
145 expect(videos[2].name).to.equal('video 2') 134 expect(videos[2].name).to.equal('video 2')
146 }) 135 })
147 136
148 it('Should not have videos history on another user', async function () { 137 it('Should not have videos history on another user', async function () {
149 const res = await listMyVideosHistory(server.url, userAccessToken) 138 const body = await command.list({ token: userAccessToken })
150 139
151 expect(res.body.total).to.equal(0) 140 expect(body.total).to.equal(0)
152 expect(res.body.data).to.have.lengthOf(0) 141 expect(body.data).to.have.lengthOf(0)
153 }) 142 })
154 143
155 it('Should be able to search through videos in my history', async function () { 144 it('Should be able to search through videos in my history', async function () {
156 const res = await listMyVideosHistory(server.url, server.accessToken, '2') 145 const body = await command.list({ search: '2' })
157 146 expect(body.total).to.equal(1)
158 expect(res.body.total).to.equal(1)
159 147
160 const videos: Video[] = res.body.data 148 const videos = body.data
161 expect(videos[0].name).to.equal('video 2') 149 expect(videos[0].name).to.equal('video 2')
162 }) 150 })
163 151
164 it('Should clear my history', async function () { 152 it('Should clear my history', async function () {
165 await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) 153 await command.remove({ beforeDate: video3WatchedDate.toISOString() })
166 }) 154 })
167 155
168 it('Should have my history cleared', async function () { 156 it('Should have my history cleared', async function () {
169 const res = await listMyVideosHistory(server.url, server.accessToken) 157 const body = await command.list()
158 expect(body.total).to.equal(1)
170 159
171 expect(res.body.total).to.equal(1) 160 const videos = body.data
172
173 const videos: Video[] = res.body.data
174 expect(videos[0].name).to.equal('video 3') 161 expect(videos[0].name).to.equal('video 3')
175 }) 162 })
176 163
177 it('Should disable videos history', async function () { 164 it('Should disable videos history', async function () {
178 await updateMyUser({ 165 await server.users.updateMe({
179 url: server.url,
180 accessToken: server.accessToken,
181 videosHistoryEnabled: false 166 videosHistoryEnabled: false
182 }) 167 })
183 168
184 await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409) 169 await command.wathVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 })
185 }) 170 })
186 171
187 it('Should re-enable videos history', async function () { 172 it('Should re-enable videos history', async function () {
188 await updateMyUser({ 173 await server.users.updateMe({
189 url: server.url,
190 accessToken: server.accessToken,
191 videosHistoryEnabled: true 174 videosHistoryEnabled: true
192 }) 175 })
193 176
194 await userWatchVideo(server.url, server.accessToken, video1UUID, 8) 177 await command.wathVideo({ videoId: video1UUID, currentTime: 8 })
195
196 const res = await listMyVideosHistory(server.url, server.accessToken)
197 178
198 expect(res.body.total).to.equal(2) 179 const body = await command.list()
180 expect(body.total).to.equal(2)
199 181
200 const videos: Video[] = res.body.data 182 const videos = body.data
201 expect(videos[0].name).to.equal('video 1') 183 expect(videos[0].name).to.equal('video 1')
202 expect(videos[1].name).to.equal('video 3') 184 expect(videos[1].name).to.equal('video 3')
203 }) 185 })
@@ -205,30 +187,29 @@ describe('Test videos history', function () {
205 it('Should not clean old history', async function () { 187 it('Should not clean old history', async function () {
206 this.timeout(50000) 188 this.timeout(50000)
207 189
208 killallServers([ server ]) 190 await killallServers([ server ])
209 191
210 await reRunServer(server, { history: { videos: { max_age: '10 days' } } }) 192 await server.run({ history: { videos: { max_age: '10 days' } } })
211 193
212 await wait(6000) 194 await wait(6000)
213 195
214 // Should still have history 196 // Should still have history
215 197
216 const res = await listMyVideosHistory(server.url, server.accessToken) 198 const body = await command.list()
217 199 expect(body.total).to.equal(2)
218 expect(res.body.total).to.equal(2)
219 }) 200 })
220 201
221 it('Should clean old history', async function () { 202 it('Should clean old history', async function () {
222 this.timeout(50000) 203 this.timeout(50000)
223 204
224 killallServers([ server ]) 205 await killallServers([ server ])
225 206
226 await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } }) 207 await server.run({ history: { videos: { max_age: '5 seconds' } } })
227 208
228 await wait(6000) 209 await wait(6000)
229 210
230 const res = await listMyVideosHistory(server.url, server.accessToken) 211 const body = await command.list()
231 expect(res.body.total).to.equal(0) 212 expect(body.total).to.equal(0)
232 }) 213 })
233 214
234 after(async function () { 215 after(async function () {
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts
index c266a1dc5..70aa66549 100644
--- a/server/tests/api/videos/videos-overview.ts
+++ b/server/tests/api/videos/videos-overview.ts
@@ -2,29 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5 5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils'
6import { 6import { VideosOverview } from '@shared/models'
7 cleanupTests,
8 flushAndRunServer,
9 generateUserAccessToken,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo,
13 wait
14} from '../../../../shared/extra-utils'
15import { getVideosOverview, getVideosOverviewWithToken } from '../../../../shared/extra-utils/overviews/overviews'
16import { VideosOverview } from '../../../../shared/models/overviews'
17import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist'
18import { Response } from 'superagent'
19 7
20const expect = chai.expect 8const expect = chai.expect
21 9
22describe('Test a videos overview', function () { 10describe('Test a videos overview', function () {
23 let server: ServerInfo = null 11 let server: PeerTubeServer = null
24
25 function testOverviewCount (res: Response, expected: number) {
26 const overview: VideosOverview = res.body
27 12
13 function testOverviewCount (overview: VideosOverview, expected: number) {
28 expect(overview.tags).to.have.lengthOf(expected) 14 expect(overview.tags).to.have.lengthOf(expected)
29 expect(overview.categories).to.have.lengthOf(expected) 15 expect(overview.categories).to.have.lengthOf(expected)
30 expect(overview.channels).to.have.lengthOf(expected) 16 expect(overview.channels).to.have.lengthOf(expected)
@@ -33,15 +19,15 @@ describe('Test a videos overview', function () {
33 before(async function () { 19 before(async function () {
34 this.timeout(30000) 20 this.timeout(30000)
35 21
36 server = await flushAndRunServer(1) 22 server = await createSingleServer(1)
37 23
38 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
39 }) 25 })
40 26
41 it('Should send empty overview', async function () { 27 it('Should send empty overview', async function () {
42 const res = await getVideosOverview(server.url, 1) 28 const body = await server.overviews.getVideos({ page: 1 })
43 29
44 testOverviewCount(res, 0) 30 testOverviewCount(body, 0)
45 }) 31 })
46 32
47 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { 33 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
@@ -49,40 +35,45 @@ describe('Test a videos overview', function () {
49 35
50 await wait(3000) 36 await wait(3000)
51 37
52 await uploadVideo(server.url, server.accessToken, { 38 await server.videos.upload({
53 name: 'video 0', 39 attributes: {
54 category: 3, 40 name: 'video 0',
55 tags: [ 'coucou1', 'coucou2' ] 41 category: 3,
42 tags: [ 'coucou1', 'coucou2' ]
43 }
56 }) 44 })
57 45
58 const res = await getVideosOverview(server.url, 1) 46 const body = await server.overviews.getVideos({ page: 1 })
59 47
60 testOverviewCount(res, 0) 48 testOverviewCount(body, 0)
61 }) 49 })
62 50
63 it('Should upload another video and include all videos in the overview', async function () { 51 it('Should upload another video and include all videos in the overview', async function () {
64 this.timeout(30000) 52 this.timeout(30000)
65 53
66 for (let i = 1; i < 6; i++) { 54 {
67 await uploadVideo(server.url, server.accessToken, { 55 for (let i = 1; i < 6; i++) {
68 name: 'video ' + i, 56 await server.videos.upload({
69 category: 3, 57 attributes: {
70 tags: [ 'coucou1', 'coucou2' ] 58 name: 'video ' + i,
71 }) 59 category: 3,
60 tags: [ 'coucou1', 'coucou2' ]
61 }
62 })
63 }
64
65 await wait(3000)
72 } 66 }
73 67
74 await wait(3000)
75
76 { 68 {
77 const res = await getVideosOverview(server.url, 1) 69 const body = await server.overviews.getVideos({ page: 1 })
78 70
79 testOverviewCount(res, 1) 71 testOverviewCount(body, 1)
80 } 72 }
81 73
82 { 74 {
83 const res = await getVideosOverview(server.url, 2) 75 const overview = await server.overviews.getVideos({ page: 2 })
84 76
85 const overview: VideosOverview = res.body
86 expect(overview.tags).to.have.lengthOf(1) 77 expect(overview.tags).to.have.lengthOf(1)
87 expect(overview.categories).to.have.lengthOf(0) 78 expect(overview.categories).to.have.lengthOf(0)
88 expect(overview.channels).to.have.lengthOf(0) 79 expect(overview.channels).to.have.lengthOf(0)
@@ -90,20 +81,10 @@ describe('Test a videos overview', function () {
90 }) 81 })
91 82
92 it('Should have the correct overview', async function () { 83 it('Should have the correct overview', async function () {
93 const res1 = await getVideosOverview(server.url, 1) 84 const overview1 = await server.overviews.getVideos({ page: 1 })
94 const res2 = await getVideosOverview(server.url, 2) 85 const overview2 = await server.overviews.getVideos({ page: 2 })
95
96 const overview1: VideosOverview = res1.body
97 const overview2: VideosOverview = res2.body
98
99 const tmp = [
100 overview1.tags,
101 overview1.categories,
102 overview1.channels,
103 overview2.tags
104 ]
105 86
106 for (const arr of tmp) { 87 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
107 expect(arr).to.have.lengthOf(1) 88 expect(arr).to.have.lengthOf(1)
108 89
109 const obj = arr[0] 90 const obj = arr[0]
@@ -127,20 +108,20 @@ describe('Test a videos overview', function () {
127 }) 108 })
128 109
129 it('Should hide muted accounts', async function () { 110 it('Should hide muted accounts', async function () {
130 const token = await generateUserAccessToken(server, 'choco') 111 const token = await server.users.generateUserAndToken('choco')
131 112
132 await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) 113 await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host })
133 114
134 { 115 {
135 const res = await getVideosOverview(server.url, 1) 116 const body = await server.overviews.getVideos({ page: 1 })
136 117
137 testOverviewCount(res, 1) 118 testOverviewCount(body, 1)
138 } 119 }
139 120
140 { 121 {
141 const res = await getVideosOverviewWithToken(server.url, 1, token) 122 const body = await server.overviews.getVideos({ page: 1, token })
142 123
143 testOverviewCount(res, 0) 124 testOverviewCount(body, 0)
144 } 125 }
145 }) 126 })
146 127
diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts
index b89f33217..82268b1be 100644
--- a/server/tests/api/videos/videos-views-cleaner.ts
+++ b/server/tests/api/videos/videos-views-cleaner.ts
@@ -1,19 +1,14 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 closeAllSequelize, 7 createMultipleServers,
8 countVideoViewsOf,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunMultipleServers,
11 killallServers, 9 killallServers,
12 reRunServer, 10 PeerTubeServer,
13 ServerInfo,
14 setAccessTokensToServers, 11 setAccessTokensToServers,
15 uploadVideoAndGetId,
16 viewVideo,
17 wait, 12 wait,
18 waitJobs 13 waitJobs
19} from '../../../../shared/extra-utils' 14} from '../../../../shared/extra-utils'
@@ -21,7 +16,7 @@ import {
21const expect = chai.expect 16const expect = chai.expect
22 17
23describe('Test video views cleaner', function () { 18describe('Test video views cleaner', function () {
24 let servers: ServerInfo[] 19 let servers: PeerTubeServer[]
25 20
26 let videoIdServer1: string 21 let videoIdServer1: string
27 let videoIdServer2: string 22 let videoIdServer2: string
@@ -29,20 +24,20 @@ describe('Test video views cleaner', function () {
29 before(async function () { 24 before(async function () {
30 this.timeout(120000) 25 this.timeout(120000)
31 26
32 servers = await flushAndRunMultipleServers(2) 27 servers = await createMultipleServers(2)
33 await setAccessTokensToServers(servers) 28 await setAccessTokensToServers(servers)
34 29
35 await doubleFollow(servers[0], servers[1]) 30 await doubleFollow(servers[0], servers[1])
36 31
37 videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid 32 videoIdServer1 = (await servers[0].videos.quickUpload({ name: 'video server 1' })).uuid
38 videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid 33 videoIdServer2 = (await servers[1].videos.quickUpload({ name: 'video server 2' })).uuid
39 34
40 await waitJobs(servers) 35 await waitJobs(servers)
41 36
42 await viewVideo(servers[0].url, videoIdServer1) 37 await servers[0].videos.view({ id: videoIdServer1 })
43 await viewVideo(servers[1].url, videoIdServer1) 38 await servers[1].videos.view({ id: videoIdServer1 })
44 await viewVideo(servers[0].url, videoIdServer2) 39 await servers[0].videos.view({ id: videoIdServer2 })
45 await viewVideo(servers[1].url, videoIdServer2) 40 await servers[1].videos.view({ id: videoIdServer2 })
46 41
47 await waitJobs(servers) 42 await waitJobs(servers)
48 }) 43 })
@@ -50,9 +45,9 @@ describe('Test video views cleaner', function () {
50 it('Should not clean old video views', async function () { 45 it('Should not clean old video views', async function () {
51 this.timeout(50000) 46 this.timeout(50000)
52 47
53 killallServers([ servers[0] ]) 48 await killallServers([ servers[0] ])
54 49
55 await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } }) 50 await servers[0].run({ views: { videos: { remote: { max_age: '10 days' } } } })
56 51
57 await wait(6000) 52 await wait(6000)
58 53
@@ -60,14 +55,14 @@ describe('Test video views cleaner', function () {
60 55
61 { 56 {
62 for (const server of servers) { 57 for (const server of servers) {
63 const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1) 58 const total = await server.sql.countVideoViewsOf(videoIdServer1)
64 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') 59 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
65 } 60 }
66 } 61 }
67 62
68 { 63 {
69 for (const server of servers) { 64 for (const server of servers) {
70 const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer2) 65 const total = await server.sql.countVideoViewsOf(videoIdServer2)
71 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') 66 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
72 } 67 }
73 } 68 }
@@ -76,9 +71,9 @@ describe('Test video views cleaner', function () {
76 it('Should clean old video views', async function () { 71 it('Should clean old video views', async function () {
77 this.timeout(50000) 72 this.timeout(50000)
78 73
79 killallServers([ servers[0] ]) 74 await killallServers([ servers[0] ])
80 75
81 await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } }) 76 await servers[0].run({ views: { videos: { remote: { max_age: '5 seconds' } } } })
82 77
83 await wait(6000) 78 await wait(6000)
84 79
@@ -86,23 +81,21 @@ describe('Test video views cleaner', function () {
86 81
87 { 82 {
88 for (const server of servers) { 83 for (const server of servers) {
89 const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1) 84 const total = await server.sql.countVideoViewsOf(videoIdServer1)
90 expect(total).to.equal(2) 85 expect(total).to.equal(2)
91 } 86 }
92 } 87 }
93 88
94 { 89 {
95 const totalServer1 = await countVideoViewsOf(servers[0].internalServerNumber, videoIdServer2) 90 const totalServer1 = await servers[0].sql.countVideoViewsOf(videoIdServer2)
96 expect(totalServer1).to.equal(0) 91 expect(totalServer1).to.equal(0)
97 92
98 const totalServer2 = await countVideoViewsOf(servers[1].internalServerNumber, videoIdServer2) 93 const totalServer2 = await servers[1].sql.countVideoViewsOf(videoIdServer2)
99 expect(totalServer2).to.equal(2) 94 expect(totalServer2).to.equal(2)
100 } 95 }
101 }) 96 })
102 97
103 after(async function () { 98 after(async function () {
104 await closeAllSequelize(servers)
105
106 await cleanupTests(servers) 99 await cleanupTests(servers)
107 }) 100 })
108}) 101})