aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-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
12 files changed, 133 insertions, 172 deletions
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