aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-13 16:57:13 +0200
committerChocobozzz <me@florianbigard.com>2018-08-14 09:27:18 +0200
commit26b7305a232e547709f433a6edf700bf495935d8 (patch)
treeb5676090c61df72f864735bcc881d5ee256cffbd /server/tests/api/check-params
parentefc9e8450a8bbeeef9cd18e3ad6037abc0f815c3 (diff)
downloadPeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.gz
PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.zst
PeerTube-26b7305a232e547709f433a6edf700bf495935d8.zip
Add blacklist reason field
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/video-blacklist.ts92
1 files changed, 82 insertions, 10 deletions
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 6cd13d23f..415474718 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -3,13 +3,24 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer, 6 createUser,
7 ServerInfo, setAccessTokensToServers, uploadVideo, userLogin 7 flushTests,
8 getBlacklistedVideosList,
9 killallServers,
10 makePostBodyRequest,
11 makePutBodyRequest,
12 removeVideoFromBlacklist,
13 runServer,
14 ServerInfo,
15 setAccessTokensToServers,
16 uploadVideo,
17 userLogin
8} from '../../utils' 18} from '../../utils'
9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 19import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
10 20
11describe('Test video blacklist API validators', function () { 21describe('Test video blacklist API validators', function () {
12 let server: ServerInfo 22 let server: ServerInfo
23 let notBlacklistedVideoId: number
13 let userAccessToken = '' 24 let userAccessToken = ''
14 25
15 // --------------------------------------------------------------- 26 // ---------------------------------------------------------------
@@ -28,8 +39,15 @@ describe('Test video blacklist API validators', function () {
28 await createUser(server.url, server.accessToken, username, password) 39 await createUser(server.url, server.accessToken, username, password)
29 userAccessToken = await userLogin(server, { username, password }) 40 userAccessToken = await userLogin(server, { username, password })
30 41
31 const res = await uploadVideo(server.url, server.accessToken, {}) 42 {
32 server.video = res.body.video 43 const res = await uploadVideo(server.url, server.accessToken, {})
44 server.video = res.body.video
45 }
46
47 {
48 const res = await uploadVideo(server.url, server.accessToken, {})
49 notBlacklistedVideoId = res.body.video.uuid
50 }
33 }) 51 })
34 52
35 describe('When adding a video in blacklist', function () { 53 describe('When adding a video in blacklist', function () {
@@ -59,20 +77,70 @@ describe('Test video blacklist API validators', function () {
59 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) 77 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
60 }) 78 })
61 79
62 it('Should fail with a local video', async function () { 80 it('Should fail with an invalid reason', async function () {
63 const path = basePath + server.video.id + '/blacklist' 81 const path = basePath + server.video.uuid + '/blacklist'
82 const fields = { reason: 'a'.repeat(305) }
83
84 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
85 })
86
87 it('Should succeed with the correct params', async function () {
88 const path = basePath + server.video.uuid + '/blacklist'
89 const fields = { }
90
91 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
92 })
93 })
94
95 describe('When updating a video in blacklist', function () {
96 const basePath = '/api/v1/videos/'
97
98 it('Should fail with a wrong video', async function () {
99 const wrongPath = '/api/v1/videos/blabla/blacklist'
100 const fields = {}
101 await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
102 })
103
104 it('Should fail with a video not blacklisted', async function () {
105 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
64 const fields = {} 106 const fields = {}
65 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) 107 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
108 })
109
110 it('Should fail with a non authenticated user', async function () {
111 const path = basePath + server.video + '/blacklist'
112 const fields = {}
113 await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
114 })
115
116 it('Should fail with a non admin user', async function () {
117 const path = basePath + server.video + '/blacklist'
118 const fields = {}
119 await makePutBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
120 })
121
122 it('Should fail with an invalid reason', async function () {
123 const path = basePath + server.video.uuid + '/blacklist'
124 const fields = { reason: 'a'.repeat(305) }
125
126 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
127 })
128
129 it('Should succeed with the correct params', async function () {
130 const path = basePath + server.video.uuid + '/blacklist'
131 const fields = { reason: 'hello' }
132
133 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
66 }) 134 })
67 }) 135 })
68 136
69 describe('When removing a video in blacklist', function () { 137 describe('When removing a video in blacklist', function () {
70 it('Should fail with a non authenticated user', async function () { 138 it('Should fail with a non authenticated user', async function () {
71 await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401) 139 await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401)
72 }) 140 })
73 141
74 it('Should fail with a non admin user', async function () { 142 it('Should fail with a non admin user', async function () {
75 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403) 143 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.uuid, 403)
76 }) 144 })
77 145
78 it('Should fail with an incorrect id', async function () { 146 it('Should fail with an incorrect id', async function () {
@@ -81,7 +149,11 @@ describe('Test video blacklist API validators', function () {
81 149
82 it('Should fail with a not blacklisted video', async function () { 150 it('Should fail with a not blacklisted video', async function () {
83 // The video was not added to the blacklist so it should fail 151 // The video was not added to the blacklist so it should fail
84 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404) 152 await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404)
153 })
154
155 it('Should succeed with the correct params', async function () {
156 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204)
85 }) 157 })
86 }) 158 })
87 159