aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-08 11:17:55 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commite3d15a6a9aed97a004d9dac1b7a6499d794e080a (patch)
tree7637ac85a8659a66a1290c9533e0206e9a0c5a30 /server/tests/api/check-params
parenta1637fa1e25b60a88f7cfe50aac8953f50d55761 (diff)
downloadPeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.tar.gz
PeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.tar.zst
PeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.zip
Introduce blacklist command
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/video-blacklist.ts47
1 files changed, 21 insertions, 26 deletions
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index ce7f5fa17..98cf2e11a 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -1,32 +1,28 @@
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'
4 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils'
5import { 6import {
7 BlacklistCommand,
8 checkBadCountPagination,
9 checkBadSortPagination,
10 checkBadStartPagination,
6 cleanupTests, 11 cleanupTests,
7 createUser, 12 createUser,
8 doubleFollow, 13 doubleFollow,
9 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
10 getBlacklistedVideosList,
11 getVideo, 15 getVideo,
12 getVideoWithToken, 16 getVideoWithToken,
13 makePostBodyRequest, 17 makePostBodyRequest,
14 makePutBodyRequest, 18 makePutBodyRequest,
15 removeVideoFromBlacklist,
16 ServerInfo, 19 ServerInfo,
17 setAccessTokensToServers, 20 setAccessTokensToServers,
18 uploadVideo, 21 uploadVideo,
19 userLogin, 22 userLogin,
20 waitJobs 23 waitJobs
21} from '../../../../shared/extra-utils' 24} from '@shared/extra-utils'
22import { 25import { VideoBlacklistType, VideoDetails } from '@shared/models'
23 checkBadCountPagination,
24 checkBadSortPagination,
25 checkBadStartPagination
26} from '../../../../shared/extra-utils/requests/check-api-params'
27import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos'
28import { expect } from 'chai'
29import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
30 26
31describe('Test video blacklist API validators', function () { 27describe('Test video blacklist API validators', function () {
32 let servers: ServerInfo[] 28 let servers: ServerInfo[]
@@ -34,6 +30,7 @@ describe('Test video blacklist API validators', function () {
34 let remoteVideoUUID: string 30 let remoteVideoUUID: string
35 let userAccessToken1 = '' 31 let userAccessToken1 = ''
36 let userAccessToken2 = '' 32 let userAccessToken2 = ''
33 let command: BlacklistCommand
37 34
38 // --------------------------------------------------------------- 35 // ---------------------------------------------------------------
39 36
@@ -75,6 +72,8 @@ describe('Test video blacklist API validators', function () {
75 } 72 }
76 73
77 await waitJobs(servers) 74 await waitJobs(servers)
75
76 command = servers[0].blacklistCommand
78 }) 77 })
79 78
80 describe('When adding a video in blacklist', function () { 79 describe('When adding a video in blacklist', function () {
@@ -234,25 +233,26 @@ describe('Test video blacklist API validators', function () {
234 }) 233 })
235 234
236 describe('When removing a video in blacklist', function () { 235 describe('When removing a video in blacklist', function () {
236
237 it('Should fail with a non authenticated user', async function () { 237 it('Should fail with a non authenticated user', async function () {
238 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) 238 await command.remove({ token: 'fake token', videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
239 }) 239 })
240 240
241 it('Should fail with a non admin user', async function () { 241 it('Should fail with a non admin user', async function () {
242 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) 242 await command.remove({ token: userAccessToken2, videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
243 }) 243 })
244 244
245 it('Should fail with an incorrect id', async function () { 245 it('Should fail with an incorrect id', async function () {
246 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) 246 await command.remove({ videoId: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
247 }) 247 })
248 248
249 it('Should fail with a not blacklisted video', async function () { 249 it('Should fail with a not blacklisted video', async function () {
250 // The video was not added to the blacklist so it should fail 250 // The video was not added to the blacklist so it should fail
251 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404) 251 await command.remove({ videoId: notBlacklistedVideoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
252 }) 252 })
253 253
254 it('Should succeed with the correct params', async function () { 254 it('Should succeed with the correct params', async function () {
255 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204) 255 await command.remove({ videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
256 }) 256 })
257 }) 257 })
258 258
@@ -260,11 +260,11 @@ describe('Test video blacklist API validators', function () {
260 const basePath = '/api/v1/videos/blacklist/' 260 const basePath = '/api/v1/videos/blacklist/'
261 261
262 it('Should fail with a non authenticated user', async function () { 262 it('Should fail with a non authenticated user', async function () {
263 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 }) 263 await servers[0].blacklistCommand.list({ token: 'fake token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
264 }) 264 })
265 265
266 it('Should fail with a non admin user', async function () { 266 it('Should fail with a non admin user', async function () {
267 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 }) 267 await servers[0].blacklistCommand.list({ token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
268 }) 268 })
269 269
270 it('Should fail with a bad start pagination', async function () { 270 it('Should fail with a bad start pagination', async function () {
@@ -280,16 +280,11 @@ describe('Test video blacklist API validators', function () {
280 }) 280 })
281 281
282 it('Should fail with an invalid type', async function () { 282 it('Should fail with an invalid type', async function () {
283 await getBlacklistedVideosList({ 283 await servers[0].blacklistCommand.list({ type: 0, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
284 url: servers[0].url,
285 token: servers[0].accessToken,
286 type: 0,
287 specialStatus: HttpStatusCode.BAD_REQUEST_400
288 })
289 }) 284 })
290 285
291 it('Should succeed with the correct parameters', async function () { 286 it('Should succeed with the correct parameters', async function () {
292 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL }) 287 await servers[0].blacklistCommand.list({ type: VideoBlacklistType.MANUAL })
293 }) 288 })
294 }) 289 })
295 290