aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-15 10:02:54 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitd23dd9fbfc4d26026352c10f81d2795ceaf2908a (patch)
treeda82286d423c5e834a1ee2dcd5970076b8263cf1 /server/tests/api
parent7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (diff)
downloadPeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.gz
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.zst
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.zip
Introduce videos command
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/activitypub/cleaner.ts50
-rw-r--r--server/tests/api/activitypub/client.ts11
-rw-r--r--server/tests/api/activitypub/fetch.ts33
-rw-r--r--server/tests/api/activitypub/refresher.ts29
-rw-r--r--server/tests/api/check-params/abuses.ts13
-rw-r--r--server/tests/api/check-params/live.ts5
-rw-r--r--server/tests/api/check-params/redundancy.ts9
-rw-r--r--server/tests/api/check-params/services.ts14
-rw-r--r--server/tests/api/check-params/upload-quota.ts37
-rw-r--r--server/tests/api/check-params/users.ts21
-rw-r--r--server/tests/api/check-params/video-blacklist.ts34
-rw-r--r--server/tests/api/check-params/video-captions.ts8
-rw-r--r--server/tests/api/check-params/video-comments.ts13
-rw-r--r--server/tests/api/check-params/video-playlists.ts29
-rw-r--r--server/tests/api/check-params/videos-history.ts13
-rw-r--r--server/tests/api/check-params/videos.ts109
-rw-r--r--server/tests/api/live/live-constraints.ts7
-rw-r--r--server/tests/api/live/live-permanent.ts11
-rw-r--r--server/tests/api/live/live-save-replay.ts48
-rw-r--r--server/tests/api/live/live-socket-messages.ts16
-rw-r--r--server/tests/api/live/live-views.ts18
-rw-r--r--server/tests/api/live/live.ts88
-rw-r--r--server/tests/api/moderation/abuses.ts57
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts16
-rw-r--r--server/tests/api/moderation/blocklist.ts100
-rw-r--r--server/tests/api/moderation/video-blacklist.ts92
-rw-r--r--server/tests/api/notifications/comments-notifications.ts46
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts51
-rw-r--r--server/tests/api/notifications/notifications-api.ts11
-rw-r--r--server/tests/api/notifications/user-notifications.ts19
-rw-r--r--server/tests/api/redundancy/manage-redundancy.ts15
-rw-r--r--server/tests/api/redundancy/redundancy-constraints.ts8
-rw-r--r--server/tests/api/redundancy/redundancy.ts57
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts37
-rw-r--r--server/tests/api/search/search-activitypub-video-playlists.ts9
-rw-r--r--server/tests/api/search/search-activitypub-videos.ts32
-rw-r--r--server/tests/api/search/search-index.ts4
-rw-r--r--server/tests/api/search/search-playlists.ts9
-rw-r--r--server/tests/api/search/search-videos.ts42
-rw-r--r--server/tests/api/server/bulk.ts33
-rw-r--r--server/tests/api/server/config.ts11
-rw-r--r--server/tests/api/server/email.ts24
-rw-r--r--server/tests/api/server/follow-constraints.ts146
-rw-r--r--server/tests/api/server/follows.ts65
-rw-r--r--server/tests/api/server/handle-down.ts73
-rw-r--r--server/tests/api/server/jobs.ts5
-rw-r--r--server/tests/api/server/logs.ts23
-rw-r--r--server/tests/api/server/reverse-proxy.ts53
-rw-r--r--server/tests/api/server/services.ts19
-rw-r--r--server/tests/api/server/stats.ts15
-rw-r--r--server/tests/api/server/tracker.ts21
-rw-r--r--server/tests/api/users/user-subscriptions.ts56
-rw-r--r--server/tests/api/users/users-multiple-servers.ts34
-rw-r--r--server/tests/api/users/users.ts166
-rw-r--r--server/tests/api/videos/audio-only.ts20
-rw-r--r--server/tests/api/videos/multiple-servers.ts334
-rw-r--r--server/tests/api/videos/resumable-upload.ts10
-rw-r--r--server/tests/api/videos/single-server.ts276
-rw-r--r--server/tests/api/videos/video-captions.ts8
-rw-r--r--server/tests/api/videos/video-change-ownership.ts38
-rw-r--r--server/tests/api/videos/video-channels.ts69
-rw-r--r--server/tests/api/videos/video-comments.ts9
-rw-r--r--server/tests/api/videos/video-description.ts41
-rw-r--r--server/tests/api/videos/video-hls.ts32
-rw-r--r--server/tests/api/videos/video-imports.ts54
-rw-r--r--server/tests/api/videos/video-nsfw.ts40
-rw-r--r--server/tests/api/videos/video-playlist-thumbnails.ts5
-rw-r--r--server/tests/api/videos/video-playlists.ts19
-rw-r--r--server/tests/api/videos/video-privacy.ts146
-rw-r--r--server/tests/api/videos/video-schedule-update.ts69
-rw-r--r--server/tests/api/videos/video-transcoder.ts208
-rw-r--r--server/tests/api/videos/videos-filter.ts20
-rw-r--r--server/tests/api/videos/videos-history.ts38
-rw-r--r--server/tests/api/videos/videos-overview.ts22
-rw-r--r--server/tests/api/videos/videos-views-cleaner.ts14
75 files changed, 1495 insertions, 1942 deletions
diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts
index 5b08880bf..dcf758711 100644
--- a/server/tests/api/activitypub/cleaner.ts
+++ b/server/tests/api/activitypub/cleaner.ts
@@ -6,11 +6,8 @@ import {
6 cleanupTests, 6 cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getVideo,
10 rateVideo,
11 ServerInfo, 9 ServerInfo,
12 setAccessTokensToServers, 10 setAccessTokensToServers,
13 uploadVideoAndGetId,
14 wait, 11 wait,
15 waitJobs 12 waitJobs
16} from '@shared/extra-utils' 13} from '@shared/extra-utils'
@@ -49,9 +46,9 @@ describe('Test AP cleaner', function () {
49 // Create 1 comment per video 46 // Create 1 comment per video
50 // Update 1 remote URL and 1 local URL on 47 // Update 1 remote URL and 1 local URL on
51 48
52 videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid 49 videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid
53 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid 50 videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid
54 videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid 51 videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid
55 52
56 videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] 53 videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ]
57 54
@@ -59,7 +56,7 @@ describe('Test AP cleaner', function () {
59 56
60 for (const server of servers) { 57 for (const server of servers) {
61 for (const uuid of videoUUIDs) { 58 for (const uuid of videoUUIDs) {
62 await rateVideo(server.url, server.accessToken, uuid, 'like') 59 await server.videosCommand.rate({ id: uuid, rating: 'like' })
63 await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) 60 await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' })
64 } 61 }
65 } 62 }
@@ -70,9 +67,10 @@ describe('Test AP cleaner', function () {
70 it('Should have the correct likes', async function () { 67 it('Should have the correct likes', async function () {
71 for (const server of servers) { 68 for (const server of servers) {
72 for (const uuid of videoUUIDs) { 69 for (const uuid of videoUUIDs) {
73 const res = await getVideo(server.url, uuid) 70 const video = await server.videosCommand.get({ id: uuid })
74 expect(res.body.likes).to.equal(3) 71
75 expect(res.body.dislikes).to.equal(0) 72 expect(video.likes).to.equal(3)
73 expect(video.dislikes).to.equal(0)
76 } 74 }
77 } 75 }
78 }) 76 })
@@ -90,16 +88,16 @@ describe('Test AP cleaner', function () {
90 88
91 // Updated rates of my video 89 // Updated rates of my video
92 { 90 {
93 const res = await getVideo(servers[0].url, videoUUID1) 91 const video = await servers[0].videosCommand.get({ id: videoUUID1 })
94 expect(res.body.likes).to.equal(2) 92 expect(video.likes).to.equal(2)
95 expect(res.body.dislikes).to.equal(0) 93 expect(video.dislikes).to.equal(0)
96 } 94 }
97 95
98 // Did not update rates of a remote video 96 // Did not update rates of a remote video
99 { 97 {
100 const res = await getVideo(servers[0].url, videoUUID2) 98 const video = await servers[0].videosCommand.get({ id: videoUUID2 })
101 expect(res.body.likes).to.equal(3) 99 expect(video.likes).to.equal(3)
102 expect(res.body.dislikes).to.equal(0) 100 expect(video.dislikes).to.equal(0)
103 } 101 }
104 }) 102 })
105 103
@@ -108,7 +106,7 @@ describe('Test AP cleaner', function () {
108 106
109 for (const server of servers) { 107 for (const server of servers) {
110 for (const uuid of videoUUIDs) { 108 for (const uuid of videoUUIDs) {
111 await rateVideo(server.url, server.accessToken, uuid, 'dislike') 109 await server.videosCommand.rate({ id: uuid, rating: 'dislike' })
112 } 110 }
113 } 111 }
114 112
@@ -116,9 +114,9 @@ describe('Test AP cleaner', function () {
116 114
117 for (const server of servers) { 115 for (const server of servers) {
118 for (const uuid of videoUUIDs) { 116 for (const uuid of videoUUIDs) {
119 const res = await getVideo(server.url, uuid) 117 const video = await server.videosCommand.get({ id: uuid })
120 expect(res.body.likes).to.equal(0) 118 expect(video.likes).to.equal(0)
121 expect(res.body.dislikes).to.equal(3) 119 expect(video.dislikes).to.equal(3)
122 } 120 }
123 } 121 }
124 }) 122 })
@@ -137,16 +135,16 @@ describe('Test AP cleaner', function () {
137 135
138 // Updated rates of my video 136 // Updated rates of my video
139 { 137 {
140 const res = await getVideo(servers[0].url, videoUUID1) 138 const video = await servers[0].videosCommand.get({ id: videoUUID1 })
141 expect(res.body.likes).to.equal(0) 139 expect(video.likes).to.equal(0)
142 expect(res.body.dislikes).to.equal(2) 140 expect(video.dislikes).to.equal(2)
143 } 141 }
144 142
145 // Did not update rates of a remote video 143 // Did not update rates of a remote video
146 { 144 {
147 const res = await getVideo(servers[0].url, videoUUID2) 145 const video = await servers[0].videosCommand.get({ id: videoUUID2 })
148 expect(res.body.likes).to.equal(0) 146 expect(video.likes).to.equal(0)
149 expect(res.body.dislikes).to.equal(3) 147 expect(video.dislikes).to.equal(3)
150 } 148 }
151 }) 149 })
152 150
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts
index e8536a214..0190df04c 100644
--- a/server/tests/api/activitypub/client.ts
+++ b/server/tests/api/activitypub/client.ts
@@ -2,8 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPlaylistPrivacy } from '@shared/models' 5import { HttpStatusCode } from '@shared/core-utils'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 6import {
8 cleanupTests, 7 cleanupTests,
9 doubleFollow, 8 doubleFollow,
@@ -11,9 +10,9 @@ import {
11 makeActivityPubGetRequest, 10 makeActivityPubGetRequest,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 setDefaultVideoChannel, 13 setDefaultVideoChannel
15 uploadVideoAndGetId 14} from '@shared/extra-utils'
16} from '../../../../shared/extra-utils' 15import { VideoPlaylistPrivacy } from '@shared/models'
17 16
18const expect = chai.expect 17const expect = chai.expect
19 18
@@ -69,7 +68,7 @@ describe('Test activitypub', function () {
69 await setDefaultVideoChannel(servers) 68 await setDefaultVideoChannel(servers)
70 69
71 { 70 {
72 video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' }) 71 video = await await servers[0].videosCommand.quickUpload({ name: 'video' })
73 } 72 }
74 73
75 { 74 {
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
index 162f3ec83..5ab4a85d7 100644
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@ -2,17 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6 cleanupTests,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 getVideosListSort,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo,
13 waitJobs
14} from '../../../../shared/extra-utils'
15import { Video } from '../../../../shared/models/videos'
16 6
17const expect = chai.expect 7const expect = chai.expect
18 8
@@ -36,10 +26,9 @@ describe('Test ActivityPub fetcher', function () {
36 26
37 const userAccessToken = await servers[0].loginCommand.getAccessToken(user) 27 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
38 28
39 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) 29 await servers[0].videosCommand.upload({ attributes: { name: 'video root' } })
40 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) 30 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'bad video root' } })
41 const badVideoUUID = res.body.video.uuid 31 await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'video user' } })
42 await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
43 32
44 { 33 {
45 const to = 'http://localhost:' + servers[0].port + '/accounts/user1' 34 const to = 'http://localhost:' + servers[0].port + '/accounts/user1'
@@ -48,8 +37,8 @@ describe('Test ActivityPub fetcher', function () {
48 } 37 }
49 38
50 { 39 {
51 const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID 40 const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid
52 await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value) 41 await servers[0].sqlCommand.setVideoField(uuid, 'url', value)
53 } 42 }
54 }) 43 })
55 44
@@ -60,20 +49,18 @@ describe('Test ActivityPub fetcher', function () {
60 await waitJobs(servers) 49 await waitJobs(servers)
61 50
62 { 51 {
63 const res = await getVideosListSort(servers[0].url, 'createdAt') 52 const { total, data } = await servers[0].videosCommand.list({ sort: 'createdAt' })
64 expect(res.body.total).to.equal(3)
65 53
66 const data: Video[] = res.body.data 54 expect(total).to.equal(3)
67 expect(data[0].name).to.equal('video root') 55 expect(data[0].name).to.equal('video root')
68 expect(data[1].name).to.equal('bad video root') 56 expect(data[1].name).to.equal('bad video root')
69 expect(data[2].name).to.equal('video user') 57 expect(data[2].name).to.equal('video user')
70 } 58 }
71 59
72 { 60 {
73 const res = await getVideosListSort(servers[1].url, 'createdAt') 61 const { total, data } = await servers[1].videosCommand.list({ sort: 'createdAt' })
74 expect(res.body.total).to.equal(1)
75 62
76 const data: Video[] = res.body.data 63 expect(total).to.equal(1)
77 expect(data[0].name).to.equal('video root') 64 expect(data[0].name).to.equal('video root')
78 } 65 }
79 }) 66 })
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index 5a37dbc40..5af4b1edb 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -6,14 +6,11 @@ import {
6 cleanupTests, 6 cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getVideo,
10 killallServers, 9 killallServers,
11 reRunServer, 10 reRunServer,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 setDefaultVideoChannel, 13 setDefaultVideoChannel,
15 uploadVideo,
16 uploadVideoAndGetId,
17 wait, 14 wait,
18 waitJobs 15 waitJobs
19} from '@shared/extra-utils' 16} from '@shared/extra-utils'
@@ -37,17 +34,17 @@ describe('Test AP refresher', function () {
37 await setDefaultVideoChannel(servers) 34 await setDefaultVideoChannel(servers)
38 35
39 { 36 {
40 videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid 37 videoUUID1 = (await servers[1].videosCommand.quickUpload({ name: 'video1' })).uuid
41 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid 38 videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'video2' })).uuid
42 videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid 39 videoUUID3 = (await servers[1].videosCommand.quickUpload({ name: 'video3' })).uuid
43 } 40 }
44 41
45 { 42 {
46 const a1 = await servers[1].usersCommand.generateUserAndToken('user1') 43 const token1 = await servers[1].usersCommand.generateUserAndToken('user1')
47 await uploadVideo(servers[1].url, a1, { name: 'video4' }) 44 await servers[1].videosCommand.upload({ token: token1, attributes: { name: 'video4' } })
48 45
49 const a2 = await servers[1].usersCommand.generateUserAndToken('user2') 46 const token2 = await servers[1].usersCommand.generateUserAndToken('user2')
50 await uploadVideo(servers[1].url, a2, { name: 'video5' }) 47 await servers[1].videosCommand.upload({ token: token2, attributes: { name: 'video5' } })
51 } 48 }
52 49
53 { 50 {
@@ -75,13 +72,13 @@ describe('Test AP refresher', function () {
75 // Change UUID so the remote server returns a 404 72 // Change UUID so the remote server returns a 404
76 await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') 73 await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
77 74
78 await getVideo(servers[0].url, videoUUID1) 75 await servers[0].videosCommand.get({ id: videoUUID1 })
79 await getVideo(servers[0].url, videoUUID2) 76 await servers[0].videosCommand.get({ id: videoUUID2 })
80 77
81 await waitJobs(servers) 78 await waitJobs(servers)
82 79
83 await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404) 80 await servers[0].videosCommand.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
84 await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200) 81 await servers[0].videosCommand.get({ id: videoUUID2 })
85 }) 82 })
86 83
87 it('Should not update a remote video if the remote instance is down', async function () { 84 it('Should not update a remote video if the remote instance is down', async function () {
@@ -94,13 +91,13 @@ describe('Test AP refresher', function () {
94 // Video will need a refresh 91 // Video will need a refresh
95 await wait(10000) 92 await wait(10000)
96 93
97 await getVideo(servers[0].url, videoUUID3) 94 await servers[0].videosCommand.get({ id: videoUUID3 })
98 // The refresh should fail 95 // The refresh should fail
99 await waitJobs([ servers[0] ]) 96 await waitJobs([ servers[0] ])
100 97
101 await reRunServer(servers[1]) 98 await reRunServer(servers[1])
102 99
103 await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200) 100 await servers[0].videosCommand.get({ id: videoUUID3 })
104 }) 101 })
105 }) 102 })
106 103
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index 4cd10a6fd..199cc5599 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -10,12 +10,10 @@ import {
10 cleanupTests, 10 cleanupTests,
11 doubleFollow, 11 doubleFollow,
12 flushAndRunServer, 12 flushAndRunServer,
13 getVideoIdFromUUID,
14 makeGetRequest, 13 makeGetRequest,
15 makePostBodyRequest, 14 makePostBodyRequest,
16 ServerInfo, 15 ServerInfo,
17 setAccessTokensToServers, 16 setAccessTokensToServers,
18 uploadVideo,
19 waitJobs 17 waitJobs
20} from '@shared/extra-utils' 18} from '@shared/extra-utils'
21import { AbuseCreate, AbuseState } from '@shared/models' 19import { AbuseCreate, AbuseState } from '@shared/models'
@@ -41,15 +39,10 @@ describe('Test abuses API validators', function () {
41 39
42 await setAccessTokensToServers([ server ]) 40 await setAccessTokensToServers([ server ])
43 41
44 const username = 'user1' 42 userToken = await server.usersCommand.generateUserAndToken('user_1')
45 const password = 'my super password'
46 await server.usersCommand.create({ username: username, password: password })
47 userToken = await server.loginCommand.getAccessToken({ username, password })
48
49 userToken2 = await server.usersCommand.generateUserAndToken('user_2') 43 userToken2 = await server.usersCommand.generateUserAndToken('user_2')
50 44
51 const res = await uploadVideo(server.url, server.accessToken, {}) 45 server.video = await server.videosCommand.upload()
52 server.video = res.body.video
53 46
54 command = server.abusesCommand 47 command = server.abusesCommand
55 }) 48 })
@@ -421,7 +414,7 @@ describe('Test abuses API validators', function () {
421 414
422 await doubleFollow(anotherServer, server) 415 await doubleFollow(anotherServer, server)
423 416
424 const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) 417 const server2VideoId = await anotherServer.videosCommand.getId({ uuid: server.video.uuid })
425 await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId }) 418 await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId })
426 419
427 await waitJobs([ server, anotherServer ]) 420 await waitJobs([ server, anotherServer ])
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 78863fd50..4b54fc31c 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -13,8 +13,7 @@ import {
13 sendRTMPStream, 13 sendRTMPStream,
14 ServerInfo, 14 ServerInfo,
15 setAccessTokensToServers, 15 setAccessTokensToServers,
16 stopFfmpeg, 16 stopFfmpeg
17 uploadVideoAndGetId
18} from '@shared/extra-utils' 17} from '@shared/extra-utils'
19import { VideoCreateResult, VideoPrivacy } from '@shared/models' 18import { VideoCreateResult, VideoPrivacy } from '@shared/models'
20 19
@@ -58,7 +57,7 @@ describe('Test video lives API validator', function () {
58 } 57 }
59 58
60 { 59 {
61 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id 60 videoIdNotLive = (await server.videosCommand.quickUpload({ name: 'not live' })).id
62 } 61 }
63 62
64 command = server.liveCommand 63 command = server.liveCommand
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index d93022c32..b1692b986 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -10,14 +10,12 @@ import {
10 cleanupTests, 10 cleanupTests,
11 doubleFollow, 11 doubleFollow,
12 flushAndRunMultipleServers, 12 flushAndRunMultipleServers,
13 getVideo,
14 makeDeleteRequest, 13 makeDeleteRequest,
15 makeGetRequest, 14 makeGetRequest,
16 makePostBodyRequest, 15 makePostBodyRequest,
17 makePutBodyRequest, 16 makePutBodyRequest,
18 ServerInfo, 17 ServerInfo,
19 setAccessTokensToServers, 18 setAccessTokensToServers,
20 uploadVideoAndGetId,
21 waitJobs 19 waitJobs
22} from '../../../../shared/extra-utils' 20} from '../../../../shared/extra-utils'
23 21
@@ -45,14 +43,13 @@ describe('Test server redundancy API validators', function () {
45 await servers[0].usersCommand.create({ username: user.username, password: user.password }) 43 await servers[0].usersCommand.create({ username: user.username, password: user.password })
46 userAccessToken = await servers[0].loginCommand.getAccessToken(user) 44 userAccessToken = await servers[0].loginCommand.getAccessToken(user)
47 45
48 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id 46 videoIdLocal = (await servers[0].videosCommand.quickUpload({ name: 'video' })).id
49 47
50 const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid 48 const remoteUUID = (await servers[1].videosCommand.quickUpload({ name: 'video' })).uuid
51 49
52 await waitJobs(servers) 50 await waitJobs(servers)
53 51
54 const resVideo = await getVideo(servers[0].url, remoteUUID) 52 videoRemote = await servers[0].videosCommand.get({ id: remoteUUID })
55 videoRemote = resVideo.body
56 }) 53 })
57 54
58 describe('When listing redundancies', function () { 55 describe('When listing redundancies', function () {
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
index 595fab70d..f86712b4e 100644
--- a/server/tests/api/check-params/services.ts
+++ b/server/tests/api/check-params/services.ts
@@ -1,17 +1,16 @@
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 'mocha' 3import 'mocha'
4import { VideoPlaylistPrivacy } from '@shared/models' 4import { HttpStatusCode } from '@shared/core-utils'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 5import {
7 cleanupTests, 6 cleanupTests,
8 flushAndRunServer, 7 flushAndRunServer,
9 makeGetRequest, 8 makeGetRequest,
10 ServerInfo, 9 ServerInfo,
11 setAccessTokensToServers, 10 setAccessTokensToServers,
12 setDefaultVideoChannel, 11 setDefaultVideoChannel
13 uploadVideo 12} from '@shared/extra-utils'
14} from '../../../../shared/extra-utils' 13import { VideoPlaylistPrivacy } from '@shared/models'
15 14
16describe('Test services API validators', function () { 15describe('Test services API validators', function () {
17 let server: ServerInfo 16 let server: ServerInfo
@@ -26,10 +25,7 @@ describe('Test services API validators', function () {
26 await setAccessTokensToServers([ server ]) 25 await setAccessTokensToServers([ server ])
27 await setDefaultVideoChannel([ server ]) 26 await setDefaultVideoChannel([ server ])
28 27
29 { 28 server.video = await server.videosCommand.upload({ attributes: { name: 'my super name' } })
30 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
31 server.video = res.body.video
32 }
33 29
34 { 30 {
35 const created = await server.playlistsCommand.create({ 31 const created = await server.playlistsCommand.create({
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts
index d94dec624..164c581e3 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -3,7 +3,6 @@
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode, randomInt } from '@shared/core-utils' 5import { HttpStatusCode, randomInt } from '@shared/core-utils'
6import { VideoImportState, VideoPrivacy } from '@shared/models'
7import { 6import {
8 cleanupTests, 7 cleanupTests,
9 flushAndRunServer, 8 flushAndRunServer,
@@ -11,13 +10,15 @@ import {
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 setDefaultVideoChannel, 12 setDefaultVideoChannel,
14 uploadVideo, 13 VideosCommand,
15 waitJobs 14 waitJobs
16} from '../../../../shared/extra-utils' 15} from '@shared/extra-utils'
16import { VideoImportState, VideoPrivacy } from '@shared/models'
17 17
18describe('Test upload quota', function () { 18describe('Test upload quota', function () {
19 let server: ServerInfo 19 let server: ServerInfo
20 let rootId: number 20 let rootId: number
21 let command: VideosCommand
21 22
22 // --------------------------------------------------------------- 23 // ---------------------------------------------------------------
23 24
@@ -32,6 +33,8 @@ describe('Test upload quota', function () {
32 rootId = user.id 33 rootId = user.id
33 34
34 await server.usersCommand.update({ userId: rootId, videoQuota: 42 }) 35 await server.usersCommand.update({ userId: rootId, videoQuota: 42 })
36
37 command = server.videosCommand
35 }) 38 })
36 39
37 describe('When having a video quota', function () { 40 describe('When having a video quota', function () {
@@ -41,14 +44,14 @@ describe('Test upload quota', function () {
41 44
42 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 45 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
43 await server.usersCommand.register(user) 46 await server.usersCommand.register(user)
44 const userAccessToken = await server.loginCommand.getAccessToken(user) 47 const userToken = await server.loginCommand.getAccessToken(user)
45 48
46 const videoAttributes = { fixture: 'video_short2.webm' } 49 const attributes = { fixture: 'video_short2.webm' }
47 for (let i = 0; i < 5; i++) { 50 for (let i = 0; i < 5; i++) {
48 await uploadVideo(server.url, userAccessToken, videoAttributes) 51 await command.upload({ token: userToken, attributes })
49 } 52 }
50 53
51 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 54 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
52 }) 55 })
53 56
54 it('Should fail with a registered user having too many videos with resumable upload', async function () { 57 it('Should fail with a registered user having too many videos with resumable upload', async function () {
@@ -56,14 +59,14 @@ describe('Test upload quota', function () {
56 59
57 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 60 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
58 await server.usersCommand.register(user) 61 await server.usersCommand.register(user)
59 const userAccessToken = await server.loginCommand.getAccessToken(user) 62 const userToken = await server.loginCommand.getAccessToken(user)
60 63
61 const videoAttributes = { fixture: 'video_short2.webm' } 64 const attributes = { fixture: 'video_short2.webm' }
62 for (let i = 0; i < 5; i++) { 65 for (let i = 0; i < 5; i++) {
63 await uploadVideo(server.url, userAccessToken, videoAttributes) 66 await command.upload({ token: userToken, attributes })
64 } 67 }
65 68
66 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 69 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
67 }) 70 })
68 71
69 it('Should fail to import with HTTP/Torrent/magnet', async function () { 72 it('Should fail to import with HTTP/Torrent/magnet', async function () {
@@ -97,8 +100,8 @@ describe('Test upload quota', function () {
97 it('Should fail with a user having too many videos daily', async function () { 100 it('Should fail with a user having too many videos daily', async function () {
98 await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 }) 101 await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 })
99 102
100 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 103 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
101 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 104 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
102 }) 105 })
103 }) 106 })
104 107
@@ -110,8 +113,8 @@ describe('Test upload quota', function () {
110 videoQuotaDaily: 1024 * 1024 * 1024 113 videoQuotaDaily: 1024 * 1024 * 1024
111 }) 114 })
112 115
113 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 116 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
114 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 117 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
115 }) 118 })
116 119
117 it('Should fail if exceeding daily quota', async function () { 120 it('Should fail if exceeding daily quota', async function () {
@@ -121,8 +124,8 @@ describe('Test upload quota', function () {
121 videoQuotaDaily: 42 124 videoQuotaDaily: 42
122 }) 125 })
123 126
124 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 127 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
125 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 128 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
126 }) 129 })
127 }) 130 })
128 131
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 801131918..33c48a009 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -2,10 +2,12 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { UserRole, VideoCreateResult } from '../../../../shared' 5import { HttpStatusCode } from '@shared/core-utils'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 6import {
8 buildAbsoluteFixturePath, 7 buildAbsoluteFixturePath,
8 checkBadCountPagination,
9 checkBadSortPagination,
10 checkBadStartPagination,
9 cleanupTests, 11 cleanupTests,
10 flushAndRunServer, 12 flushAndRunServer,
11 killallServers, 13 killallServers,
@@ -13,19 +15,13 @@ import {
13 makePostBodyRequest, 15 makePostBodyRequest,
14 makePutBodyRequest, 16 makePutBodyRequest,
15 makeUploadRequest, 17 makeUploadRequest,
18 MockSmtpServer,
16 reRunServer, 19 reRunServer,
17 ServerInfo, 20 ServerInfo,
18 setAccessTokensToServers, 21 setAccessTokensToServers,
19 uploadVideo,
20 UsersCommand 22 UsersCommand
21} from '../../../../shared/extra-utils' 23} from '@shared/extra-utils'
22import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' 24import { UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models'
23import {
24 checkBadCountPagination,
25 checkBadSortPagination,
26 checkBadStartPagination
27} from '../../../../shared/extra-utils/requests/check-api-params'
28import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
29 25
30describe('Test users API validators', function () { 26describe('Test users API validators', function () {
31 const path = '/api/v1/users/' 27 const path = '/api/v1/users/'
@@ -80,8 +76,7 @@ describe('Test users API validators', function () {
80 } 76 }
81 77
82 { 78 {
83 const res = await uploadVideo(server.url, server.accessToken, {}) 79 video = await server.videosCommand.upload()
84 video = res.body.video
85 } 80 }
86 81
87 { 82 {
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 5097f8069..0fda31b29 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -11,20 +11,17 @@ import {
11 cleanupTests, 11 cleanupTests,
12 doubleFollow, 12 doubleFollow,
13 flushAndRunMultipleServers, 13 flushAndRunMultipleServers,
14 getVideo,
15 getVideoWithToken,
16 makePostBodyRequest, 14 makePostBodyRequest,
17 makePutBodyRequest, 15 makePutBodyRequest,
18 ServerInfo, 16 ServerInfo,
19 setAccessTokensToServers, 17 setAccessTokensToServers,
20 uploadVideo,
21 waitJobs 18 waitJobs
22} from '@shared/extra-utils' 19} from '@shared/extra-utils'
23import { VideoBlacklistType, VideoDetails } from '@shared/models' 20import { VideoBlacklistType } from '@shared/models'
24 21
25describe('Test video blacklist API validators', function () { 22describe('Test video blacklist API validators', function () {
26 let servers: ServerInfo[] 23 let servers: ServerInfo[]
27 let notBlacklistedVideoId: number 24 let notBlacklistedVideoId: string
28 let remoteVideoUUID: string 25 let remoteVideoUUID: string
29 let userAccessToken1 = '' 26 let userAccessToken1 = ''
30 let userAccessToken2 = '' 27 let userAccessToken2 = ''
@@ -55,18 +52,17 @@ describe('Test video blacklist API validators', function () {
55 } 52 }
56 53
57 { 54 {
58 const res = await uploadVideo(servers[0].url, userAccessToken1, {}) 55 servers[0].video = await servers[0].videosCommand.upload({ token: userAccessToken1 })
59 servers[0].video = res.body.video
60 } 56 }
61 57
62 { 58 {
63 const res = await uploadVideo(servers[0].url, servers[0].accessToken, {}) 59 const { uuid } = await servers[0].videosCommand.upload()
64 notBlacklistedVideoId = res.body.video.uuid 60 notBlacklistedVideoId = uuid
65 } 61 }
66 62
67 { 63 {
68 const res = await uploadVideo(servers[1].url, servers[1].accessToken, {}) 64 const { uuid } = await servers[1].videosCommand.upload()
69 remoteVideoUUID = res.body.video.uuid 65 remoteVideoUUID = uuid
70 } 66 }
71 67
72 await waitJobs(servers) 68 await waitJobs(servers)
@@ -204,17 +200,19 @@ describe('Test video blacklist API validators', function () {
204 describe('When getting blacklisted video', function () { 200 describe('When getting blacklisted video', function () {
205 201
206 it('Should fail with a non authenticated user', async function () { 202 it('Should fail with a non authenticated user', async function () {
207 await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) 203 await servers[0].videosCommand.get({ id: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
208 }) 204 })
209 205
210 it('Should fail with another user', async function () { 206 it('Should fail with another user', async function () {
211 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) 207 await servers[0].videosCommand.getWithToken({
208 token: userAccessToken2,
209 id: servers[0].video.uuid,
210 expectedStatus: HttpStatusCode.FORBIDDEN_403
211 })
212 }) 212 })
213 213
214 it('Should succeed with the owner authenticated user', async function () { 214 it('Should succeed with the owner authenticated user', async function () {
215 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200) 215 const video = await servers[0].videosCommand.getWithToken({ token: userAccessToken1, id: servers[0].video.uuid })
216 const video: VideoDetails = res.body
217
218 expect(video.blacklisted).to.be.true 216 expect(video.blacklisted).to.be.true
219 }) 217 })
220 218
@@ -222,9 +220,7 @@ describe('Test video blacklist API validators', function () {
222 const video = servers[0].video 220 const video = servers[0].video
223 221
224 for (const id of [ video.id, video.uuid, video.shortUUID ]) { 222 for (const id of [ video.id, video.uuid, video.shortUUID ]) {
225 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id, HttpStatusCode.OK_200) 223 const video = await servers[0].videosCommand.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 })
226 const video: VideoDetails = res.body
227
228 expect(video.blacklisted).to.be.true 224 expect(video.blacklisted).to.be.true
229 } 225 }
230 }) 226 })
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index 631ef4dac..f3941b3fa 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -10,8 +10,7 @@ import {
10 makeGetRequest, 10 makeGetRequest,
11 makeUploadRequest, 11 makeUploadRequest,
12 ServerInfo, 12 ServerInfo,
13 setAccessTokensToServers, 13 setAccessTokensToServers
14 uploadVideo
15} from '@shared/extra-utils' 14} from '@shared/extra-utils'
16import { VideoCreateResult } from '@shared/models' 15import { VideoCreateResult } from '@shared/models'
17 16
@@ -31,10 +30,7 @@ describe('Test video captions API validator', function () {
31 30
32 await setAccessTokensToServers([ server ]) 31 await setAccessTokensToServers([ server ])
33 32
34 { 33 video = await server.videosCommand.upload()
35 const res = await uploadVideo(server.url, server.accessToken, {})
36 video = res.body.video
37 }
38 34
39 { 35 {
40 const user = { 36 const user = {
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index b7656a176..bdf7f91ee 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -13,8 +13,7 @@ import {
13 makeGetRequest, 13 makeGetRequest,
14 makePostBodyRequest, 14 makePostBodyRequest,
15 ServerInfo, 15 ServerInfo,
16 setAccessTokensToServers, 16 setAccessTokensToServers
17 uploadVideo
18} from '@shared/extra-utils' 17} from '@shared/extra-utils'
19import { VideoCreateResult } from '@shared/models' 18import { VideoCreateResult } from '@shared/models'
20 19
@@ -39,8 +38,7 @@ describe('Test video comments API validator', function () {
39 await setAccessTokensToServers([ server ]) 38 await setAccessTokensToServers([ server ])
40 39
41 { 40 {
42 const res = await uploadVideo(server.url, server.accessToken, {}) 41 const video = await server.videosCommand.upload({ attributes: {} })
43 video = res.body.video
44 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' 42 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
45 } 43 }
46 44
@@ -291,8 +289,8 @@ describe('Test video comments API validator', function () {
291 let anotherVideoUUID: string 289 let anotherVideoUUID: string
292 290
293 { 291 {
294 const res = await uploadVideo(server.url, userAccessToken, { name: 'video' }) 292 const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes: { name: 'video' } })
295 anotherVideoUUID = res.body.video.uuid 293 anotherVideoUUID = uuid
296 } 294 }
297 295
298 { 296 {
@@ -318,8 +316,7 @@ describe('Test video comments API validator', function () {
318 316
319 describe('When a video has comments disabled', function () { 317 describe('When a video has comments disabled', function () {
320 before(async function () { 318 before(async function () {
321 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) 319 video = await server.videosCommand.upload({ attributes: { commentsEnabled: false } })
322 video = res.body.video
323 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' 320 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
324 }) 321 })
325 322
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 46c09bb11..ebd7e2413 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -3,15 +3,6 @@
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '@shared/core-utils' 4import { HttpStatusCode } from '@shared/core-utils'
5import { 5import {
6 VideoPlaylistCreate,
7 VideoPlaylistCreateResult,
8 VideoPlaylistElementCreate,
9 VideoPlaylistElementUpdate,
10 VideoPlaylistPrivacy,
11 VideoPlaylistReorder,
12 VideoPlaylistType
13} from '@shared/models'
14import {
15 checkBadCountPagination, 6 checkBadCountPagination,
16 checkBadSortPagination, 7 checkBadSortPagination,
17 checkBadStartPagination, 8 checkBadStartPagination,
@@ -21,9 +12,17 @@ import {
21 PlaylistsCommand, 12 PlaylistsCommand,
22 ServerInfo, 13 ServerInfo,
23 setAccessTokensToServers, 14 setAccessTokensToServers,
24 setDefaultVideoChannel, 15 setDefaultVideoChannel
25 uploadVideoAndGetId 16} from '@shared/extra-utils'
26} from '../../../../shared/extra-utils' 17import {
18 VideoPlaylistCreate,
19 VideoPlaylistCreateResult,
20 VideoPlaylistElementCreate,
21 VideoPlaylistElementUpdate,
22 VideoPlaylistPrivacy,
23 VideoPlaylistReorder,
24 VideoPlaylistType
25} from '@shared/models'
27 26
28describe('Test video playlists API validator', function () { 27describe('Test video playlists API validator', function () {
29 let server: ServerInfo 28 let server: ServerInfo
@@ -49,7 +48,7 @@ describe('Test video playlists API validator', function () {
49 await setDefaultVideoChannel([ server ]) 48 await setDefaultVideoChannel([ server ])
50 49
51 userAccessToken = await server.usersCommand.generateUserAndToken('user1') 50 userAccessToken = await server.usersCommand.generateUserAndToken('user1')
52 videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id 51 videoId = (await server.videosCommand.quickUpload({ name: 'video 1' })).id
53 52
54 command = server.playlistsCommand 53 command = server.playlistsCommand
55 54
@@ -486,8 +485,8 @@ describe('Test video playlists API validator', function () {
486 } 485 }
487 486
488 before(async function () { 487 before(async function () {
489 videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id 488 videoId3 = (await server.videosCommand.quickUpload({ name: 'video 3' })).id
490 videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id 489 videoId4 = (await server.videosCommand.quickUpload({ name: 'video 4' })).id
491 490
492 for (const id of [ videoId3, videoId4 ]) { 491 for (const id of [ videoId3, videoId4 ]) {
493 await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } }) 492 await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } })
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts
index 0e91fe0a8..1da922a17 100644
--- a/server/tests/api/check-params/videos-history.ts
+++ b/server/tests/api/check-params/videos-history.ts
@@ -1,6 +1,7 @@
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 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '@shared/core-utils'
4import { 5import {
5 checkBadCountPagination, 6 checkBadCountPagination,
6 checkBadStartPagination, 7 checkBadStartPagination,
@@ -10,10 +11,8 @@ import {
10 makePostBodyRequest, 11 makePostBodyRequest,
11 makePutBodyRequest, 12 makePutBodyRequest,
12 ServerInfo, 13 ServerInfo,
13 setAccessTokensToServers, 14 setAccessTokensToServers
14 uploadVideo 15} from '@shared/extra-utils'
15} from '../../../../shared/extra-utils'
16import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
17 16
18describe('Test videos history API validator', function () { 17describe('Test videos history API validator', function () {
19 const myHistoryPath = '/api/v1/users/me/history/videos' 18 const myHistoryPath = '/api/v1/users/me/history/videos'
@@ -30,10 +29,8 @@ describe('Test videos history API validator', function () {
30 29
31 await setAccessTokensToServers([ server ]) 30 await setAccessTokensToServers([ server ])
32 31
33 const res = await uploadVideo(server.url, server.accessToken, {}) 32 const { uuid } = await server.videosCommand.upload()
34 const videoUUID = res.body.video.uuid 33 watchingPath = '/api/v1/videos/' + uuid + '/watching'
35
36 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
37 }) 34 })
38 35
39 describe('When notifying a user is watching a video', function () { 36 describe('When notifying a user is watching a video', function () {
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 855b09f39..8f9f33b8c 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -4,30 +4,23 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { join } from 'path' 6import { join } from 'path'
7import { randomInt } from '@shared/core-utils' 7import { HttpStatusCode, randomInt } from '@shared/core-utils'
8import { PeerTubeProblemDocument, VideoCreateResult } from '@shared/models'
9import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
10import { 8import {
9 checkBadCountPagination,
10 checkBadSortPagination,
11 checkBadStartPagination,
11 checkUploadVideoParam, 12 checkUploadVideoParam,
12 cleanupTests, 13 cleanupTests,
13 flushAndRunServer, 14 flushAndRunServer,
14 getVideo,
15 getVideosList,
16 makeDeleteRequest, 15 makeDeleteRequest,
17 makeGetRequest, 16 makeGetRequest,
18 makePutBodyRequest, 17 makePutBodyRequest,
19 makeUploadRequest, 18 makeUploadRequest,
20 removeVideo,
21 root, 19 root,
22 ServerInfo, 20 ServerInfo,
23 setAccessTokensToServers 21 setAccessTokensToServers
24} from '../../../../shared/extra-utils' 22} from '@shared/extra-utils'
25import { 23import { PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models'
26 checkBadCountPagination,
27 checkBadSortPagination,
28 checkBadStartPagination
29} from '../../../../shared/extra-utils/requests/check-api-params'
30import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
31 24
32const expect = chai.expect 25const expect = chai.expect
33 26
@@ -210,70 +203,70 @@ describe('Test videos API validator', function () {
210 it('Should fail with nothing', async function () { 203 it('Should fail with nothing', async function () {
211 const fields = {} 204 const fields = {}
212 const attaches = {} 205 const attaches = {}
213 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 206 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
214 }) 207 })
215 208
216 it('Should fail without name', async function () { 209 it('Should fail without name', async function () {
217 const fields = omit(baseCorrectParams, 'name') 210 const fields = omit(baseCorrectParams, 'name')
218 const attaches = baseCorrectAttaches 211 const attaches = baseCorrectAttaches
219 212
220 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 213 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
221 }) 214 })
222 215
223 it('Should fail with a long name', async function () { 216 it('Should fail with a long name', async function () {
224 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } 217 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
225 const attaches = baseCorrectAttaches 218 const attaches = baseCorrectAttaches
226 219
227 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 220 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
228 }) 221 })
229 222
230 it('Should fail with a bad category', async function () { 223 it('Should fail with a bad category', async function () {
231 const fields = { ...baseCorrectParams, category: 125 } 224 const fields = { ...baseCorrectParams, category: 125 }
232 const attaches = baseCorrectAttaches 225 const attaches = baseCorrectAttaches
233 226
234 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 227 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
235 }) 228 })
236 229
237 it('Should fail with a bad licence', async function () { 230 it('Should fail with a bad licence', async function () {
238 const fields = { ...baseCorrectParams, licence: 125 } 231 const fields = { ...baseCorrectParams, licence: 125 }
239 const attaches = baseCorrectAttaches 232 const attaches = baseCorrectAttaches
240 233
241 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 234 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
242 }) 235 })
243 236
244 it('Should fail with a bad language', async function () { 237 it('Should fail with a bad language', async function () {
245 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } 238 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
246 const attaches = baseCorrectAttaches 239 const attaches = baseCorrectAttaches
247 240
248 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 241 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
249 }) 242 })
250 243
251 it('Should fail with a long description', async function () { 244 it('Should fail with a long description', async function () {
252 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } 245 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
253 const attaches = baseCorrectAttaches 246 const attaches = baseCorrectAttaches
254 247
255 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 248 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
256 }) 249 })
257 250
258 it('Should fail with a long support text', async function () { 251 it('Should fail with a long support text', async function () {
259 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } 252 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
260 const attaches = baseCorrectAttaches 253 const attaches = baseCorrectAttaches
261 254
262 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 255 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
263 }) 256 })
264 257
265 it('Should fail without a channel', async function () { 258 it('Should fail without a channel', async function () {
266 const fields = omit(baseCorrectParams, 'channelId') 259 const fields = omit(baseCorrectParams, 'channelId')
267 const attaches = baseCorrectAttaches 260 const attaches = baseCorrectAttaches
268 261
269 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 262 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
270 }) 263 })
271 264
272 it('Should fail with a bad channel', async function () { 265 it('Should fail with a bad channel', async function () {
273 const fields = { ...baseCorrectParams, channelId: 545454 } 266 const fields = { ...baseCorrectParams, channelId: 545454 }
274 const attaches = baseCorrectAttaches 267 const attaches = baseCorrectAttaches
275 268
276 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 269 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
277 }) 270 })
278 271
279 it('Should fail with another user channel', async function () { 272 it('Should fail with another user channel', async function () {
@@ -290,35 +283,35 @@ describe('Test videos API validator', function () {
290 const fields = { ...baseCorrectParams, channelId: customChannelId } 283 const fields = { ...baseCorrectParams, channelId: customChannelId }
291 const attaches = baseCorrectAttaches 284 const attaches = baseCorrectAttaches
292 285
293 await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 286 await checkUploadVideoParam(server, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
294 }) 287 })
295 288
296 it('Should fail with too many tags', async function () { 289 it('Should fail with too many tags', async function () {
297 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } 290 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
298 const attaches = baseCorrectAttaches 291 const attaches = baseCorrectAttaches
299 292
300 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 293 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
301 }) 294 })
302 295
303 it('Should fail with a tag length too low', async function () { 296 it('Should fail with a tag length too low', async function () {
304 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } 297 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
305 const attaches = baseCorrectAttaches 298 const attaches = baseCorrectAttaches
306 299
307 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 300 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
308 }) 301 })
309 302
310 it('Should fail with a tag length too big', async function () { 303 it('Should fail with a tag length too big', async function () {
311 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } 304 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
312 const attaches = baseCorrectAttaches 305 const attaches = baseCorrectAttaches
313 306
314 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 307 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
315 }) 308 })
316 309
317 it('Should fail with a bad schedule update (miss updateAt)', async function () { 310 it('Should fail with a bad schedule update (miss updateAt)', async function () {
318 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } 311 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
319 const attaches = baseCorrectAttaches 312 const attaches = baseCorrectAttaches
320 313
321 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 314 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
322 }) 315 })
323 316
324 it('Should fail with a bad schedule update (wrong updateAt)', async function () { 317 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
@@ -332,20 +325,20 @@ describe('Test videos API validator', function () {
332 } 325 }
333 const attaches = baseCorrectAttaches 326 const attaches = baseCorrectAttaches
334 327
335 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 328 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
336 }) 329 })
337 330
338 it('Should fail with a bad originally published at attribute', async function () { 331 it('Should fail with a bad originally published at attribute', async function () {
339 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } 332 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
340 const attaches = baseCorrectAttaches 333 const attaches = baseCorrectAttaches
341 334
342 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 335 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
343 }) 336 })
344 337
345 it('Should fail without an input file', async function () { 338 it('Should fail without an input file', async function () {
346 const fields = baseCorrectParams 339 const fields = baseCorrectParams
347 const attaches = {} 340 const attaches = {}
348 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 341 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
349 }) 342 })
350 343
351 it('Should fail with an incorrect input file', async function () { 344 it('Should fail with an incorrect input file', async function () {
@@ -353,7 +346,7 @@ describe('Test videos API validator', function () {
353 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } 346 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
354 347
355 await checkUploadVideoParam( 348 await checkUploadVideoParam(
356 server.url, 349 server,
357 server.accessToken, 350 server.accessToken,
358 { ...fields, ...attaches }, 351 { ...fields, ...attaches },
359 HttpStatusCode.UNPROCESSABLE_ENTITY_422, 352 HttpStatusCode.UNPROCESSABLE_ENTITY_422,
@@ -362,7 +355,7 @@ describe('Test videos API validator', function () {
362 355
363 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } 356 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
364 await checkUploadVideoParam( 357 await checkUploadVideoParam(
365 server.url, 358 server,
366 server.accessToken, 359 server.accessToken,
367 { ...fields, ...attaches }, 360 { ...fields, ...attaches },
368 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415, 361 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
@@ -377,7 +370,7 @@ describe('Test videos API validator', function () {
377 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 370 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
378 } 371 }
379 372
380 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 373 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
381 }) 374 })
382 375
383 it('Should fail with a big thumbnail file', async function () { 376 it('Should fail with a big thumbnail file', async function () {
@@ -387,7 +380,7 @@ describe('Test videos API validator', function () {
387 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 380 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
388 } 381 }
389 382
390 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 383 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
391 }) 384 })
392 385
393 it('Should fail with an incorrect preview file', async function () { 386 it('Should fail with an incorrect preview file', async function () {
@@ -397,7 +390,7 @@ describe('Test videos API validator', function () {
397 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 390 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
398 } 391 }
399 392
400 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 393 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
401 }) 394 })
402 395
403 it('Should fail with a big preview file', async function () { 396 it('Should fail with a big preview file', async function () {
@@ -407,7 +400,7 @@ describe('Test videos API validator', function () {
407 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 400 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
408 } 401 }
409 402
410 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 403 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
411 }) 404 })
412 405
413 it('Should report the appropriate error', async function () { 406 it('Should report the appropriate error', async function () {
@@ -415,9 +408,9 @@ describe('Test videos API validator', function () {
415 const attaches = baseCorrectAttaches 408 const attaches = baseCorrectAttaches
416 409
417 const attributes = { ...fields, ...attaches } 410 const attributes = { ...fields, ...attaches }
418 const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode) 411 const body = await checkUploadVideoParam(server, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
419 412
420 const error = res.body as PeerTubeProblemDocument 413 const error = body as unknown as PeerTubeProblemDocument
421 414
422 if (mode === 'legacy') { 415 if (mode === 'legacy') {
423 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy') 416 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy')
@@ -442,7 +435,7 @@ describe('Test videos API validator', function () {
442 435
443 { 436 {
444 const attaches = baseCorrectAttaches 437 const attaches = baseCorrectAttaches
445 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 438 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
446 } 439 }
447 440
448 { 441 {
@@ -452,7 +445,7 @@ describe('Test videos API validator', function () {
452 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 445 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
453 } 446 }
454 447
455 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 448 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
456 } 449 }
457 450
458 { 451 {
@@ -462,7 +455,7 @@ describe('Test videos API validator', function () {
462 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') 455 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
463 } 456 }
464 457
465 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 458 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
466 } 459 }
467 }) 460 })
468 } 461 }
@@ -491,8 +484,8 @@ describe('Test videos API validator', function () {
491 } 484 }
492 485
493 before(async function () { 486 before(async function () {
494 const res = await getVideosList(server.url) 487 const { data } = await server.videosCommand.list()
495 video = res.body.data[0] 488 video = data[0]
496 }) 489 })
497 490
498 it('Should fail with nothing', async function () { 491 it('Should fail with nothing', async function () {
@@ -717,16 +710,16 @@ describe('Test videos API validator', function () {
717 }) 710 })
718 711
719 it('Should fail without a correct uuid', async function () { 712 it('Should fail without a correct uuid', async function () {
720 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400) 713 await server.videosCommand.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
721 }) 714 })
722 715
723 it('Should return 404 with an incorrect video', async function () { 716 it('Should return 404 with an incorrect video', async function () {
724 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) 717 await server.videosCommand.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
725 }) 718 })
726 719
727 it('Shoud report the appropriate error', async function () { 720 it('Shoud report the appropriate error', async function () {
728 const res = await getVideo(server.url, 'hi', HttpStatusCode.BAD_REQUEST_400) 721 const body = await server.videosCommand.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
729 const error = res.body as PeerTubeProblemDocument 722 const error = body as unknown as PeerTubeProblemDocument
730 723
731 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo') 724 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo')
732 725
@@ -741,16 +734,16 @@ describe('Test videos API validator', function () {
741 }) 734 })
742 735
743 it('Should succeed with the correct parameters', async function () { 736 it('Should succeed with the correct parameters', async function () {
744 await getVideo(server.url, video.shortUUID) 737 await server.videosCommand.get({ id: video.shortUUID })
745 }) 738 })
746 }) 739 })
747 740
748 describe('When rating a video', function () { 741 describe('When rating a video', function () {
749 let videoId 742 let videoId: number
750 743
751 before(async function () { 744 before(async function () {
752 const res = await getVideosList(server.url) 745 const { data } = await server.videosCommand.list()
753 videoId = res.body.data[0].id 746 videoId = data[0].id
754 }) 747 })
755 748
756 it('Should fail without a valid uuid', async function () { 749 it('Should fail without a valid uuid', async function () {
@@ -804,22 +797,22 @@ describe('Test videos API validator', function () {
804 }) 797 })
805 798
806 it('Should fail without a correct uuid', async function () { 799 it('Should fail without a correct uuid', async function () {
807 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) 800 await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
808 }) 801 })
809 802
810 it('Should fail with a video which does not exist', async function () { 803 it('Should fail with a video which does not exist', async function () {
811 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) 804 await server.videosCommand.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
812 }) 805 })
813 806
814 it('Should fail with a video of another user without the appropriate right', async function () { 807 it('Should fail with a video of another user without the appropriate right', async function () {
815 await removeVideo(server.url, userAccessToken, video.uuid, HttpStatusCode.FORBIDDEN_403) 808 await server.videosCommand.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
816 }) 809 })
817 810
818 it('Should fail with a video of another server') 811 it('Should fail with a video of another server')
819 812
820 it('Shoud report the appropriate error', async function () { 813 it('Shoud report the appropriate error', async function () {
821 const res = await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) 814 const body = await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
822 const error = res.body as PeerTubeProblemDocument 815 const error = body as unknown as PeerTubeProblemDocument
823 816
824 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo') 817 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo')
825 818
@@ -834,7 +827,7 @@ describe('Test videos API validator', function () {
834 }) 827 })
835 828
836 it('Should succeed with the correct parameters', async function () { 829 it('Should succeed with the correct parameters', async function () {
837 await removeVideo(server.url, server.accessToken, video.uuid) 830 await server.videosCommand.remove({ id: video.uuid })
838 }) 831 })
839 }) 832 })
840 833
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts
index 290d325d4..7900b1abe 100644
--- a/server/tests/api/live/live-constraints.ts
+++ b/server/tests/api/live/live-constraints.ts
@@ -2,14 +2,13 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails, VideoPrivacy } from '@shared/models' 5import { VideoPrivacy } from '@shared/models'
6import { 6import {
7 checkLiveCleanup, 7 checkLiveCleanup,
8 cleanupTests, 8 cleanupTests,
9 ConfigCommand, 9 ConfigCommand,
10 doubleFollow, 10 doubleFollow,
11 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
12 getVideo,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 setDefaultVideoChannel, 14 setDefaultVideoChannel,
@@ -39,9 +38,7 @@ describe('Test live constraints', function () {
39 38
40 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { 39 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
41 for (const server of servers) { 40 for (const server of servers) {
42 const res = await getVideo(server.url, videoId) 41 const video = await server.videosCommand.get({ id: videoId })
43
44 const video: VideoDetails = res.body
45 expect(video.isLive).to.be.false 42 expect(video.isLive).to.be.false
46 expect(video.duration).to.be.greaterThan(0) 43 expect(video.duration).to.be.greaterThan(0)
47 } 44 }
diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts
index 6f4915a6b..707f2edf8 100644
--- a/server/tests/api/live/live-permanent.ts
+++ b/server/tests/api/live/live-permanent.ts
@@ -2,13 +2,12 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' 5import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 ConfigCommand, 8 ConfigCommand,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideo,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 setDefaultVideoChannel, 13 setDefaultVideoChannel,
@@ -38,8 +37,8 @@ describe('Permanent live', function () {
38 37
39 async function checkVideoState (videoId: string, state: VideoState) { 38 async function checkVideoState (videoId: string, state: VideoState) {
40 for (const server of servers) { 39 for (const server of servers) {
41 const res = await getVideo(server.url, videoId) 40 const video = await server.videosCommand.get({ id: videoId })
42 expect((res.body as VideoDetails).state.id).to.equal(state) 41 expect(video.state.id).to.equal(state)
43 } 42 }
44 } 43 }
45 44
@@ -123,9 +122,7 @@ describe('Permanent live', function () {
123 await waitJobs(servers) 122 await waitJobs(servers)
124 123
125 for (const server of servers) { 124 for (const server of servers) {
126 const res = await getVideo(server.url, videoUUID) 125 const videoDetails = await server.videosCommand.get({ id: videoUUID })
127
128 const videoDetails = res.body as VideoDetails
129 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) 126 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
130 } 127 }
131 }) 128 })
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts
index 363fb561c..a87a2cd12 100644
--- a/server/tests/api/live/live-save-replay.ts
+++ b/server/tests/api/live/live-save-replay.ts
@@ -3,26 +3,22 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg' 5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' 6import { HttpStatusCode } from '@shared/core-utils'
7import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8import { 7import {
9 checkLiveCleanup, 8 checkLiveCleanup,
10 cleanupTests, 9 cleanupTests,
11 ConfigCommand, 10 ConfigCommand,
12 doubleFollow, 11 doubleFollow,
13 flushAndRunMultipleServers, 12 flushAndRunMultipleServers,
14 getVideo,
15 getVideosList,
16 removeVideo,
17 ServerInfo, 13 ServerInfo,
18 setAccessTokensToServers, 14 setAccessTokensToServers,
19 setDefaultVideoChannel, 15 setDefaultVideoChannel,
20 stopFfmpeg, 16 stopFfmpeg,
21 testFfmpegStreamError, 17 testFfmpegStreamError,
22 updateVideo,
23 wait, 18 wait,
24 waitJobs 19 waitJobs
25} from '../../../../shared/extra-utils' 20} from '@shared/extra-utils'
21import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
26 22
27const expect = chai.expect 23const expect = chai.expect
28 24
@@ -34,7 +30,7 @@ describe('Save replay setting', function () {
34 async function createLiveWrapper (saveReplay: boolean) { 30 async function createLiveWrapper (saveReplay: boolean) {
35 if (liveVideoUUID) { 31 if (liveVideoUUID) {
36 try { 32 try {
37 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) 33 await servers[0].videosCommand.remove({ id: liveVideoUUID })
38 await waitJobs(servers) 34 await waitJobs(servers)
39 } catch {} 35 } catch {}
40 } 36 }
@@ -50,24 +46,24 @@ describe('Save replay setting', function () {
50 return uuid 46 return uuid
51 } 47 }
52 48
53 async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) { 49 async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) {
54 for (const server of servers) { 50 for (const server of servers) {
55 const length = existsInList ? 1 : 0 51 const length = existsInList ? 1 : 0
56 52
57 const resVideos = await getVideosList(server.url) 53 const { data, total } = await server.videosCommand.list()
58 expect(resVideos.body.data).to.have.lengthOf(length) 54 expect(data).to.have.lengthOf(length)
59 expect(resVideos.body.total).to.equal(length) 55 expect(total).to.equal(length)
60 56
61 if (getStatus) { 57 if (expectedStatus) {
62 await getVideo(server.url, videoId, getStatus) 58 await server.videosCommand.get({ id: videoId, expectedStatus })
63 } 59 }
64 } 60 }
65 } 61 }
66 62
67 async function checkVideoState (videoId: string, state: VideoState) { 63 async function checkVideoState (videoId: string, state: VideoState) {
68 for (const server of servers) { 64 for (const server of servers) {
69 const res = await getVideo(server.url, videoId) 65 const video = await server.videosCommand.get({ id: videoId })
70 expect((res.body as VideoDetails).state.id).to.equal(state) 66 expect(video.state.id).to.equal(state)
71 } 67 }
72 } 68 }
73 69
@@ -179,8 +175,8 @@ describe('Save replay setting', function () {
179 175
180 await checkVideosExist(liveVideoUUID, false) 176 await checkVideosExist(liveVideoUUID, false)
181 177
182 await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) 178 await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
183 await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) 179 await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
184 180
185 await wait(5000) 181 await wait(5000)
186 await waitJobs(servers) 182 await waitJobs(servers)
@@ -201,7 +197,7 @@ describe('Save replay setting', function () {
201 197
202 await Promise.all([ 198 await Promise.all([
203 testFfmpegStreamError(ffmpegCommand, true), 199 testFfmpegStreamError(ffmpegCommand, true),
204 removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) 200 servers[0].videosCommand.remove({ id: liveVideoUUID })
205 ]) 201 ])
206 202
207 await wait(5000) 203 await wait(5000)
@@ -253,13 +249,13 @@ describe('Save replay setting', function () {
253 it('Should update the saved live and correctly federate the updated attributes', async function () { 249 it('Should update the saved live and correctly federate the updated attributes', async function () {
254 this.timeout(30000) 250 this.timeout(30000)
255 251
256 await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' }) 252 await servers[0].videosCommand.update({ id: liveVideoUUID, attributes: { name: 'video updated' } })
257 await waitJobs(servers) 253 await waitJobs(servers)
258 254
259 for (const server of servers) { 255 for (const server of servers) {
260 const res = await getVideo(server.url, liveVideoUUID) 256 const video = await server.videosCommand.get({ id: liveVideoUUID })
261 expect(res.body.name).to.equal('video updated') 257 expect(video.name).to.equal('video updated')
262 expect(res.body.isLive).to.be.false 258 expect(video.isLive).to.be.false
263 } 259 }
264 }) 260 })
265 261
@@ -287,8 +283,8 @@ describe('Save replay setting', function () {
287 283
288 await checkVideosExist(liveVideoUUID, false) 284 await checkVideosExist(liveVideoUUID, false)
289 285
290 await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) 286 await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
291 await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) 287 await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
292 288
293 await wait(5000) 289 await wait(5000)
294 await waitJobs(servers) 290 await waitJobs(servers)
@@ -307,7 +303,7 @@ describe('Save replay setting', function () {
307 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) 303 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
308 304
309 await Promise.all([ 305 await Promise.all([
310 removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), 306 servers[0].videosCommand.remove({ id: liveVideoUUID }),
311 testFfmpegStreamError(ffmpegCommand, true) 307 testFfmpegStreamError(ffmpegCommand, true)
312 ]) 308 ])
313 309
diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts
index 4a6677c0a..1f3d455a8 100644
--- a/server/tests/api/live/live-socket-messages.ts
+++ b/server/tests/api/live/live-socket-messages.ts
@@ -7,12 +7,10 @@ import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getVideoIdFromUUID,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 setDefaultVideoChannel, 12 setDefaultVideoChannel,
14 stopFfmpeg, 13 stopFfmpeg,
15 viewVideo,
16 wait, 14 wait,
17 waitJobs, 15 waitJobs,
18 waitUntilLivePublishedOnAllServers 16 waitUntilLivePublishedOnAllServers
@@ -71,7 +69,7 @@ describe('Test live', function () {
71 await waitJobs(servers) 69 await waitJobs(servers)
72 70
73 { 71 {
74 const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) 72 const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
75 73
76 const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() 74 const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
77 localSocket.on('state-change', data => localStateChanges.push(data.state)) 75 localSocket.on('state-change', data => localStateChanges.push(data.state))
@@ -79,7 +77,7 @@ describe('Test live', function () {
79 } 77 }
80 78
81 { 79 {
82 const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) 80 const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID })
83 81
84 const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() 82 const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
85 remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) 83 remoteSocket.on('state-change', data => remoteStateChanges.push(data.state))
@@ -119,7 +117,7 @@ describe('Test live', function () {
119 await waitJobs(servers) 117 await waitJobs(servers)
120 118
121 { 119 {
122 const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) 120 const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
123 121
124 const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() 122 const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
125 localSocket.on('views-change', data => { localLastVideoViews = data.views }) 123 localSocket.on('views-change', data => { localLastVideoViews = data.views })
@@ -127,7 +125,7 @@ describe('Test live', function () {
127 } 125 }
128 126
129 { 127 {
130 const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) 128 const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID })
131 129
132 const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() 130 const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
133 remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) 131 remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views })
@@ -142,8 +140,8 @@ describe('Test live', function () {
142 expect(localLastVideoViews).to.equal(0) 140 expect(localLastVideoViews).to.equal(0)
143 expect(remoteLastVideoViews).to.equal(0) 141 expect(remoteLastVideoViews).to.equal(0)
144 142
145 await viewVideo(servers[0].url, liveVideoUUID) 143 await servers[0].videosCommand.view({ id: liveVideoUUID })
146 await viewVideo(servers[1].url, liveVideoUUID) 144 await servers[1].videosCommand.view({ id: liveVideoUUID })
147 145
148 await waitJobs(servers) 146 await waitJobs(servers)
149 await wait(5000) 147 await wait(5000)
@@ -163,7 +161,7 @@ describe('Test live', function () {
163 const liveVideoUUID = await createLiveWrapper() 161 const liveVideoUUID = await createLiveWrapper()
164 await waitJobs(servers) 162 await waitJobs(servers)
165 163
166 const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) 164 const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID })
167 165
168 const socket = servers[0].socketIOCommand.getLiveNotificationSocket() 166 const socket = servers[0].socketIOCommand.getLiveNotificationSocket()
169 socket.on('state-change', data => stateChanges.push(data.state)) 167 socket.on('state-change', data => stateChanges.push(data.state))
diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts
index 75f95b167..1951b11a5 100644
--- a/server/tests/api/live/live-views.ts
+++ b/server/tests/api/live/live-views.ts
@@ -3,17 +3,15 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg' 5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { VideoDetails, VideoPrivacy } from '@shared/models' 6import { VideoPrivacy } from '@shared/models'
7import { 7import {
8 cleanupTests, 8 cleanupTests,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideo,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 setDefaultVideoChannel, 13 setDefaultVideoChannel,
15 stopFfmpeg, 14 stopFfmpeg,
16 viewVideo,
17 wait, 15 wait,
18 waitJobs, 16 waitJobs,
19 waitUntilLivePublishedOnAllServers 17 waitUntilLivePublishedOnAllServers
@@ -55,9 +53,7 @@ describe('Test live', function () {
55 53
56 async function countViews (expected: number) { 54 async function countViews (expected: number) {
57 for (const server of servers) { 55 for (const server of servers) {
58 const res = await getVideo(server.url, liveVideoId) 56 const video = await server.videosCommand.get({ id: liveVideoId })
59 const video: VideoDetails = res.body
60
61 expect(video.views).to.equal(expected) 57 expect(video.views).to.equal(expected)
62 } 58 }
63 } 59 }
@@ -86,8 +82,8 @@ describe('Test live', function () {
86 it('Should view a live twice and display 1 view', async function () { 82 it('Should view a live twice and display 1 view', async function () {
87 this.timeout(30000) 83 this.timeout(30000)
88 84
89 await viewVideo(servers[0].url, liveVideoId) 85 await servers[0].videosCommand.view({ id: liveVideoId })
90 await viewVideo(servers[0].url, liveVideoId) 86 await servers[0].videosCommand.view({ id: liveVideoId })
91 87
92 await wait(7000) 88 await wait(7000)
93 89
@@ -108,9 +104,9 @@ describe('Test live', function () {
108 it('Should view a live on a remote and on local and display 2 views', async function () { 104 it('Should view a live on a remote and on local and display 2 views', async function () {
109 this.timeout(30000) 105 this.timeout(30000)
110 106
111 await viewVideo(servers[0].url, liveVideoId) 107 await servers[0].videosCommand.view({ id: liveVideoId })
112 await viewVideo(servers[1].url, liveVideoId) 108 await servers[1].videosCommand.view({ id: liveVideoId })
113 await viewVideo(servers[1].url, liveVideoId) 109 await servers[1].videosCommand.view({ id: liveVideoId })
114 110
115 await wait(7000) 111 await wait(7000)
116 await waitJobs(servers) 112 await waitJobs(servers)
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts
index 999a49051..c88143982 100644
--- a/server/tests/api/live/live.ts
+++ b/server/tests/api/live/live.ts
@@ -4,8 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' 6import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
7import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' 7import { HttpStatusCode } from '@shared/core-utils'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
9import { 8import {
10 checkLiveCleanup, 9 checkLiveCleanup,
11 checkLiveSegmentHash, 10 checkLiveSegmentHash,
@@ -13,14 +12,9 @@ import {
13 cleanupTests, 12 cleanupTests,
14 doubleFollow, 13 doubleFollow,
15 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
16 getMyVideosWithFilter,
17 getVideo,
18 getVideosList,
19 getVideosWithFilters,
20 killallServers, 15 killallServers,
21 LiveCommand, 16 LiveCommand,
22 makeRawRequest, 17 makeRawRequest,
23 removeVideo,
24 reRunServer, 18 reRunServer,
25 sendRTMPStream, 19 sendRTMPStream,
26 ServerInfo, 20 ServerInfo,
@@ -29,11 +23,11 @@ import {
29 stopFfmpeg, 23 stopFfmpeg,
30 testFfmpegStreamError, 24 testFfmpegStreamError,
31 testImage, 25 testImage,
32 uploadVideoAndGetId,
33 wait, 26 wait,
34 waitJobs, 27 waitJobs,
35 waitUntilLivePublishedOnAllServers 28 waitUntilLivePublishedOnAllServers
36} from '../../../../shared/extra-utils' 29} from '@shared/extra-utils'
30import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
37 31
38const expect = chai.expect 32const expect = chai.expect
39 33
@@ -99,8 +93,7 @@ describe('Test live', function () {
99 await waitJobs(servers) 93 await waitJobs(servers)
100 94
101 for (const server of servers) { 95 for (const server of servers) {
102 const resVideo = await getVideo(server.url, liveVideoUUID) 96 const video = await server.videosCommand.get({ id: liveVideoUUID })
103 const video: VideoDetails = resVideo.body
104 97
105 expect(video.category.id).to.equal(1) 98 expect(video.category.id).to.equal(1)
106 expect(video.licence.id).to.equal(2) 99 expect(video.licence.id).to.equal(2)
@@ -154,9 +147,7 @@ describe('Test live', function () {
154 await waitJobs(servers) 147 await waitJobs(servers)
155 148
156 for (const server of servers) { 149 for (const server of servers) {
157 const resVideo = await getVideo(server.url, videoId) 150 const video = await server.videosCommand.get({ id: videoId })
158 const video: VideoDetails = resVideo.body
159
160 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) 151 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
161 expect(video.nsfw).to.be.true 152 expect(video.nsfw).to.be.true
162 153
@@ -167,10 +158,10 @@ describe('Test live', function () {
167 158
168 it('Should not have the live listed since nobody streams into', async function () { 159 it('Should not have the live listed since nobody streams into', async function () {
169 for (const server of servers) { 160 for (const server of servers) {
170 const res = await getVideosList(server.url) 161 const { total, data } = await server.videosCommand.list()
171 162
172 expect(res.body.total).to.equal(0) 163 expect(total).to.equal(0)
173 expect(res.body.data).to.have.lengthOf(0) 164 expect(data).to.have.lengthOf(0)
174 } 165 }
175 }) 166 })
176 167
@@ -204,13 +195,13 @@ describe('Test live', function () {
204 it('Delete the live', async function () { 195 it('Delete the live', async function () {
205 this.timeout(10000) 196 this.timeout(10000)
206 197
207 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) 198 await servers[0].videosCommand.remove({ id: liveVideoUUID })
208 await waitJobs(servers) 199 await waitJobs(servers)
209 }) 200 })
210 201
211 it('Should have the live deleted', async function () { 202 it('Should have the live deleted', async function () {
212 for (const server of servers) { 203 for (const server of servers) {
213 await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) 204 await server.videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
214 await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 205 await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
215 } 206 }
216 }) 207 })
@@ -224,7 +215,7 @@ describe('Test live', function () {
224 before(async function () { 215 before(async function () {
225 this.timeout(120000) 216 this.timeout(120000)
226 217
227 vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid 218 vodVideoId = (await servers[0].videosCommand.quickUpload({ name: 'vod video' })).uuid
228 219
229 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } 220 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id }
230 const live = await commands[0].create({ fields: liveOptions }) 221 const live = await commands[0].create({ fields: liveOptions })
@@ -236,19 +227,19 @@ describe('Test live', function () {
236 }) 227 })
237 228
238 it('Should only display lives', async function () { 229 it('Should only display lives', async function () {
239 const res = await getVideosWithFilters(servers[0].url, { isLive: true }) 230 const { data, total } = await servers[0].videosCommand.list({ isLive: true })
240 231
241 expect(res.body.total).to.equal(1) 232 expect(total).to.equal(1)
242 expect(res.body.data).to.have.lengthOf(1) 233 expect(data).to.have.lengthOf(1)
243 expect(res.body.data[0].name).to.equal('live') 234 expect(data[0].name).to.equal('live')
244 }) 235 })
245 236
246 it('Should not display lives', async function () { 237 it('Should not display lives', async function () {
247 const res = await getVideosWithFilters(servers[0].url, { isLive: false }) 238 const { data, total } = await servers[0].videosCommand.list({ isLive: false })
248 239
249 expect(res.body.total).to.equal(1) 240 expect(total).to.equal(1)
250 expect(res.body.data).to.have.lengthOf(1) 241 expect(data).to.have.lengthOf(1)
251 expect(res.body.data[0].name).to.equal('vod video') 242 expect(data[0].name).to.equal('vod video')
252 }) 243 })
253 244
254 it('Should display my lives', async function () { 245 it('Should display my lives', async function () {
@@ -257,24 +248,22 @@ describe('Test live', function () {
257 await stopFfmpeg(ffmpegCommand) 248 await stopFfmpeg(ffmpegCommand)
258 await waitJobs(servers) 249 await waitJobs(servers)
259 250
260 const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) 251 const { data } = await servers[0].videosCommand.listMyVideos({ isLive: true })
261 const videos = res.body.data as Video[]
262 252
263 const result = videos.every(v => v.isLive) 253 const result = data.every(v => v.isLive)
264 expect(result).to.be.true 254 expect(result).to.be.true
265 }) 255 })
266 256
267 it('Should not display my lives', async function () { 257 it('Should not display my lives', async function () {
268 const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: false }) 258 const { data } = await servers[0].videosCommand.listMyVideos({ isLive: false })
269 const videos = res.body.data as Video[]
270 259
271 const result = videos.every(v => !v.isLive) 260 const result = data.every(v => !v.isLive)
272 expect(result).to.be.true 261 expect(result).to.be.true
273 }) 262 })
274 263
275 after(async function () { 264 after(async function () {
276 await removeVideo(servers[0].url, servers[0].accessToken, vodVideoId) 265 await servers[0].videosCommand.remove({ id: vodVideoId })
277 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoId) 266 await servers[0].videosCommand.remove({ id: liveVideoId })
278 }) 267 })
279 }) 268 })
280 269
@@ -297,9 +286,9 @@ describe('Test live', function () {
297 const { uuid } = await commands[0].create({ fields: liveAttributes }) 286 const { uuid } = await commands[0].create({ fields: liveAttributes })
298 287
299 const live = await commands[0].get({ videoId: uuid }) 288 const live = await commands[0].get({ videoId: uuid })
300 const resVideo = await getVideo(servers[0].url, uuid) 289 const video = await servers[0].videosCommand.get({ id: uuid })
301 290
302 return Object.assign(resVideo.body as VideoDetails, live) 291 return Object.assign(video, live)
303 } 292 }
304 293
305 it('Should not allow a stream without the appropriate path', async function () { 294 it('Should not allow a stream without the appropriate path', async function () {
@@ -327,13 +316,12 @@ describe('Test live', function () {
327 316
328 it('Should list this live now someone stream into it', async function () { 317 it('Should list this live now someone stream into it', async function () {
329 for (const server of servers) { 318 for (const server of servers) {
330 const res = await getVideosList(server.url) 319 const { total, data } = await server.videosCommand.list()
331
332 expect(res.body.total).to.equal(1)
333 expect(res.body.data).to.have.lengthOf(1)
334 320
335 const video: Video = res.body.data[0] 321 expect(total).to.equal(1)
322 expect(data).to.have.lengthOf(1)
336 323
324 const video = data[0]
337 expect(video.name).to.equal('user live') 325 expect(video.name).to.equal('user live')
338 expect(video.isLive).to.be.true 326 expect(video.isLive).to.be.true
339 } 327 }
@@ -355,7 +343,7 @@ describe('Test live', function () {
355 343
356 liveVideo = await createLiveWrapper() 344 liveVideo = await createLiveWrapper()
357 345
358 await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid) 346 await servers[0].videosCommand.remove({ id: liveVideo.uuid })
359 347
360 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) 348 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
361 await testFfmpegStreamError(command, true) 349 await testFfmpegStreamError(command, true)
@@ -379,13 +367,10 @@ describe('Test live', function () {
379 367
380 async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { 368 async function testVideoResolutions (liveVideoId: string, resolutions: number[]) {
381 for (const server of servers) { 369 for (const server of servers) {
382 const resList = await getVideosList(server.url) 370 const { data } = await server.videosCommand.list()
383 const videos: Video[] = resList.body.data 371 expect(data.find(v => v.uuid === liveVideoId)).to.exist
384
385 expect(videos.find(v => v.uuid === liveVideoId)).to.exist
386 372
387 const resVideo = await getVideo(server.url, liveVideoId) 373 const video = await server.videosCommand.get({ id: liveVideoId })
388 const video: VideoDetails = resVideo.body
389 374
390 expect(video.streamingPlaylists).to.have.lengthOf(1) 375 expect(video.streamingPlaylists).to.have.lengthOf(1)
391 376
@@ -505,8 +490,7 @@ describe('Test live', function () {
505 } 490 }
506 491
507 for (const server of servers) { 492 for (const server of servers) {
508 const resVideo = await getVideo(server.url, liveVideoId) 493 const video = await server.videosCommand.get({ id: liveVideoId })
509 const video: VideoDetails = resVideo.body
510 494
511 expect(video.state.id).to.equal(VideoState.PUBLISHED) 495 expect(video.state.id).to.equal(VideoState.PUBLISHED)
512 expect(video.duration).to.be.greaterThan(1) 496 expect(video.duration).to.be.greaterThan(1)
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index a7119263c..7574b8f4a 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -7,13 +7,8 @@ import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getVideoIdFromUUID,
11 getVideosList,
12 removeVideo,
13 ServerInfo, 10 ServerInfo,
14 setAccessTokensToServers, 11 setAccessTokensToServers,
15 uploadVideo,
16 uploadVideoAndGetId,
17 waitJobs 12 waitJobs
18} from '@shared/extra-utils' 13} from '@shared/extra-utils'
19import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' 14import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
@@ -47,28 +42,30 @@ describe('Test abuses', function () {
47 this.timeout(50000) 42 this.timeout(50000)
48 43
49 // Upload some videos on each servers 44 // Upload some videos on each servers
50 const video1Attributes = { 45 {
51 name: 'my super name for server 1', 46 const attributes = {
52 description: 'my super description for server 1' 47 name: 'my super name for server 1',
48 description: 'my super description for server 1'
49 }
50 await servers[0].videosCommand.upload({ attributes })
53 } 51 }
54 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
55 52
56 const video2Attributes = { 53 {
57 name: 'my super name for server 2', 54 const attributes = {
58 description: 'my super description for server 2' 55 name: 'my super name for server 2',
56 description: 'my super description for server 2'
57 }
58 await servers[1].videosCommand.upload({ attributes })
59 } 59 }
60 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
61 60
62 // Wait videos propagation, server 2 has transcoding enabled 61 // Wait videos propagation, server 2 has transcoding enabled
63 await waitJobs(servers) 62 await waitJobs(servers)
64 63
65 const res = await getVideosList(servers[0].url) 64 const { data } = await servers[0].videosCommand.list()
66 const videos = res.body.data 65 expect(data.length).to.equal(2)
67
68 expect(videos.length).to.equal(2)
69 66
70 servers[0].video = videos.find(video => video.name === 'my super name for server 1') 67 servers[0].video = data.find(video => video.name === 'my super name for server 1')
71 servers[1].video = videos.find(video => video.name === 'my super name for server 2') 68 servers[1].video = data.find(video => video.name === 'my super name for server 2')
72 }) 69 })
73 70
74 it('Should not have abuses', async function () { 71 it('Should not have abuses', async function () {
@@ -130,7 +127,7 @@ describe('Test abuses', function () {
130 this.timeout(10000) 127 this.timeout(10000)
131 128
132 const reason = 'my super bad reason 2' 129 const reason = 'my super bad reason 2'
133 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) 130 const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid })
134 await commands[0].report({ videoId, reason }) 131 await commands[0].report({ videoId, reason })
135 132
136 // We wait requests propagation 133 // We wait requests propagation
@@ -203,7 +200,7 @@ describe('Test abuses', function () {
203 this.timeout(10000) 200 this.timeout(10000)
204 201
205 { 202 {
206 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) 203 const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid })
207 await commands[1].report({ videoId, reason: 'will mute this' }) 204 await commands[1].report({ videoId, reason: 'will mute this' })
208 await waitJobs(servers) 205 await waitJobs(servers)
209 206
@@ -255,7 +252,7 @@ describe('Test abuses', function () {
255 it('Should keep the video abuse when deleting the video', async function () { 252 it('Should keep the video abuse when deleting the video', async function () {
256 this.timeout(10000) 253 this.timeout(10000)
257 254
258 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) 255 await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid })
259 256
260 await waitJobs(servers) 257 await waitJobs(servers)
261 258
@@ -279,12 +276,12 @@ describe('Test abuses', function () {
279 const userAccessToken = await servers[0].loginCommand.getAccessToken(user) 276 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
280 277
281 // upload a third video via this user 278 // upload a third video via this user
282 const video3Attributes = { 279 const attributes = {
283 name: 'my second super name for server 1', 280 name: 'my second super name for server 1',
284 description: 'my second super description for server 1' 281 description: 'my second super description for server 1'
285 } 282 }
286 const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) 283 const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
287 const video3Id = resUpload.body.video.id 284 const video3Id = id
288 285
289 // resume with the test 286 // resume with the test
290 const reason3 = 'my super bad reason 3' 287 const reason3 = 'my super bad reason 3'
@@ -394,7 +391,7 @@ describe('Test abuses', function () {
394 391
395 async function getComment (server: ServerInfo, videoIdArg: number | string) { 392 async function getComment (server: ServerInfo, videoIdArg: number | string) {
396 const videoId = typeof videoIdArg === 'string' 393 const videoId = typeof videoIdArg === 'string'
397 ? await getVideoIdFromUUID(server.url, videoIdArg) 394 ? await server.videosCommand.getId({ uuid: videoIdArg })
398 : videoIdArg 395 : videoIdArg
399 396
400 const { data } = await server.commentsCommand.listThreads({ videoId }) 397 const { data } = await server.commentsCommand.listThreads({ videoId })
@@ -405,8 +402,8 @@ describe('Test abuses', function () {
405 before(async function () { 402 before(async function () {
406 this.timeout(50000) 403 this.timeout(50000)
407 404
408 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) 405 servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' })
409 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) 406 servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' })
410 407
411 await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) 408 await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
412 await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) 409 await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
@@ -604,7 +601,7 @@ describe('Test abuses', function () {
604 await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) 601 await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' })
605 602
606 const token = await servers[1].usersCommand.generateUserAndToken('user_2') 603 const token = await servers[1].usersCommand.generateUserAndToken('user_2')
607 await uploadVideo(servers[1].url, token, { name: 'super video' }) 604 await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } })
608 605
609 await waitJobs(servers) 606 await waitJobs(servers)
610 }) 607 })
@@ -766,7 +763,7 @@ describe('Test abuses', function () {
766 763
767 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) 764 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
768 765
769 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) 766 const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid })
770 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) 767 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
771 }) 768 })
772 769
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index b44bcb012..92a0ec681 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -2,15 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6 cleanupTests,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 ServerInfo,
10 setAccessTokensToServers,
11 uploadVideo,
12 waitJobs
13} from '@shared/extra-utils'
14import { UserNotificationType } from '@shared/models' 6import { UserNotificationType } from '@shared/models'
15 7
16const expect = chai.expect 8const expect = chai.expect
@@ -44,8 +36,8 @@ describe('Test blocklist', function () {
44 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) 36 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
45 37
46 { 38 {
47 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) 39 const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } })
48 videoUUID = res.body.video.uuid 40 videoUUID = uuid
49 41
50 await waitJobs(servers) 42 await waitJobs(servers)
51 } 43 }
@@ -83,7 +75,7 @@ describe('Test blocklist', function () {
83 }) 75 })
84 76
85 userToken1 = await servers[0].loginCommand.getAccessToken(user) 77 userToken1 = await servers[0].loginCommand.getAccessToken(user)
86 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) 78 await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } })
87 } 79 }
88 80
89 { 81 {
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index c253b5c11..3c3b2d6fd 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -8,28 +8,23 @@ import {
8 CommentsCommand, 8 CommentsCommand,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideosList,
12 getVideosListWithToken,
13 ServerInfo, 11 ServerInfo,
14 setAccessTokensToServers, 12 setAccessTokensToServers,
15 uploadVideo,
16 waitJobs 13 waitJobs
17} from '@shared/extra-utils' 14} from '@shared/extra-utils'
18import { UserNotificationType, Video } from '@shared/models' 15import { UserNotificationType } from '@shared/models'
19 16
20const expect = chai.expect 17const expect = chai.expect
21 18
22async function checkAllVideos (server: ServerInfo, token: string) { 19async function checkAllVideos (server: ServerInfo, token: string) {
23 { 20 {
24 const res = await getVideosListWithToken(server.url, token) 21 const { data } = await server.videosCommand.listWithToken({ token })
25 22 expect(data).to.have.lengthOf(5)
26 expect(res.body.data).to.have.lengthOf(5)
27 } 23 }
28 24
29 { 25 {
30 const res = await getVideosList(server.url) 26 const { data } = await server.videosCommand.list()
31 27 expect(data).to.have.lengthOf(5)
32 expect(res.body.data).to.have.lengthOf(5)
33 } 28 }
34} 29}
35 30
@@ -93,7 +88,7 @@ describe('Test blocklist', function () {
93 await servers[0].usersCommand.create({ username: user.username, password: user.password }) 88 await servers[0].usersCommand.create({ username: user.username, password: user.password })
94 89
95 userToken1 = await servers[0].loginCommand.getAccessToken(user) 90 userToken1 = await servers[0].loginCommand.getAccessToken(user)
96 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) 91 await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } })
97 } 92 }
98 93
99 { 94 {
@@ -108,22 +103,22 @@ describe('Test blocklist', function () {
108 await servers[1].usersCommand.create({ username: user.username, password: user.password }) 103 await servers[1].usersCommand.create({ username: user.username, password: user.password })
109 104
110 userToken2 = await servers[1].loginCommand.getAccessToken(user) 105 userToken2 = await servers[1].loginCommand.getAccessToken(user)
111 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) 106 await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } })
112 } 107 }
113 108
114 { 109 {
115 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) 110 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } })
116 videoUUID1 = res.body.video.uuid 111 videoUUID1 = uuid
117 } 112 }
118 113
119 { 114 {
120 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) 115 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } })
121 videoUUID2 = res.body.video.uuid 116 videoUUID2 = uuid
122 } 117 }
123 118
124 { 119 {
125 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) 120 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } })
126 videoUUID3 = res.body.video.uuid 121 videoUUID3 = uuid
127 } 122 }
128 123
129 await doubleFollow(servers[0], servers[1]) 124 await doubleFollow(servers[0], servers[1])
@@ -164,12 +159,11 @@ describe('Test blocklist', function () {
164 }) 159 })
165 160
166 it('Should hide its videos', async function () { 161 it('Should hide its videos', async function () {
167 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 162 const { data } = await servers[0].videosCommand.listWithToken()
168 163
169 const videos: Video[] = res.body.data 164 expect(data).to.have.lengthOf(4)
170 expect(videos).to.have.lengthOf(4)
171 165
172 const v = videos.find(v => v.name === 'video user 2') 166 const v = data.find(v => v.name === 'video user 2')
173 expect(v).to.be.undefined 167 expect(v).to.be.undefined
174 }) 168 })
175 169
@@ -178,12 +172,11 @@ describe('Test blocklist', function () {
178 }) 172 })
179 173
180 it('Should hide its videos', async function () { 174 it('Should hide its videos', async function () {
181 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 175 const { data } = await servers[0].videosCommand.listWithToken()
182 176
183 const videos: Video[] = res.body.data 177 expect(data).to.have.lengthOf(3)
184 expect(videos).to.have.lengthOf(3)
185 178
186 const v = videos.find(v => v.name === 'video user 1') 179 const v = data.find(v => v.name === 'video user 1')
187 expect(v).to.be.undefined 180 expect(v).to.be.undefined
188 }) 181 })
189 182
@@ -313,12 +306,10 @@ describe('Test blocklist', function () {
313 }) 306 })
314 307
315 it('Should display its videos', async function () { 308 it('Should display its videos', async function () {
316 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 309 const { data } = await servers[0].videosCommand.listWithToken()
310 expect(data).to.have.lengthOf(4)
317 311
318 const videos: Video[] = res.body.data 312 const v = data.find(v => v.name === 'video user 2')
319 expect(videos).to.have.lengthOf(4)
320
321 const v = videos.find(v => v.name === 'video user 2')
322 expect(v).not.to.be.undefined 313 expect(v).not.to.be.undefined
323 }) 314 })
324 315
@@ -387,13 +378,12 @@ describe('Test blocklist', function () {
387 }) 378 })
388 379
389 it('Should hide its videos', async function () { 380 it('Should hide its videos', async function () {
390 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 381 const { data } = await servers[0].videosCommand.listWithToken()
391 382
392 const videos: Video[] = res.body.data 383 expect(data).to.have.lengthOf(3)
393 expect(videos).to.have.lengthOf(3)
394 384
395 const v1 = videos.find(v => v.name === 'video user 2') 385 const v1 = data.find(v => v.name === 'video user 2')
396 const v2 = videos.find(v => v.name === 'video server 2') 386 const v2 = data.find(v => v.name === 'video server 2')
397 387
398 expect(v1).to.be.undefined 388 expect(v1).to.be.undefined
399 expect(v2).to.be.undefined 389 expect(v2).to.be.undefined
@@ -498,12 +488,11 @@ describe('Test blocklist', function () {
498 488
499 it('Should hide its videos', async function () { 489 it('Should hide its videos', async function () {
500 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 490 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
501 const res = await getVideosListWithToken(servers[0].url, token) 491 const { data } = await servers[0].videosCommand.listWithToken({ token })
502 492
503 const videos: Video[] = res.body.data 493 expect(data).to.have.lengthOf(4)
504 expect(videos).to.have.lengthOf(4)
505 494
506 const v = videos.find(v => v.name === 'video user 2') 495 const v = data.find(v => v.name === 'video user 2')
507 expect(v).to.be.undefined 496 expect(v).to.be.undefined
508 } 497 }
509 }) 498 })
@@ -514,12 +503,11 @@ describe('Test blocklist', function () {
514 503
515 it('Should hide its videos', async function () { 504 it('Should hide its videos', async function () {
516 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 505 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
517 const res = await getVideosListWithToken(servers[0].url, token) 506 const { data } = await servers[0].videosCommand.listWithToken({ token })
518 507
519 const videos: Video[] = res.body.data 508 expect(data).to.have.lengthOf(3)
520 expect(videos).to.have.lengthOf(3)
521 509
522 const v = videos.find(v => v.name === 'video user 1') 510 const v = data.find(v => v.name === 'video user 1')
523 expect(v).to.be.undefined 511 expect(v).to.be.undefined
524 } 512 }
525 }) 513 })
@@ -593,12 +581,10 @@ describe('Test blocklist', function () {
593 581
594 it('Should display its videos', async function () { 582 it('Should display its videos', async function () {
595 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 583 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
596 const res = await getVideosListWithToken(servers[0].url, token) 584 const { data } = await servers[0].videosCommand.listWithToken({ token })
597 585 expect(data).to.have.lengthOf(4)
598 const videos: Video[] = res.body.data
599 expect(videos).to.have.lengthOf(4)
600 586
601 const v = videos.find(v => v.name === 'video user 2') 587 const v = data.find(v => v.name === 'video user 2')
602 expect(v).not.to.be.undefined 588 expect(v).not.to.be.undefined
603 } 589 }
604 }) 590 })
@@ -652,15 +638,17 @@ describe('Test blocklist', function () {
652 638
653 it('Should hide its videos', async function () { 639 it('Should hide its videos', async function () {
654 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 640 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
655 const res1 = await getVideosList(servers[0].url) 641 const requests = [
656 const res2 = await getVideosListWithToken(servers[0].url, token) 642 servers[0].videosCommand.list(),
643 servers[0].videosCommand.listWithToken({ token })
644 ]
657 645
658 for (const res of [ res1, res2 ]) { 646 for (const req of requests) {
659 const videos: Video[] = res.body.data 647 const { data } = await req
660 expect(videos).to.have.lengthOf(3) 648 expect(data).to.have.lengthOf(3)
661 649
662 const v1 = videos.find(v => v.name === 'video user 2') 650 const v1 = data.find(v => v.name === 'video user 2')
663 const v2 = videos.find(v => v.name === 'video server 2') 651 const v2 = data.find(v => v.name === 'video server 2')
664 652
665 expect(v1).to.be.undefined 653 expect(v1).to.be.undefined
666 expect(v2).to.be.undefined 654 expect(v2).to.be.undefined
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index ef25cfb8e..2f2e678e7 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -8,15 +8,11 @@ import {
8 cleanupTests, 8 cleanupTests,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getMyVideos,
12 getVideosList,
13 ImportsCommand, 11 ImportsCommand,
14 killallServers, 12 killallServers,
15 reRunServer, 13 reRunServer,
16 ServerInfo, 14 ServerInfo,
17 setAccessTokensToServers, 15 setAccessTokensToServers,
18 updateVideo,
19 uploadVideo,
20 waitJobs 16 waitJobs
21} from '@shared/extra-utils' 17} from '@shared/extra-utils'
22import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' 18import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
@@ -29,10 +25,9 @@ describe('Test video blacklist', function () {
29 let command: BlacklistCommand 25 let command: BlacklistCommand
30 26
31 async function blacklistVideosOnServer (server: ServerInfo) { 27 async function blacklistVideosOnServer (server: ServerInfo) {
32 const res = await getVideosList(server.url) 28 const { data } = await server.videosCommand.list()
33 29
34 const videos = res.body.data 30 for (const video of data) {
35 for (const video of videos) {
36 await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) 31 await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' })
37 } 32 }
38 } 33 }
@@ -50,8 +45,8 @@ describe('Test video blacklist', function () {
50 await doubleFollow(servers[0], servers[1]) 45 await doubleFollow(servers[0], servers[1])
51 46
52 // Upload 2 videos on server 2 47 // Upload 2 videos on server 2
53 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) 48 await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } })
54 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) 49 await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } })
55 50
56 // Wait videos propagation, server 2 has transcoding enabled 51 // Wait videos propagation, server 2 has transcoding enabled
57 await waitJobs(servers) 52 await waitJobs(servers)
@@ -66,11 +61,11 @@ describe('Test video blacklist', function () {
66 61
67 it('Should not have the video blacklisted in videos list/search on server 1', async function () { 62 it('Should not have the video blacklisted in videos list/search on server 1', async function () {
68 { 63 {
69 const res = await getVideosList(servers[0].url) 64 const { total, data } = await servers[0].videosCommand.list()
70 65
71 expect(res.body.total).to.equal(0) 66 expect(total).to.equal(0)
72 expect(res.body.data).to.be.an('array') 67 expect(data).to.be.an('array')
73 expect(res.body.data.length).to.equal(0) 68 expect(data.length).to.equal(0)
74 } 69 }
75 70
76 { 71 {
@@ -84,11 +79,11 @@ describe('Test video blacklist', function () {
84 79
85 it('Should have the blacklisted video in videos list/search on server 2', async function () { 80 it('Should have the blacklisted video in videos list/search on server 2', async function () {
86 { 81 {
87 const res = await getVideosList(servers[1].url) 82 const { total, data } = await servers[1].videosCommand.list()
88 83
89 expect(res.body.total).to.equal(2) 84 expect(total).to.equal(2)
90 expect(res.body.data).to.be.an('array') 85 expect(data).to.be.an('array')
91 expect(res.body.data.length).to.equal(2) 86 expect(data.length).to.equal(2)
92 } 87 }
93 88
94 { 89 {
@@ -186,12 +181,12 @@ describe('Test video blacklist', function () {
186 it('Should display blacklisted videos', async function () { 181 it('Should display blacklisted videos', async function () {
187 await blacklistVideosOnServer(servers[1]) 182 await blacklistVideosOnServer(servers[1])
188 183
189 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) 184 const { total, data } = await servers[1].videosCommand.listMyVideos()
190 185
191 expect(res.body.total).to.equal(2) 186 expect(total).to.equal(2)
192 expect(res.body.data).to.have.lengthOf(2) 187 expect(data).to.have.lengthOf(2)
193 188
194 for (const video of res.body.data) { 189 for (const video of data) {
195 expect(video.blacklisted).to.be.true 190 expect(video.blacklisted).to.be.true
196 expect(video.blacklistedReason).to.equal('super reason') 191 expect(video.blacklistedReason).to.equal('super reason')
197 } 192 }
@@ -203,10 +198,10 @@ describe('Test video blacklist', function () {
203 let blacklist = [] 198 let blacklist = []
204 199
205 it('Should not have any video in videos list on server 1', async function () { 200 it('Should not have any video in videos list on server 1', async function () {
206 const res = await getVideosList(servers[0].url) 201 const { total, data } = await servers[0].videosCommand.list()
207 expect(res.body.total).to.equal(0) 202 expect(total).to.equal(0)
208 expect(res.body.data).to.be.an('array') 203 expect(data).to.be.an('array')
209 expect(res.body.data.length).to.equal(0) 204 expect(data.length).to.equal(0)
210 }) 205 })
211 206
212 it('Should remove a video from the blacklist on server 1', async function () { 207 it('Should remove a video from the blacklist on server 1', async function () {
@@ -220,15 +215,14 @@ describe('Test video blacklist', function () {
220 }) 215 })
221 216
222 it('Should have the ex-blacklisted video in videos list on server 1', async function () { 217 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
223 const res = await getVideosList(servers[0].url) 218 const { total, data } = await servers[0].videosCommand.list()
224 expect(res.body.total).to.equal(1) 219 expect(total).to.equal(1)
225 220
226 const videos = res.body.data 221 expect(data).to.be.an('array')
227 expect(videos).to.be.an('array') 222 expect(data.length).to.equal(1)
228 expect(videos.length).to.equal(1)
229 223
230 expect(videos[0].name).to.equal(videoToRemove.video.name) 224 expect(data[0].name).to.equal(videoToRemove.video.name)
231 expect(videos[0].id).to.equal(videoToRemove.video.id) 225 expect(data[0].id).to.equal(videoToRemove.video.id)
232 }) 226 })
233 227
234 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { 228 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
@@ -250,12 +244,12 @@ describe('Test video blacklist', function () {
250 this.timeout(10000) 244 this.timeout(10000)
251 245
252 { 246 {
253 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) 247 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } })
254 video3UUID = res.body.video.uuid 248 video3UUID = uuid
255 } 249 }
256 { 250 {
257 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) 251 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } })
258 video4UUID = res.body.video.uuid 252 video4UUID = uuid
259 } 253 }
260 254
261 await waitJobs(servers) 255 await waitJobs(servers)
@@ -269,13 +263,13 @@ describe('Test video blacklist', function () {
269 await waitJobs(servers) 263 await waitJobs(servers)
270 264
271 { 265 {
272 const res = await getVideosList(servers[0].url) 266 const { data } = await servers[0].videosCommand.list()
273 expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined 267 expect(data.find(v => v.uuid === video3UUID)).to.be.undefined
274 } 268 }
275 269
276 { 270 {
277 const res = await getVideosList(servers[1].url) 271 const { data } = await servers[1].videosCommand.list()
278 expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined 272 expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined
279 } 273 }
280 }) 274 })
281 275
@@ -287,21 +281,21 @@ describe('Test video blacklist', function () {
287 await waitJobs(servers) 281 await waitJobs(servers)
288 282
289 for (const server of servers) { 283 for (const server of servers) {
290 const res = await getVideosList(server.url) 284 const { data } = await server.videosCommand.list()
291 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined 285 expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
292 } 286 }
293 }) 287 })
294 288
295 it('Should have the video unfederated even after an Update AP message', async function () { 289 it('Should have the video unfederated even after an Update AP message', async function () {
296 this.timeout(10000) 290 this.timeout(10000)
297 291
298 await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) 292 await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } })
299 293
300 await waitJobs(servers) 294 await waitJobs(servers)
301 295
302 for (const server of servers) { 296 for (const server of servers) {
303 const res = await getVideosList(server.url) 297 const { data } = await server.videosCommand.list()
304 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined 298 expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
305 } 299 }
306 }) 300 })
307 301
@@ -324,8 +318,8 @@ describe('Test video blacklist', function () {
324 await waitJobs(servers) 318 await waitJobs(servers)
325 319
326 for (const server of servers) { 320 for (const server of servers) {
327 const res = await getVideosList(server.url) 321 const { data } = await server.videosCommand.list()
328 expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined 322 expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined
329 } 323 }
330 }) 324 })
331 325
@@ -383,7 +377,7 @@ describe('Test video blacklist', function () {
383 }) 377 })
384 378
385 it('Should auto blacklist a video on upload', async function () { 379 it('Should auto blacklist a video on upload', async function () {
386 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) 380 await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } })
387 381
388 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) 382 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
389 expect(body.total).to.equal(1) 383 expect(body.total).to.equal(1)
@@ -419,7 +413,7 @@ describe('Test video blacklist', function () {
419 }) 413 })
420 414
421 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { 415 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
422 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) 416 await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } })
423 417
424 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) 418 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
425 expect(body.total).to.equal(3) 419 expect(body.total).to.equal(3)
diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts
index 62569f810..a74b38e8a 100644
--- a/server/tests/api/notifications/comments-notifications.ts
+++ b/server/tests/api/notifications/comments-notifications.ts
@@ -10,7 +10,6 @@ import {
10 MockSmtpServer, 10 MockSmtpServer,
11 prepareNotificationsTest, 11 prepareNotificationsTest,
12 ServerInfo, 12 ServerInfo,
13 uploadVideo,
14 waitJobs 13 waitJobs
15} from '@shared/extra-utils' 14} from '@shared/extra-utils'
16import { UserNotification } from '@shared/models' 15import { UserNotification } from '@shared/models'
@@ -53,8 +52,7 @@ describe('Test comments notifications', function () {
53 it('Should not send a new comment notification after a comment on another video', async function () { 52 it('Should not send a new comment notification after a comment on another video', async function () {
54 this.timeout(20000) 53 this.timeout(20000)
55 54
56 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 55 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
57 const uuid = resVideo.body.video.uuid
58 56
59 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) 57 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
60 const commentId = created.id 58 const commentId = created.id
@@ -66,8 +64,7 @@ describe('Test comments notifications', function () {
66 it('Should not send a new comment notification if I comment my own video', async function () { 64 it('Should not send a new comment notification if I comment my own video', async function () {
67 this.timeout(20000) 65 this.timeout(20000)
68 66
69 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) 67 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
70 const uuid = resVideo.body.video.uuid
71 68
72 const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' }) 69 const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
73 const commentId = created.id 70 const commentId = created.id
@@ -81,8 +78,7 @@ describe('Test comments notifications', function () {
81 78
82 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) 79 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
83 80
84 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) 81 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
85 const uuid = resVideo.body.video.uuid
86 82
87 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) 83 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
88 const commentId = created.id 84 const commentId = created.id
@@ -96,8 +92,7 @@ describe('Test comments notifications', function () {
96 it('Should send a new comment notification after a local comment on my video', async function () { 92 it('Should send a new comment notification after a local comment on my video', async function () {
97 this.timeout(20000) 93 this.timeout(20000)
98 94
99 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) 95 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
100 const uuid = resVideo.body.video.uuid
101 96
102 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) 97 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
103 const commentId = created.id 98 const commentId = created.id
@@ -109,8 +104,7 @@ describe('Test comments notifications', function () {
109 it('Should send a new comment notification after a remote comment on my video', async function () { 104 it('Should send a new comment notification after a remote comment on my video', async function () {
110 this.timeout(20000) 105 this.timeout(20000)
111 106
112 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) 107 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
113 const uuid = resVideo.body.video.uuid
114 108
115 await waitJobs(servers) 109 await waitJobs(servers)
116 110
@@ -128,8 +122,7 @@ describe('Test comments notifications', function () {
128 it('Should send a new comment notification after a local reply on my video', async function () { 122 it('Should send a new comment notification after a local reply on my video', async function () {
129 this.timeout(20000) 123 this.timeout(20000)
130 124
131 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) 125 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
132 const uuid = resVideo.body.video.uuid
133 126
134 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) 127 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
135 128
@@ -142,8 +135,7 @@ describe('Test comments notifications', function () {
142 it('Should send a new comment notification after a remote reply on my video', async function () { 135 it('Should send a new comment notification after a remote reply on my video', async function () {
143 this.timeout(20000) 136 this.timeout(20000)
144 137
145 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) 138 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
146 const uuid = resVideo.body.video.uuid
147 await waitJobs(servers) 139 await waitJobs(servers)
148 140
149 { 141 {
@@ -169,8 +161,7 @@ describe('Test comments notifications', function () {
169 it('Should convert markdown in comment to html', async function () { 161 it('Should convert markdown in comment to html', async function () {
170 this.timeout(20000) 162 this.timeout(20000)
171 163
172 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' }) 164 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'cool video' } })
173 const uuid = resVideo.body.video.uuid
174 165
175 await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText }) 166 await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText })
176 167
@@ -199,8 +190,7 @@ describe('Test comments notifications', function () {
199 it('Should not send a new mention comment notification if I mention the video owner', async function () { 190 it('Should not send a new mention comment notification if I mention the video owner', async function () {
200 this.timeout(10000) 191 this.timeout(10000)
201 192
202 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) 193 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
203 const uuid = resVideo.body.video.uuid
204 194
205 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) 195 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
206 196
@@ -211,8 +201,7 @@ describe('Test comments notifications', function () {
211 it('Should not send a new mention comment notification if I mention myself', async function () { 201 it('Should not send a new mention comment notification if I mention myself', async function () {
212 this.timeout(10000) 202 this.timeout(10000)
213 203
214 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 204 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
215 const uuid = resVideo.body.video.uuid
216 205
217 const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) 206 const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
218 207
@@ -225,8 +214,7 @@ describe('Test comments notifications', function () {
225 214
226 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) 215 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
227 216
228 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 217 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
229 const uuid = resVideo.body.video.uuid
230 218
231 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) 219 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
232 220
@@ -239,8 +227,7 @@ describe('Test comments notifications', function () {
239 it('Should not send a new mention notification if the remote account mention a local account', async function () { 227 it('Should not send a new mention notification if the remote account mention a local account', async function () {
240 this.timeout(20000) 228 this.timeout(20000)
241 229
242 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 230 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
243 const uuid = resVideo.body.video.uuid
244 231
245 await waitJobs(servers) 232 await waitJobs(servers)
246 const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) 233 const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
@@ -252,8 +239,7 @@ describe('Test comments notifications', function () {
252 it('Should send a new mention notification after local comments', async function () { 239 it('Should send a new mention notification after local comments', async function () {
253 this.timeout(10000) 240 this.timeout(10000)
254 241
255 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 242 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
256 const uuid = resVideo.body.video.uuid
257 243
258 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) 244 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
259 245
@@ -269,8 +255,7 @@ describe('Test comments notifications', function () {
269 it('Should send a new mention notification after remote comments', async function () { 255 it('Should send a new mention notification after remote comments', async function () {
270 this.timeout(20000) 256 this.timeout(20000)
271 257
272 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 258 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
273 const uuid = resVideo.body.video.uuid
274 259
275 await waitJobs(servers) 260 await waitJobs(servers)
276 261
@@ -301,8 +286,7 @@ describe('Test comments notifications', function () {
301 it('Should convert markdown in comment to html', async function () { 286 it('Should convert markdown in comment to html', async function () {
302 this.timeout(10000) 287 this.timeout(10000)
303 288
304 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 289 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
305 const uuid = resVideo.body.video.uuid
306 290
307 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' }) 291 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' })
308 292
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index 0269124c5..91a2b4fa5 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -17,12 +17,10 @@ import {
17 checkVideoAutoBlacklistForModerators, 17 checkVideoAutoBlacklistForModerators,
18 checkVideoIsPublished, 18 checkVideoIsPublished,
19 cleanupTests, 19 cleanupTests,
20 getVideoIdFromUUID,
21 MockInstancesIndex, 20 MockInstancesIndex,
22 MockSmtpServer, 21 MockSmtpServer,
23 prepareNotificationsTest, 22 prepareNotificationsTest,
24 ServerInfo, 23 ServerInfo,
25 uploadVideo,
26 wait, 24 wait,
27 waitJobs 25 waitJobs
28} from '@shared/extra-utils' 26} from '@shared/extra-utils'
@@ -64,8 +62,7 @@ describe('Test moderation notifications', function () {
64 this.timeout(20000) 62 this.timeout(20000)
65 63
66 const name = 'video for abuse ' + buildUUID() 64 const name = 'video for abuse ' + buildUUID()
67 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 65 const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
68 const video = resVideo.body.video
69 66
70 await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' }) 67 await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' })
71 68
@@ -77,12 +74,11 @@ describe('Test moderation notifications', function () {
77 this.timeout(20000) 74 this.timeout(20000)
78 75
79 const name = 'video for abuse ' + buildUUID() 76 const name = 'video for abuse ' + buildUUID()
80 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 77 const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
81 const video = resVideo.body.video
82 78
83 await waitJobs(servers) 79 await waitJobs(servers)
84 80
85 const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) 81 const videoId = await servers[1].videosCommand.getId({ uuid: video.uuid })
86 await servers[1].abusesCommand.report({ videoId, reason: 'super reason' }) 82 await servers[1].abusesCommand.report({ videoId, reason: 'super reason' })
87 83
88 await waitJobs(servers) 84 await waitJobs(servers)
@@ -93,8 +89,7 @@ describe('Test moderation notifications', function () {
93 this.timeout(20000) 89 this.timeout(20000)
94 90
95 const name = 'video for abuse ' + buildUUID() 91 const name = 'video for abuse ' + buildUUID()
96 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 92 const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
97 const video = resVideo.body.video
98 const comment = await servers[0].commentsCommand.createThread({ 93 const comment = await servers[0].commentsCommand.createThread({
99 token: userAccessToken, 94 token: userAccessToken,
100 videoId: video.id, 95 videoId: video.id,
@@ -113,8 +108,7 @@ describe('Test moderation notifications', function () {
113 this.timeout(20000) 108 this.timeout(20000)
114 109
115 const name = 'video for abuse ' + buildUUID() 110 const name = 'video for abuse ' + buildUUID()
116 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 111 const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
117 const video = resVideo.body.video
118 112
119 await servers[0].commentsCommand.createThread({ 113 await servers[0].commentsCommand.createThread({
120 token: userAccessToken, 114 token: userAccessToken,
@@ -150,7 +144,7 @@ describe('Test moderation notifications', function () {
150 144
151 const username = 'user' + new Date().getTime() 145 const username = 'user' + new Date().getTime()
152 const tmpToken = await servers[0].usersCommand.generateUserAndToken(username) 146 const tmpToken = await servers[0].usersCommand.generateUserAndToken(username)
153 await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) 147 await servers[0].videosCommand.upload({ token: tmpToken, attributes: { name: 'super video' } })
154 148
155 await waitJobs(servers) 149 await waitJobs(servers)
156 150
@@ -175,8 +169,7 @@ describe('Test moderation notifications', function () {
175 } 169 }
176 170
177 const name = 'abuse ' + buildUUID() 171 const name = 'abuse ' + buildUUID()
178 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 172 const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
179 const video = resVideo.body.video
180 173
181 const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) 174 const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
182 abuseId = body.abuse.id 175 abuseId = body.abuse.id
@@ -223,8 +216,7 @@ describe('Test moderation notifications', function () {
223 } 216 }
224 217
225 const name = 'abuse ' + buildUUID() 218 const name = 'abuse ' + buildUUID()
226 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 219 const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
227 const video = resVideo.body.video
228 220
229 { 221 {
230 const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) 222 const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
@@ -294,8 +286,7 @@ describe('Test moderation notifications', function () {
294 this.timeout(10000) 286 this.timeout(10000)
295 287
296 const name = 'video for abuse ' + buildUUID() 288 const name = 'video for abuse ' + buildUUID()
297 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 289 const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
298 const uuid = resVideo.body.video.uuid
299 290
300 await servers[0].blacklistCommand.add({ videoId: uuid }) 291 await servers[0].blacklistCommand.add({ videoId: uuid })
301 292
@@ -307,8 +298,7 @@ describe('Test moderation notifications', function () {
307 this.timeout(10000) 298 this.timeout(10000)
308 299
309 const name = 'video for abuse ' + buildUUID() 300 const name = 'video for abuse ' + buildUUID()
310 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 301 const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } })
311 const uuid = resVideo.body.video.uuid
312 302
313 await servers[0].blacklistCommand.add({ videoId: uuid }) 303 await servers[0].blacklistCommand.add({ videoId: uuid })
314 304
@@ -497,8 +487,8 @@ describe('Test moderation notifications', function () {
497 this.timeout(40000) 487 this.timeout(40000)
498 488
499 videoName = 'video with auto-blacklist ' + buildUUID() 489 videoName = 'video with auto-blacklist ' + buildUUID()
500 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) 490 const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: videoName } })
501 videoUUID = resVideo.body.video.uuid 491 videoUUID = uuid
502 492
503 await waitJobs(servers) 493 await waitJobs(servers)
504 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') 494 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
@@ -544,17 +534,16 @@ describe('Test moderation notifications', function () {
544 534
545 const name = 'video with auto-blacklist and future schedule ' + buildUUID() 535 const name = 'video with auto-blacklist and future schedule ' + buildUUID()
546 536
547 const data = { 537 const attributes = {
548 name, 538 name,
549 privacy: VideoPrivacy.PRIVATE, 539 privacy: VideoPrivacy.PRIVATE,
550 scheduleUpdate: { 540 scheduleUpdate: {
551 updateAt: updateAt.toISOString(), 541 updateAt: updateAt.toISOString(),
552 privacy: VideoPrivacy.PUBLIC 542 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
553 } 543 }
554 } 544 }
555 545
556 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) 546 const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
557 const uuid = resVideo.body.video.uuid
558 547
559 await servers[0].blacklistCommand.remove({ videoId: uuid }) 548 await servers[0].blacklistCommand.remove({ videoId: uuid })
560 549
@@ -577,17 +566,16 @@ describe('Test moderation notifications', function () {
577 566
578 const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() 567 const name = 'video with schedule done and still auto-blacklisted ' + buildUUID()
579 568
580 const data = { 569 const attributes = {
581 name, 570 name,
582 privacy: VideoPrivacy.PRIVATE, 571 privacy: VideoPrivacy.PRIVATE,
583 scheduleUpdate: { 572 scheduleUpdate: {
584 updateAt: updateAt.toISOString(), 573 updateAt: updateAt.toISOString(),
585 privacy: VideoPrivacy.PUBLIC 574 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
586 } 575 }
587 } 576 }
588 577
589 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) 578 const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes })
590 const uuid = resVideo.body.video.uuid
591 579
592 await wait(6000) 580 await wait(6000)
593 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') 581 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
@@ -601,8 +589,7 @@ describe('Test moderation notifications', function () {
601 const name = 'video without auto-blacklist ' + buildUUID() 589 const name = 'video without auto-blacklist ' + buildUUID()
602 590
603 // admin with blacklist right will not be auto-blacklisted 591 // admin with blacklist right will not be auto-blacklisted
604 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) 592 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name } })
605 const uuid = resVideo.body.video.uuid
606 593
607 await waitJobs(servers) 594 await waitJobs(servers)
608 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') 595 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index f33d8e64d..41e1b8015 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -10,7 +10,6 @@ import {
10 MockSmtpServer, 10 MockSmtpServer,
11 prepareNotificationsTest, 11 prepareNotificationsTest,
12 ServerInfo, 12 ServerInfo,
13 uploadRandomVideo,
14 waitJobs 13 waitJobs
15} from '@shared/extra-utils' 14} from '@shared/extra-utils'
16import { UserNotification, UserNotificationSettingValue } from '@shared/models' 15import { UserNotification, UserNotificationSettingValue } from '@shared/models'
@@ -35,7 +34,7 @@ describe('Test notifications API', function () {
35 await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) 34 await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
36 35
37 for (let i = 0; i < 10; i++) { 36 for (let i = 0; i < 10; i++) {
38 await uploadRandomVideo(server, false) 37 await server.videosCommand.randomUpload({ wait: false })
39 } 38 }
40 39
41 await waitJobs([ server ]) 40 await waitJobs([ server ])
@@ -112,7 +111,7 @@ describe('Test notifications API', function () {
112 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) 111 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
113 } 112 }
114 113
115 const { name, uuid } = await uploadRandomVideo(server) 114 const { name, uuid } = await server.videosCommand.randomUpload()
116 115
117 const check = { web: true, mail: true } 116 const check = { web: true, mail: true }
118 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') 117 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
@@ -131,7 +130,7 @@ describe('Test notifications API', function () {
131 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) 130 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
132 } 131 }
133 132
134 const { name, uuid } = await uploadRandomVideo(server) 133 const { name, uuid } = await server.videosCommand.randomUpload()
135 134
136 { 135 {
137 const check = { mail: true, web: false } 136 const check = { mail: true, web: false }
@@ -157,7 +156,7 @@ describe('Test notifications API', function () {
157 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) 156 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
158 } 157 }
159 158
160 const { name, uuid } = await uploadRandomVideo(server) 159 const { name, uuid } = await server.videosCommand.randomUpload()
161 160
162 { 161 {
163 const check = { mail: false, web: true } 162 const check = { mail: false, web: true }
@@ -188,7 +187,7 @@ describe('Test notifications API', function () {
188 ) 187 )
189 } 188 }
190 189
191 const { name, uuid } = await uploadRandomVideo(server) 190 const { name, uuid } = await server.videosCommand.randomUpload()
192 191
193 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 192 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
194 }) 193 })
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 465349fb9..4db8c1576 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -14,7 +14,6 @@ import {
14 MockSmtpServer, 14 MockSmtpServer,
15 prepareNotificationsTest, 15 prepareNotificationsTest,
16 ServerInfo, 16 ServerInfo,
17 updateVideo,
18 uploadRandomVideoOnServers, 17 uploadRandomVideoOnServers,
19 wait, 18 wait,
20 waitJobs 19 waitJobs
@@ -99,7 +98,7 @@ describe('Test user notifications', function () {
99 privacy: VideoPrivacy.PRIVATE, 98 privacy: VideoPrivacy.PRIVATE,
100 scheduleUpdate: { 99 scheduleUpdate: {
101 updateAt: updateAt.toISOString(), 100 updateAt: updateAt.toISOString(),
102 privacy: VideoPrivacy.PUBLIC 101 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
103 } 102 }
104 } 103 }
105 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 104 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
@@ -118,7 +117,7 @@ describe('Test user notifications', function () {
118 privacy: VideoPrivacy.PRIVATE, 117 privacy: VideoPrivacy.PRIVATE,
119 scheduleUpdate: { 118 scheduleUpdate: {
120 updateAt: updateAt.toISOString(), 119 updateAt: updateAt.toISOString(),
121 privacy: VideoPrivacy.PUBLIC 120 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
122 } 121 }
123 } 122 }
124 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 123 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
@@ -137,7 +136,7 @@ describe('Test user notifications', function () {
137 privacy: VideoPrivacy.PRIVATE, 136 privacy: VideoPrivacy.PRIVATE,
138 scheduleUpdate: { 137 scheduleUpdate: {
139 updateAt: updateAt.toISOString(), 138 updateAt: updateAt.toISOString(),
140 privacy: VideoPrivacy.PUBLIC 139 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
141 } 140 }
142 } 141 }
143 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 142 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
@@ -154,7 +153,7 @@ describe('Test user notifications', function () {
154 153
155 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 154 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
156 155
157 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) 156 await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
158 157
159 await waitJobs(servers) 158 await waitJobs(servers)
160 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 159 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
@@ -168,7 +167,7 @@ describe('Test user notifications', function () {
168 167
169 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 168 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
170 169
171 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) 170 await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
172 171
173 await waitJobs(servers) 172 await waitJobs(servers)
174 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 173 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
@@ -180,7 +179,7 @@ describe('Test user notifications', function () {
180 const data = { privacy: VideoPrivacy.PRIVATE } 179 const data = { privacy: VideoPrivacy.PRIVATE }
181 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 180 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
182 181
183 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) 182 await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
184 183
185 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 184 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
186 }) 185 })
@@ -191,7 +190,7 @@ describe('Test user notifications', function () {
191 const data = { privacy: VideoPrivacy.PRIVATE } 190 const data = { privacy: VideoPrivacy.PRIVATE }
192 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 191 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
193 192
194 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) 193 await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
195 194
196 await waitJobs(servers) 195 await waitJobs(servers)
197 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 196 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
@@ -295,7 +294,7 @@ describe('Test user notifications', function () {
295 privacy: VideoPrivacy.PRIVATE, 294 privacy: VideoPrivacy.PRIVATE,
296 scheduleUpdate: { 295 scheduleUpdate: {
297 updateAt: updateAt.toISOString(), 296 updateAt: updateAt.toISOString(),
298 privacy: VideoPrivacy.PUBLIC 297 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
299 } 298 }
300 } 299 }
301 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 300 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
@@ -313,7 +312,7 @@ describe('Test user notifications', function () {
313 privacy: VideoPrivacy.PRIVATE, 312 privacy: VideoPrivacy.PRIVATE,
314 scheduleUpdate: { 313 scheduleUpdate: {
315 updateAt: updateAt.toISOString(), 314 updateAt: updateAt.toISOString(),
316 privacy: VideoPrivacy.PUBLIC 315 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
317 } 316 }
318 } 317 }
319 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 318 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts
index 03857f512..efb60dc56 100644
--- a/server/tests/api/redundancy/manage-redundancy.ts
+++ b/server/tests/api/redundancy/manage-redundancy.ts
@@ -6,12 +6,9 @@ import {
6 cleanupTests, 6 cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getLocalIdByUUID,
10 RedundancyCommand, 9 RedundancyCommand,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 uploadVideo,
14 uploadVideoAndGetId,
15 waitJobs 12 waitJobs
16} from '@shared/extra-utils' 13} from '@shared/extra-utils'
17import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' 14import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
@@ -59,13 +56,13 @@ describe('Test manage videos redundancy', function () {
59 commands = servers.map(s => s.redundancyCommand) 56 commands = servers.map(s => s.redundancyCommand)
60 57
61 { 58 {
62 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) 59 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
63 video1Server2UUID = res.body.video.uuid 60 video1Server2UUID = uuid
64 } 61 }
65 62
66 { 63 {
67 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' }) 64 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2' } })
68 video2Server2UUID = res.body.video.uuid 65 video2Server2UUID = uuid
69 } 66 }
70 67
71 await waitJobs(servers) 68 await waitJobs(servers)
@@ -206,9 +203,9 @@ describe('Test manage videos redundancy', function () {
206 it('Should manually add a redundancy and list it', async function () { 203 it('Should manually add a redundancy and list it', async function () {
207 this.timeout(120000) 204 this.timeout(120000)
208 205
209 const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid 206 const uuid = (await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
210 await waitJobs(servers) 207 await waitJobs(servers)
211 const videoId = await getLocalIdByUUID(servers[0].url, uuid) 208 const videoId = await servers[0].videosCommand.getId({ uuid })
212 209
213 await commands[0].addVideo({ videoId }) 210 await commands[0].addVideo({ videoId })
214 211
diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts
index a31278de7..b3f6ed160 100644
--- a/server/tests/api/redundancy/redundancy-constraints.ts
+++ b/server/tests/api/redundancy/redundancy-constraints.ts
@@ -9,8 +9,6 @@ import {
9 reRunServer, 9 reRunServer,
10 ServerInfo, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 updateVideo,
13 uploadVideo,
14 waitJobs 12 waitJobs
15} from '@shared/extra-utils' 13} from '@shared/extra-utils'
16import { VideoPrivacy } from '@shared/models' 14import { VideoPrivacy } from '@shared/models'
@@ -38,11 +36,11 @@ describe('Test redundancy constraints', function () {
38 36
39 async function uploadWrapper (videoName: string) { 37 async function uploadWrapper (videoName: string) {
40 // Wait for transcoding 38 // Wait for transcoding
41 const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE }) 39 const { id } = await localServer.videosCommand.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
42 await waitJobs([ localServer ]) 40 await waitJobs([ localServer ])
43 41
44 // Update video to schedule a federation 42 // Update video to schedule a federation
45 await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC }) 43 await localServer.videosCommand.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
46 } 44 }
47 45
48 async function getTotalRedundanciesLocalServer () { 46 async function getTotalRedundanciesLocalServer () {
@@ -80,7 +78,7 @@ describe('Test redundancy constraints', function () {
80 // Get the access tokens 78 // Get the access tokens
81 await setAccessTokensToServers(servers) 79 await setAccessTokensToServers(servers)
82 80
83 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' }) 81 await localServer.videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
84 82
85 await waitJobs(servers) 83 await waitJobs(servers)
86 84
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index 00a5e86cc..6ca9c9303 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -12,22 +12,16 @@ import {
12 cleanupTests, 12 cleanupTests,
13 doubleFollow, 13 doubleFollow,
14 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
15 getVideo,
16 getVideoWithToken,
17 killallServers, 15 killallServers,
18 makeGetRequest, 16 makeGetRequest,
19 removeVideo,
20 reRunServer, 17 reRunServer,
21 root, 18 root,
22 ServerInfo, 19 ServerInfo,
23 setAccessTokensToServers, 20 setAccessTokensToServers,
24 updateVideo,
25 uploadVideo,
26 viewVideo,
27 wait, 21 wait,
28 waitJobs 22 waitJobs
29} from '@shared/extra-utils' 23} from '@shared/extra-utils'
30import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' 24import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models'
31 25
32const expect = chai.expect 26const expect = chai.expect
33 27
@@ -84,11 +78,11 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add
84 await setAccessTokensToServers(servers) 78 await setAccessTokensToServers(servers)
85 79
86 { 80 {
87 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) 81 const { uuid, id } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
88 video1Server2UUID = res.body.video.uuid 82 video1Server2UUID = uuid
89 video1Server2Id = res.body.video.id 83 video1Server2Id = id
90 84
91 await viewVideo(servers[1].url, video1Server2UUID) 85 await servers[1].videosCommand.view({ id: video1Server2UUID })
92 } 86 }
93 87
94 await waitJobs(servers) 88 await waitJobs(servers)
@@ -112,9 +106,8 @@ async function check1WebSeed (videoUUID?: string) {
112 106
113 for (const server of servers) { 107 for (const server of servers) {
114 // With token to avoid issues with video follow constraints 108 // With token to avoid issues with video follow constraints
115 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) 109 const video = await server.videosCommand.getWithToken({ id: videoUUID })
116 110
117 const video: VideoDetails = res.body
118 for (const f of video.files) { 111 for (const f of video.files) {
119 checkMagnetWebseeds(f, webseeds, server) 112 checkMagnetWebseeds(f, webseeds, server)
120 } 113 }
@@ -130,9 +123,7 @@ async function check2Webseeds (videoUUID?: string) {
130 ] 123 ]
131 124
132 for (const server of servers) { 125 for (const server of servers) {
133 const res = await getVideo(server.url, videoUUID) 126 const video = await server.videosCommand.get({ id: videoUUID })
134
135 const video: VideoDetails = res.body
136 127
137 for (const file of video.files) { 128 for (const file of video.files) {
138 checkMagnetWebseeds(file, webseeds, server) 129 checkMagnetWebseeds(file, webseeds, server)
@@ -172,8 +163,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) {
172 163
173 for (const server of servers) { 164 for (const server of servers) {
174 // With token to avoid issues with video follow constraints 165 // With token to avoid issues with video follow constraints
175 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) 166 const video = await server.videosCommand.getWithToken({ id: videoUUID })
176 const video: VideoDetails = res.body
177 167
178 expect(video.streamingPlaylists).to.be.an('array') 168 expect(video.streamingPlaylists).to.be.an('array')
179 expect(video.streamingPlaylists).to.have.lengthOf(1) 169 expect(video.streamingPlaylists).to.have.lengthOf(1)
@@ -185,8 +175,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) {
185 if (!videoUUID) videoUUID = video1Server2UUID 175 if (!videoUUID) videoUUID = video1Server2UUID
186 176
187 for (const server of servers) { 177 for (const server of servers) {
188 const res = await getVideo(server.url, videoUUID) 178 const video = await server.videosCommand.get({ id: videoUUID })
189 const video: VideoDetails = res.body
190 179
191 expect(video.streamingPlaylists).to.have.lengthOf(1) 180 expect(video.streamingPlaylists).to.have.lengthOf(1)
192 expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) 181 expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1)
@@ -199,8 +188,8 @@ async function check1PlaylistRedundancies (videoUUID?: string) {
199 const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' 188 const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls'
200 const baseUrlSegment = servers[0].url + '/static/redundancy/hls' 189 const baseUrlSegment = servers[0].url + '/static/redundancy/hls'
201 190
202 const res = await getVideo(servers[0].url, videoUUID) 191 const video = await servers[0].videosCommand.get({ id: videoUUID })
203 const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] 192 const hlsPlaylist = video.streamingPlaylists[0]
204 193
205 for (const resolution of [ 240, 360, 480, 720 ]) { 194 for (const resolution of [ 240, 360, 480, 720 ]) {
206 await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) 195 await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist })
@@ -427,8 +416,8 @@ describe('Test videos redundancy', function () {
427 it('Should view 2 times the first video to have > min_views config', async function () { 416 it('Should view 2 times the first video to have > min_views config', async function () {
428 this.timeout(80000) 417 this.timeout(80000)
429 418
430 await viewVideo(servers[0].url, video1Server2UUID) 419 await servers[0].videosCommand.view({ id: video1Server2UUID })
431 await viewVideo(servers[2].url, video1Server2UUID) 420 await servers[2].videosCommand.view({ id: video1Server2UUID })
432 421
433 await wait(10000) 422 await wait(10000)
434 await waitJobs(servers) 423 await waitJobs(servers)
@@ -449,7 +438,7 @@ describe('Test videos redundancy', function () {
449 it('Should remove the video and the redundancy files', async function () { 438 it('Should remove the video and the redundancy files', async function () {
450 this.timeout(20000) 439 this.timeout(20000)
451 440
452 await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) 441 await servers[1].videosCommand.remove({ id: video1Server2UUID })
453 442
454 await waitJobs(servers) 443 await waitJobs(servers)
455 444
@@ -495,8 +484,8 @@ describe('Test videos redundancy', function () {
495 it('Should have 1 redundancy on the first video', async function () { 484 it('Should have 1 redundancy on the first video', async function () {
496 this.timeout(160000) 485 this.timeout(160000)
497 486
498 await viewVideo(servers[0].url, video1Server2UUID) 487 await servers[0].videosCommand.view({ id: video1Server2UUID })
499 await viewVideo(servers[2].url, video1Server2UUID) 488 await servers[2].videosCommand.view({ id: video1Server2UUID })
500 489
501 await wait(10000) 490 await wait(10000)
502 await waitJobs(servers) 491 await waitJobs(servers)
@@ -512,7 +501,7 @@ describe('Test videos redundancy', function () {
512 it('Should remove the video and the redundancy files', async function () { 501 it('Should remove the video and the redundancy files', async function () {
513 this.timeout(20000) 502 this.timeout(20000)
514 503
515 await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) 504 await servers[1].videosCommand.remove({ id: video1Server2UUID })
516 505
517 await waitJobs(servers) 506 await waitJobs(servers)
518 507
@@ -588,8 +577,7 @@ describe('Test videos redundancy', function () {
588 577
589 async function checkContains (servers: ServerInfo[], str: string) { 578 async function checkContains (servers: ServerInfo[], str: string) {
590 for (const server of servers) { 579 for (const server of servers) {
591 const res = await getVideo(server.url, video1Server2UUID) 580 const video = await server.videosCommand.get({ id: video1Server2UUID })
592 const video: VideoDetails = res.body
593 581
594 for (const f of video.files) { 582 for (const f of video.files) {
595 expect(f.magnetUri).to.contain(str) 583 expect(f.magnetUri).to.contain(str)
@@ -599,8 +587,7 @@ describe('Test videos redundancy', function () {
599 587
600 async function checkNotContains (servers: ServerInfo[], str: string) { 588 async function checkNotContains (servers: ServerInfo[], str: string) {
601 for (const server of servers) { 589 for (const server of servers) {
602 const res = await getVideo(server.url, video1Server2UUID) 590 const video = await server.videosCommand.get({ id: video1Server2UUID })
603 const video: VideoDetails = res.body
604 591
605 for (const f of video.files) { 592 for (const f of video.files) {
606 expect(f.magnetUri).to.not.contain(str) 593 expect(f.magnetUri).to.not.contain(str)
@@ -665,13 +652,13 @@ describe('Test videos redundancy', function () {
665 await check1PlaylistRedundancies(video1Server2UUID) 652 await check1PlaylistRedundancies(video1Server2UUID)
666 await checkStatsWith1Redundancy(strategy) 653 await checkStatsWith1Redundancy(strategy)
667 654
668 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE }) 655 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } })
669 video2Server2UUID = res.body.video.uuid 656 video2Server2UUID = uuid
670 657
671 // Wait transcoding before federation 658 // Wait transcoding before federation
672 await waitJobs(servers) 659 await waitJobs(servers)
673 660
674 await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC }) 661 await servers[1].videosCommand.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } })
675 }) 662 })
676 663
677 it('Should cache video 2 webseeds on the first video', async function () { 664 it('Should cache video 2 webseeds on the first video', async function () {
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
index bcc21381c..75794402d 100644
--- a/server/tests/api/search/search-activitypub-video-channels.ts
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -5,12 +5,9 @@ import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
8 getVideoChannelVideos,
9 SearchCommand, 8 SearchCommand,
10 ServerInfo, 9 ServerInfo,
11 setAccessTokensToServers, 10 setAccessTokensToServers,
12 updateVideo,
13 uploadVideo,
14 wait, 11 wait,
15 waitJobs 12 waitJobs
16} from '@shared/extra-utils' 13} from '@shared/extra-utils'
@@ -53,8 +50,9 @@ describe('Test ActivityPub video channels search', function () {
53 const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel }) 50 const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel })
54 channelIdServer2 = created.id 51 channelIdServer2 = created.id
55 52
56 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 }) 53 const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 }
57 videoServer2UUID = res.body.video.uuid 54 const { uuid } = await servers[1].videosCommand.upload({ token: userServer2Token, attributes })
55 videoServer2UUID = uuid
58 } 56 }
59 57
60 await waitJobs(servers) 58 await waitJobs(servers)
@@ -149,16 +147,21 @@ describe('Test ActivityPub video channels search', function () {
149 147
150 await waitJobs(servers) 148 await waitJobs(servers)
151 149
152 const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5) 150 const { total, data } = await servers[0].videosCommand.listByChannel({
153 expect(res.body.total).to.equal(0) 151 token: null,
154 expect(res.body.data).to.have.lengthOf(0) 152 videoChannelName: 'channel1_server2@localhost:' + servers[1].port
153 })
154 expect(total).to.equal(0)
155 expect(data).to.have.lengthOf(0)
155 }) 156 })
156 157
157 it('Should list video channel videos of server 2 with token', async function () { 158 it('Should list video channel videos of server 2 with token', async function () {
158 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5) 159 const { total, data } = await servers[0].videosCommand.listByChannel({
160 videoChannelName: 'channel1_server2@localhost:' + servers[1].port
161 })
159 162
160 expect(res.body.total).to.equal(1) 163 expect(total).to.equal(1)
161 expect(res.body.data[0].name).to.equal('video 1 server 2') 164 expect(data[0].name).to.equal('video 1 server 2')
162 }) 165 })
163 166
164 it('Should update video channel of server 2, and refresh it on server 1', async function () { 167 it('Should update video channel of server 2, and refresh it on server 1', async function () {
@@ -190,8 +193,8 @@ describe('Test ActivityPub video channels search', function () {
190 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { 193 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
191 this.timeout(60000) 194 this.timeout(60000)
192 195
193 await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' }) 196 await servers[1].videosCommand.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } })
194 await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 }) 197 await servers[1].videosCommand.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } })
195 198
196 await waitJobs(servers) 199 await waitJobs(servers)
197 200
@@ -204,11 +207,11 @@ describe('Test ActivityPub video channels search', function () {
204 await waitJobs(servers) 207 await waitJobs(servers)
205 208
206 const videoChannelName = 'channel1_server2@localhost:' + servers[1].port 209 const videoChannelName = 'channel1_server2@localhost:' + servers[1].port
207 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt') 210 const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName, sort: '-createdAt' })
208 211
209 expect(res.body.total).to.equal(2) 212 expect(total).to.equal(2)
210 expect(res.body.data[0].name).to.equal('video 2 server 2') 213 expect(data[0].name).to.equal('video 2 server 2')
211 expect(res.body.data[1].name).to.equal('video 1 updated') 214 expect(data[1].name).to.equal('video 1 updated')
212 }) 215 })
213 216
214 it('Should delete video channel of server 2, and delete it on server 1', async function () { 217 it('Should delete video channel of server 2, and delete it on server 1', async function () {
diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts
index cb7582d29..46105c12c 100644
--- a/server/tests/api/search/search-activitypub-video-playlists.ts
+++ b/server/tests/api/search/search-activitypub-video-playlists.ts
@@ -9,7 +9,6 @@ import {
9 ServerInfo, 9 ServerInfo,
10 setAccessTokensToServers, 10 setAccessTokensToServers,
11 setDefaultVideoChannel, 11 setDefaultVideoChannel,
12 uploadVideoAndGetId,
13 wait, 12 wait,
14 waitJobs 13 waitJobs
15} from '@shared/extra-utils' 14} from '@shared/extra-utils'
@@ -34,8 +33,8 @@ describe('Test ActivityPub playlists search', function () {
34 await setDefaultVideoChannel(servers) 33 await setDefaultVideoChannel(servers)
35 34
36 { 35 {
37 const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid 36 const video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid
38 const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid 37 const video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid
39 38
40 const attributes = { 39 const attributes = {
41 displayName: 'playlist 1 on server 1', 40 displayName: 'playlist 1 on server 1',
@@ -51,8 +50,8 @@ describe('Test ActivityPub playlists search', function () {
51 } 50 }
52 51
53 { 52 {
54 const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid 53 const videoId = (await servers[1].videosCommand.quickUpload({ name: 'video 1' })).uuid
55 video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid 54 video2Server2 = (await servers[1].videosCommand.quickUpload({ name: 'video 2' })).uuid
56 55
57 const attributes = { 56 const attributes = {
58 displayName: 'playlist 1 on server 2', 57 displayName: 'playlist 1 on server 2',
diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts
index 403c84010..19b4d5ed8 100644
--- a/server/tests/api/search/search-activitypub-videos.ts
+++ b/server/tests/api/search/search-activitypub-videos.ts
@@ -5,17 +5,13 @@ import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
8 getVideosList,
9 removeVideo,
10 SearchCommand, 8 SearchCommand,
11 ServerInfo, 9 ServerInfo,
12 setAccessTokensToServers, 10 setAccessTokensToServers,
13 updateVideo, 11 wait,
14 uploadVideo, 12 waitJobs
15 wait 13} from '@shared/extra-utils'
16} from '../../../../shared/extra-utils' 14import { VideoPrivacy } from '@shared/models'
17import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18import { VideoPrivacy } from '../../../../shared/models/videos'
19 15
20const expect = chai.expect 16const expect = chai.expect
21 17
@@ -34,13 +30,13 @@ describe('Test ActivityPub videos search', function () {
34 await setAccessTokensToServers(servers) 30 await setAccessTokensToServers(servers)
35 31
36 { 32 {
37 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 on server 1' }) 33 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1 on server 1' } })
38 videoServer1UUID = res.body.video.uuid 34 videoServer1UUID = uuid
39 } 35 }
40 36
41 { 37 {
42 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 on server 2' }) 38 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 on server 2' } })
43 videoServer2UUID = res.body.video.uuid 39 videoServer2UUID = uuid
44 } 40 }
45 41
46 await waitJobs(servers) 42 await waitJobs(servers)
@@ -109,10 +105,10 @@ describe('Test ActivityPub videos search', function () {
109 }) 105 })
110 106
111 it('Should not list this remote video', async function () { 107 it('Should not list this remote video', async function () {
112 const res = await getVideosList(servers[0].url) 108 const { total, data } = await servers[0].videosCommand.list()
113 expect(res.body.total).to.equal(1) 109 expect(total).to.equal(1)
114 expect(res.body.data).to.have.lengthOf(1) 110 expect(data).to.have.lengthOf(1)
115 expect(res.body.data[0].name).to.equal('video 1 on server 1') 111 expect(data[0].name).to.equal('video 1 on server 1')
116 }) 112 })
117 113
118 it('Should update video of server 2, and refresh it on server 1', async function () { 114 it('Should update video of server 2, and refresh it on server 1', async function () {
@@ -131,7 +127,7 @@ describe('Test ActivityPub videos search', function () {
131 privacy: VideoPrivacy.UNLISTED, 127 privacy: VideoPrivacy.UNLISTED,
132 channelId: videoChannelId 128 channelId: videoChannelId
133 } 129 }
134 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes) 130 await servers[1].videosCommand.update({ id: videoServer2UUID, attributes })
135 131
136 await waitJobs(servers) 132 await waitJobs(servers)
137 // Expire video 133 // Expire video
@@ -157,7 +153,7 @@ describe('Test ActivityPub videos search', function () {
157 it('Should delete video of server 2, and delete it on server 1', async function () { 153 it('Should delete video of server 2, and delete it on server 1', async function () {
158 this.timeout(120000) 154 this.timeout(120000)
159 155
160 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID) 156 await servers[1].videosCommand.remove({ id: videoServer2UUID })
161 157
162 await waitJobs(servers) 158 await waitJobs(servers)
163 // Expire video 159 // Expire video
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index 306f84c3a..d5dc40f60 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' 5import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
6import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' 6import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
7 7
8const expect = chai.expect 8const expect = chai.expect
@@ -20,7 +20,7 @@ describe('Test videos search', function () {
20 20
21 await setAccessTokensToServers([ server ]) 21 await setAccessTokensToServers([ server ])
22 22
23 await uploadVideo(server.url, server.accessToken, { name: localVideoName }) 23 await server.videosCommand.upload({ attributes: { name: localVideoName } })
24 24
25 command = server.searchCommand 25 command = server.searchCommand
26 }) 26 })
diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts
index 517884503..2e4773ed6 100644
--- a/server/tests/api/search/search-playlists.ts
+++ b/server/tests/api/search/search-playlists.ts
@@ -2,16 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPlaylistPrivacy } from '@shared/models'
6import { 5import {
7 cleanupTests, 6 cleanupTests,
8 flushAndRunServer, 7 flushAndRunServer,
9 SearchCommand, 8 SearchCommand,
10 ServerInfo, 9 ServerInfo,
11 setAccessTokensToServers, 10 setAccessTokensToServers,
12 setDefaultVideoChannel, 11 setDefaultVideoChannel
13 uploadVideoAndGetId 12} from '@shared/extra-utils'
14} from '../../../../shared/extra-utils' 13import { VideoPlaylistPrivacy } from '@shared/models'
15 14
16const expect = chai.expect 15const expect = chai.expect
17 16
@@ -27,7 +26,7 @@ describe('Test playlists search', function () {
27 await setAccessTokensToServers([ server ]) 26 await setAccessTokensToServers([ server ])
28 await setDefaultVideoChannel([ server ]) 27 await setDefaultVideoChannel([ server ])
29 28
30 const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid 29 const videoId = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
31 30
32 { 31 {
33 const attributes = { 32 const attributes = {
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts
index 66f5f3182..148499d5f 100644
--- a/server/tests/api/search/search-videos.ts
+++ b/server/tests/api/search/search-videos.ts
@@ -10,7 +10,6 @@ import {
10 setAccessTokensToServers, 10 setAccessTokensToServers,
11 setDefaultVideoChannel, 11 setDefaultVideoChannel,
12 stopFfmpeg, 12 stopFfmpeg,
13 uploadVideo,
14 wait 13 wait
15} from '@shared/extra-utils' 14} from '@shared/extra-utils'
16import { VideoPrivacy } from '@shared/models' 15import { VideoPrivacy } from '@shared/models'
@@ -41,50 +40,49 @@ describe('Test videos search', function () {
41 nsfw: false, 40 nsfw: false,
42 language: 'fr' 41 language: 'fr'
43 } 42 }
44 await uploadVideo(server.url, server.accessToken, attributes1) 43 await server.videosCommand.upload({ attributes: attributes1 })
45 44
46 const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } 45 const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
47 await uploadVideo(server.url, server.accessToken, attributes2) 46 await server.videosCommand.upload({ attributes: attributes2 })
48 47
49 { 48 {
50 const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } 49 const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
51 const res = await uploadVideo(server.url, server.accessToken, attributes3) 50 const { id, uuid } = await server.videosCommand.upload({ attributes: attributes3 })
52 const videoId = res.body.video.id 51 videoUUID = uuid
53 videoUUID = res.body.video.uuid
54 52
55 await server.captionsCommand.createVideoCaption({ 53 await server.captionsCommand.createVideoCaption({
56 language: 'en', 54 language: 'en',
57 videoId, 55 videoId: id,
58 fixture: 'subtitle-good2.vtt', 56 fixture: 'subtitle-good2.vtt',
59 mimeType: 'application/octet-stream' 57 mimeType: 'application/octet-stream'
60 }) 58 })
61 59
62 await server.captionsCommand.createVideoCaption({ 60 await server.captionsCommand.createVideoCaption({
63 language: 'aa', 61 language: 'aa',
64 videoId, 62 videoId: id,
65 fixture: 'subtitle-good2.vtt', 63 fixture: 'subtitle-good2.vtt',
66 mimeType: 'application/octet-stream' 64 mimeType: 'application/octet-stream'
67 }) 65 })
68 } 66 }
69 67
70 const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } 68 const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
71 await uploadVideo(server.url, server.accessToken, attributes4) 69 await server.videosCommand.upload({ attributes: attributes4 })
72 70
73 await wait(1000) 71 await wait(1000)
74 72
75 startDate = new Date().toISOString() 73 startDate = new Date().toISOString()
76 74
77 const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } 75 const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
78 await uploadVideo(server.url, server.accessToken, attributes5) 76 await server.videosCommand.upload({ attributes: attributes5 })
79 77
80 const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } 78 const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
81 await uploadVideo(server.url, server.accessToken, attributes6) 79 await server.videosCommand.upload({ attributes: attributes6 })
82 80
83 const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } 81 const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
84 await uploadVideo(server.url, server.accessToken, attributes7) 82 await server.videosCommand.upload({ attributes: attributes7 })
85 83
86 const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } 84 const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
87 await uploadVideo(server.url, server.accessToken, attributes8) 85 await server.videosCommand.upload({ attributes: attributes8 })
88 } 86 }
89 87
90 { 88 {
@@ -95,9 +93,9 @@ describe('Test videos search', function () {
95 licence: 2, 93 licence: 2,
96 language: 'en' 94 language: 'en'
97 } 95 }
98 await uploadVideo(server.url, server.accessToken, attributes) 96 await server.videosCommand.upload({ attributes: attributes })
99 97
100 await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' }) 98 await server.videosCommand.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } })
101 } 99 }
102 100
103 { 101 {
@@ -108,7 +106,7 @@ describe('Test videos search', function () {
108 licence: 3, 106 licence: 3,
109 language: 'pl' 107 language: 'pl'
110 } 108 }
111 await uploadVideo(server.url, server.accessToken, attributes) 109 await server.videosCommand.upload({ attributes: attributes })
112 } 110 }
113 111
114 { 112 {
@@ -117,11 +115,11 @@ describe('Test videos search', function () {
117 tags: [ 'aaaa', 'bbbb', 'cccc' ], 115 tags: [ 'aaaa', 'bbbb', 'cccc' ],
118 category: 1 116 category: 1
119 } 117 }
120 await uploadVideo(server.url, server.accessToken, attributes1) 118 await server.videosCommand.upload({ attributes: attributes1 })
121 await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) 119 await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } })
122 120
123 await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] }) 121 await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } })
124 await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] }) 122 await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } })
125 } 123 }
126 124
127 { 125 {
@@ -129,8 +127,8 @@ describe('Test videos search', function () {
129 name: 'aaaa 2', 127 name: 'aaaa 2',
130 category: 1 128 category: 1
131 } 129 }
132 await uploadVideo(server.url, server.accessToken, attributes1) 130 await server.videosCommand.upload({ attributes: attributes1 })
133 await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) 131 await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } })
134 } 132 }
135 133
136 command = server.searchCommand 134 command = server.searchCommand
diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts
index 20a9a3dc7..c83bcfb22 100644
--- a/server/tests/api/server/bulk.ts
+++ b/server/tests/api/server/bulk.ts
@@ -7,13 +7,10 @@ import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getVideosList,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 uploadVideo,
14 waitJobs 12 waitJobs
15} from '@shared/extra-utils' 13} from '@shared/extra-utils'
16import { Video } from '@shared/models'
17 14
18const expect = chai.expect 15const expect = chai.expect
19 16
@@ -64,11 +61,10 @@ describe('Test bulk actions', function () {
64 describe('Bulk remove comments', function () { 61 describe('Bulk remove comments', function () {
65 async function checkInstanceCommentsRemoved () { 62 async function checkInstanceCommentsRemoved () {
66 { 63 {
67 const res = await getVideosList(servers[0].url) 64 const { data } = await servers[0].videosCommand.list()
68 const videos = res.body.data as Video[]
69 65
70 // Server 1 should not have these comments anymore 66 // Server 1 should not have these comments anymore
71 for (const video of videos) { 67 for (const video of data) {
72 const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id }) 68 const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id })
73 const comment = data.find(c => c.text === 'comment by user 3') 69 const comment = data.find(c => c.text === 'comment by user 3')
74 70
@@ -77,11 +73,10 @@ describe('Test bulk actions', function () {
77 } 73 }
78 74
79 { 75 {
80 const res = await getVideosList(servers[1].url) 76 const { data } = await servers[1].videosCommand.list()
81 const videos = res.body.data as Video[]
82 77
83 // Server 1 should not have these comments on videos of server 1 78 // Server 1 should not have these comments on videos of server 1
84 for (const video of videos) { 79 for (const video of data) {
85 const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id }) 80 const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id })
86 const comment = data.find(c => c.text === 'comment by user 3') 81 const comment = data.find(c => c.text === 'comment by user 3')
87 82
@@ -97,17 +92,17 @@ describe('Test bulk actions', function () {
97 before(async function () { 92 before(async function () {
98 this.timeout(120000) 93 this.timeout(120000)
99 94
100 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' }) 95 await servers[0].videosCommand.upload({ attributes: { name: 'video 1 server 1' } })
101 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) 96 await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } })
102 await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' }) 97 await servers[0].videosCommand.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } })
103 98
104 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) 99 await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } })
105 100
106 await waitJobs(servers) 101 await waitJobs(servers)
107 102
108 { 103 {
109 const res = await getVideosList(servers[0].url) 104 const { data } = await servers[0].videosCommand.list()
110 for (const video of res.body.data) { 105 for (const video of data) {
111 await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' }) 106 await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' })
112 await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' }) 107 await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' })
113 await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' }) 108 await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' })
@@ -115,9 +110,9 @@ describe('Test bulk actions', function () {
115 } 110 }
116 111
117 { 112 {
118 const res = await getVideosList(servers[1].url) 113 const { data } = await servers[1].videosCommand.list()
119 114
120 for (const video of res.body.data) { 115 for (const video of data) {
121 await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' }) 116 await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' })
122 117
123 const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' }) 118 const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' })
@@ -142,9 +137,9 @@ describe('Test bulk actions', function () {
142 await waitJobs(servers) 137 await waitJobs(servers)
143 138
144 for (const server of servers) { 139 for (const server of servers) {
145 const res = await getVideosList(server.url) 140 const { data } = await server.videosCommand.list()
146 141
147 for (const video of res.body.data) { 142 for (const video of data) {
148 const { data } = await server.commentsCommand.listThreads({ videoId: video.id }) 143 const { data } = await server.commentsCommand.listThreads({ videoId: video.id })
149 const comment = data.find(c => c.text === 'comment by user 2') 144 const comment = data.find(c => c.text === 'comment by user 2')
150 145
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 95dafd378..c613511ed 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -11,8 +11,7 @@ import {
11 parallelTests, 11 parallelTests,
12 reRunServer, 12 reRunServer,
13 ServerInfo, 13 ServerInfo,
14 setAccessTokensToServers, 14 setAccessTokensToServers
15 uploadVideo
16} from '@shared/extra-utils' 15} from '@shared/extra-utils'
17import { CustomConfig } from '@shared/models' 16import { CustomConfig } from '@shared/models'
18 17
@@ -242,8 +241,8 @@ describe('Test config', function () {
242 expect(data.video.file.extensions).to.contain('.webm') 241 expect(data.video.file.extensions).to.contain('.webm')
243 expect(data.video.file.extensions).to.contain('.ogv') 242 expect(data.video.file.extensions).to.contain('.ogv')
244 243
245 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) 244 await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
246 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) 245 await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
247 246
248 expect(data.contactForm.enabled).to.be.true 247 expect(data.contactForm.enabled).to.be.true
249 }) 248 })
@@ -448,8 +447,8 @@ describe('Test config', function () {
448 expect(data.video.file.extensions).to.contain('.ogg') 447 expect(data.video.file.extensions).to.contain('.ogg')
449 expect(data.video.file.extensions).to.contain('.flac') 448 expect(data.video.file.extensions).to.contain('.flac')
450 449
451 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200) 450 await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
452 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200) 451 await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
453 }) 452 })
454 453
455 it('Should have the configuration updated after a restart', async function () { 454 it('Should have the configuration updated after a restart', async function () {
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index 422db6ceb..aeda5fddb 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -3,15 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
7 cleanupTests,
8 flushAndRunServer,
9 MockSmtpServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo,
13 waitJobs
14} from '@shared/extra-utils'
15 7
16const expect = chai.expect 8const expect = chai.expect
17 9
@@ -58,20 +50,18 @@ describe('Test emails', function () {
58 } 50 }
59 51
60 { 52 {
61 const attributes = { 53 const attributes = { name: 'my super user video' }
62 name: 'my super user video' 54 const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes })
63 } 55 videoUserUUID = uuid
64 const res = await uploadVideo(server.url, userAccessToken, attributes)
65 videoUserUUID = res.body.video.uuid
66 } 56 }
67 57
68 { 58 {
69 const attributes = { 59 const attributes = {
70 name: 'my super name' 60 name: 'my super name'
71 } 61 }
72 const res = await uploadVideo(server.url, server.accessToken, attributes) 62 const { uuid, id } = await server.videosCommand.upload({ attributes })
73 videoUUID = res.body.video.uuid 63 videoUUID = uuid
74 videoId = res.body.video.id 64 videoId = id
75 } 65 }
76 }) 66 })
77 67
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts
index 29ccb264d..f9014aeee 100644
--- a/server/tests/api/server/follow-constraints.ts
+++ b/server/tests/api/server/follow-constraints.ts
@@ -3,19 +3,8 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
6import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' 7import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
7import {
8 cleanupTests,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 getAccountVideos,
12 getVideo,
13 getVideoChannelVideos,
14 getVideoWithToken,
15 ServerInfo,
16 setAccessTokensToServers,
17 uploadVideo
18} from '../../../../shared/extra-utils'
19 8
20const expect = chai.expect 9const expect = chai.expect
21 10
@@ -23,7 +12,7 @@ describe('Test follow constraints', function () {
23 let servers: ServerInfo[] = [] 12 let servers: ServerInfo[] = []
24 let video1UUID: string 13 let video1UUID: string
25 let video2UUID: string 14 let video2UUID: string
26 let userAccessToken: string 15 let userToken: string
27 16
28 before(async function () { 17 before(async function () {
29 this.timeout(90000) 18 this.timeout(90000)
@@ -34,12 +23,12 @@ describe('Test follow constraints', function () {
34 await setAccessTokensToServers(servers) 23 await setAccessTokensToServers(servers)
35 24
36 { 25 {
37 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) 26 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } })
38 video1UUID = res.body.video.uuid 27 video1UUID = uuid
39 } 28 }
40 { 29 {
41 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) 30 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } })
42 video2UUID = res.body.video.uuid 31 video2UUID = uuid
43 } 32 }
44 33
45 const user = { 34 const user = {
@@ -47,7 +36,7 @@ describe('Test follow constraints', function () {
47 password: 'super_password' 36 password: 'super_password'
48 } 37 }
49 await servers[0].usersCommand.create({ username: user.username, password: user.password }) 38 await servers[0].usersCommand.create({ username: user.username, password: user.password })
50 userAccessToken = await servers[0].loginCommand.getAccessToken(user) 39 userToken = await servers[0].loginCommand.getAccessToken(user)
51 40
52 await doubleFollow(servers[0], servers[1]) 41 await doubleFollow(servers[0], servers[1])
53 }) 42 })
@@ -57,81 +46,81 @@ describe('Test follow constraints', function () {
57 describe('With an unlogged user', function () { 46 describe('With an unlogged user', function () {
58 47
59 it('Should get the local video', async function () { 48 it('Should get the local video', async function () {
60 await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) 49 await servers[0].videosCommand.get({ id: video1UUID })
61 }) 50 })
62 51
63 it('Should get the remote video', async function () { 52 it('Should get the remote video', async function () {
64 await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200) 53 await servers[0].videosCommand.get({ id: video2UUID })
65 }) 54 })
66 55
67 it('Should list local account videos', async function () { 56 it('Should list local account videos', async function () {
68 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) 57 const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[0].port })
69 58
70 expect(res.body.total).to.equal(1) 59 expect(total).to.equal(1)
71 expect(res.body.data).to.have.lengthOf(1) 60 expect(data).to.have.lengthOf(1)
72 }) 61 })
73 62
74 it('Should list remote account videos', async function () { 63 it('Should list remote account videos', async function () {
75 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) 64 const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[1].port })
76 65
77 expect(res.body.total).to.equal(1) 66 expect(total).to.equal(1)
78 expect(res.body.data).to.have.lengthOf(1) 67 expect(data).to.have.lengthOf(1)
79 }) 68 })
80 69
81 it('Should list local channel videos', async function () { 70 it('Should list local channel videos', async function () {
82 const videoChannelName = 'root_channel@localhost:' + servers[0].port 71 const videoChannelName = 'root_channel@localhost:' + servers[0].port
83 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) 72 const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
84 73
85 expect(res.body.total).to.equal(1) 74 expect(total).to.equal(1)
86 expect(res.body.data).to.have.lengthOf(1) 75 expect(data).to.have.lengthOf(1)
87 }) 76 })
88 77
89 it('Should list remote channel videos', async function () { 78 it('Should list remote channel videos', async function () {
90 const videoChannelName = 'root_channel@localhost:' + servers[1].port 79 const videoChannelName = 'root_channel@localhost:' + servers[1].port
91 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) 80 const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
92 81
93 expect(res.body.total).to.equal(1) 82 expect(total).to.equal(1)
94 expect(res.body.data).to.have.lengthOf(1) 83 expect(data).to.have.lengthOf(1)
95 }) 84 })
96 }) 85 })
97 86
98 describe('With a logged user', function () { 87 describe('With a logged user', function () {
99 it('Should get the local video', async function () { 88 it('Should get the local video', async function () {
100 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) 89 await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
101 }) 90 })
102 91
103 it('Should get the remote video', async function () { 92 it('Should get the remote video', async function () {
104 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) 93 await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
105 }) 94 })
106 95
107 it('Should list local account videos', async function () { 96 it('Should list local account videos', async function () {
108 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) 97 const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
109 98
110 expect(res.body.total).to.equal(1) 99 expect(total).to.equal(1)
111 expect(res.body.data).to.have.lengthOf(1) 100 expect(data).to.have.lengthOf(1)
112 }) 101 })
113 102
114 it('Should list remote account videos', async function () { 103 it('Should list remote account videos', async function () {
115 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) 104 const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
116 105
117 expect(res.body.total).to.equal(1) 106 expect(total).to.equal(1)
118 expect(res.body.data).to.have.lengthOf(1) 107 expect(data).to.have.lengthOf(1)
119 }) 108 })
120 109
121 it('Should list local channel videos', async function () { 110 it('Should list local channel videos', async function () {
122 const videoChannelName = 'root_channel@localhost:' + servers[0].port 111 const videoChannelName = 'root_channel@localhost:' + servers[0].port
123 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) 112 const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
124 113
125 expect(res.body.total).to.equal(1) 114 expect(total).to.equal(1)
126 expect(res.body.data).to.have.lengthOf(1) 115 expect(data).to.have.lengthOf(1)
127 }) 116 })
128 117
129 it('Should list remote channel videos', async function () { 118 it('Should list remote channel videos', async function () {
130 const videoChannelName = 'root_channel@localhost:' + servers[1].port 119 const videoChannelName = 'root_channel@localhost:' + servers[1].port
131 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) 120 const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
132 121
133 expect(res.body.total).to.equal(1) 122 expect(total).to.equal(1)
134 expect(res.body.data).to.have.lengthOf(1) 123 expect(data).to.have.lengthOf(1)
135 }) 124 })
136 }) 125 })
137 }) 126 })
@@ -147,13 +136,12 @@ describe('Test follow constraints', function () {
147 describe('With an unlogged user', function () { 136 describe('With an unlogged user', function () {
148 137
149 it('Should get the local video', async function () { 138 it('Should get the local video', async function () {
150 await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) 139 await servers[0].videosCommand.get({ id: video1UUID })
151 }) 140 })
152 141
153 it('Should not get the remote video', async function () { 142 it('Should not get the remote video', async function () {
154 const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403) 143 const body = await servers[0].videosCommand.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
155 144 const error = body as unknown as PeerTubeProblemDocument
156 const error = res.body as PeerTubeProblemDocument
157 145
158 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints' 146 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
159 expect(error.type).to.equal(doc) 147 expect(error.type).to.equal(doc)
@@ -168,73 +156,79 @@ describe('Test follow constraints', function () {
168 }) 156 })
169 157
170 it('Should list local account videos', async function () { 158 it('Should list local account videos', async function () {
171 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) 159 const { total, data } = await servers[0].videosCommand.listByAccount({
160 token: undefined,
161 accountName: 'root@localhost:' + servers[0].port
162 })
172 163
173 expect(res.body.total).to.equal(1) 164 expect(total).to.equal(1)
174 expect(res.body.data).to.have.lengthOf(1) 165 expect(data).to.have.lengthOf(1)
175 }) 166 })
176 167
177 it('Should not list remote account videos', async function () { 168 it('Should not list remote account videos', async function () {
178 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) 169 const { total, data } = await servers[0].videosCommand.listByAccount({
170 token: undefined,
171 accountName: 'root@localhost:' + servers[1].port
172 })
179 173
180 expect(res.body.total).to.equal(0) 174 expect(total).to.equal(0)
181 expect(res.body.data).to.have.lengthOf(0) 175 expect(data).to.have.lengthOf(0)
182 }) 176 })
183 177
184 it('Should list local channel videos', async function () { 178 it('Should list local channel videos', async function () {
185 const videoChannelName = 'root_channel@localhost:' + servers[0].port 179 const videoChannelName = 'root_channel@localhost:' + servers[0].port
186 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) 180 const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
187 181
188 expect(res.body.total).to.equal(1) 182 expect(total).to.equal(1)
189 expect(res.body.data).to.have.lengthOf(1) 183 expect(data).to.have.lengthOf(1)
190 }) 184 })
191 185
192 it('Should not list remote channel videos', async function () { 186 it('Should not list remote channel videos', async function () {
193 const videoChannelName = 'root_channel@localhost:' + servers[1].port 187 const videoChannelName = 'root_channel@localhost:' + servers[1].port
194 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) 188 const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
195 189
196 expect(res.body.total).to.equal(0) 190 expect(total).to.equal(0)
197 expect(res.body.data).to.have.lengthOf(0) 191 expect(data).to.have.lengthOf(0)
198 }) 192 })
199 }) 193 })
200 194
201 describe('With a logged user', function () { 195 describe('With a logged user', function () {
202 it('Should get the local video', async function () { 196 it('Should get the local video', async function () {
203 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) 197 await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
204 }) 198 })
205 199
206 it('Should get the remote video', async function () { 200 it('Should get the remote video', async function () {
207 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) 201 await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
208 }) 202 })
209 203
210 it('Should list local account videos', async function () { 204 it('Should list local account videos', async function () {
211 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) 205 const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
212 206
213 expect(res.body.total).to.equal(1) 207 expect(total).to.equal(1)
214 expect(res.body.data).to.have.lengthOf(1) 208 expect(data).to.have.lengthOf(1)
215 }) 209 })
216 210
217 it('Should list remote account videos', async function () { 211 it('Should list remote account videos', async function () {
218 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) 212 const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
219 213
220 expect(res.body.total).to.equal(1) 214 expect(total).to.equal(1)
221 expect(res.body.data).to.have.lengthOf(1) 215 expect(data).to.have.lengthOf(1)
222 }) 216 })
223 217
224 it('Should list local channel videos', async function () { 218 it('Should list local channel videos', async function () {
225 const videoChannelName = 'root_channel@localhost:' + servers[0].port 219 const videoChannelName = 'root_channel@localhost:' + servers[0].port
226 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) 220 const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
227 221
228 expect(res.body.total).to.equal(1) 222 expect(total).to.equal(1)
229 expect(res.body.data).to.have.lengthOf(1) 223 expect(data).to.have.lengthOf(1)
230 }) 224 })
231 225
232 it('Should list remote channel videos', async function () { 226 it('Should list remote channel videos', async function () {
233 const videoChannelName = 'root_channel@localhost:' + servers[1].port 227 const videoChannelName = 'root_channel@localhost:' + servers[1].port
234 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) 228 const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
235 229
236 expect(res.body.total).to.equal(1) 230 expect(total).to.equal(1)
237 expect(res.body.data).to.have.lengthOf(1) 231 expect(data).to.have.lengthOf(1)
238 }) 232 })
239 }) 233 })
240 }) 234 })
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index 02d25e67f..5ce8938fa 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -9,12 +9,9 @@ import {
9 expectAccountFollows, 9 expectAccountFollows,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 FollowsCommand, 11 FollowsCommand,
12 getVideosList,
13 rateVideo,
14 ServerInfo, 12 ServerInfo,
15 setAccessTokensToServers, 13 setAccessTokensToServers,
16 testCaptionFile, 14 testCaptionFile,
17 uploadVideo,
18 waitJobs 15 waitJobs
19} from '@shared/extra-utils' 16} from '@shared/extra-utils'
20import { Video, VideoPrivacy } from '@shared/models' 17import { Video, VideoPrivacy } from '@shared/models'
@@ -287,22 +284,28 @@ describe('Test follows', function () {
287 it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { 284 it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () {
288 this.timeout(60000) 285 this.timeout(60000)
289 286
290 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) 287 await servers[1].videosCommand.upload({ attributes: { name: 'server2' } })
291 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) 288 await servers[2].videosCommand.upload({ attributes: { name: 'server3' } })
292 289
293 await waitJobs(servers) 290 await waitJobs(servers)
294 291
295 let res = await getVideosList(servers[0].url) 292 {
296 expect(res.body.total).to.equal(1) 293 const { total, data } = await servers[0].videosCommand.list()
297 expect(res.body.data[0].name).to.equal('server2') 294 expect(total).to.equal(1)
295 expect(data[0].name).to.equal('server2')
296 }
298 297
299 res = await getVideosList(servers[1].url) 298 {
300 expect(res.body.total).to.equal(1) 299 const { total, data } = await servers[1].videosCommand.list()
301 expect(res.body.data[0].name).to.equal('server2') 300 expect(total).to.equal(1)
301 expect(data[0].name).to.equal('server2')
302 }
302 303
303 res = await getVideosList(servers[2].url) 304 {
304 expect(res.body.total).to.equal(1) 305 const { total, data } = await servers[2].videosCommand.list()
305 expect(res.body.data[0].name).to.equal('server3') 306 expect(total).to.equal(1)
307 expect(data[0].name).to.equal('server3')
308 }
306 }) 309 })
307 310
308 describe('Should propagate data on a new following', function () { 311 describe('Should propagate data on a new following', function () {
@@ -319,21 +322,21 @@ describe('Test follows', function () {
319 tags: [ 'tag1', 'tag2', 'tag3' ] 322 tags: [ 'tag1', 'tag2', 'tag3' ]
320 } 323 }
321 324
322 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' }) 325 await servers[2].videosCommand.upload({ attributes: { name: 'server3-2' } })
323 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' }) 326 await servers[2].videosCommand.upload({ attributes: { name: 'server3-3' } })
324 await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes) 327 await servers[2].videosCommand.upload({ attributes: video4Attributes })
325 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' }) 328 await servers[2].videosCommand.upload({ attributes: { name: 'server3-5' } })
326 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) 329 await servers[2].videosCommand.upload({ attributes: { name: 'server3-6' } })
327 330
328 { 331 {
329 const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain') 332 const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain')
330 333
331 const resVideos = await getVideosList(servers[2].url) 334 const { data } = await servers[2].videosCommand.list()
332 video4 = resVideos.body.data.find(v => v.name === 'server3-4') 335 video4 = data.find(v => v.name === 'server3-4')
333 336
334 { 337 {
335 await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like') 338 await servers[2].videosCommand.rate({ id: video4.id, rating: 'like' })
336 await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike') 339 await servers[2].videosCommand.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' })
337 } 340 }
338 341
339 { 342 {
@@ -401,12 +404,12 @@ describe('Test follows', function () {
401 }) 404 })
402 405
403 it('Should have propagated videos', async function () { 406 it('Should have propagated videos', async function () {
404 const res = await getVideosList(servers[0].url) 407 const { total, data } = await servers[0].videosCommand.list()
405 expect(res.body.total).to.equal(7) 408 expect(total).to.equal(7)
406 409
407 const video2 = res.body.data.find(v => v.name === 'server3-2') 410 const video2 = data.find(v => v.name === 'server3-2')
408 video4 = res.body.data.find(v => v.name === 'server3-4') 411 video4 = data.find(v => v.name === 'server3-4')
409 const video6 = res.body.data.find(v => v.name === 'server3-6') 412 const video6 = data.find(v => v.name === 'server3-6')
410 413
411 expect(video2).to.not.be.undefined 414 expect(video2).to.not.be.undefined
412 expect(video4).to.not.be.undefined 415 expect(video4).to.not.be.undefined
@@ -447,7 +450,7 @@ describe('Test follows', function () {
447 } 450 }
448 ] 451 ]
449 } 452 }
450 await completeVideoCheck(servers[0].url, video4, checkAttributes) 453 await completeVideoCheck(servers[0], video4, checkAttributes)
451 }) 454 })
452 455
453 it('Should have propagated comments', async function () { 456 it('Should have propagated comments', async function () {
@@ -542,8 +545,8 @@ describe('Test follows', function () {
542 545
543 await waitJobs(servers) 546 await waitJobs(servers)
544 547
545 const res = await getVideosList(servers[0].url) 548 const { total } = await servers[0].videosCommand.list()
546 expect(res.body.total).to.equal(1) 549 expect(total).to.equal(1)
547 }) 550 })
548 551
549 }) 552 })
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts
index d45c3ae8a..35b905a8c 100644
--- a/server/tests/api/server/handle-down.ts
+++ b/server/tests/api/server/handle-down.ts
@@ -8,19 +8,14 @@ import {
8 CommentsCommand, 8 CommentsCommand,
9 completeVideoCheck, 9 completeVideoCheck,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideo,
12 getVideosList,
13 killallServers, 11 killallServers,
14 reRunServer, 12 reRunServer,
15 ServerInfo, 13 ServerInfo,
16 setAccessTokensToServers, 14 setAccessTokensToServers,
17 updateVideo,
18 uploadVideo,
19 uploadVideoAndGetId,
20 wait, 15 wait,
21 waitJobs 16 waitJobs
22} from '@shared/extra-utils' 17} from '@shared/extra-utils'
23import { JobState, Video, VideoPrivacy } from '@shared/models' 18import { JobState, VideoCreateResult, VideoPrivacy } from '@shared/models'
24 19
25const expect = chai.expect 20const expect = chai.expect
26 21
@@ -30,9 +25,9 @@ describe('Test handle downs', function () {
30 let threadIdServer2: number 25 let threadIdServer2: number
31 let commentIdServer1: number 26 let commentIdServer1: number
32 let commentIdServer2: number 27 let commentIdServer2: number
33 let missedVideo1: Video 28 let missedVideo1: VideoCreateResult
34 let missedVideo2: Video 29 let missedVideo2: VideoCreateResult
35 let unlistedVideo: Video 30 let unlistedVideo: VideoCreateResult
36 31
37 const videoIdsServer1: string[] = [] 32 const videoIdsServer1: string[] = []
38 33
@@ -110,15 +105,15 @@ describe('Test handle downs', function () {
110 await waitJobs(servers) 105 await waitJobs(servers)
111 106
112 // Upload a video to server 1 107 // Upload a video to server 1
113 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 108 await servers[0].videosCommand.upload({ attributes: videoAttributes })
114 109
115 await waitJobs(servers) 110 await waitJobs(servers)
116 111
117 // And check all servers have this video 112 // And check all servers have this video
118 for (const server of servers) { 113 for (const server of servers) {
119 const res = await getVideosList(server.url) 114 const { data } = await server.videosCommand.list()
120 expect(res.body.data).to.be.an('array') 115 expect(data).to.be.an('array')
121 expect(res.body.data).to.have.lengthOf(1) 116 expect(data).to.have.lengthOf(1)
122 } 117 }
123 118
124 // Kill server 2 119 // Kill server 2
@@ -126,7 +121,7 @@ describe('Test handle downs', function () {
126 121
127 // Remove server 2 follower 122 // Remove server 2 follower
128 for (let i = 0; i < 10; i++) { 123 for (let i = 0; i < 10; i++) {
129 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 124 await servers[0].videosCommand.upload({ attributes: videoAttributes })
130 } 125 }
131 126
132 await waitJobs([ servers[0], servers[2] ]) 127 await waitJobs([ servers[0], servers[2] ])
@@ -134,15 +129,12 @@ describe('Test handle downs', function () {
134 // Kill server 3 129 // Kill server 3
135 await killallServers([ servers[2] ]) 130 await killallServers([ servers[2] ])
136 131
137 const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 132 missedVideo1 = await servers[0].videosCommand.upload({ attributes: videoAttributes })
138 missedVideo1 = resLastVideo1.body.video
139 133
140 const resLastVideo2 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 134 missedVideo2 = await servers[0].videosCommand.upload({ attributes: videoAttributes })
141 missedVideo2 = resLastVideo2.body.video
142 135
143 // Unlisted video 136 // Unlisted video
144 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, unlistedVideoAttributes) 137 unlistedVideo = await servers[0].videosCommand.upload({ attributes: unlistedVideoAttributes })
145 unlistedVideo = resVideo.body.video
146 138
147 // Add comments to video 2 139 // Add comments to video 2
148 { 140 {
@@ -202,25 +194,27 @@ describe('Test handle downs', function () {
202 it('Should send an update to server 3, and automatically fetch the video', async function () { 194 it('Should send an update to server 3, and automatically fetch the video', async function () {
203 this.timeout(15000) 195 this.timeout(15000)
204 196
205 const res1 = await getVideosList(servers[2].url) 197 {
206 expect(res1.body.data).to.be.an('array') 198 const { data } = await servers[2].videosCommand.list()
207 expect(res1.body.data).to.have.lengthOf(11) 199 expect(data).to.be.an('array')
200 expect(data).to.have.lengthOf(11)
201 }
208 202
209 await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, {}) 203 await servers[0].videosCommand.update({ id: missedVideo1.uuid })
210 await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, {}) 204 await servers[0].videosCommand.update({ id: unlistedVideo.uuid })
211 205
212 await waitJobs(servers) 206 await waitJobs(servers)
213 207
214 const res = await getVideosList(servers[2].url) 208 {
215 expect(res.body.data).to.be.an('array') 209 const { data } = await servers[2].videosCommand.list()
216 // 1 video is unlisted 210 expect(data).to.be.an('array')
217 expect(res.body.data).to.have.lengthOf(12) 211 // 1 video is unlisted
212 expect(data).to.have.lengthOf(12)
213 }
218 214
219 // Check unlisted video 215 // Check unlisted video
220 const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid) 216 const video = await servers[2].videosCommand.get({ id: unlistedVideo.uuid })
221 expect(resVideo.body).not.to.be.undefined 217 await completeVideoCheck(servers[2], video, unlistedCheckAttributes)
222
223 await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes)
224 }) 218 })
225 219
226 it('Should send comments on a video to server 3, and automatically fetch the video', async function () { 220 it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
@@ -230,8 +224,7 @@ describe('Test handle downs', function () {
230 224
231 await waitJobs(servers) 225 await waitJobs(servers)
232 226
233 const resVideo = await getVideo(servers[2].url, missedVideo2.uuid) 227 await servers[2].videosCommand.get({ id: missedVideo2.uuid })
234 expect(resVideo.body).not.to.be.undefined
235 228
236 { 229 {
237 const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid }) 230 const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid })
@@ -293,14 +286,14 @@ describe('Test handle downs', function () {
293 this.timeout(120000) 286 this.timeout(120000)
294 287
295 for (let i = 0; i < 10; i++) { 288 for (let i = 0; i < 10; i++) {
296 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video ' + i })).uuid 289 const uuid = (await servers[0].videosCommand.quickUpload({ name: 'video ' + i })).uuid
297 videoIdsServer1.push(uuid) 290 videoIdsServer1.push(uuid)
298 } 291 }
299 292
300 await waitJobs(servers) 293 await waitJobs(servers)
301 294
302 for (const id of videoIdsServer1) { 295 for (const id of videoIdsServer1) {
303 await getVideo(servers[1].url, id) 296 await servers[1].videosCommand.get({ id })
304 } 297 }
305 298
306 await waitJobs(servers) 299 await waitJobs(servers)
@@ -310,7 +303,7 @@ describe('Test handle downs', function () {
310 await wait(11000) 303 await wait(11000)
311 304
312 // Refresh video -> score + 10 = 30 305 // Refresh video -> score + 10 = 30
313 await getVideo(servers[1].url, videoIdsServer1[0]) 306 await servers[1].videosCommand.get({ id: videoIdsServer1[0] })
314 307
315 await waitJobs(servers) 308 await waitJobs(servers)
316 }) 309 })
@@ -325,14 +318,14 @@ describe('Test handle downs', function () {
325 318
326 for (let i = 0; i < 5; i++) { 319 for (let i = 0; i < 5; i++) {
327 try { 320 try {
328 await getVideo(servers[1].url, videoIdsServer1[i]) 321 await servers[1].videosCommand.get({ id: videoIdsServer1[i] })
329 await waitJobs([ servers[1] ]) 322 await waitJobs([ servers[1] ])
330 await wait(1500) 323 await wait(1500)
331 } catch {} 324 } catch {}
332 } 325 }
333 326
334 for (const id of videoIdsServer1) { 327 for (const id of videoIdsServer1) {
335 await getVideo(servers[1].url, id, HttpStatusCode.FORBIDDEN_403) 328 await servers[1].videosCommand.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
336 } 329 }
337 }) 330 })
338 331
diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts
index 6854568d3..aa4c7587b 100644
--- a/server/tests/api/server/jobs.ts
+++ b/server/tests/api/server/jobs.ts
@@ -9,7 +9,6 @@ import {
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 ServerInfo, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 uploadVideo,
13 waitJobs 12 waitJobs
14} from '@shared/extra-utils' 13} from '@shared/extra-utils'
15 14
@@ -32,8 +31,8 @@ describe('Test jobs', function () {
32 it('Should create some jobs', async function () { 31 it('Should create some jobs', async function () {
33 this.timeout(120000) 32 this.timeout(120000)
34 33
35 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) 34 await servers[1].videosCommand.upload({ attributes: { name: 'video1' } })
36 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) 35 await servers[1].videosCommand.upload({ attributes: { name: 'video2' } })
37 36
38 await waitJobs(servers) 37 await waitJobs(servers)
39 }) 38 })
diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts
index 096d63e21..e7bef5a4a 100644
--- a/server/tests/api/server/logs.ts
+++ b/server/tests/api/server/logs.ts
@@ -10,7 +10,6 @@ import {
10 reRunServer, 10 reRunServer,
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 uploadVideo,
14 waitJobs 13 waitJobs
15} from '@shared/extra-utils' 14} from '@shared/extra-utils'
16 15
@@ -34,12 +33,12 @@ describe('Test logs', function () {
34 it('Should get logs with a start date', async function () { 33 it('Should get logs with a start date', async function () {
35 this.timeout(20000) 34 this.timeout(20000)
36 35
37 await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) 36 await server.videosCommand.upload({ attributes: { name: 'video 1' } })
38 await waitJobs([ server ]) 37 await waitJobs([ server ])
39 38
40 const now = new Date() 39 const now = new Date()
41 40
42 await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) 41 await server.videosCommand.upload({ attributes: { name: 'video 2' } })
43 await waitJobs([ server ]) 42 await waitJobs([ server ])
44 43
45 const body = await logsCommand.getLogs({ startDate: now }) 44 const body = await logsCommand.getLogs({ startDate: now })
@@ -52,17 +51,17 @@ describe('Test logs', function () {
52 it('Should get logs with an end date', async function () { 51 it('Should get logs with an end date', async function () {
53 this.timeout(30000) 52 this.timeout(30000)
54 53
55 await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) 54 await server.videosCommand.upload({ attributes: { name: 'video 3' } })
56 await waitJobs([ server ]) 55 await waitJobs([ server ])
57 56
58 const now1 = new Date() 57 const now1 = new Date()
59 58
60 await uploadVideo(server.url, server.accessToken, { name: 'video 4' }) 59 await server.videosCommand.upload({ attributes: { name: 'video 4' } })
61 await waitJobs([ server ]) 60 await waitJobs([ server ])
62 61
63 const now2 = new Date() 62 const now2 = new Date()
64 63
65 await uploadVideo(server.url, server.accessToken, { name: 'video 5' }) 64 await server.videosCommand.upload({ attributes: { name: 'video 5' } })
66 await waitJobs([ server ]) 65 await waitJobs([ server ])
67 66
68 const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 }) 67 const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 })
@@ -78,7 +77,7 @@ describe('Test logs', function () {
78 77
79 const now = new Date() 78 const now = new Date()
80 79
81 await uploadVideo(server.url, server.accessToken, { name: 'video 6' }) 80 await server.videosCommand.upload({ attributes: { name: 'video 6' } })
82 await waitJobs([ server ]) 81 await waitJobs([ server ])
83 82
84 { 83 {
@@ -131,12 +130,12 @@ describe('Test logs', function () {
131 it('Should get logs with a start date', async function () { 130 it('Should get logs with a start date', async function () {
132 this.timeout(20000) 131 this.timeout(20000)
133 132
134 await uploadVideo(server.url, server.accessToken, { name: 'video 7' }) 133 await server.videosCommand.upload({ attributes: { name: 'video 7' } })
135 await waitJobs([ server ]) 134 await waitJobs([ server ])
136 135
137 const now = new Date() 136 const now = new Date()
138 137
139 await uploadVideo(server.url, server.accessToken, { name: 'video 8' }) 138 await server.videosCommand.upload({ attributes: { name: 'video 8' } })
140 await waitJobs([ server ]) 139 await waitJobs([ server ])
141 140
142 const body = await logsCommand.getAuditLogs({ startDate: now }) 141 const body = await logsCommand.getAuditLogs({ startDate: now })
@@ -157,17 +156,17 @@ describe('Test logs', function () {
157 it('Should get logs with an end date', async function () { 156 it('Should get logs with an end date', async function () {
158 this.timeout(30000) 157 this.timeout(30000)
159 158
160 await uploadVideo(server.url, server.accessToken, { name: 'video 9' }) 159 await server.videosCommand.upload({ attributes: { name: 'video 9' } })
161 await waitJobs([ server ]) 160 await waitJobs([ server ])
162 161
163 const now1 = new Date() 162 const now1 = new Date()
164 163
165 await uploadVideo(server.url, server.accessToken, { name: 'video 10' }) 164 await server.videosCommand.upload({ attributes: { name: 'video 10' } })
166 await waitJobs([ server ]) 165 await waitJobs([ server ])
167 166
168 const now2 = new Date() 167 const now2 = new Date()
169 168
170 await uploadVideo(server.url, server.accessToken, { name: 'video 11' }) 169 await server.videosCommand.upload({ attributes: { name: 'video 11' } })
171 await waitJobs([ server ]) 170 await waitJobs([ server ])
172 171
173 const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 }) 172 const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 })
diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts
index b8bae161a..5a6491430 100644
--- a/server/tests/api/server/reverse-proxy.ts
+++ b/server/tests/api/server/reverse-proxy.ts
@@ -2,20 +2,11 @@
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { HttpStatusCode } from '@shared/core-utils' 4import { HttpStatusCode } from '@shared/core-utils'
5import { 5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils'
6 cleanupTests,
7 flushAndRunServer,
8 getVideo,
9 ServerInfo,
10 setAccessTokensToServers,
11 uploadVideo,
12 viewVideo,
13 wait
14} from '@shared/extra-utils'
15 6
16describe('Test application behind a reverse proxy', function () { 7describe('Test application behind a reverse proxy', function () {
17 let server: ServerInfo 8 let server: ServerInfo
18 let videoId: number 9 let videoId: string
19 10
20 before(async function () { 11 before(async function () {
21 this.timeout(30000) 12 this.timeout(30000)
@@ -42,60 +33,60 @@ describe('Test application behind a reverse proxy', function () {
42 server = await flushAndRunServer(1, config) 33 server = await flushAndRunServer(1, config)
43 await setAccessTokensToServers([ server ]) 34 await setAccessTokensToServers([ server ])
44 35
45 const { body } = await uploadVideo(server.url, server.accessToken, {}) 36 const { uuid } = await server.videosCommand.upload()
46 videoId = body.video.uuid 37 videoId = uuid
47 }) 38 })
48 39
49 it('Should view a video only once with the same IP by default', async function () { 40 it('Should view a video only once with the same IP by default', async function () {
50 this.timeout(20000) 41 this.timeout(20000)
51 42
52 await viewVideo(server.url, videoId) 43 await server.videosCommand.view({ id: videoId })
53 await viewVideo(server.url, videoId) 44 await server.videosCommand.view({ id: videoId })
54 45
55 // Wait the repeatable job 46 // Wait the repeatable job
56 await wait(8000) 47 await wait(8000)
57 48
58 const { body } = await getVideo(server.url, videoId) 49 const video = await server.videosCommand.get({ id: videoId })
59 expect(body.views).to.equal(1) 50 expect(video.views).to.equal(1)
60 }) 51 })
61 52
62 it('Should view a video 2 times with the X-Forwarded-For header set', async function () { 53 it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
63 this.timeout(20000) 54 this.timeout(20000)
64 55
65 await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.1,127.0.0.1') 56 await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.1,127.0.0.1' })
66 await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.2,127.0.0.1') 57 await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.2,127.0.0.1' })
67 58
68 // Wait the repeatable job 59 // Wait the repeatable job
69 await wait(8000) 60 await wait(8000)
70 61
71 const { body } = await getVideo(server.url, videoId) 62 const video = await server.videosCommand.get({ id: videoId })
72 expect(body.views).to.equal(3) 63 expect(video.views).to.equal(3)
73 }) 64 })
74 65
75 it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () { 66 it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
76 this.timeout(20000) 67 this.timeout(20000)
77 68
78 await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1') 69 await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.4,0.0.0.3,::ffff:127.0.0.1' })
79 await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.5,0.0.0.3,127.0.0.1') 70 await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.5,0.0.0.3,127.0.0.1' })
80 71
81 // Wait the repeatable job 72 // Wait the repeatable job
82 await wait(8000) 73 await wait(8000)
83 74
84 const { body } = await getVideo(server.url, videoId) 75 const video = await server.videosCommand.get({ id: videoId })
85 expect(body.views).to.equal(4) 76 expect(video.views).to.equal(4)
86 }) 77 })
87 78
88 it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () { 79 it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
89 this.timeout(20000) 80 this.timeout(20000)
90 81
91 await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.6,127.0.0.1') 82 await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.6,127.0.0.1' })
92 await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.7,127.0.0.1') 83 await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.7,127.0.0.1' })
93 84
94 // Wait the repeatable job 85 // Wait the repeatable job
95 await wait(8000) 86 await wait(8000)
96 87
97 const { body } = await getVideo(server.url, videoId) 88 const video = await server.videosCommand.get({ id: videoId })
98 expect(body.views).to.equal(6) 89 expect(video.views).to.equal(6)
99 }) 90 })
100 91
101 it('Should rate limit logins', async function () { 92 it('Should rate limit logins', async function () {
@@ -140,13 +131,13 @@ describe('Test application behind a reverse proxy', function () {
140 131
141 for (let i = 0; i < 100; i++) { 132 for (let i = 0; i < 100; i++) {
142 try { 133 try {
143 await getVideo(server.url, videoId) 134 await server.videosCommand.get({ id: videoId })
144 } catch { 135 } catch {
145 // don't care if it fails 136 // don't care if it fails
146 } 137 }
147 } 138 }
148 139
149 await getVideo(server.url, videoId, HttpStatusCode.TOO_MANY_REQUESTS_429) 140 await server.videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
150 }) 141 })
151 142
152 after(async function () { 143 after(async function () {
diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts
index 77b95de10..a62fb3939 100644
--- a/server/tests/api/server/services.ts
+++ b/server/tests/api/server/services.ts
@@ -2,15 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils'
5import { Video, VideoPlaylistPrivacy } from '@shared/models' 6import { Video, VideoPlaylistPrivacy } from '@shared/models'
6import {
7 getVideosList,
8 ServerInfo,
9 setAccessTokensToServers,
10 setDefaultVideoChannel,
11 uploadVideo
12} from '../../../../shared/extra-utils'
13import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
14 7
15const expect = chai.expect 8const expect = chai.expect
16 9
@@ -29,13 +22,11 @@ describe('Test services', function () {
29 await setDefaultVideoChannel([ server ]) 22 await setDefaultVideoChannel([ server ])
30 23
31 { 24 {
32 const videoAttributes = { 25 const attributes = { name: 'my super name' }
33 name: 'my super name' 26 await server.videosCommand.upload({ attributes })
34 }
35 await uploadVideo(server.url, server.accessToken, videoAttributes)
36 27
37 const res = await getVideosList(server.url) 28 const { data } = await server.videosCommand.list()
38 video = res.body.data[0] 29 video = data[0]
39 } 30 }
40 31
41 { 32 {
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index a35709c26..3eb1efb94 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -8,8 +8,6 @@ import {
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 ServerInfo, 9 ServerInfo,
10 setAccessTokensToServers, 10 setAccessTokensToServers,
11 uploadVideo,
12 viewVideo,
13 wait, 11 wait,
14 waitJobs 12 waitJobs
15} from '@shared/extra-utils' 13} from '@shared/extra-utils'
@@ -36,12 +34,11 @@ describe('Test stats (excluding redundancy)', function () {
36 34
37 await servers[0].usersCommand.create({ username: user.username, password: user.password }) 35 await servers[0].usersCommand.create({ username: user.username, password: user.password })
38 36
39 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) 37 const { uuid } = await servers[0].videosCommand.upload({ attributes: { fixture: 'video_short.webm' } })
40 const videoUUID = resVideo.body.video.uuid
41 38
42 await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'comment' }) 39 await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
43 40
44 await viewVideo(servers[0].url, videoUUID) 41 await servers[0].videosCommand.view({ id: uuid })
45 42
46 // Wait the video views repeatable job 43 // Wait the video views repeatable job
47 await wait(8000) 44 await wait(8000)
@@ -154,7 +151,7 @@ describe('Test stats (excluding redundancy)', function () {
154 } 151 }
155 152
156 { 153 {
157 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId }) 154 await server.videosCommand.upload({ attributes: { fixture: 'video_short.webm', channelId } })
158 155
159 const data = await server.statsCommand.get() 156 const data = await server.statsCommand.get()
160 157
@@ -213,7 +210,7 @@ describe('Test stats (excluding redundancy)', function () {
213 } 210 }
214 }) 211 })
215 212
216 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' }) 213 await servers[0].videosCommand.upload({ attributes: { name: 'video', fixture: 'video_short.webm' } })
217 214
218 await waitJobs(servers) 215 await waitJobs(servers)
219 216
@@ -243,7 +240,7 @@ describe('Test stats (excluding redundancy)', function () {
243 const first = await servers[1].statsCommand.get() 240 const first = await servers[1].statsCommand.get()
244 241
245 for (let i = 0; i < 10; i++) { 242 for (let i = 0; i < 10; i++) {
246 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 243 await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
247 } 244 }
248 245
249 await waitJobs(servers) 246 await waitJobs(servers)
diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts
index 868dc8977..032012edf 100644
--- a/server/tests/api/server/tracker.ts
+++ b/server/tests/api/server/tracker.ts
@@ -1,19 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */
2 2
3import * as magnetUtil from 'magnet-uri'
4import 'mocha' 3import 'mocha'
5import { 4import * as magnetUtil from 'magnet-uri'
6 cleanupTests,
7 flushAndRunServer,
8 getVideo,
9 killallServers,
10 reRunServer,
11 ServerInfo,
12 uploadVideo
13} from '../../../../shared/extra-utils'
14import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
15import { VideoDetails } from '../../../../shared/models/videos'
16import * as WebTorrent from 'webtorrent' 5import * as WebTorrent from 'webtorrent'
6import { cleanupTests, flushAndRunServer, killallServers, reRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
17 7
18describe('Test tracker', function () { 8describe('Test tracker', function () {
19 let server: ServerInfo 9 let server: ServerInfo
@@ -26,11 +16,8 @@ describe('Test tracker', function () {
26 await setAccessTokensToServers([ server ]) 16 await setAccessTokensToServers([ server ])
27 17
28 { 18 {
29 const res = await uploadVideo(server.url, server.accessToken, {}) 19 const { uuid } = await server.videosCommand.upload()
30 const videoUUID = res.body.video.uuid 20 const video = await server.videosCommand.get({ id: uuid })
31
32 const resGet = await getVideo(server.url, videoUUID)
33 const video: VideoDetails = resGet.body
34 goodMagnet = video.files[0].magnetUri 21 goodMagnet = video.files[0].magnetUri
35 22
36 const parsed = magnetUtil.decode(goodMagnet) 23 const parsed = magnetUtil.decode(goodMagnet)
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index c09a85a32..622cddb7d 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -6,12 +6,9 @@ import {
6 cleanupTests, 6 cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getVideosList,
10 ServerInfo, 9 ServerInfo,
11 setAccessTokensToServers, 10 setAccessTokensToServers,
12 SubscriptionsCommand, 11 SubscriptionsCommand,
13 updateVideo,
14 uploadVideo,
15 waitJobs 12 waitJobs
16} from '@shared/extra-utils' 13} from '@shared/extra-utils'
17 14
@@ -44,10 +41,10 @@ describe('Test users subscriptions', function () {
44 users.push({ accessToken }) 41 users.push({ accessToken })
45 42
46 const videoName1 = 'video 1-' + server.serverNumber 43 const videoName1 = 'video 1-' + server.serverNumber
47 await uploadVideo(server.url, accessToken, { name: videoName1 }) 44 await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } })
48 45
49 const videoName2 = 'video 2-' + server.serverNumber 46 const videoName2 = 'video 2-' + server.serverNumber
50 await uploadVideo(server.url, accessToken, { name: videoName2 }) 47 await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } })
51 } 48 }
52 } 49 }
53 50
@@ -57,9 +54,9 @@ describe('Test users subscriptions', function () {
57 }) 54 })
58 55
59 it('Should display videos of server 2 on server 1', async function () { 56 it('Should display videos of server 2 on server 1', async function () {
60 const res = await getVideosList(servers[0].url) 57 const { total } = await servers[0].videosCommand.list()
61 58
62 expect(res.body.total).to.equal(4) 59 expect(total).to.equal(4)
63 }) 60 })
64 61
65 it('User of server 1 should follow user of server 3 and root of server 1', async function () { 62 it('User of server 1 should follow user of server 3 and root of server 1', async function () {
@@ -70,17 +67,17 @@ describe('Test users subscriptions', function () {
70 67
71 await waitJobs(servers) 68 await waitJobs(servers)
72 69
73 const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) 70 const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } })
74 video3UUID = res.body.video.uuid 71 video3UUID = uuid
75 72
76 await waitJobs(servers) 73 await waitJobs(servers)
77 }) 74 })
78 75
79 it('Should not display videos of server 3 on server 1', async function () { 76 it('Should not display videos of server 3 on server 1', async function () {
80 const res = await getVideosList(servers[0].url) 77 const { total, data } = await servers[0].videosCommand.list()
78 expect(total).to.equal(4)
81 79
82 expect(res.body.total).to.equal(4) 80 for (const video of data) {
83 for (const video of res.body.data) {
84 expect(video.name).to.not.contain('1-3') 81 expect(video.name).to.not.contain('1-3')
85 expect(video.name).to.not.contain('2-3') 82 expect(video.name).to.not.contain('2-3')
86 expect(video.name).to.not.contain('video server 3 added after follow') 83 expect(video.name).to.not.contain('video server 3 added after follow')
@@ -186,7 +183,7 @@ describe('Test users subscriptions', function () {
186 this.timeout(60000) 183 this.timeout(60000)
187 184
188 const videoName = 'video server 1 added after follow' 185 const videoName = 'video server 1 added after follow'
189 await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) 186 await servers[0].videosCommand.upload({ attributes: { name: videoName } })
190 187
191 await waitJobs(servers) 188 await waitJobs(servers)
192 189
@@ -212,10 +209,10 @@ describe('Test users subscriptions', function () {
212 } 209 }
213 210
214 { 211 {
215 const res = await getVideosList(servers[0].url) 212 const { data, total } = await servers[0].videosCommand.list()
213 expect(total).to.equal(5)
216 214
217 expect(res.body.total).to.equal(5) 215 for (const video of data) {
218 for (const video of res.body.data) {
219 expect(video.name).to.not.contain('1-3') 216 expect(video.name).to.not.contain('1-3')
220 expect(video.name).to.not.contain('2-3') 217 expect(video.name).to.not.contain('2-3')
221 expect(video.name).to.not.contain('video server 3 added after follow') 218 expect(video.name).to.not.contain('video server 3 added after follow')
@@ -230,13 +227,12 @@ describe('Test users subscriptions', function () {
230 227
231 await waitJobs(servers) 228 await waitJobs(servers)
232 229
233 const res = await getVideosList(servers[0].url) 230 const { data, total } = await servers[0].videosCommand.list()
234 231 expect(total).to.equal(8)
235 expect(res.body.total).to.equal(8)
236 232
237 const names = [ '1-3', '2-3', 'video server 3 added after follow' ] 233 const names = [ '1-3', '2-3', 'video server 3 added after follow' ]
238 for (const name of names) { 234 for (const name of names) {
239 const video = res.body.data.find(v => v.name.indexOf(name) === -1) 235 const video = data.find(v => v.name.includes(name))
240 expect(video).to.not.be.undefined 236 expect(video).to.not.be.undefined
241 } 237 }
242 }) 238 })
@@ -248,10 +244,10 @@ describe('Test users subscriptions', function () {
248 244
249 await waitJobs(servers) 245 await waitJobs(servers)
250 246
251 const res = await getVideosList(servers[0].url) 247 const { total, data } = await servers[0].videosCommand.list()
248 expect(total).to.equal(5)
252 249
253 expect(res.body.total).to.equal(5) 250 for (const video of data) {
254 for (const video of res.body.data) {
255 expect(video.name).to.not.contain('1-3') 251 expect(video.name).to.not.contain('1-3')
256 expect(video.name).to.not.contain('2-3') 252 expect(video.name).to.not.contain('2-3')
257 expect(video.name).to.not.contain('video server 3 added after follow') 253 expect(video.name).to.not.contain('video server 3 added after follow')
@@ -284,7 +280,7 @@ describe('Test users subscriptions', function () {
284 it('Should update a video of server 3 and see the updated video on server 1', async function () { 280 it('Should update a video of server 3 and see the updated video on server 1', async function () {
285 this.timeout(30000) 281 this.timeout(30000)
286 282
287 await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) 283 await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } })
288 284
289 await waitJobs(servers) 285 await waitJobs(servers)
290 286
@@ -329,10 +325,10 @@ describe('Test users subscriptions', function () {
329 }) 325 })
330 326
331 it('Should correctly display public videos on server 1', async function () { 327 it('Should correctly display public videos on server 1', async function () {
332 const res = await getVideosList(servers[0].url) 328 const { total, data } = await servers[0].videosCommand.list()
329 expect(total).to.equal(5)
333 330
334 expect(res.body.total).to.equal(5) 331 for (const video of data) {
335 for (const video of res.body.data) {
336 expect(video.name).to.not.contain('1-3') 332 expect(video.name).to.not.contain('1-3')
337 expect(video.name).to.not.contain('2-3') 333 expect(video.name).to.not.contain('2-3')
338 expect(video.name).to.not.contain('video server 3 added after follow updated') 334 expect(video.name).to.not.contain('video server 3 added after follow updated')
@@ -360,10 +356,10 @@ describe('Test users subscriptions', function () {
360 } 356 }
361 357
362 { 358 {
363 const res = await getVideosList(servers[0].url) 359 const { total, data } = await servers[0].videosCommand.list()
360 expect(total).to.equal(5)
364 361
365 expect(res.body.total).to.equal(5) 362 for (const video of data) {
366 for (const video of res.body.data) {
367 expect(video.name).to.not.contain('1-3') 363 expect(video.name).to.not.contain('1-3')
368 expect(video.name).to.not.contain('2-3') 364 expect(video.name).to.not.contain('2-3')
369 expect(video.name).to.not.contain('video server 3 added after follow updated') 365 expect(video.name).to.not.contain('video server 3 added after follow updated')
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index 43e67ee60..3ae105008 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -9,11 +9,9 @@ import {
9 cleanupTests, 9 cleanupTests,
10 doubleFollow, 10 doubleFollow,
11 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
12 getAccountVideos,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 testImage, 14 testImage,
16 uploadVideo,
17 waitJobs 15 waitJobs
18} from '@shared/extra-utils' 16} from '@shared/extra-utils'
19import { User } from '@shared/models' 17import { User } from '@shared/models'
@@ -44,7 +42,7 @@ describe('Test users with multiple servers', function () {
44 await doubleFollow(servers[1], servers[2]) 42 await doubleFollow(servers[1], servers[2])
45 43
46 // The root user of server 1 is propagated to servers 2 and 3 44 // The root user of server 1 is propagated to servers 2 and 3
47 await uploadVideo(servers[0].url, servers[0].accessToken, {}) 45 await servers[0].videosCommand.upload()
48 46
49 { 47 {
50 const user = { 48 const user = {
@@ -57,8 +55,8 @@ describe('Test users with multiple servers', function () {
57 } 55 }
58 56
59 { 57 {
60 const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) 58 const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken })
61 videoUUID = resVideo.body.video.uuid 59 videoUUID = uuid
62 } 60 }
63 61
64 await waitJobs(servers) 62 await waitJobs(servers)
@@ -133,31 +131,29 @@ describe('Test users with multiple servers', function () {
133 131
134 it('Should list account videos', async function () { 132 it('Should list account videos', async function () {
135 for (const server of servers) { 133 for (const server of servers) {
136 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5) 134 const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port })
137 135
138 expect(res.body.total).to.equal(1) 136 expect(total).to.equal(1)
139 expect(res.body.data).to.be.an('array') 137 expect(data).to.be.an('array')
140 expect(res.body.data).to.have.lengthOf(1) 138 expect(data).to.have.lengthOf(1)
141 expect(res.body.data[0].uuid).to.equal(videoUUID) 139 expect(data[0].uuid).to.equal(videoUUID)
142 } 140 }
143 }) 141 })
144 142
145 it('Should search through account videos', async function () { 143 it('Should search through account videos', async function () {
146 this.timeout(10_000) 144 this.timeout(10_000)
147 145
148 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) 146 const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
149 147
150 await waitJobs(servers) 148 await waitJobs(servers)
151 149
152 for (const server of servers) { 150 for (const server of servers) {
153 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { 151 const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' })
154 search: 'Kami' 152
155 }) 153 expect(total).to.equal(1)
156 154 expect(data).to.be.an('array')
157 expect(res.body.total).to.equal(1) 155 expect(data).to.have.lengthOf(1)
158 expect(res.body.data).to.be.an('array') 156 expect(data[0].uuid).to.equal(created.uuid)
159 expect(res.body.data).to.have.lengthOf(1)
160 expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid)
161 } 157 }
162 }) 158 })
163 159
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 30d7e850d..6f3873939 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -6,17 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 flushAndRunServer, 8 flushAndRunServer,
9 getMyVideos,
10 getVideosList,
11 killallServers, 9 killallServers,
12 makePutBodyRequest, 10 makePutBodyRequest,
13 rateVideo,
14 removeVideo,
15 reRunServer, 11 reRunServer,
16 ServerInfo, 12 ServerInfo,
17 setAccessTokensToServers, 13 setAccessTokensToServers,
18 testImage, 14 testImage,
19 uploadVideo,
20 waitJobs 15 waitJobs
21} from '@shared/extra-utils' 16} from '@shared/extra-utils'
22import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' 17import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
@@ -25,8 +20,8 @@ const expect = chai.expect
25 20
26describe('Test users', function () { 21describe('Test users', function () {
27 let server: ServerInfo 22 let server: ServerInfo
28 let accessToken: string 23 let token: string
29 let accessTokenUser: string 24 let userToken: string
30 let videoId: number 25 let videoId: number
31 let userId: number 26 let userId: number
32 const user = { 27 const user = {
@@ -101,18 +96,17 @@ describe('Test users', function () {
101 }) 96 })
102 97
103 it('Should not be able to upload a video', async function () { 98 it('Should not be able to upload a video', async function () {
104 accessToken = 'my_super_token' 99 token = 'my_super_token'
105 100
106 const videoAttributes = {} 101 await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
107 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
108 }) 102 })
109 103
110 it('Should not be able to follow', async function () { 104 it('Should not be able to follow', async function () {
111 accessToken = 'my_super_token' 105 token = 'my_super_token'
112 106
113 await server.followsCommand.follow({ 107 await server.followsCommand.follow({
114 targets: [ 'http://example.com' ], 108 targets: [ 'http://example.com' ],
115 token: accessToken, 109 token,
116 expectedStatus: HttpStatusCode.UNAUTHORIZED_401 110 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
117 }) 111 })
118 }) 112 })
@@ -122,7 +116,7 @@ describe('Test users', function () {
122 it('Should be able to login', async function () { 116 it('Should be able to login', async function () {
123 const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) 117 const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 })
124 118
125 accessToken = body.access_token 119 token = body.access_token
126 }) 120 })
127 121
128 it('Should be able to login with an insensitive username', async function () { 122 it('Should be able to login with an insensitive username', async function () {
@@ -140,33 +134,31 @@ describe('Test users', function () {
140 describe('Upload', function () { 134 describe('Upload', function () {
141 135
142 it('Should upload the video with the correct token', async function () { 136 it('Should upload the video with the correct token', async function () {
143 const videoAttributes = {} 137 await server.videosCommand.upload({ token })
144 await uploadVideo(server.url, accessToken, videoAttributes) 138 const { data } = await server.videosCommand.list()
145 const res = await getVideosList(server.url) 139 const video = data[0]
146 const video = res.body.data[0]
147 140
148 expect(video.account.name).to.equal('root') 141 expect(video.account.name).to.equal('root')
149 videoId = video.id 142 videoId = video.id
150 }) 143 })
151 144
152 it('Should upload the video again with the correct token', async function () { 145 it('Should upload the video again with the correct token', async function () {
153 const videoAttributes = {} 146 await server.videosCommand.upload({ token })
154 await uploadVideo(server.url, accessToken, videoAttributes)
155 }) 147 })
156 }) 148 })
157 149
158 describe('Ratings', function () { 150 describe('Ratings', function () {
159 151
160 it('Should retrieve a video rating', async function () { 152 it('Should retrieve a video rating', async function () {
161 await rateVideo(server.url, accessToken, videoId, 'like') 153 await server.videosCommand.rate({ id: videoId, rating: 'like' })
162 const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) 154 const rating = await server.usersCommand.getMyRating({ token, videoId })
163 155
164 expect(rating.videoId).to.equal(videoId) 156 expect(rating.videoId).to.equal(videoId)
165 expect(rating.rating).to.equal('like') 157 expect(rating.rating).to.equal('like')
166 }) 158 })
167 159
168 it('Should retrieve ratings list', async function () { 160 it('Should retrieve ratings list', async function () {
169 await rateVideo(server.url, accessToken, videoId, 'like') 161 await server.videosCommand.rate({ id: videoId, rating: 'like' })
170 162
171 const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) 163 const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
172 164
@@ -190,13 +182,13 @@ describe('Test users', function () {
190 182
191 describe('Remove video', function () { 183 describe('Remove video', function () {
192 it('Should not be able to remove the video with an incorrect token', async function () { 184 it('Should not be able to remove the video with an incorrect token', async function () {
193 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) 185 await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
194 }) 186 })
195 187
196 it('Should not be able to remove the video with the token of another account') 188 it('Should not be able to remove the video with the token of another account')
197 189
198 it('Should be able to remove the video with the correct token', async function () { 190 it('Should be able to remove the video with the correct token', async function () {
199 await removeVideo(server.url, accessToken, videoId) 191 await server.videosCommand.remove({ token, id: videoId })
200 }) 192 })
201 }) 193 })
202 194
@@ -210,7 +202,7 @@ describe('Test users', function () {
210 }) 202 })
211 203
212 it('Should not be able to upload a video', async function () { 204 it('Should not be able to upload a video', async function () {
213 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) 205 await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
214 }) 206 })
215 207
216 it('Should not be able to rate a video', async function () { 208 it('Should not be able to rate a video', async function () {
@@ -281,11 +273,11 @@ describe('Test users', function () {
281 }) 273 })
282 274
283 it('Should be able to login with this user', async function () { 275 it('Should be able to login with this user', async function () {
284 accessTokenUser = await server.loginCommand.getAccessToken(user) 276 userToken = await server.loginCommand.getAccessToken(user)
285 }) 277 })
286 278
287 it('Should be able to get user information', async function () { 279 it('Should be able to get user information', async function () {
288 const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 280 const userMe = await server.usersCommand.getMyInfo({ token: userToken })
289 281
290 const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) 282 const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true })
291 283
@@ -323,15 +315,15 @@ describe('Test users', function () {
323 it('Should be able to upload a video with this user', async function () { 315 it('Should be able to upload a video with this user', async function () {
324 this.timeout(10000) 316 this.timeout(10000)
325 317
326 const videoAttributes = { 318 const attributes = {
327 name: 'super user video', 319 name: 'super user video',
328 fixture: 'video_short.webm' 320 fixture: 'video_short.webm'
329 } 321 }
330 await uploadVideo(server.url, accessTokenUser, videoAttributes) 322 await server.videosCommand.upload({ token: userToken, attributes })
331 }) 323 })
332 324
333 it('Should have video quota updated', async function () { 325 it('Should have video quota updated', async function () {
334 const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) 326 const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken })
335 expect(quota.videoQuotaUsed).to.equal(218910) 327 expect(quota.videoQuotaUsed).to.equal(218910)
336 328
337 const { data } = await server.usersCommand.list() 329 const { data } = await server.usersCommand.list()
@@ -340,13 +332,11 @@ describe('Test users', function () {
340 }) 332 })
341 333
342 it('Should be able to list my videos', async function () { 334 it('Should be able to list my videos', async function () {
343 const res = await getMyVideos(server.url, accessTokenUser, 0, 5) 335 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken })
344 expect(res.body.total).to.equal(1) 336 expect(total).to.equal(1)
345 337 expect(data).to.have.lengthOf(1)
346 const videos = res.body.data
347 expect(videos).to.have.lengthOf(1)
348 338
349 const video: Video = videos[0] 339 const video: Video = data[0]
350 expect(video.name).to.equal('super user video') 340 expect(video.name).to.equal('super user video')
351 expect(video.thumbnailPath).to.not.be.null 341 expect(video.thumbnailPath).to.not.be.null
352 expect(video.previewPath).to.not.be.null 342 expect(video.previewPath).to.not.be.null
@@ -354,19 +344,15 @@ describe('Test users', function () {
354 344
355 it('Should be able to search in my videos', async function () { 345 it('Should be able to search in my videos', async function () {
356 { 346 {
357 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') 347 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' })
358 expect(res.body.total).to.equal(1) 348 expect(total).to.equal(1)
359 349 expect(data).to.have.lengthOf(1)
360 const videos = res.body.data
361 expect(videos).to.have.lengthOf(1)
362 } 350 }
363 351
364 { 352 {
365 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') 353 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' })
366 expect(res.body.total).to.equal(0) 354 expect(total).to.equal(0)
367 355 expect(data).to.have.lengthOf(0)
368 const videos = res.body.data
369 expect(videos).to.have.lengthOf(0)
370 } 356 }
371 }) 357 })
372 358
@@ -382,17 +368,17 @@ describe('Test users', function () {
382 } 368 }
383 369
384 { 370 {
385 const videoAttributes = { 371 const attributes = {
386 name: 'super user video 2', 372 name: 'super user video 2',
387 fixture: 'video_short.webm' 373 fixture: 'video_short.webm'
388 } 374 }
389 await uploadVideo(server.url, accessTokenUser, videoAttributes) 375 await server.videosCommand.upload({ token: userToken, attributes })
390 376
391 await waitJobs([ server ]) 377 await waitJobs([ server ])
392 } 378 }
393 379
394 { 380 {
395 const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) 381 const data = await server.usersCommand.getMyQuotaUsed({ token: userToken })
396 expect(data.videoQuotaUsed).to.be.greaterThan(220000) 382 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
397 } 383 }
398 }) 384 })
@@ -505,7 +491,7 @@ describe('Test users', function () {
505 491
506 it('Should update my password', async function () { 492 it('Should update my password', async function () {
507 await server.usersCommand.updateMe({ 493 await server.usersCommand.updateMe({
508 token: accessTokenUser, 494 token: userToken,
509 currentPassword: 'super password', 495 currentPassword: 'super password',
510 password: 'new password' 496 password: 'new password'
511 }) 497 })
@@ -516,11 +502,11 @@ describe('Test users', function () {
516 502
517 it('Should be able to change the NSFW display attribute', async function () { 503 it('Should be able to change the NSFW display attribute', async function () {
518 await server.usersCommand.updateMe({ 504 await server.usersCommand.updateMe({
519 token: accessTokenUser, 505 token: userToken,
520 nsfwPolicy: 'do_not_list' 506 nsfwPolicy: 'do_not_list'
521 }) 507 })
522 508
523 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 509 const user = await server.usersCommand.getMyInfo({ token: userToken })
524 expect(user.username).to.equal('user_1') 510 expect(user.username).to.equal('user_1')
525 expect(user.email).to.equal('user_1@example.com') 511 expect(user.email).to.equal('user_1@example.com')
526 expect(user.nsfwPolicy).to.equal('do_not_list') 512 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -532,32 +518,32 @@ describe('Test users', function () {
532 518
533 it('Should be able to change the autoPlayVideo attribute', async function () { 519 it('Should be able to change the autoPlayVideo attribute', async function () {
534 await server.usersCommand.updateMe({ 520 await server.usersCommand.updateMe({
535 token: accessTokenUser, 521 token: userToken,
536 autoPlayVideo: false 522 autoPlayVideo: false
537 }) 523 })
538 524
539 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 525 const user = await server.usersCommand.getMyInfo({ token: userToken })
540 expect(user.autoPlayVideo).to.be.false 526 expect(user.autoPlayVideo).to.be.false
541 }) 527 })
542 528
543 it('Should be able to change the autoPlayNextVideo attribute', async function () { 529 it('Should be able to change the autoPlayNextVideo attribute', async function () {
544 await server.usersCommand.updateMe({ 530 await server.usersCommand.updateMe({
545 token: accessTokenUser, 531 token: userToken,
546 autoPlayNextVideo: true 532 autoPlayNextVideo: true
547 }) 533 })
548 534
549 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 535 const user = await server.usersCommand.getMyInfo({ token: userToken })
550 expect(user.autoPlayNextVideo).to.be.true 536 expect(user.autoPlayNextVideo).to.be.true
551 }) 537 })
552 538
553 it('Should be able to change the email attribute', async function () { 539 it('Should be able to change the email attribute', async function () {
554 await server.usersCommand.updateMe({ 540 await server.usersCommand.updateMe({
555 token: accessTokenUser, 541 token: userToken,
556 currentPassword: 'new password', 542 currentPassword: 'new password',
557 email: 'updated@example.com' 543 email: 'updated@example.com'
558 }) 544 })
559 545
560 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 546 const user = await server.usersCommand.getMyInfo({ token: userToken })
561 expect(user.username).to.equal('user_1') 547 expect(user.username).to.equal('user_1')
562 expect(user.email).to.equal('updated@example.com') 548 expect(user.email).to.equal('updated@example.com')
563 expect(user.nsfwPolicy).to.equal('do_not_list') 549 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -570,9 +556,9 @@ describe('Test users', function () {
570 it('Should be able to update my avatar with a gif', async function () { 556 it('Should be able to update my avatar with a gif', async function () {
571 const fixture = 'avatar.gif' 557 const fixture = 'avatar.gif'
572 558
573 await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) 559 await server.usersCommand.updateMyAvatar({ token: userToken, fixture })
574 560
575 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 561 const user = await server.usersCommand.getMyInfo({ token: userToken })
576 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') 562 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
577 }) 563 })
578 564
@@ -580,17 +566,17 @@ describe('Test users', function () {
580 for (const extension of [ '.png', '.gif' ]) { 566 for (const extension of [ '.png', '.gif' ]) {
581 const fixture = 'avatar' + extension 567 const fixture = 'avatar' + extension
582 568
583 await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) 569 await server.usersCommand.updateMyAvatar({ token: userToken, fixture })
584 570
585 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 571 const user = await server.usersCommand.getMyInfo({ token: userToken })
586 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) 572 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
587 } 573 }
588 }) 574 })
589 575
590 it('Should be able to update my display name', async function () { 576 it('Should be able to update my display name', async function () {
591 await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) 577 await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' })
592 578
593 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 579 const user = await server.usersCommand.getMyInfo({ token: userToken })
594 expect(user.username).to.equal('user_1') 580 expect(user.username).to.equal('user_1')
595 expect(user.email).to.equal('updated@example.com') 581 expect(user.email).to.equal('updated@example.com')
596 expect(user.nsfwPolicy).to.equal('do_not_list') 582 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -601,9 +587,9 @@ describe('Test users', function () {
601 }) 587 })
602 588
603 it('Should be able to update my description', async function () { 589 it('Should be able to update my description', async function () {
604 await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) 590 await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' })
605 591
606 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 592 const user = await server.usersCommand.getMyInfo({ token: userToken })
607 expect(user.username).to.equal('user_1') 593 expect(user.username).to.equal('user_1')
608 expect(user.email).to.equal('updated@example.com') 594 expect(user.email).to.equal('updated@example.com')
609 expect(user.nsfwPolicy).to.equal('do_not_list') 595 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -617,21 +603,21 @@ describe('Test users', function () {
617 603
618 it('Should be able to update my theme', async function () { 604 it('Should be able to update my theme', async function () {
619 for (const theme of [ 'background-red', 'default', 'instance-default' ]) { 605 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
620 await server.usersCommand.updateMe({ token: accessTokenUser, theme }) 606 await server.usersCommand.updateMe({ token: userToken, theme })
621 607
622 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 608 const user = await server.usersCommand.getMyInfo({ token: userToken })
623 expect(user.theme).to.equal(theme) 609 expect(user.theme).to.equal(theme)
624 } 610 }
625 }) 611 })
626 612
627 it('Should be able to update my modal preferences', async function () { 613 it('Should be able to update my modal preferences', async function () {
628 await server.usersCommand.updateMe({ 614 await server.usersCommand.updateMe({
629 token: accessTokenUser, 615 token: userToken,
630 noInstanceConfigWarningModal: true, 616 noInstanceConfigWarningModal: true,
631 noWelcomeModal: true 617 noWelcomeModal: true
632 }) 618 })
633 619
634 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 620 const user = await server.usersCommand.getMyInfo({ token: userToken })
635 expect(user.noWelcomeModal).to.be.true 621 expect(user.noWelcomeModal).to.be.true
636 expect(user.noInstanceConfigWarningModal).to.be.true 622 expect(user.noInstanceConfigWarningModal).to.be.true
637 }) 623 })
@@ -641,7 +627,7 @@ describe('Test users', function () {
641 it('Should be able to update another user', async function () { 627 it('Should be able to update another user', async function () {
642 await server.usersCommand.update({ 628 await server.usersCommand.update({
643 userId, 629 userId,
644 token: accessToken, 630 token,
645 email: 'updated2@example.com', 631 email: 'updated2@example.com',
646 emailVerified: true, 632 emailVerified: true,
647 videoQuota: 42, 633 videoQuota: 42,
@@ -650,7 +636,7 @@ describe('Test users', function () {
650 pluginAuth: 'toto' 636 pluginAuth: 'toto'
651 }) 637 })
652 638
653 const user = await server.usersCommand.get({ token: accessToken, userId }) 639 const user = await server.usersCommand.get({ token, userId })
654 640
655 expect(user.username).to.equal('user_1') 641 expect(user.username).to.equal('user_1')
656 expect(user.email).to.equal('updated2@example.com') 642 expect(user.email).to.equal('updated2@example.com')
@@ -664,39 +650,39 @@ describe('Test users', function () {
664 }) 650 })
665 651
666 it('Should reset the auth plugin', async function () { 652 it('Should reset the auth plugin', async function () {
667 await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) 653 await server.usersCommand.update({ userId, token, pluginAuth: null })
668 654
669 const user = await server.usersCommand.get({ token: accessToken, userId }) 655 const user = await server.usersCommand.get({ token, userId })
670 expect(user.pluginAuth).to.be.null 656 expect(user.pluginAuth).to.be.null
671 }) 657 })
672 658
673 it('Should have removed the user token', async function () { 659 it('Should have removed the user token', async function () {
674 await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 660 await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
675 661
676 accessTokenUser = await server.loginCommand.getAccessToken(user) 662 userToken = await server.loginCommand.getAccessToken(user)
677 }) 663 })
678 664
679 it('Should be able to update another user password', async function () { 665 it('Should be able to update another user password', async function () {
680 await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) 666 await server.usersCommand.update({ userId, token, password: 'password updated' })
681 667
682 await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 668 await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
683 669
684 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 670 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
685 671
686 user.password = 'password updated' 672 user.password = 'password updated'
687 accessTokenUser = await server.loginCommand.getAccessToken(user) 673 userToken = await server.loginCommand.getAccessToken(user)
688 }) 674 })
689 }) 675 })
690 676
691 describe('Video blacklists', function () { 677 describe('Video blacklists', function () {
692 it('Should be able to list video blacklist by a moderator', async function () { 678 it('Should be able to list video blacklist by a moderator', async function () {
693 await server.blacklistCommand.list({ token: accessTokenUser }) 679 await server.blacklistCommand.list({ token: userToken })
694 }) 680 })
695 }) 681 })
696 682
697 describe('Remove a user', function () { 683 describe('Remove a user', function () {
698 it('Should be able to remove this user', async function () { 684 it('Should be able to remove this user', async function () {
699 await server.usersCommand.remove({ userId, token: accessToken }) 685 await server.usersCommand.remove({ userId, token })
700 }) 686 })
701 687
702 it('Should not be able to login with this user', async function () { 688 it('Should not be able to login with this user', async function () {
@@ -704,11 +690,10 @@ describe('Test users', function () {
704 }) 690 })
705 691
706 it('Should not have videos of this user', async function () { 692 it('Should not have videos of this user', async function () {
707 const res = await getVideosList(server.url) 693 const { data, total } = await server.videosCommand.list()
708 694 expect(total).to.equal(1)
709 expect(res.body.total).to.equal(1)
710 695
711 const video = res.body.data[0] 696 const video = data[0]
712 expect(video.account.name).to.equal('root') 697 expect(video.account.name).to.equal('root')
713 }) 698 })
714 }) 699 })
@@ -832,12 +817,11 @@ describe('Test users', function () {
832 }) 817 })
833 818
834 it('Should report correct videos count', async function () { 819 it('Should report correct videos count', async function () {
835 const videoAttributes = { 820 const attributes = { name: 'video to test user stats' }
836 name: 'video to test user stats' 821 await server.videosCommand.upload({ token: user17AccessToken, attributes })
837 } 822
838 await uploadVideo(server.url, user17AccessToken, videoAttributes) 823 const { data } = await server.videosCommand.list()
839 const res1 = await getVideosList(server.url) 824 videoId = data.find(video => video.name === attributes.name).id
840 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
841 825
842 const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) 826 const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
843 expect(user.videosCount).to.equal(1) 827 expect(user.videosCount).to.equal(1)
diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts
index 9b516af81..e31905b36 100644
--- a/server/tests/api/videos/audio-only.ts
+++ b/server/tests/api/videos/audio-only.ts
@@ -4,17 +4,7 @@ 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, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
8 cleanupTests,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 getVideo,
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo,
15 waitJobs
16} from '../../../../shared/extra-utils'
17import { VideoDetails } from '../../../../shared/models/videos'
18 8
19const expect = chai.expect 9const expect = chai.expect
20 10
@@ -58,15 +48,13 @@ describe('Test audio only video transcoding', function () {
58 it('Should upload a video and transcode it', async function () { 48 it('Should upload a video and transcode it', async function () {
59 this.timeout(120000) 49 this.timeout(120000)
60 50
61 const resUpload = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'audio only' }) 51 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'audio only' } })
62 videoUUID = resUpload.body.video.uuid 52 videoUUID = uuid
63 53
64 await waitJobs(servers) 54 await waitJobs(servers)
65 55
66 for (const server of servers) { 56 for (const server of servers) {
67 const res = await getVideo(server.url, videoUUID) 57 const video = await server.videosCommand.get({ id: videoUUID })
68 const video: VideoDetails = res.body
69
70 expect(video.streamingPlaylists).to.have.lengthOf(1) 58 expect(video.streamingPlaylists).to.have.lengthOf(1)
71 59
72 for (const files of [ video.files, video.streamingPlaylists[0].files ]) { 60 for (const files of [ video.files, video.streamingPlaylists[0].files ]) {
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 169bb2e23..5c13ac629 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -13,17 +13,9 @@ import {
13 dateIsValid, 13 dateIsValid,
14 doubleFollow, 14 doubleFollow,
15 flushAndRunMultipleServers, 15 flushAndRunMultipleServers,
16 getLocalVideos,
17 getVideo,
18 getVideosList,
19 rateVideo,
20 removeVideo,
21 ServerInfo, 16 ServerInfo,
22 setAccessTokensToServers, 17 setAccessTokensToServers,
23 testImage, 18 testImage,
24 updateVideo,
25 uploadVideo,
26 viewVideo,
27 wait, 19 wait,
28 waitJobs, 20 waitJobs,
29 webtorrentAdd 21 webtorrentAdd
@@ -67,10 +59,9 @@ describe('Test multiple servers', function () {
67 59
68 it('Should not have videos for all servers', async function () { 60 it('Should not have videos for all servers', async function () {
69 for (const server of servers) { 61 for (const server of servers) {
70 const res = await getVideosList(server.url) 62 const { data } = await server.videosCommand.list()
71 const videos = res.body.data 63 expect(data).to.be.an('array')
72 expect(videos).to.be.an('array') 64 expect(data.length).to.equal(0)
73 expect(videos.length).to.equal(0)
74 } 65 }
75 }) 66 })
76 67
@@ -78,7 +69,7 @@ describe('Test multiple servers', function () {
78 it('Should upload the video on server 1 and propagate on each server', async function () { 69 it('Should upload the video on server 1 and propagate on each server', async function () {
79 this.timeout(25000) 70 this.timeout(25000)
80 71
81 const videoAttributes = { 72 const attributes = {
82 name: 'my super name for server 1', 73 name: 'my super name for server 1',
83 category: 5, 74 category: 5,
84 licence: 4, 75 licence: 4,
@@ -91,7 +82,7 @@ describe('Test multiple servers', function () {
91 channelId: videoChannelId, 82 channelId: videoChannelId,
92 fixture: 'video_short1.webm' 83 fixture: 'video_short1.webm'
93 } 84 }
94 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 85 await servers[0].videosCommand.upload({ attributes })
95 86
96 await waitJobs(servers) 87 await waitJobs(servers)
97 88
@@ -134,14 +125,13 @@ describe('Test multiple servers', function () {
134 ] 125 ]
135 } 126 }
136 127
137 const res = await getVideosList(server.url) 128 const { data } = await server.videosCommand.list()
138 const videos = res.body.data 129 expect(data).to.be.an('array')
139 expect(videos).to.be.an('array') 130 expect(data.length).to.equal(1)
140 expect(videos.length).to.equal(1) 131 const video = data[0]
141 const video = videos[0]
142 132
143 await completeVideoCheck(server.url, video, checkAttributes) 133 await completeVideoCheck(server, video, checkAttributes)
144 publishedAt = video.publishedAt 134 publishedAt = video.publishedAt as string
145 } 135 }
146 }) 136 })
147 137
@@ -155,7 +145,7 @@ describe('Test multiple servers', function () {
155 await servers[1].usersCommand.create({ username: user.username, password: user.password }) 145 await servers[1].usersCommand.create({ username: user.username, password: user.password })
156 const userAccessToken = await servers[1].loginCommand.getAccessToken(user) 146 const userAccessToken = await servers[1].loginCommand.getAccessToken(user)
157 147
158 const videoAttributes = { 148 const attributes = {
159 name: 'my super name for server 2', 149 name: 'my super name for server 2',
160 category: 4, 150 category: 4,
161 licence: 3, 151 licence: 3,
@@ -168,7 +158,7 @@ describe('Test multiple servers', function () {
168 thumbnailfile: 'thumbnail.jpg', 158 thumbnailfile: 'thumbnail.jpg',
169 previewfile: 'preview.jpg' 159 previewfile: 'preview.jpg'
170 } 160 }
171 await uploadVideo(servers[1].url, userAccessToken, videoAttributes, HttpStatusCode.OK_200, 'resumable') 161 await servers[1].videosCommand.upload({ token: userAccessToken, attributes, mode: 'resumable' })
172 162
173 // Transcoding 163 // Transcoding
174 await waitJobs(servers) 164 await waitJobs(servers)
@@ -223,65 +213,67 @@ describe('Test multiple servers', function () {
223 previewfile: 'preview' 213 previewfile: 'preview'
224 } 214 }
225 215
226 const res = await getVideosList(server.url) 216 const { data } = await server.videosCommand.list()
227 const videos = res.body.data 217 expect(data).to.be.an('array')
228 expect(videos).to.be.an('array') 218 expect(data.length).to.equal(2)
229 expect(videos.length).to.equal(2) 219 const video = data[1]
230 const video = videos[1]
231 220
232 await completeVideoCheck(server.url, video, checkAttributes) 221 await completeVideoCheck(server, video, checkAttributes)
233 } 222 }
234 }) 223 })
235 224
236 it('Should upload two videos on server 3 and propagate on each server', async function () { 225 it('Should upload two videos on server 3 and propagate on each server', async function () {
237 this.timeout(45000) 226 this.timeout(45000)
238 227
239 const videoAttributes1 = { 228 {
240 name: 'my super name for server 3', 229 const attributes = {
241 category: 6, 230 name: 'my super name for server 3',
242 licence: 5, 231 category: 6,
243 language: 'de', 232 licence: 5,
244 nsfw: true, 233 language: 'de',
245 description: 'my super description for server 3', 234 nsfw: true,
246 support: 'my super support text for server 3', 235 description: 'my super description for server 3',
247 tags: [ 'tag1p3' ], 236 support: 'my super support text for server 3',
248 fixture: 'video_short3.webm' 237 tags: [ 'tag1p3' ],
238 fixture: 'video_short3.webm'
239 }
240 await servers[2].videosCommand.upload({ attributes })
249 } 241 }
250 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) 242
251 243 {
252 const videoAttributes2 = { 244 const attributes = {
253 name: 'my super name for server 3-2', 245 name: 'my super name for server 3-2',
254 category: 7, 246 category: 7,
255 licence: 6, 247 licence: 6,
256 language: 'ko', 248 language: 'ko',
257 nsfw: false, 249 nsfw: false,
258 description: 'my super description for server 3-2', 250 description: 'my super description for server 3-2',
259 support: 'my super support text for server 3-2', 251 support: 'my super support text for server 3-2',
260 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], 252 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
261 fixture: 'video_short.webm' 253 fixture: 'video_short.webm'
254 }
255 await servers[2].videosCommand.upload({ attributes })
262 } 256 }
263 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
264 257
265 await waitJobs(servers) 258 await waitJobs(servers)
266 259
267 // All servers should have this video 260 // All servers should have this video
268 for (const server of servers) { 261 for (const server of servers) {
269 const isLocal = server.url === 'http://localhost:' + servers[2].port 262 const isLocal = server.url === 'http://localhost:' + servers[2].port
270 const res = await getVideosList(server.url) 263 const { data } = await server.videosCommand.list()
271 264
272 const videos = res.body.data 265 expect(data).to.be.an('array')
273 expect(videos).to.be.an('array') 266 expect(data.length).to.equal(4)
274 expect(videos.length).to.equal(4)
275 267
276 // We not sure about the order of the two last uploads 268 // We not sure about the order of the two last uploads
277 let video1 = null 269 let video1 = null
278 let video2 = null 270 let video2 = null
279 if (videos[2].name === 'my super name for server 3') { 271 if (data[2].name === 'my super name for server 3') {
280 video1 = videos[2] 272 video1 = data[2]
281 video2 = videos[3] 273 video2 = data[3]
282 } else { 274 } else {
283 video1 = videos[3] 275 video1 = data[3]
284 video2 = videos[2] 276 video2 = data[2]
285 } 277 }
286 278
287 const checkAttributesVideo1 = { 279 const checkAttributesVideo1 = {
@@ -316,7 +308,7 @@ describe('Test multiple servers', function () {
316 } 308 }
317 ] 309 ]
318 } 310 }
319 await completeVideoCheck(server.url, video1, checkAttributesVideo1) 311 await completeVideoCheck(server, video1, checkAttributesVideo1)
320 312
321 const checkAttributesVideo2 = { 313 const checkAttributesVideo2 = {
322 name: 'my super name for server 3-2', 314 name: 'my super name for server 3-2',
@@ -350,38 +342,38 @@ describe('Test multiple servers', function () {
350 } 342 }
351 ] 343 ]
352 } 344 }
353 await completeVideoCheck(server.url, video2, checkAttributesVideo2) 345 await completeVideoCheck(server, video2, checkAttributesVideo2)
354 } 346 }
355 }) 347 })
356 }) 348 })
357 349
358 describe('It should list local videos', function () { 350 describe('It should list local videos', function () {
359 it('Should list only local videos on server 1', async function () { 351 it('Should list only local videos on server 1', async function () {
360 const { body } = await getLocalVideos(servers[0].url) 352 const { data, total } = await servers[0].videosCommand.list({ filter: 'local' })
361 353
362 expect(body.total).to.equal(1) 354 expect(total).to.equal(1)
363 expect(body.data).to.be.an('array') 355 expect(data).to.be.an('array')
364 expect(body.data.length).to.equal(1) 356 expect(data.length).to.equal(1)
365 expect(body.data[0].name).to.equal('my super name for server 1') 357 expect(data[0].name).to.equal('my super name for server 1')
366 }) 358 })
367 359
368 it('Should list only local videos on server 2', async function () { 360 it('Should list only local videos on server 2', async function () {
369 const { body } = await getLocalVideos(servers[1].url) 361 const { data, total } = await servers[1].videosCommand.list({ filter: 'local' })
370 362
371 expect(body.total).to.equal(1) 363 expect(total).to.equal(1)
372 expect(body.data).to.be.an('array') 364 expect(data).to.be.an('array')
373 expect(body.data.length).to.equal(1) 365 expect(data.length).to.equal(1)
374 expect(body.data[0].name).to.equal('my super name for server 2') 366 expect(data[0].name).to.equal('my super name for server 2')
375 }) 367 })
376 368
377 it('Should list only local videos on server 3', async function () { 369 it('Should list only local videos on server 3', async function () {
378 const { body } = await getLocalVideos(servers[2].url) 370 const { data, total } = await servers[2].videosCommand.list({ filter: 'local' })
379 371
380 expect(body.total).to.equal(2) 372 expect(total).to.equal(2)
381 expect(body.data).to.be.an('array') 373 expect(data).to.be.an('array')
382 expect(body.data.length).to.equal(2) 374 expect(data.length).to.equal(2)
383 expect(body.data[0].name).to.equal('my super name for server 3') 375 expect(data[0].name).to.equal('my super name for server 3')
384 expect(body.data[1].name).to.equal('my super name for server 3-2') 376 expect(data[1].name).to.equal('my super name for server 3-2')
385 }) 377 })
386 }) 378 })
387 379
@@ -389,15 +381,13 @@ describe('Test multiple servers', function () {
389 it('Should add the file 1 by asking server 3', async function () { 381 it('Should add the file 1 by asking server 3', async function () {
390 this.timeout(10000) 382 this.timeout(10000)
391 383
392 const res = await getVideosList(servers[2].url) 384 const { data } = await servers[2].videosCommand.list()
393
394 const video = res.body.data[0]
395 toRemove.push(res.body.data[2])
396 toRemove.push(res.body.data[3])
397 385
398 const res2 = await getVideo(servers[2].url, video.id) 386 const video = data[0]
399 const videoDetails = res2.body 387 toRemove.push(data[2])
388 toRemove.push(data[3])
400 389
390 const videoDetails = await servers[2].videosCommand.get({ id: video.id })
401 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 391 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
402 expect(torrent.files).to.be.an('array') 392 expect(torrent.files).to.be.an('array')
403 expect(torrent.files.length).to.equal(1) 393 expect(torrent.files.length).to.equal(1)
@@ -407,11 +397,10 @@ describe('Test multiple servers', function () {
407 it('Should add the file 2 by asking server 1', async function () { 397 it('Should add the file 2 by asking server 1', async function () {
408 this.timeout(10000) 398 this.timeout(10000)
409 399
410 const res = await getVideosList(servers[0].url) 400 const { data } = await servers[0].videosCommand.list()
411 401
412 const video = res.body.data[1] 402 const video = data[1]
413 const res2 = await getVideo(servers[0].url, video.id) 403 const videoDetails = await servers[0].videosCommand.get({ id: video.id })
414 const videoDetails = res2.body
415 404
416 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 405 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
417 expect(torrent.files).to.be.an('array') 406 expect(torrent.files).to.be.an('array')
@@ -422,11 +411,10 @@ describe('Test multiple servers', function () {
422 it('Should add the file 3 by asking server 2', async function () { 411 it('Should add the file 3 by asking server 2', async function () {
423 this.timeout(10000) 412 this.timeout(10000)
424 413
425 const res = await getVideosList(servers[1].url) 414 const { data } = await servers[1].videosCommand.list()
426 415
427 const video = res.body.data[2] 416 const video = data[2]
428 const res2 = await getVideo(servers[1].url, video.id) 417 const videoDetails = await servers[1].videosCommand.get({ id: video.id })
429 const videoDetails = res2.body
430 418
431 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 419 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
432 expect(torrent.files).to.be.an('array') 420 expect(torrent.files).to.be.an('array')
@@ -437,11 +425,10 @@ describe('Test multiple servers', function () {
437 it('Should add the file 3-2 by asking server 1', async function () { 425 it('Should add the file 3-2 by asking server 1', async function () {
438 this.timeout(10000) 426 this.timeout(10000)
439 427
440 const res = await getVideosList(servers[0].url) 428 const { data } = await servers[0].videosCommand.list()
441 429
442 const video = res.body.data[3] 430 const video = data[3]
443 const res2 = await getVideo(servers[0].url, video.id) 431 const videoDetails = await servers[0].videosCommand.get({ id: video.id })
444 const videoDetails = res2.body
445 432
446 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) 433 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
447 expect(torrent.files).to.be.an('array') 434 expect(torrent.files).to.be.an('array')
@@ -452,11 +439,10 @@ describe('Test multiple servers', function () {
452 it('Should add the file 2 in 360p by asking server 1', async function () { 439 it('Should add the file 2 in 360p by asking server 1', async function () {
453 this.timeout(10000) 440 this.timeout(10000)
454 441
455 const res = await getVideosList(servers[0].url) 442 const { data } = await servers[0].videosCommand.list()
456 443
457 const video = res.body.data.find(v => v.name === 'my super name for server 2') 444 const video = data.find(v => v.name === 'my super name for server 2')
458 const res2 = await getVideo(servers[0].url, video.id) 445 const videoDetails = await servers[0].videosCommand.get({ id: video.id })
459 const videoDetails = res2.body
460 446
461 const file = videoDetails.files.find(f => f.resolution.id === 360) 447 const file = videoDetails.files.find(f => f.resolution.id === 360)
462 expect(file).not.to.be.undefined 448 expect(file).not.to.be.undefined
@@ -475,30 +461,36 @@ describe('Test multiple servers', function () {
475 let remoteVideosServer3 = [] 461 let remoteVideosServer3 = []
476 462
477 before(async function () { 463 before(async function () {
478 const res1 = await getVideosList(servers[0].url) 464 {
479 remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 465 const { data } = await servers[0].videosCommand.list()
466 remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid)
467 }
480 468
481 const res2 = await getVideosList(servers[1].url) 469 {
482 remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 470 const { data } = await servers[1].videosCommand.list()
471 remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid)
472 }
483 473
484 const res3 = await getVideosList(servers[2].url) 474 {
485 localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) 475 const { data } = await servers[2].videosCommand.list()
486 remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 476 localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid)
477 remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid)
478 }
487 }) 479 })
488 480
489 it('Should view multiple videos on owned servers', async function () { 481 it('Should view multiple videos on owned servers', async function () {
490 this.timeout(30000) 482 this.timeout(30000)
491 483
492 await viewVideo(servers[2].url, localVideosServer3[0]) 484 await servers[2].videosCommand.view({ id: localVideosServer3[0] })
493 await wait(1000) 485 await wait(1000)
494 486
495 await viewVideo(servers[2].url, localVideosServer3[0]) 487 await servers[2].videosCommand.view({ id: localVideosServer3[0] })
496 await viewVideo(servers[2].url, localVideosServer3[1]) 488 await servers[2].videosCommand.view({ id: localVideosServer3[1] })
497 489
498 await wait(1000) 490 await wait(1000)
499 491
500 await viewVideo(servers[2].url, localVideosServer3[0]) 492 await servers[2].videosCommand.view({ id: localVideosServer3[0] })
501 await viewVideo(servers[2].url, localVideosServer3[0]) 493 await servers[2].videosCommand.view({ id: localVideosServer3[0] })
502 494
503 await waitJobs(servers) 495 await waitJobs(servers)
504 496
@@ -508,11 +500,10 @@ describe('Test multiple servers', function () {
508 await waitJobs(servers) 500 await waitJobs(servers)
509 501
510 for (const server of servers) { 502 for (const server of servers) {
511 const res = await getVideosList(server.url) 503 const { data } = await server.videosCommand.list()
512 504
513 const videos = res.body.data 505 const video0 = data.find(v => v.uuid === localVideosServer3[0])
514 const video0 = videos.find(v => v.uuid === localVideosServer3[0]) 506 const video1 = data.find(v => v.uuid === localVideosServer3[1])
515 const video1 = videos.find(v => v.uuid === localVideosServer3[1])
516 507
517 expect(video0.views).to.equal(3) 508 expect(video0.views).to.equal(3)
518 expect(video1.views).to.equal(1) 509 expect(video1.views).to.equal(1)
@@ -523,16 +514,16 @@ describe('Test multiple servers', function () {
523 this.timeout(45000) 514 this.timeout(45000)
524 515
525 const tasks: Promise<any>[] = [] 516 const tasks: Promise<any>[] = []
526 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) 517 tasks.push(servers[0].videosCommand.view({ id: remoteVideosServer1[0] }))
527 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) 518 tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] }))
528 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) 519 tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] }))
529 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) 520 tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[0] }))
530 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 521 tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
531 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 522 tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
532 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 523 tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] }))
533 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 524 tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
534 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 525 tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
535 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 526 tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] }))
536 527
537 await Promise.all(tasks) 528 await Promise.all(tasks)
538 529
@@ -546,18 +537,16 @@ describe('Test multiple servers', function () {
546 let baseVideos = null 537 let baseVideos = null
547 538
548 for (const server of servers) { 539 for (const server of servers) {
549 const res = await getVideosList(server.url) 540 const { data } = await server.videosCommand.list()
550
551 const videos = res.body.data
552 541
553 // Initialize base videos for future comparisons 542 // Initialize base videos for future comparisons
554 if (baseVideos === null) { 543 if (baseVideos === null) {
555 baseVideos = videos 544 baseVideos = data
556 continue 545 continue
557 } 546 }
558 547
559 for (const baseVideo of baseVideos) { 548 for (const baseVideo of baseVideos) {
560 const sameVideo = videos.find(video => video.name === baseVideo.name) 549 const sameVideo = data.find(video => video.name === baseVideo.name)
561 expect(baseVideo.views).to.equal(sameVideo.views) 550 expect(baseVideo.views).to.equal(sameVideo.views)
562 } 551 }
563 } 552 }
@@ -566,17 +555,17 @@ describe('Test multiple servers', function () {
566 it('Should like and dislikes videos on different services', async function () { 555 it('Should like and dislikes videos on different services', async function () {
567 this.timeout(50000) 556 this.timeout(50000)
568 557
569 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') 558 await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' })
570 await wait(500) 559 await wait(500)
571 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike') 560 await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'dislike' })
572 await wait(500) 561 await wait(500)
573 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') 562 await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' })
574 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like') 563 await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'like' })
575 await wait(500) 564 await wait(500)
576 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike') 565 await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'dislike' })
577 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike') 566 await servers[2].videosCommand.rate({ id: remoteVideosServer3[1], rating: 'dislike' })
578 await wait(500) 567 await wait(500)
579 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') 568 await servers[2].videosCommand.rate({ id: remoteVideosServer3[0], rating: 'like' })
580 569
581 await waitJobs(servers) 570 await waitJobs(servers)
582 await wait(5000) 571 await wait(5000)
@@ -584,18 +573,16 @@ describe('Test multiple servers', function () {
584 573
585 let baseVideos = null 574 let baseVideos = null
586 for (const server of servers) { 575 for (const server of servers) {
587 const res = await getVideosList(server.url) 576 const { data } = await server.videosCommand.list()
588
589 const videos = res.body.data
590 577
591 // Initialize base videos for future comparisons 578 // Initialize base videos for future comparisons
592 if (baseVideos === null) { 579 if (baseVideos === null) {
593 baseVideos = videos 580 baseVideos = data
594 continue 581 continue
595 } 582 }
596 583
597 for (const baseVideo of baseVideos) { 584 for (const baseVideo of baseVideos) {
598 const sameVideo = videos.find(video => video.name === baseVideo.name) 585 const sameVideo = data.find(video => video.name === baseVideo.name)
599 expect(baseVideo.likes).to.equal(sameVideo.likes) 586 expect(baseVideo.likes).to.equal(sameVideo.likes)
600 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) 587 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
601 } 588 }
@@ -621,7 +608,7 @@ describe('Test multiple servers', function () {
621 previewfile: 'preview.jpg' 608 previewfile: 'preview.jpg'
622 } 609 }
623 610
624 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) 611 await servers[2].videosCommand.update({ id: toRemove[0].id, attributes })
625 612
626 await waitJobs(servers) 613 await waitJobs(servers)
627 }) 614 })
@@ -630,10 +617,9 @@ describe('Test multiple servers', function () {
630 this.timeout(10000) 617 this.timeout(10000)
631 618
632 for (const server of servers) { 619 for (const server of servers) {
633 const res = await getVideosList(server.url) 620 const { data } = await server.videosCommand.list()
634 621
635 const videos = res.body.data 622 const videoUpdated = data.find(video => video.name === 'my super video updated')
636 const videoUpdated = videos.find(video => video.name === 'my super video updated')
637 expect(!!videoUpdated).to.be.true 623 expect(!!videoUpdated).to.be.true
638 624
639 const isLocal = server.url === 'http://localhost:' + servers[2].port 625 const isLocal = server.url === 'http://localhost:' + servers[2].port
@@ -672,15 +658,15 @@ describe('Test multiple servers', function () {
672 thumbnailfile: 'thumbnail', 658 thumbnailfile: 'thumbnail',
673 previewfile: 'preview' 659 previewfile: 'preview'
674 } 660 }
675 await completeVideoCheck(server.url, videoUpdated, checkAttributes) 661 await completeVideoCheck(server, videoUpdated, checkAttributes)
676 } 662 }
677 }) 663 })
678 664
679 it('Should remove the videos 3 and 3-2 by asking server 3', async function () { 665 it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
680 this.timeout(10000) 666 this.timeout(10000)
681 667
682 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) 668 await servers[2].videosCommand.remove({ id: toRemove[0].id })
683 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) 669 await servers[2].videosCommand.remove({ id: toRemove[1].id })
684 670
685 await waitJobs(servers) 671 await waitJobs(servers)
686 }) 672 })
@@ -694,27 +680,24 @@ describe('Test multiple servers', function () {
694 680
695 it('Should have videos 1 and 3 on each server', async function () { 681 it('Should have videos 1 and 3 on each server', async function () {
696 for (const server of servers) { 682 for (const server of servers) {
697 const res = await getVideosList(server.url) 683 const { data } = await server.videosCommand.list()
698 684
699 const videos = res.body.data 685 expect(data).to.be.an('array')
700 expect(videos).to.be.an('array') 686 expect(data.length).to.equal(2)
701 expect(videos.length).to.equal(2) 687 expect(data[0].name).not.to.equal(data[1].name)
702 expect(videos[0].name).not.to.equal(videos[1].name) 688 expect(data[0].name).not.to.equal(toRemove[0].name)
703 expect(videos[0].name).not.to.equal(toRemove[0].name) 689 expect(data[1].name).not.to.equal(toRemove[0].name)
704 expect(videos[1].name).not.to.equal(toRemove[0].name) 690 expect(data[0].name).not.to.equal(toRemove[1].name)
705 expect(videos[0].name).not.to.equal(toRemove[1].name) 691 expect(data[1].name).not.to.equal(toRemove[1].name)
706 expect(videos[1].name).not.to.equal(toRemove[1].name) 692
707 693 videoUUID = data.find(video => video.name === 'my super name for server 1').uuid
708 videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
709 } 694 }
710 }) 695 })
711 696
712 it('Should get the same video by UUID on each server', async function () { 697 it('Should get the same video by UUID on each server', async function () {
713 let baseVideo = null 698 let baseVideo = null
714 for (const server of servers) { 699 for (const server of servers) {
715 const res = await getVideo(server.url, videoUUID) 700 const video = await server.videosCommand.get({ id: videoUUID })
716
717 const video = res.body
718 701
719 if (baseVideo === null) { 702 if (baseVideo === null) {
720 baseVideo = video 703 baseVideo = video
@@ -737,8 +720,7 @@ describe('Test multiple servers', function () {
737 720
738 it('Should get the preview from each server', async function () { 721 it('Should get the preview from each server', async function () {
739 for (const server of servers) { 722 for (const server of servers) {
740 const res = await getVideo(server.url, videoUUID) 723 const video = await server.videosCommand.get({ id: videoUUID })
741 const video = res.body
742 724
743 await testImage(server.url, 'video_short1-preview.webm', video.previewPath) 725 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
744 } 726 }
@@ -975,14 +957,14 @@ describe('Test multiple servers', function () {
975 downloadEnabled: false 957 downloadEnabled: false
976 } 958 }
977 959
978 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) 960 await servers[0].videosCommand.update({ id: videoUUID, attributes })
979 961
980 await waitJobs(servers) 962 await waitJobs(servers)
981 963
982 for (const server of servers) { 964 for (const server of servers) {
983 const res = await getVideo(server.url, videoUUID) 965 const video = await server.videosCommand.get({ id: videoUUID })
984 expect(res.body.commentsEnabled).to.be.false 966 expect(video.commentsEnabled).to.be.false
985 expect(res.body.downloadEnabled).to.be.false 967 expect(video.downloadEnabled).to.be.false
986 968
987 const text = 'my super forbidden comment' 969 const text = 'my super forbidden comment'
988 await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) 970 await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
@@ -1010,8 +992,8 @@ describe('Test multiple servers', function () {
1010 await waitJobs(servers) 992 await waitJobs(servers)
1011 993
1012 for (const server of servers) { 994 for (const server of servers) {
1013 const res = await getVideosList(server.url) 995 const { data } = await server.videosCommand.list()
1014 const video = res.body.data.find(v => v.name === 'minimum parameters') 996 const video = data.find(v => v.name === 'minimum parameters')
1015 997
1016 const isLocal = server.url === 'http://localhost:' + servers[1].port 998 const isLocal = server.url === 'http://localhost:' + servers[1].port
1017 const checkAttributes = { 999 const checkAttributes = {
@@ -1058,7 +1040,7 @@ describe('Test multiple servers', function () {
1058 } 1040 }
1059 ] 1041 ]
1060 } 1042 }
1061 await completeVideoCheck(server.url, video, checkAttributes) 1043 await completeVideoCheck(server, video, checkAttributes)
1062 } 1044 }
1063 }) 1045 })
1064 }) 1046 })
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index 642c115d0..b7756a4a8 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -9,8 +9,6 @@ import {
9 buildAbsoluteFixturePath, 9 buildAbsoluteFixturePath,
10 cleanupTests, 10 cleanupTests,
11 flushAndRunServer, 11 flushAndRunServer,
12 prepareResumableUpload,
13 sendResumableChunks,
14 ServerInfo, 12 ServerInfo,
15 setAccessTokensToServers, 13 setAccessTokensToServers,
16 setDefaultVideoChannel 14 setDefaultVideoChannel
@@ -45,7 +43,7 @@ describe('Test resumable upload', function () {
45 43
46 const mimetype = 'video/mp4' 44 const mimetype = 'video/mp4'
47 45
48 const res = await prepareResumableUpload({ url: server.url, token: server.accessToken, attributes, size, mimetype }) 46 const res = await server.videosCommand.prepareResumableUpload({ attributes, size, mimetype })
49 47
50 return res.header['location'].split('?')[1] 48 return res.header['location'].split('?')[1]
51 } 49 }
@@ -63,15 +61,13 @@ describe('Test resumable upload', function () {
63 const size = await buildSize(defaultFixture, options.size) 61 const size = await buildSize(defaultFixture, options.size)
64 const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture) 62 const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture)
65 63
66 return sendResumableChunks({ 64 return server.videosCommand.sendResumableChunks({
67 url: server.url,
68 token: server.accessToken,
69 pathUploadId, 65 pathUploadId,
70 videoFilePath: absoluteFilePath, 66 videoFilePath: absoluteFilePath,
71 size, 67 size,
72 contentLength, 68 contentLength,
73 contentRangeBuilder, 69 contentRangeBuilder,
74 specialStatus: expectedStatus 70 expectedStatus
75 }) 71 })
76 } 72 }
77 73
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index af1703e02..da0b2011e 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -2,34 +2,17 @@
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 flushAndRunServer,
12 getVideo,
13 getVideoCategories,
14 getVideoLanguages,
15 getVideoLicences,
16 getVideoPrivacies,
17 getVideosList,
18 getVideosListPagination,
19 getVideosListSort,
20 getVideosWithFilters,
21 rateVideo,
22 removeVideo,
23 ServerInfo, 10 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
@@ -37,8 +20,8 @@ describe('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: ServerInfo = 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
@@ -117,128 +100,116 @@ describe('Test a single server', function () {
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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.view({ id: videoId })
208 await viewVideo(server.url, videoId) 181 await server.videosCommand.view({ id: videoId })
209 await viewVideo(server.url, videoId) 182 await server.videosCommand.view({ id: videoId })
210 183
211 await wait(1500) 184 await wait(1500)
212 185
213 await viewVideo(server.url, videoId) 186 await server.videosCommand.view({ id: videoId })
214 await viewVideo(server.url, videoId) 187 await server.videosCommand.view({ id: videoId })
215 188
216 await wait(1500) 189 await wait(1500)
217 190
218 await viewVideo(server.url, videoId) 191 await server.videosCommand.view({ id: videoId })
219 await viewVideo(server.url, videoId) 192 await server.videosCommand.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.videosCommand.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.videosCommand.remove({ id: videoId })
232 203
233 await checkVideoFilesWereRemoved(videoUUID, server) 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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.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.videosCommand.update({ id: videoId, attributes })
416 382
417 const res = await getVideo(server.url, videoId) 383 const video = await server.videosCommand.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.videosCommand.update({ id: videoId, attributes })
428 393
429 const res = await getVideo(server.url, videoId) 394 const video = await server.videosCommand.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.videosCommand.rate({ id: videoId, rating: 'like' })
438 402
439 const res = await getVideo(server.url, videoId) 403 const video = await server.videosCommand.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.videosCommand.rate({ id: videoId, rating: 'dislike' })
448 411
449 const res = await getVideo(server.url, videoId) 412 const video = await server.videosCommand.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.videosCommand.update({ id: videoId, attributes })
461 423
462 const res = await getVideosListSort(server.url, '-originallyPublishedAt') 424 const { data } = await server.videosCommand.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.videosCommand.update({ id: videoId2, attributes })
477 439
478 const res = await getVideosListSort(server.url, '-originallyPublishedAt') 440 const { data } = await server.videosCommand.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 d4a5385ab..4c67e96f7 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -7,11 +7,9 @@ import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 removeVideo,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 testCaptionFile, 12 testCaptionFile,
14 uploadVideo,
15 wait, 13 wait,
16 waitJobs 14 waitJobs
17} from '@shared/extra-utils' 15} from '@shared/extra-utils'
@@ -34,8 +32,8 @@ describe('Test video captions', function () {
34 32
35 await waitJobs(servers) 33 await waitJobs(servers)
36 34
37 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' }) 35 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'my video name' } })
38 videoUUID = res.body.video.uuid 36 videoUUID = uuid
39 37
40 await waitJobs(servers) 38 await waitJobs(servers)
41 }) 39 })
@@ -180,7 +178,7 @@ describe('Test video captions', function () {
180 }) 178 })
181 179
182 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 () {
183 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) 181 await servers[0].videosCommand.remove({ id: videoUUID })
184 182
185 await checkVideoFilesWereRemoved(videoUUID, servers[0]) 183 await checkVideoFilesWereRemoved(videoUUID, servers[0])
186 }) 184 })
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index b0bbd5a0d..b85edd920 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -2,22 +2,19 @@
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 { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 ChangeOwnershipCommand, 7 ChangeOwnershipCommand,
8 cleanupTests, 8 cleanupTests,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 flushAndRunServer, 11 flushAndRunServer,
12 getVideo,
13 getVideosList,
14 ServerInfo, 12 ServerInfo,
15 setAccessTokensToServers, 13 setAccessTokensToServers,
16 setDefaultVideoChannel, 14 setDefaultVideoChannel,
17 uploadVideo 15 waitJobs
18} from '../../../../shared/extra-utils' 16} from '@shared/extra-utils'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 17import { VideoPrivacy } from '@shared/models'
20import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
21 18
22const expect = chai.expect 19const expect = chai.expect
23 20
@@ -71,14 +68,13 @@ describe('Test video change ownership - nominal', function () {
71 } 68 }
72 69
73 { 70 {
74 const videoAttributes = { 71 const attributes = {
75 name: 'my super name', 72 name: 'my super name',
76 description: 'my super description' 73 description: 'my super description'
77 } 74 }
78 const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes) 75 const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes })
79 76
80 const resVideo = await getVideo(servers[0].url, res.body.video.id) 77 servers[0].video = await servers[0].videosCommand.get({ id })
81 servers[0].video = resVideo.body
82 } 78 }
83 79
84 { 80 {
@@ -212,9 +208,7 @@ describe('Test video change ownership - nominal', function () {
212 208
213 it('Should have the channel of the video updated', async function () { 209 it('Should have the channel of the video updated', async function () {
214 for (const server of servers) { 210 for (const server of servers) {
215 const res = await getVideo(server.url, servers[0].video.uuid) 211 const video = await server.videosCommand.get({ id: servers[0].video.uuid })
216
217 const video: VideoDetails = res.body
218 212
219 expect(video.name).to.equal('my super name') 213 expect(video.name).to.equal('my super name')
220 expect(video.channel.displayName).to.equal('Main second channel') 214 expect(video.channel.displayName).to.equal('Main second channel')
@@ -243,9 +237,7 @@ describe('Test video change ownership - nominal', function () {
243 await waitJobs(servers) 237 await waitJobs(servers)
244 238
245 for (const server of servers) { 239 for (const server of servers) {
246 const res = await getVideo(server.url, servers[0].video.uuid) 240 const video = await server.videosCommand.get({ id: servers[0].video.uuid })
247
248 const video: VideoDetails = res.body
249 241
250 expect(video.name).to.equal('my super name') 242 expect(video.name).to.equal('my super name')
251 expect(video.channel.displayName).to.equal('Main second channel') 243 expect(video.channel.displayName).to.equal('Main second channel')
@@ -280,20 +272,18 @@ describe('Test video change ownership - quota too small', function () {
280 secondUserToken = await server.loginCommand.getAccessToken(secondUser) 272 secondUserToken = await server.loginCommand.getAccessToken(secondUser)
281 273
282 // Upload some videos on the server 274 // Upload some videos on the server
283 const video1Attributes = { 275 const attributes = {
284 name: 'my super name', 276 name: 'my super name',
285 description: 'my super description' 277 description: 'my super description'
286 } 278 }
287 await uploadVideo(server.url, firstUserToken, video1Attributes) 279 await server.videosCommand.upload({ token: firstUserToken, attributes })
288 280
289 await waitJobs(server) 281 await waitJobs(server)
290 282
291 const res = await getVideosList(server.url) 283 const { data } = await server.videosCommand.list()
292 const videos = res.body.data 284 expect(data.length).to.equal(1)
293
294 expect(videos.length).to.equal(1)
295 285
296 server.video = videos.find(video => video.name === 'my super name') 286 server.video = data.find(video => video.name === 'my super name')
297 }) 287 })
298 288
299 it('Should send a request to change ownership of a video', async function () { 289 it('Should send a request to change ownership of a video', async function () {
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 2e57cbbff..170cc942e 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -8,20 +8,15 @@ import {
8 cleanupTests, 8 cleanupTests,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideo,
12 getVideoChannelVideos,
13 ServerInfo, 11 ServerInfo,
14 setAccessTokensToServers, 12 setAccessTokensToServers,
15 setDefaultVideoChannel, 13 setDefaultVideoChannel,
16 testFileExistsOrNot, 14 testFileExistsOrNot,
17 testImage, 15 testImage,
18 updateVideo,
19 uploadVideo,
20 viewVideo,
21 wait, 16 wait,
22 waitJobs 17 waitJobs
23} from '@shared/extra-utils' 18} from '@shared/extra-utils'
24import { User, Video, VideoChannel, VideoDetails } from '@shared/models' 19import { User, VideoChannel } from '@shared/models'
25 20
26const expect = chai.expect 21const expect = chai.expect
27 22
@@ -77,9 +72,9 @@ describe('Test video channels', function () {
77 72
78 // The channel is 1 is propagated to servers 2 73 // The channel is 1 is propagated to servers 2
79 { 74 {
80 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' }
81 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg) 76 const { uuid } = await servers[0].videosCommand.upload({ attributes })
82 videoUUID = res.body.video.uuid 77 videoUUID = uuid
83 } 78 }
84 79
85 await waitJobs(servers) 80 await waitJobs(servers)
@@ -219,9 +214,7 @@ describe('Test video channels', function () {
219 214
220 it('Should not have updated the video support field', async function () { 215 it('Should not have updated the video support field', async function () {
221 for (const server of servers) { 216 for (const server of servers) {
222 const res = await getVideo(server.url, videoUUID) 217 const video = await server.videosCommand.get({ id: videoUUID })
223 const video: VideoDetails = res.body
224
225 expect(video.support).to.equal('video support field') 218 expect(video.support).to.equal('video support field')
226 } 219 }
227 }) 220 })
@@ -239,9 +232,7 @@ describe('Test video channels', function () {
239 await waitJobs(servers) 232 await waitJobs(servers)
240 233
241 for (const server of servers) { 234 for (const server of servers) {
242 const res = await getVideo(server.url, videoUUID) 235 const video = await server.videosCommand.get({ id: videoUUID })
243 const video: VideoDetails = res.body
244
245 expect(video.support).to.equal(videoChannelAttributes.support) 236 expect(video.support).to.equal(videoChannelAttributes.support)
246 } 237 }
247 }) 238 })
@@ -333,18 +324,19 @@ describe('Test video channels', function () {
333 324
334 for (const server of servers) { 325 for (const server of servers) {
335 const channelURI = 'second_video_channel@localhost:' + servers[0].port 326 const channelURI = 'second_video_channel@localhost:' + servers[0].port
336 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) 327 const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI })
337 expect(res1.body.total).to.equal(1) 328
338 expect(res1.body.data).to.be.an('array') 329 expect(total).to.equal(1)
339 expect(res1.body.data).to.have.lengthOf(1) 330 expect(data).to.be.an('array')
340 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')
341 } 333 }
342 }) 334 })
343 335
344 it('Should change the video channel of a video', async function () { 336 it('Should change the video channel of a video', async function () {
345 this.timeout(10000) 337 this.timeout(10000)
346 338
347 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: servers[0].videoChannel.id }) 339 await servers[0].videosCommand.update({ id: videoUUID, attributes: { channelId: servers[0].videoChannel.id } })
348 340
349 await waitJobs(servers) 341 await waitJobs(servers)
350 }) 342 })
@@ -353,18 +345,21 @@ describe('Test video channels', function () {
353 this.timeout(10000) 345 this.timeout(10000)
354 346
355 for (const server of servers) { 347 for (const server of servers) {
356 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port 348 {
357 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) 349 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
358 expect(res1.body.total).to.equal(0) 350 const { total } = await server.videosCommand.listByChannel({ videoChannelName: secondChannelURI })
359 351 expect(total).to.equal(0)
360 const channelURI = 'root_channel@localhost:' + servers[0].port 352 }
361 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) 353
362 expect(res2.body.total).to.equal(1) 354 {
363 355 const channelURI = 'root_channel@localhost:' + servers[0].port
364 const videos: Video[] = res2.body.data 356 const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI })
365 expect(videos).to.be.an('array') 357 expect(total).to.equal(1)
366 expect(videos).to.have.lengthOf(1) 358
367 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 }
368 } 363 }
369 }) 364 })
370 365
@@ -417,8 +412,8 @@ describe('Test video channels', function () {
417 412
418 { 413 {
419 // video has been posted on channel servers[0].videoChannel.id since last update 414 // video has been posted on channel servers[0].videoChannel.id since last update
420 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') 415 await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' })
421 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') 416 await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' })
422 417
423 // Wait the repeatable job 418 // Wait the repeatable job
424 await wait(8000) 419 await wait(8000)
@@ -460,7 +455,7 @@ describe('Test video channels', function () {
460 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 () {
461 this.timeout(30000) 456 this.timeout(30000)
462 457
463 await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: totoChannel }) 458 await servers[0].videosCommand.upload({ attributes: { channelId: totoChannel } })
464 await waitJobs(servers) 459 await waitJobs(servers)
465 460
466 for (const server of servers) { 461 for (const server of servers) {
@@ -470,7 +465,7 @@ describe('Test video channels', function () {
470 expect(data[1].name).to.equal('root_channel') 465 expect(data[1].name).to.equal('root_channel')
471 } 466 }
472 467
473 await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: servers[0].videoChannel.id }) 468 await servers[0].videosCommand.upload({ attributes: { channelId: servers[0].videoChannel.id } })
474 await waitJobs(servers) 469 await waitJobs(servers)
475 470
476 for (const server of servers) { 471 for (const server of servers) {
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index 266824d58..41be54c81 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -9,8 +9,7 @@ import {
9 flushAndRunServer, 9 flushAndRunServer,
10 ServerInfo, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 testImage, 12 testImage
13 uploadVideo
14} from '@shared/extra-utils' 13} from '@shared/extra-utils'
15 14
16const expect = chai.expect 15const expect = chai.expect
@@ -33,9 +32,9 @@ describe('Test video comments', function () {
33 32
34 await setAccessTokensToServers([ server ]) 33 await setAccessTokensToServers([ server ])
35 34
36 const res = await uploadVideo(server.url, server.accessToken, {}) 35 const { id, uuid } = await server.videosCommand.upload()
37 videoUUID = res.body.video.uuid 36 videoUUID = uuid
38 videoId = res.body.video.id 37 videoId = id
39 38
40 await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) 39 await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
41 40
diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts
index e1c9afe79..6ac9206f5 100644
--- a/server/tests/api/videos/video-description.ts
+++ b/server/tests/api/videos/video-description.ts
@@ -2,19 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6 cleanupTests,
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
@@ -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].videosCommand.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].videosCommand.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.videosCommand.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.videosCommand.get({ id: videoUUID })
72 const video = res.body
73 59
74 const res2 = await getVideoDescription(server.url, video.descriptionPath) 60 const { description } = await server.videosCommand.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].videosCommand.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.videosCommand.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.videosCommand.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 428e1316d..d63b81694 100644
--- a/server/tests/api/videos/video-hls.ts
+++ b/server/tests/api/videos/video-hls.ts
@@ -3,7 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 6import { HttpStatusCode } from '@shared/core-utils'
7import { 7import {
8 checkDirectoryIsEmpty, 8 checkDirectoryIsEmpty,
9 checkResolutionsInMasterPlaylist, 9 checkResolutionsInMasterPlaylist,
@@ -12,26 +12,20 @@ import {
12 cleanupTests, 12 cleanupTests,
13 doubleFollow, 13 doubleFollow,
14 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
15 getVideo,
16 makeRawRequest, 15 makeRawRequest,
17 removeVideo,
18 ServerInfo, 16 ServerInfo,
19 setAccessTokensToServers, 17 setAccessTokensToServers,
20 updateVideo,
21 uploadVideo,
22 waitJobs, 18 waitJobs,
23 webtorrentAdd 19 webtorrentAdd
24} from '../../../../shared/extra-utils' 20} from '@shared/extra-utils'
25import { VideoDetails } from '../../../../shared/models/videos' 21import { VideoStreamingPlaylistType } from '@shared/models'
26import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
27import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' 22import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
28 23
29const expect = chai.expect 24const expect = chai.expect
30 25
31async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { 26async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) {
32 for (const server of servers) { 27 for (const server of servers) {
33 const resVideoDetails = await getVideo(server.url, videoUUID) 28 const videoDetails = await server.videosCommand.get({ id: videoUUID })
34 const videoDetails: VideoDetails = resVideoDetails.body
35 const baseUrl = `http://${videoDetails.account.host}` 29 const baseUrl = `http://${videoDetails.account.host}`
36 30
37 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) 31 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
@@ -113,8 +107,8 @@ describe('Test HLS videos', function () {
113 it('Should upload a video and transcode it to HLS', async function () { 107 it('Should upload a video and transcode it to HLS', async function () {
114 this.timeout(120000) 108 this.timeout(120000)
115 109
116 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) 110 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
117 videoUUID = res.body.video.uuid 111 videoUUID = uuid
118 112
119 await waitJobs(servers) 113 await waitJobs(servers)
120 114
@@ -124,8 +118,8 @@ describe('Test HLS videos', function () {
124 it('Should upload an audio file and transcode it to HLS', async function () { 118 it('Should upload an audio file and transcode it to HLS', async function () {
125 this.timeout(120000) 119 this.timeout(120000)
126 120
127 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) 121 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
128 videoAudioUUID = res.body.video.uuid 122 videoAudioUUID = uuid
129 123
130 await waitJobs(servers) 124 await waitJobs(servers)
131 125
@@ -135,7 +129,7 @@ describe('Test HLS videos', function () {
135 it('Should update the video', async function () { 129 it('Should update the video', async function () {
136 this.timeout(10000) 130 this.timeout(10000)
137 131
138 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' }) 132 await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video 1 updated' } })
139 133
140 await waitJobs(servers) 134 await waitJobs(servers)
141 135
@@ -145,14 +139,14 @@ describe('Test HLS videos', function () {
145 it('Should delete videos', async function () { 139 it('Should delete videos', async function () {
146 this.timeout(10000) 140 this.timeout(10000)
147 141
148 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) 142 await servers[0].videosCommand.remove({ id: videoUUID })
149 await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) 143 await servers[0].videosCommand.remove({ id: videoAudioUUID })
150 144
151 await waitJobs(servers) 145 await waitJobs(servers)
152 146
153 for (const server of servers) { 147 for (const server of servers) {
154 await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) 148 await server.videosCommand.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
155 await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) 149 await server.videosCommand.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
156 } 150 }
157 }) 151 })
158 152
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index 052c052b4..31fdfe12e 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -7,9 +7,6 @@ import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getMyVideos,
11 getVideo,
12 getVideosList,
13 ImportsCommand, 10 ImportsCommand,
14 ServerInfo, 11 ServerInfo,
15 setAccessTokensToServers, 12 setAccessTokensToServers,
@@ -17,7 +14,7 @@ import {
17 testImage, 14 testImage,
18 waitJobs 15 waitJobs
19} from '@shared/extra-utils' 16} from '@shared/extra-utils'
20import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models' 17import { VideoPrivacy, VideoResolution } from '@shared/models'
21 18
22const expect = chai.expect 19const expect = chai.expect
23 20
@@ -29,8 +26,7 @@ describe('Test video imports', function () {
29 if (areHttpImportTestsDisabled()) return 26 if (areHttpImportTestsDisabled()) return
30 27
31 async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { 28 async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) {
32 const resHttp = await getVideo(server.url, idHttp) 29 const videoHttp = await server.videosCommand.get({ id: idHttp })
33 const videoHttp: VideoDetails = resHttp.body
34 30
35 expect(videoHttp.name).to.equal('small video - youtube') 31 expect(videoHttp.name).to.equal('small video - youtube')
36 // FIXME: youtube-dl seems broken 32 // FIXME: youtube-dl seems broken
@@ -47,10 +43,8 @@ describe('Test video imports', function () {
47 expect(originallyPublishedAt.getMonth()).to.equal(0) 43 expect(originallyPublishedAt.getMonth()).to.equal(0)
48 expect(originallyPublishedAt.getFullYear()).to.equal(2019) 44 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
49 45
50 const resMagnet = await getVideo(server.url, idMagnet) 46 const videoMagnet = await server.videosCommand.get({ id: idMagnet })
51 const videoMagnet: VideoDetails = resMagnet.body 47 const videoTorrent = await server.videosCommand.get({ id: idTorrent })
52 const resTorrent = await getVideo(server.url, idTorrent)
53 const videoTorrent: VideoDetails = resTorrent.body
54 48
55 for (const video of [ videoMagnet, videoTorrent ]) { 49 for (const video of [ videoMagnet, videoTorrent ]) {
56 expect(video.category.label).to.equal('Misc') 50 expect(video.category.label).to.equal('Misc')
@@ -70,8 +64,7 @@ describe('Test video imports', function () {
70 } 64 }
71 65
72 async function checkVideoServer2 (server: ServerInfo, id: number | string) { 66 async function checkVideoServer2 (server: ServerInfo, id: number | string) {
73 const res = await getVideo(server.url, id) 67 const video = await server.videosCommand.get({ id })
74 const video: VideoDetails = res.body
75 68
76 expect(video.name).to.equal('my super name') 69 expect(video.name).to.equal('my super name')
77 expect(video.category.label).to.equal('Entertainment') 70 expect(video.category.label).to.equal('Entertainment')
@@ -190,15 +183,14 @@ Ajouter un sous-titre est vraiment facile`)
190 }) 183 })
191 184
192 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 () {
193 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt') 186 const { total, data } = await servers[0].videosCommand.listMyVideos({ sort: 'createdAt' })
194 187
195 expect(res.body.total).to.equal(3) 188 expect(total).to.equal(3)
196 189
197 const videos = res.body.data 190 expect(data).to.have.lengthOf(3)
198 expect(videos).to.have.lengthOf(3) 191 expect(data[0].name).to.equal('small video - youtube')
199 expect(videos[0].name).to.equal('small video - youtube') 192 expect(data[1].name).to.equal('super peertube2 video')
200 expect(videos[1].name).to.equal('super peertube2 video') 193 expect(data[2].name).to.equal('你好 世界 720p.mp4')
201 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
202 }) 194 })
203 195
204 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 () {
@@ -229,11 +221,11 @@ Ajouter un sous-titre est vraiment facile`)
229 await waitJobs(servers) 221 await waitJobs(servers)
230 222
231 for (const server of servers) { 223 for (const server of servers) {
232 const res = await getVideosList(server.url) 224 const { total, data } = await server.videosCommand.list()
233 expect(res.body.total).to.equal(3) 225 expect(total).to.equal(3)
234 expect(res.body.data).to.have.lengthOf(3) 226 expect(data).to.have.lengthOf(3)
235 227
236 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data 228 const [ videoHttp, videoMagnet, videoTorrent ] = data
237 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) 229 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
238 } 230 }
239 }) 231 })
@@ -262,13 +254,13 @@ Ajouter un sous-titre est vraiment facile`)
262 await waitJobs(servers) 254 await waitJobs(servers)
263 255
264 for (const server of servers) { 256 for (const server of servers) {
265 const res = await getVideosList(server.url) 257 const { total, data } = await server.videosCommand.list()
266 expect(res.body.total).to.equal(4) 258 expect(total).to.equal(4)
267 expect(res.body.data).to.have.lengthOf(4) 259 expect(data).to.have.lengthOf(4)
268 260
269 await checkVideoServer2(server, res.body.data[0].uuid) 261 await checkVideoServer2(server, data[0].uuid)
270 262
271 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data 263 const [ , videoHttp, videoMagnet, videoTorrent ] = data
272 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) 264 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
273 } 265 }
274 }) 266 })
@@ -288,8 +280,7 @@ Ajouter un sous-titre est vraiment facile`)
288 await waitJobs(servers) 280 await waitJobs(servers)
289 281
290 for (const server of servers) { 282 for (const server of servers) {
291 const res = await getVideo(server.url, videoUUID) 283 const video = await server.videosCommand.get({ id: videoUUID })
292 const video: VideoDetails = res.body
293 284
294 expect(video.name).to.equal('transcoded video') 285 expect(video.name).to.equal('transcoded video')
295 expect(video.files).to.have.lengthOf(4) 286 expect(video.files).to.have.lengthOf(4)
@@ -339,8 +330,7 @@ Ajouter un sous-titre est vraiment facile`)
339 await waitJobs(servers) 330 await waitJobs(servers)
340 331
341 // test resolution 332 // test resolution
342 const res2 = await getVideo(servers[0].url, videoUUID) 333 const video = await servers[0].videosCommand.get({ id: videoUUID })
343 const video: VideoDetails = res2.body
344 expect(video.name).to.equal('hdr video') 334 expect(video.name).to.equal('hdr video')
345 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 }))
346 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 9dc26fca6..b8fff096d 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -2,18 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
6 cleanupTests,
7 flushAndRunServer,
8 getAccountVideos,
9 getMyVideos,
10 getVideoChannelVideos,
11 getVideosList,
12 getVideosListWithToken,
13 ServerInfo,
14 setAccessTokensToServers,
15 uploadVideo
16} from '@shared/extra-utils'
17import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' 6import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models'
18 7
19const expect = chai.expect 8const expect = chai.expect
@@ -37,10 +26,10 @@ describe('Test video NSFW policy', function () {
37 26
38 if (token) { 27 if (token) {
39 promises = [ 28 promises = [
40 getVideosListWithToken(server.url, token, query).then(res => res.body),
41 server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), 29 server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }),
42 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body), 30 server.videosCommand.listWithToken({ token, ...query }),
43 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body) 31 server.videosCommand.listByAccount({ token, accountName, ...query }),
32 server.videosCommand.listByChannel({ token, videoChannelName, ...query })
44 ] 33 ]
45 34
46 // Overviews do not support video filters 35 // Overviews do not support video filters
@@ -54,10 +43,10 @@ describe('Test video NSFW policy', function () {
54 } 43 }
55 44
56 promises = [ 45 promises = [
57 getVideosList(server.url).then(res => res.body),
58 server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }), 46 server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }),
59 getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body), 47 server.videosCommand.list(),
60 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body) 48 server.videosCommand.listByAccount({ accountName }),
49 server.videosCommand.listByChannel({ videoChannelName })
61 ] 50 ]
62 51
63 // Overviews do not support video filters 52 // Overviews do not support video filters
@@ -79,12 +68,12 @@ describe('Test video NSFW policy', function () {
79 68
80 { 69 {
81 const attributes = { name: 'nsfw', nsfw: true, category: 1 } 70 const attributes = { name: 'nsfw', nsfw: true, category: 1 }
82 await uploadVideo(server.url, server.accessToken, attributes) 71 await server.videosCommand.upload({ attributes })
83 } 72 }
84 73
85 { 74 {
86 const attributes = { name: 'normal', nsfw: false, category: 1 } 75 const attributes = { name: 'normal', nsfw: false, category: 1 }
87 await uploadVideo(server.url, server.accessToken, attributes) 76 await server.videosCommand.upload({ attributes })
88 } 77 }
89 78
90 customConfig = await server.configCommand.getCustomConfig() 79 customConfig = await server.configCommand.getCustomConfig()
@@ -192,13 +181,12 @@ describe('Test video NSFW policy', function () {
192 }) 181 })
193 182
194 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () { 183 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
195 const res = await getMyVideos(server.url, server.accessToken, 0, 5) 184 const { total, data } = await server.videosCommand.listMyVideos()
196 expect(res.body.total).to.equal(2) 185 expect(total).to.equal(2)
197 186
198 const videos = res.body.data 187 expect(data).to.have.lengthOf(2)
199 expect(videos).to.have.lengthOf(2) 188 expect(data[0].name).to.equal('normal')
200 expect(videos[0].name).to.equal('normal') 189 expect(data[1].name).to.equal('nsfw')
201 expect(videos[1].name).to.equal('nsfw')
202 }) 190 })
203 191
204 it('Should display NSFW videos when the nsfw param === true', async function () { 192 it('Should display NSFW videos when the nsfw param === true', async function () {
diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts
index af5df8d90..14739af20 100644
--- a/server/tests/api/videos/video-playlist-thumbnails.ts
+++ b/server/tests/api/videos/video-playlist-thumbnails.ts
@@ -10,7 +10,6 @@ import {
10 setAccessTokensToServers, 10 setAccessTokensToServers,
11 setDefaultVideoChannel, 11 setDefaultVideoChannel,
12 testImage, 12 testImage,
13 uploadVideoAndGetId,
14 waitJobs 13 waitJobs
15} from '../../../../shared/extra-utils' 14} from '../../../../shared/extra-utils'
16import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 15import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
@@ -55,8 +54,8 @@ describe('Playlist thumbnail', function () {
55 // Server 1 and server 2 follow each other 54 // Server 1 and server 2 follow each other
56 await doubleFollow(servers[0], servers[1]) 55 await doubleFollow(servers[0], servers[1])
57 56
58 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id 57 video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).id
59 video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id 58 video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).id
60 59
61 await waitJobs(servers) 60 await waitJobs(servers)
62 }) 61 })
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index e57d86c14..40f61ca19 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -13,9 +13,6 @@ import {
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 setDefaultVideoChannel, 14 setDefaultVideoChannel,
15 testImage, 15 testImage,
16 updateVideo,
17 uploadVideo,
18 uploadVideoAndGetId,
19 wait, 16 wait,
20 waitJobs 17 waitJobs
21} from '@shared/extra-utils' 18} from '@shared/extra-utils'
@@ -99,14 +96,14 @@ describe('Test video playlists', function () {
99 for (const server of servers) { 96 for (const server of servers) {
100 for (let i = 0; i < 7; i++) { 97 for (let i = 0; i < 7; i++) {
101 const name = `video ${i} server ${server.serverNumber}` 98 const name = `video ${i} server ${server.serverNumber}`
102 const resVideo = await uploadVideo(server.url, server.accessToken, { name, nsfw: false }) 99 const video = await server.videosCommand.upload({ attributes: { name, nsfw: false } })
103 100
104 server.videos.push(resVideo.body.video) 101 server.videos.push(video)
105 } 102 }
106 } 103 }
107 } 104 }
108 105
109 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id 106 nsfwVideoServer1 = (await servers[0].videosCommand.quickUpload({ name: 'NSFW video', nsfw: true })).id
110 107
111 userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1') 108 userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1')
112 109
@@ -620,9 +617,9 @@ describe('Test video playlists', function () {
620 return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes }) 617 return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes })
621 } 618 }
622 619
623 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userTokenServer1 })).uuid 620 video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid
624 video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid 621 video2 = (await servers[1].videosCommand.quickUpload({ name: 'video 90' })).uuid
625 video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid 622 video3 = (await servers[0].videosCommand.quickUpload({ name: 'video 91', nsfw: true })).uuid
626 623
627 await waitJobs(servers) 624 await waitJobs(servers)
628 625
@@ -640,7 +637,7 @@ describe('Test video playlists', function () {
640 const position = 1 637 const position = 1
641 638
642 { 639 {
643 await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE }) 640 await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } })
644 await waitJobs(servers) 641 await waitJobs(servers)
645 642
646 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 643 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
@@ -650,7 +647,7 @@ describe('Test video playlists', function () {
650 } 647 }
651 648
652 { 649 {
653 await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC }) 650 await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } })
654 await waitJobs(servers) 651 await waitJobs(servers)
655 652
656 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 653 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index 4e349e350..bcf431edb 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -3,22 +3,8 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import { cleanupTests, doubleFollow, flushAndRunServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
7 cleanupTests, 7import { VideoCreateResult, VideoPrivacy } from '@shared/models'
8 doubleFollow,
9 flushAndRunServer,
10 getMyVideos,
11 getVideo,
12 getVideosList,
13 getVideosListWithToken,
14 getVideoWithToken,
15 ServerInfo,
16 setAccessTokensToServers,
17 updateVideo,
18 uploadVideo,
19 waitJobs
20} from '@shared/extra-utils'
21import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models'
22 8
23const expect = chai.expect 9const expect = chai.expect
24 10
@@ -66,55 +52,53 @@ describe('Test video privacy', function () {
66 52
67 for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { 53 for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) {
68 const attributes = { privacy } 54 const attributes = { privacy }
69 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 55 await servers[0].videosCommand.upload({ attributes })
70 } 56 }
71 57
72 await waitJobs(servers) 58 await waitJobs(servers)
73 }) 59 })
74 60
75 it('Should not have these private and internal videos on server 2', async function () { 61 it('Should not have these private and internal videos on server 2', async function () {
76 const res = await getVideosList(servers[1].url) 62 const { total, data } = await servers[1].videosCommand.list()
77 63
78 expect(res.body.total).to.equal(0) 64 expect(total).to.equal(0)
79 expect(res.body.data).to.have.lengthOf(0) 65 expect(data).to.have.lengthOf(0)
80 }) 66 })
81 67
82 it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () { 68 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) 69 const { total, data } = await servers[0].videosCommand.list()
84 70
85 expect(res.body.total).to.equal(0) 71 expect(total).to.equal(0)
86 expect(res.body.data).to.have.lengthOf(0) 72 expect(data).to.have.lengthOf(0)
87 }) 73 })
88 74
89 it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () { 75 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) 76 const { total, data } = await servers[0].videosCommand.listWithToken()
91 77
92 expect(res.body.total).to.equal(1) 78 expect(total).to.equal(1)
93 expect(res.body.data).to.have.lengthOf(1) 79 expect(data).to.have.lengthOf(1)
94 80
95 expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) 81 expect(data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL)
96 }) 82 })
97 83
98 it('Should list my (private and internal) videos', async function () { 84 it('Should list my (private and internal) videos', async function () {
99 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10) 85 const { total, data } = await servers[0].videosCommand.listMyVideos()
100 86
101 expect(res.body.total).to.equal(2) 87 expect(total).to.equal(2)
102 expect(res.body.data).to.have.lengthOf(2) 88 expect(data).to.have.lengthOf(2)
103 89
104 const videos: Video[] = res.body.data 90 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 91 privateVideoId = privateVideo.id
108 privateVideoUUID = privateVideo.uuid 92 privateVideoUUID = privateVideo.uuid
109 93
110 const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL) 94 const internalVideo = data.find(v => v.privacy.id === VideoPrivacy.INTERNAL)
111 internalVideoId = internalVideo.id 95 internalVideoId = internalVideo.id
112 internalVideoUUID = internalVideo.uuid 96 internalVideoUUID = internalVideo.uuid
113 }) 97 })
114 98
115 it('Should not be able to watch the private/internal video with non authenticated user', async function () { 99 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) 100 await servers[0].videosCommand.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
117 await getVideo(servers[0].url, internalVideoUUID, HttpStatusCode.UNAUTHORIZED_401) 101 await servers[0].videosCommand.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
118 }) 102 })
119 103
120 it('Should not be able to watch the private video with another user', async function () { 104 it('Should not be able to watch the private video with another user', async function () {
@@ -127,15 +111,20 @@ describe('Test video privacy', function () {
127 await servers[0].usersCommand.create({ username: user.username, password: user.password }) 111 await servers[0].usersCommand.create({ username: user.username, password: user.password })
128 112
129 anotherUserToken = await servers[0].loginCommand.getAccessToken(user) 113 anotherUserToken = await servers[0].loginCommand.getAccessToken(user)
130 await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) 114
115 await servers[0].videosCommand.getWithToken({
116 token: anotherUserToken,
117 id: privateVideoUUID,
118 expectedStatus: HttpStatusCode.FORBIDDEN_403
119 })
131 }) 120 })
132 121
133 it('Should be able to watch the internal video with another user', async function () { 122 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) 123 await servers[0].videosCommand.getWithToken({ token: anotherUserToken, id: internalVideoUUID })
135 }) 124 })
136 125
137 it('Should be able to watch the private video with the correct user', async function () { 126 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) 127 await servers[0].videosCommand.getWithToken({ id: privateVideoUUID })
139 }) 128 })
140 }) 129 })
141 130
@@ -148,7 +137,7 @@ describe('Test video privacy', function () {
148 name: 'unlisted video', 137 name: 'unlisted video',
149 privacy: VideoPrivacy.UNLISTED 138 privacy: VideoPrivacy.UNLISTED
150 } 139 }
151 await uploadVideo(servers[1].url, servers[1].accessToken, attributes) 140 await servers[1].videosCommand.upload({ attributes })
152 141
153 // Server 2 has transcoding enabled 142 // Server 2 has transcoding enabled
154 await waitJobs(servers) 143 await waitJobs(servers)
@@ -156,32 +145,32 @@ describe('Test video privacy', function () {
156 145
157 it('Should not have this unlisted video listed on server 1 and 2', async function () { 146 it('Should not have this unlisted video listed on server 1 and 2', async function () {
158 for (const server of servers) { 147 for (const server of servers) {
159 const res = await getVideosList(server.url) 148 const { total, data } = await server.videosCommand.list()
160 149
161 expect(res.body.total).to.equal(0) 150 expect(total).to.equal(0)
162 expect(res.body.data).to.have.lengthOf(0) 151 expect(data).to.have.lengthOf(0)
163 } 152 }
164 }) 153 })
165 154
166 it('Should list my (unlisted) videos', async function () { 155 it('Should list my (unlisted) videos', async function () {
167 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) 156 const { total, data } = await servers[1].videosCommand.listMyVideos()
168 157
169 expect(res.body.total).to.equal(1) 158 expect(total).to.equal(1)
170 expect(res.body.data).to.have.lengthOf(1) 159 expect(data).to.have.lengthOf(1)
171 160
172 unlistedVideo = res.body.data[0] 161 unlistedVideo = data[0]
173 }) 162 })
174 163
175 it('Should not be able to get this unlisted video using its id', async function () { 164 it('Should not be able to get this unlisted video using its id', async function () {
176 await getVideo(servers[1].url, unlistedVideo.id, 404) 165 await servers[1].videosCommand.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
177 }) 166 })
178 167
179 it('Should be able to get this unlisted video using its uuid/shortUUID', async function () { 168 it('Should be able to get this unlisted video using its uuid/shortUUID', async function () {
180 for (const server of servers) { 169 for (const server of servers) {
181 for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) { 170 for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) {
182 const res = await getVideo(server.url, id) 171 const video = await server.videosCommand.get({ id })
183 172
184 expect(res.body.name).to.equal('unlisted video') 173 expect(video.name).to.equal('unlisted video')
185 } 174 }
186 } 175 }
187 }) 176 })
@@ -193,28 +182,28 @@ describe('Test video privacy', function () {
193 name: 'unlisted video', 182 name: 'unlisted video',
194 privacy: VideoPrivacy.UNLISTED 183 privacy: VideoPrivacy.UNLISTED
195 } 184 }
196 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 185 await servers[0].videosCommand.upload({ attributes })
197 186
198 await waitJobs(servers) 187 await waitJobs(servers)
199 }) 188 })
200 189
201 it('Should list my new unlisted video', async function () { 190 it('Should list my new unlisted video', async function () {
202 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 3) 191 const { total, data } = await servers[0].videosCommand.listMyVideos()
203 192
204 expect(res.body.total).to.equal(3) 193 expect(total).to.equal(3)
205 expect(res.body.data).to.have.lengthOf(3) 194 expect(data).to.have.lengthOf(3)
206 195
207 nonFederatedUnlistedVideoUUID = res.body.data[0].uuid 196 nonFederatedUnlistedVideoUUID = data[0].uuid
208 }) 197 })
209 198
210 it('Should be able to get non-federated unlisted video from origin', async function () { 199 it('Should be able to get non-federated unlisted video from origin', async function () {
211 const res = await getVideo(servers[0].url, nonFederatedUnlistedVideoUUID) 200 const video = await servers[0].videosCommand.get({ id: nonFederatedUnlistedVideoUUID })
212 201
213 expect(res.body.name).to.equal('unlisted video') 202 expect(video.name).to.equal('unlisted video')
214 }) 203 })
215 204
216 it('Should not be able to get non-federated unlisted video from federated server', async function () { 205 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) 206 await servers[1].videosCommand.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
218 }) 207 })
219 }) 208 })
220 209
@@ -226,20 +215,20 @@ describe('Test video privacy', function () {
226 now = Date.now() 215 now = Date.now()
227 216
228 { 217 {
229 const attribute = { 218 const attributes = {
230 name: 'private video becomes public', 219 name: 'private video becomes public',
231 privacy: VideoPrivacy.PUBLIC 220 privacy: VideoPrivacy.PUBLIC
232 } 221 }
233 222
234 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) 223 await servers[0].videosCommand.update({ id: privateVideoId, attributes })
235 } 224 }
236 225
237 { 226 {
238 const attribute = { 227 const attributes = {
239 name: 'internal video becomes public', 228 name: 'internal video becomes public',
240 privacy: VideoPrivacy.PUBLIC 229 privacy: VideoPrivacy.PUBLIC
241 } 230 }
242 await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, attribute) 231 await servers[0].videosCommand.update({ id: internalVideoId, attributes })
243 } 232 }
244 233
245 await waitJobs(servers) 234 await waitJobs(servers)
@@ -247,13 +236,12 @@ describe('Test video privacy', function () {
247 236
248 it('Should have this new public video listed on server 1 and 2', async function () { 237 it('Should have this new public video listed on server 1 and 2', async function () {
249 for (const server of servers) { 238 for (const server of servers) {
250 const res = await getVideosList(server.url) 239 const { total, data } = await server.videosCommand.list()
251 expect(res.body.total).to.equal(2) 240 expect(total).to.equal(2)
252 expect(res.body.data).to.have.lengthOf(2) 241 expect(data).to.have.lengthOf(2)
253 242
254 const videos: Video[] = res.body.data 243 const privateVideo = data.find(v => v.name === 'private video becomes public')
255 const privateVideo = videos.find(v => v.name === 'private video becomes public') 244 const internalVideo = data.find(v => v.name === 'internal video becomes public')
256 const internalVideo = videos.find(v => v.name === 'internal video becomes public')
257 245
258 expect(privateVideo).to.not.be.undefined 246 expect(privateVideo).to.not.be.undefined
259 expect(internalVideo).to.not.be.undefined 247 expect(internalVideo).to.not.be.undefined
@@ -270,27 +258,25 @@ describe('Test video privacy', function () {
270 it('Should set these videos as private and internal', async function () { 258 it('Should set these videos as private and internal', async function () {
271 this.timeout(10000) 259 this.timeout(10000)
272 260
273 await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE }) 261 await servers[0].videosCommand.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } })
274 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL }) 262 await servers[0].videosCommand.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } })
275 263
276 await waitJobs(servers) 264 await waitJobs(servers)
277 265
278 for (const server of servers) { 266 for (const server of servers) {
279 const res = await getVideosList(server.url) 267 const { total, data } = await server.videosCommand.list()
280 268
281 expect(res.body.total).to.equal(0) 269 expect(total).to.equal(0)
282 expect(res.body.data).to.have.lengthOf(0) 270 expect(data).to.have.lengthOf(0)
283 } 271 }
284 272
285 { 273 {
286 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) 274 const { total, data } = await servers[0].videosCommand.listMyVideos()
287 const videos = res.body.data 275 expect(total).to.equal(3)
288 276 expect(data).to.have.lengthOf(3)
289 expect(res.body.total).to.equal(3)
290 expect(videos).to.have.lengthOf(3)
291 277
292 const privateVideo = videos.find(v => v.name === 'private video becomes public') 278 const privateVideo = data.find(v => v.name === 'private video becomes public')
293 const internalVideo = videos.find(v => v.name === 'internal video becomes public') 279 const internalVideo = data.find(v => v.name === 'internal video becomes public')
294 280
295 expect(privateVideo).to.not.be.undefined 281 expect(privateVideo).to.not.be.undefined
296 expect(internalVideo).to.not.be.undefined 282 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..635ae6ff1 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,
8 doubleFollow, 7 doubleFollow,
9 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
10 getMyVideos,
11 getVideosList,
12 getVideoWithToken,
13 ServerInfo, 9 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
@@ -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].videosCommand.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.videosCommand.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].videosCommand.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].videosCommand.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.videosCommand.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].videosCommand.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].videosCommand.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.videosCommand.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].videosCommand.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.videosCommand.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 f16b22bae..b41c68283 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -2,11 +2,9 @@
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 { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' 7import { HttpStatusCode } from '@shared/core-utils'
9import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
10import { 8import {
11 buildAbsoluteFixturePath, 9 buildAbsoluteFixturePath,
12 cleanupTests, 10 cleanupTests,
@@ -14,19 +12,14 @@ import {
14 flushAndRunMultipleServers, 12 flushAndRunMultipleServers,
15 generateHighBitrateVideo, 13 generateHighBitrateVideo,
16 generateVideoWithFramerate, 14 generateVideoWithFramerate,
17 getMyVideos,
18 getVideo,
19 getVideoFileMetadataUrl,
20 getVideosList,
21 makeGetRequest, 15 makeGetRequest,
22 ServerInfo, 16 ServerInfo,
23 setAccessTokensToServers, 17 setAccessTokensToServers,
24 uploadVideo,
25 uploadVideoAndGetId,
26 waitJobs, 18 waitJobs,
27 webtorrentAdd 19 webtorrentAdd
28} from '../../../../shared/extra-utils' 20} from '@shared/extra-utils'
29import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' 21import { getMaxBitrate, VideoResolution, VideoState } from '@shared/models'
22import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
30import { 23import {
31 canDoQuickTranscode, 24 canDoQuickTranscode,
32 getAudioStream, 25 getAudioStream,
@@ -84,21 +77,20 @@ describe('Test video transcoding', function () {
84 it('Should not transcode video on server 1', async function () { 77 it('Should not transcode video on server 1', async function () {
85 this.timeout(60_000) 78 this.timeout(60_000)
86 79
87 const videoAttributes = { 80 const attributes = {
88 name: 'my super name for server 1', 81 name: 'my super name for server 1',
89 description: 'my super description for server 1', 82 description: 'my super description for server 1',
90 fixture: 'video_short.webm' 83 fixture: 'video_short.webm'
91 } 84 }
92 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 85 await servers[0].videosCommand.upload({ attributes })
93 86
94 await waitJobs(servers) 87 await waitJobs(servers)
95 88
96 for (const server of servers) { 89 for (const server of servers) {
97 const res = await getVideosList(server.url) 90 const { data } = await server.videosCommand.list()
98 const video = res.body.data[0] 91 const video = data[0]
99 92
100 const res2 = await getVideo(server.url, video.id) 93 const videoDetails = await server.videosCommand.get({ id: video.id })
101 const videoDetails = res2.body
102 expect(videoDetails.files).to.have.lengthOf(1) 94 expect(videoDetails.files).to.have.lengthOf(1)
103 95
104 const magnetUri = videoDetails.files[0].magnetUri 96 const magnetUri = videoDetails.files[0].magnetUri
@@ -114,21 +106,20 @@ describe('Test video transcoding', function () {
114 it('Should transcode video on server 2', async function () { 106 it('Should transcode video on server 2', async function () {
115 this.timeout(120_000) 107 this.timeout(120_000)
116 108
117 const videoAttributes = { 109 const attributes = {
118 name: 'my super name for server 2', 110 name: 'my super name for server 2',
119 description: 'my super description for server 2', 111 description: 'my super description for server 2',
120 fixture: 'video_short.webm' 112 fixture: 'video_short.webm'
121 } 113 }
122 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 114 await servers[1].videosCommand.upload({ attributes })
123 115
124 await waitJobs(servers) 116 await waitJobs(servers)
125 117
126 for (const server of servers) { 118 for (const server of servers) {
127 const res = await getVideosList(server.url) 119 const { data } = await server.videosCommand.list()
128 120
129 const video = res.body.data.find(v => v.name === videoAttributes.name) 121 const video = data.find(v => v.name === attributes.name)
130 const res2 = await getVideo(server.url, video.id) 122 const videoDetails = await server.videosCommand.get({ id: video.id })
131 const videoDetails = res2.body
132 123
133 expect(videoDetails.files).to.have.lengthOf(4) 124 expect(videoDetails.files).to.have.lengthOf(4)
134 125
@@ -147,47 +138,50 @@ describe('Test video transcoding', function () {
147 138
148 { 139 {
149 // Upload the video, but wait transcoding 140 // Upload the video, but wait transcoding
150 const videoAttributes = { 141 const attributes = {
151 name: 'waiting video', 142 name: 'waiting video',
152 fixture: 'video_short1.webm', 143 fixture: 'video_short1.webm',
153 waitTranscoding: true 144 waitTranscoding: true
154 } 145 }
155 const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 146 const { uuid } = await servers[1].videosCommand.upload({ attributes })
156 const videoId = resVideo.body.video.uuid 147 const videoId = uuid
157 148
158 // Should be in transcode state 149 // Should be in transcode state
159 const { body } = await getVideo(servers[1].url, videoId) 150 const body = await servers[1].videosCommand.get({ id: videoId })
160 expect(body.name).to.equal('waiting video') 151 expect(body.name).to.equal('waiting video')
161 expect(body.state.id).to.equal(VideoState.TO_TRANSCODE) 152 expect(body.state.id).to.equal(VideoState.TO_TRANSCODE)
162 expect(body.state.label).to.equal('To transcode') 153 expect(body.state.label).to.equal('To transcode')
163 expect(body.waitTranscoding).to.be.true 154 expect(body.waitTranscoding).to.be.true
164 155
165 // Should have my video 156 {
166 const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10) 157 // Should have my video
167 const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name) 158 const { data } = await servers[1].videosCommand.listMyVideos()
168 expect(videoToFindInMine).not.to.be.undefined 159 const videoToFindInMine = data.find(v => v.name === attributes.name)
169 expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) 160 expect(videoToFindInMine).not.to.be.undefined
170 expect(videoToFindInMine.state.label).to.equal('To transcode') 161 expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE)
171 expect(videoToFindInMine.waitTranscoding).to.be.true 162 expect(videoToFindInMine.state.label).to.equal('To transcode')
163 expect(videoToFindInMine.waitTranscoding).to.be.true
164 }
172 165
173 // Should not list this video 166 {
174 const resVideos = await getVideosList(servers[1].url) 167 // Should not list this video
175 const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name) 168 const { data } = await servers[1].videosCommand.list()
176 expect(videoToFindInList).to.be.undefined 169 const videoToFindInList = data.find(v => v.name === attributes.name)
170 expect(videoToFindInList).to.be.undefined
171 }
177 172
178 // Server 1 should not have the video yet 173 // Server 1 should not have the video yet
179 await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404) 174 await servers[0].videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
180 } 175 }
181 176
182 await waitJobs(servers) 177 await waitJobs(servers)
183 178
184 for (const server of servers) { 179 for (const server of servers) {
185 const res = await getVideosList(server.url) 180 const { data } = await server.videosCommand.list()
186 const videoToFind = res.body.data.find(v => v.name === 'waiting video') 181 const videoToFind = data.find(v => v.name === 'waiting video')
187 expect(videoToFind).not.to.be.undefined 182 expect(videoToFind).not.to.be.undefined
188 183
189 const res2 = await getVideo(server.url, videoToFind.id) 184 const videoDetails = await server.videosCommand.get({ id: videoToFind.id })
190 const videoDetails: VideoDetails = res2.body
191 185
192 expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) 186 expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED)
193 expect(videoDetails.state.label).to.equal('Published') 187 expect(videoDetails.state.label).to.equal('Published')
@@ -208,22 +202,20 @@ describe('Test video transcoding', function () {
208 } 202 }
209 203
210 for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { 204 for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) {
211 const videoAttributes = { 205 const attributes = {
212 name: fixture, 206 name: fixture,
213 fixture 207 fixture
214 } 208 }
215 209
216 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 210 await servers[1].videosCommand.upload({ attributes })
217 211
218 await waitJobs(servers) 212 await waitJobs(servers)
219 213
220 for (const server of servers) { 214 for (const server of servers) {
221 const res = await getVideosList(server.url) 215 const { data } = await server.videosCommand.list()
222
223 const video = res.body.data.find(v => v.name === videoAttributes.name)
224 const res2 = await getVideo(server.url, video.id)
225 const videoDetails = res2.body
226 216
217 const video = data.find(v => v.name === attributes.name)
218 const videoDetails = await server.videosCommand.get({ id: video.id })
227 expect(videoDetails.files).to.have.lengthOf(4) 219 expect(videoDetails.files).to.have.lengthOf(4)
228 220
229 const magnetUri = videoDetails.files[0].magnetUri 221 const magnetUri = videoDetails.files[0].magnetUri
@@ -235,22 +227,20 @@ describe('Test video transcoding', function () {
235 it('Should transcode a 4k video', async function () { 227 it('Should transcode a 4k video', async function () {
236 this.timeout(200_000) 228 this.timeout(200_000)
237 229
238 const videoAttributes = { 230 const attributes = {
239 name: '4k video', 231 name: '4k video',
240 fixture: 'video_short_4k.mp4' 232 fixture: 'video_short_4k.mp4'
241 } 233 }
242 234
243 const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 235 const { uuid } = await servers[1].videosCommand.upload({ attributes })
244 video4k = resUpload.body.video.uuid 236 video4k = uuid
245 237
246 await waitJobs(servers) 238 await waitJobs(servers)
247 239
248 const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] 240 const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ]
249 241
250 for (const server of servers) { 242 for (const server of servers) {
251 const res = await getVideo(server.url, video4k) 243 const videoDetails = await server.videosCommand.get({ id: video4k })
252 const videoDetails: VideoDetails = res.body
253
254 expect(videoDetails.files).to.have.lengthOf(resolutions.length) 244 expect(videoDetails.files).to.have.lengthOf(resolutions.length)
255 245
256 for (const r of resolutions) { 246 for (const r of resolutions) {
@@ -266,20 +256,19 @@ describe('Test video transcoding', function () {
266 it('Should transcode high bit rate mp3 to proper bit rate', async function () { 256 it('Should transcode high bit rate mp3 to proper bit rate', async function () {
267 this.timeout(60_000) 257 this.timeout(60_000)
268 258
269 const videoAttributes = { 259 const attributes = {
270 name: 'mp3_256k', 260 name: 'mp3_256k',
271 fixture: 'video_short_mp3_256k.mp4' 261 fixture: 'video_short_mp3_256k.mp4'
272 } 262 }
273 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 263 await servers[1].videosCommand.upload({ attributes })
274 264
275 await waitJobs(servers) 265 await waitJobs(servers)
276 266
277 for (const server of servers) { 267 for (const server of servers) {
278 const res = await getVideosList(server.url) 268 const { data } = await server.videosCommand.list()
279 269
280 const video = res.body.data.find(v => v.name === videoAttributes.name) 270 const video = data.find(v => v.name === attributes.name)
281 const res2 = await getVideo(server.url, video.id) 271 const videoDetails = await server.videosCommand.get({ id: video.id })
282 const videoDetails: VideoDetails = res2.body
283 272
284 expect(videoDetails.files).to.have.lengthOf(4) 273 expect(videoDetails.files).to.have.lengthOf(4)
285 274
@@ -298,20 +287,19 @@ describe('Test video transcoding', function () {
298 it('Should transcode video with no audio and have no audio itself', async function () { 287 it('Should transcode video with no audio and have no audio itself', async function () {
299 this.timeout(60_000) 288 this.timeout(60_000)
300 289
301 const videoAttributes = { 290 const attributes = {
302 name: 'no_audio', 291 name: 'no_audio',
303 fixture: 'video_short_no_audio.mp4' 292 fixture: 'video_short_no_audio.mp4'
304 } 293 }
305 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 294 await servers[1].videosCommand.upload({ attributes })
306 295
307 await waitJobs(servers) 296 await waitJobs(servers)
308 297
309 for (const server of servers) { 298 for (const server of servers) {
310 const res = await getVideosList(server.url) 299 const { data } = await server.videosCommand.list()
311 300
312 const video = res.body.data.find(v => v.name === videoAttributes.name) 301 const video = data.find(v => v.name === attributes.name)
313 const res2 = await getVideo(server.url, video.id) 302 const videoDetails = await server.videosCommand.get({ id: video.id })
314 const videoDetails: VideoDetails = res2.body
315 303
316 expect(videoDetails.files).to.have.lengthOf(4) 304 expect(videoDetails.files).to.have.lengthOf(4)
317 const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) 305 const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4'))
@@ -323,24 +311,23 @@ describe('Test video transcoding', function () {
323 it('Should leave the audio untouched, but properly transcode the video', async function () { 311 it('Should leave the audio untouched, but properly transcode the video', async function () {
324 this.timeout(60_000) 312 this.timeout(60_000)
325 313
326 const videoAttributes = { 314 const attributes = {
327 name: 'untouched_audio', 315 name: 'untouched_audio',
328 fixture: 'video_short.mp4' 316 fixture: 'video_short.mp4'
329 } 317 }
330 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 318 await servers[1].videosCommand.upload({ attributes })
331 319
332 await waitJobs(servers) 320 await waitJobs(servers)
333 321
334 for (const server of servers) { 322 for (const server of servers) {
335 const res = await getVideosList(server.url) 323 const { data } = await server.videosCommand.list()
336 324
337 const video = res.body.data.find(v => v.name === videoAttributes.name) 325 const video = data.find(v => v.name === attributes.name)
338 const res2 = await getVideo(server.url, video.id) 326 const videoDetails = await server.videosCommand.get({ id: video.id })
339 const videoDetails: VideoDetails = res2.body
340 327
341 expect(videoDetails.files).to.have.lengthOf(4) 328 expect(videoDetails.files).to.have.lengthOf(4)
342 329
343 const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) 330 const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
344 const fixtureVideoProbe = await getAudioStream(fixturePath) 331 const fixtureVideoProbe = await getAudioStream(fixturePath)
345 const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) 332 const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4'))
346 333
@@ -384,17 +371,16 @@ describe('Test video transcoding', function () {
384 it('Should merge an audio file with the preview file', async function () { 371 it('Should merge an audio file with the preview file', async function () {
385 this.timeout(60_000) 372 this.timeout(60_000)
386 373
387 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } 374 const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
388 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) 375 await servers[1].videosCommand.upload({ attributes, mode })
389 376
390 await waitJobs(servers) 377 await waitJobs(servers)
391 378
392 for (const server of servers) { 379 for (const server of servers) {
393 const res = await getVideosList(server.url) 380 const { data } = await server.videosCommand.list()
394 381
395 const video = res.body.data.find(v => v.name === 'audio_with_preview') 382 const video = data.find(v => v.name === 'audio_with_preview')
396 const res2 = await getVideo(server.url, video.id) 383 const videoDetails = await server.videosCommand.get({ id: video.id })
397 const videoDetails: VideoDetails = res2.body
398 384
399 expect(videoDetails.files).to.have.lengthOf(1) 385 expect(videoDetails.files).to.have.lengthOf(1)
400 386
@@ -409,17 +395,16 @@ describe('Test video transcoding', function () {
409 it('Should upload an audio file and choose a default background image', async function () { 395 it('Should upload an audio file and choose a default background image', async function () {
410 this.timeout(60_000) 396 this.timeout(60_000)
411 397
412 const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } 398 const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' }
413 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) 399 await servers[1].videosCommand.upload({ attributes, mode })
414 400
415 await waitJobs(servers) 401 await waitJobs(servers)
416 402
417 for (const server of servers) { 403 for (const server of servers) {
418 const res = await getVideosList(server.url) 404 const { data } = await server.videosCommand.list()
419 405
420 const video = res.body.data.find(v => v.name === 'audio_without_preview') 406 const video = data.find(v => v.name === 'audio_without_preview')
421 const res2 = await getVideo(server.url, video.id) 407 const videoDetails = await server.videosCommand.get({ id: video.id })
422 const videoDetails = res2.body
423 408
424 expect(videoDetails.files).to.have.lengthOf(1) 409 expect(videoDetails.files).to.have.lengthOf(1)
425 410
@@ -448,14 +433,13 @@ describe('Test video transcoding', function () {
448 } 433 }
449 }) 434 })
450 435
451 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } 436 const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
452 const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) 437 const { id } = await servers[1].videosCommand.upload({ attributes, mode })
453 438
454 await waitJobs(servers) 439 await waitJobs(servers)
455 440
456 for (const server of servers) { 441 for (const server of servers) {
457 const res2 = await getVideo(server.url, resVideo.body.video.id) 442 const videoDetails = await server.videosCommand.get({ id })
458 const videoDetails: VideoDetails = res2.body
459 443
460 for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { 444 for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
461 expect(files).to.have.lengthOf(2) 445 expect(files).to.have.lengthOf(2)
@@ -481,21 +465,20 @@ describe('Test video transcoding', function () {
481 it('Should transcode a 60 FPS video', async function () { 465 it('Should transcode a 60 FPS video', async function () {
482 this.timeout(60_000) 466 this.timeout(60_000)
483 467
484 const videoAttributes = { 468 const attributes = {
485 name: 'my super 30fps name for server 2', 469 name: 'my super 30fps name for server 2',
486 description: 'my super 30fps description for server 2', 470 description: 'my super 30fps description for server 2',
487 fixture: '60fps_720p_small.mp4' 471 fixture: '60fps_720p_small.mp4'
488 } 472 }
489 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 473 await servers[1].videosCommand.upload({ attributes })
490 474
491 await waitJobs(servers) 475 await waitJobs(servers)
492 476
493 for (const server of servers) { 477 for (const server of servers) {
494 const res = await getVideosList(server.url) 478 const { data } = await server.videosCommand.list()
495 479
496 const video = res.body.data.find(v => v.name === videoAttributes.name) 480 const video = data.find(v => v.name === attributes.name)
497 const res2 = await getVideo(server.url, video.id) 481 const videoDetails = await server.videosCommand.get({ id: video.id })
498 const videoDetails: VideoDetails = res2.body
499 482
500 expect(videoDetails.files).to.have.lengthOf(4) 483 expect(videoDetails.files).to.have.lengthOf(4)
501 expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) 484 expect(videoDetails.files[0].fps).to.be.above(58).and.below(62)
@@ -529,20 +512,20 @@ describe('Test video transcoding', function () {
529 expect(fps).to.be.equal(59) 512 expect(fps).to.be.equal(59)
530 } 513 }
531 514
532 const videoAttributes = { 515 const attributes = {
533 name: '59fps video', 516 name: '59fps video',
534 description: '59fps video', 517 description: '59fps video',
535 fixture: tempFixturePath 518 fixture: tempFixturePath
536 } 519 }
537 520
538 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 521 await servers[1].videosCommand.upload({ attributes })
539 522
540 await waitJobs(servers) 523 await waitJobs(servers)
541 524
542 for (const server of servers) { 525 for (const server of servers) {
543 const res = await getVideosList(server.url) 526 const { data } = await server.videosCommand.list()
544 527
545 const video = res.body.data.find(v => v.name === videoAttributes.name) 528 const video = data.find(v => v.name === attributes.name)
546 529
547 { 530 {
548 const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) 531 const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4'))
@@ -572,20 +555,20 @@ describe('Test video transcoding', function () {
572 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) 555 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
573 } 556 }
574 557
575 const videoAttributes = { 558 const attributes = {
576 name: 'high bitrate video', 559 name: 'high bitrate video',
577 description: 'high bitrate video', 560 description: 'high bitrate video',
578 fixture: tempFixturePath 561 fixture: tempFixturePath
579 } 562 }
580 563
581 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 564 await servers[1].videosCommand.upload({ attributes })
582 565
583 await waitJobs(servers) 566 await waitJobs(servers)
584 567
585 for (const server of servers) { 568 for (const server of servers) {
586 const res = await getVideosList(server.url) 569 const { data } = await server.videosCommand.list()
587 570
588 const video = res.body.data.find(v => v.name === videoAttributes.name) 571 const video = data.find(v => v.name === attributes.name)
589 572
590 for (const resolution of [ '240', '360', '480', '720', '1080' ]) { 573 for (const resolution of [ '240', '360', '480', '720', '1080' ]) {
591 const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) 574 const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
@@ -621,19 +604,18 @@ describe('Test video transcoding', function () {
621 } 604 }
622 await servers[1].configCommand.updateCustomSubConfig({ newConfig }) 605 await servers[1].configCommand.updateCustomSubConfig({ newConfig })
623 606
624 const videoAttributes = { 607 const attributes = {
625 name: 'low bitrate', 608 name: 'low bitrate',
626 fixture: 'low-bitrate.mp4' 609 fixture: 'low-bitrate.mp4'
627 } 610 }
628 611
629 const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 612 const { uuid } = await servers[1].videosCommand.upload({ attributes })
630 const videoUUID = resUpload.body.video.uuid
631 613
632 await waitJobs(servers) 614 await waitJobs(servers)
633 615
634 const resolutions = [ 240, 360, 480, 720, 1080 ] 616 const resolutions = [ 240, 360, 480, 720, 1080 ]
635 for (const r of resolutions) { 617 for (const r of resolutions) {
636 const path = `videos/${videoUUID}-${r}.mp4` 618 const path = `videos/${uuid}-${r}.mp4`
637 const size = await servers[1].serversCommand.getServerFileSize(path) 619 const size = await servers[1].serversCommand.getServerFileSize(path)
638 expect(size, `${path} not below ${60_000}`).to.be.below(60_000) 620 expect(size, `${path} not below ${60_000}`).to.be.below(60_000)
639 } 621 }
@@ -645,7 +627,7 @@ describe('Test video transcoding', function () {
645 it('Should provide valid ffprobe data', async function () { 627 it('Should provide valid ffprobe data', async function () {
646 this.timeout(160_000) 628 this.timeout(160_000)
647 629
648 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid 630 const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'ffprobe data' })).uuid
649 await waitJobs(servers) 631 await waitJobs(servers)
650 632
651 { 633 {
@@ -679,8 +661,7 @@ describe('Test video transcoding', function () {
679 } 661 }
680 662
681 for (const server of servers) { 663 for (const server of servers) {
682 const res2 = await getVideo(server.url, videoUUID) 664 const videoDetails = await server.videosCommand.get({ id: videoUUID })
683 const videoDetails: VideoDetails = res2.body
684 665
685 const videoFiles = videoDetails.files 666 const videoFiles = videoDetails.files
686 .concat(videoDetails.streamingPlaylists[0].files) 667 .concat(videoDetails.streamingPlaylists[0].files)
@@ -692,8 +673,7 @@ describe('Test video transcoding', function () {
692 expect(file.metadataUrl).to.contain(servers[1].url) 673 expect(file.metadataUrl).to.contain(servers[1].url)
693 expect(file.metadataUrl).to.contain(videoUUID) 674 expect(file.metadataUrl).to.contain(videoUUID)
694 675
695 const res3 = await getVideoFileMetadataUrl(file.metadataUrl) 676 const metadata = await server.videosCommand.getFileMetadata({ url: file.metadataUrl })
696 const metadata: FfprobeData = res3.body
697 expect(metadata).to.have.nested.property('format.size') 677 expect(metadata).to.have.nested.property('format.size')
698 } 678 }
699 } 679 }
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
index 4aa00cfc4..4a5a83ee6 100644
--- a/server/tests/api/videos/videos-filter.ts
+++ b/server/tests/api/videos/videos-filter.ts
@@ -1,21 +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 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 makeGetRequest, 10 makeGetRequest,
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers, 12 setAccessTokensToServers
13 uploadVideo 13} from '@shared/extra-utils'
14} from '../../../../shared/extra-utils' 14import { UserRole, Video, VideoPrivacy } from '@shared/models'
15import { UserRole } from '../../../../shared/models/users'
16import { Video, VideoPrivacy } from '../../../../shared/models/videos'
17
18const expect = chai.expect
19 15
20async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { 16async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
21 const paths = [ 17 const paths = [
@@ -62,16 +58,16 @@ describe('Test videos filter', function () {
62 await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) 58 await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
63 server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) 59 server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator)
64 60
65 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) 61 await server.videosCommand.upload({ attributes: { name: 'public ' + server.serverNumber } })
66 62
67 { 63 {
68 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED } 64 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
69 await uploadVideo(server.url, server.accessToken, attributes) 65 await server.videosCommand.upload({ attributes })
70 } 66 }
71 67
72 { 68 {
73 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } 69 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
74 await uploadVideo(server.url, server.accessToken, attributes) 70 await server.videosCommand.upload({ attributes })
75 } 71 }
76 } 72 }
77 73
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index aa0623f7d..8614078f1 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -6,17 +6,14 @@ import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 flushAndRunServer, 8 flushAndRunServer,
9 getVideosListWithToken,
10 getVideoWithToken,
11 HistoryCommand, 9 HistoryCommand,
12 killallServers, 10 killallServers,
13 reRunServer, 11 reRunServer,
14 ServerInfo, 12 ServerInfo,
15 setAccessTokensToServers, 13 setAccessTokensToServers,
16 uploadVideo,
17 wait 14 wait
18} from '@shared/extra-utils' 15} from '@shared/extra-utils'
19import { Video, VideoDetails } from '@shared/models' 16import { Video } from '@shared/models'
20 17
21const expect = chai.expect 18const expect = chai.expect
22 19
@@ -39,18 +36,18 @@ describe('Test videos history', function () {
39 command = server.historyCommand 36 command = server.historyCommand
40 37
41 { 38 {
42 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) 39 const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 1' } })
43 video1UUID = res.body.video.uuid 40 video1UUID = uuid
44 } 41 }
45 42
46 { 43 {
47 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) 44 const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 2' } })
48 video2UUID = res.body.video.uuid 45 video2UUID = uuid
49 } 46 }
50 47
51 { 48 {
52 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) 49 const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 3' } })
53 video3UUID = res.body.video.uuid 50 video3UUID = uuid
54 } 51 }
55 52
56 const user = { 53 const user = {
@@ -62,12 +59,10 @@ describe('Test videos history', function () {
62 }) 59 })
63 60
64 it('Should get videos, without watching history', async function () { 61 it('Should get videos, without watching history', async function () {
65 const res = await getVideosListWithToken(server.url, server.accessToken) 62 const { data } = await server.videosCommand.listWithToken()
66 const videos: Video[] = res.body.data
67 63
68 for (const video of videos) { 64 for (const video of data) {
69 const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id) 65 const videoDetails = await server.videosCommand.getWithToken({ id: video.id })
70 const videoDetails: VideoDetails = resDetail.body
71 66
72 expect(video.userHistory).to.be.undefined 67 expect(video.userHistory).to.be.undefined
73 expect(videoDetails.userHistory).to.be.undefined 68 expect(videoDetails.userHistory).to.be.undefined
@@ -83,8 +78,8 @@ describe('Test videos history', function () {
83 const videosOfVideos: Video[][] = [] 78 const videosOfVideos: Video[][] = []
84 79
85 { 80 {
86 const res = await getVideosListWithToken(server.url, server.accessToken) 81 const { data } = await server.videosCommand.listWithToken()
87 videosOfVideos.push(res.body.data) 82 videosOfVideos.push(data)
88 } 83 }
89 84
90 { 85 {
@@ -107,24 +102,21 @@ describe('Test videos history', function () {
107 } 102 }
108 103
109 { 104 {
110 const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID) 105 const videoDetails = await server.videosCommand.getWithToken({ id: video1UUID })
111 const videoDetails: VideoDetails = resDetail.body
112 106
113 expect(videoDetails.userHistory).to.not.be.undefined 107 expect(videoDetails.userHistory).to.not.be.undefined
114 expect(videoDetails.userHistory.currentTime).to.equal(3) 108 expect(videoDetails.userHistory.currentTime).to.equal(3)
115 } 109 }
116 110
117 { 111 {
118 const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID) 112 const videoDetails = await server.videosCommand.getWithToken({ id: video2UUID })
119 const videoDetails: VideoDetails = resDetail.body
120 113
121 expect(videoDetails.userHistory).to.not.be.undefined 114 expect(videoDetails.userHistory).to.not.be.undefined
122 expect(videoDetails.userHistory.currentTime).to.equal(8) 115 expect(videoDetails.userHistory.currentTime).to.equal(8)
123 } 116 }
124 117
125 { 118 {
126 const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID) 119 const videoDetails = await server.videosCommand.getWithToken({ id: video3UUID })
127 const videoDetails: VideoDetails = resDetail.body
128 120
129 expect(videoDetails.userHistory).to.be.undefined 121 expect(videoDetails.userHistory).to.be.undefined
130 } 122 }
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts
index a2da2eaef..969393842 100644
--- a/server/tests/api/videos/videos-overview.ts
+++ b/server/tests/api/videos/videos-overview.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils' 5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils'
6import { VideosOverview } from '@shared/models' 6import { VideosOverview } from '@shared/models'
7 7
8const expect = chai.expect 8const expect = chai.expect
@@ -35,10 +35,12 @@ describe('Test a videos overview', function () {
35 35
36 await wait(3000) 36 await wait(3000)
37 37
38 await uploadVideo(server.url, server.accessToken, { 38 await server.videosCommand.upload({
39 name: 'video 0', 39 attributes: {
40 category: 3, 40 name: 'video 0',
41 tags: [ 'coucou1', 'coucou2' ] 41 category: 3,
42 tags: [ 'coucou1', 'coucou2' ]
43 }
42 }) 44 })
43 45
44 const body = await server.overviewsCommand.getVideos({ page: 1 }) 46 const body = await server.overviewsCommand.getVideos({ page: 1 })
@@ -51,10 +53,12 @@ describe('Test a videos overview', function () {
51 53
52 { 54 {
53 for (let i = 1; i < 6; i++) { 55 for (let i = 1; i < 6; i++) {
54 await uploadVideo(server.url, server.accessToken, { 56 await server.videosCommand.upload({
55 name: 'video ' + i, 57 attributes: {
56 category: 3, 58 name: 'video ' + i,
57 tags: [ 'coucou1', 'coucou2' ] 59 category: 3,
60 tags: [ 'coucou1', 'coucou2' ]
61 }
58 }) 62 })
59 } 63 }
60 64
diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts
index b6cde6b50..7ded1bf38 100644
--- a/server/tests/api/videos/videos-views-cleaner.ts
+++ b/server/tests/api/videos/videos-views-cleaner.ts
@@ -10,8 +10,6 @@ import {
10 reRunServer, 10 reRunServer,
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 uploadVideoAndGetId,
14 viewVideo,
15 wait, 13 wait,
16 waitJobs 14 waitJobs
17} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
@@ -32,15 +30,15 @@ describe('Test video views cleaner', function () {
32 30
33 await doubleFollow(servers[0], servers[1]) 31 await doubleFollow(servers[0], servers[1])
34 32
35 videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid 33 videoIdServer1 = (await servers[0].videosCommand.quickUpload({ name: 'video server 1' })).uuid
36 videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid 34 videoIdServer2 = (await servers[1].videosCommand.quickUpload({ name: 'video server 2' })).uuid
37 35
38 await waitJobs(servers) 36 await waitJobs(servers)
39 37
40 await viewVideo(servers[0].url, videoIdServer1) 38 await servers[0].videosCommand.view({ id: videoIdServer1 })
41 await viewVideo(servers[1].url, videoIdServer1) 39 await servers[1].videosCommand.view({ id: videoIdServer1 })
42 await viewVideo(servers[0].url, videoIdServer2) 40 await servers[0].videosCommand.view({ id: videoIdServer2 })
43 await viewVideo(servers[1].url, videoIdServer2) 41 await servers[1].videosCommand.view({ id: videoIdServer2 })
44 42
45 await waitJobs(servers) 43 await waitJobs(servers)
46 }) 44 })