]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-blacklist.ts
Add new follow, mention and user registered notifs
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-blacklist.ts
CommitLineData
792dbaf0
GS
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
792dbaf0
GS
4
5import {
26b7305a
C
6 createUser,
7 flushTests,
e5e7f7fe 8 getBlacklistedVideosList, getVideo, getVideoWithToken,
26b7305a
C
9 killallServers,
10 makePostBodyRequest,
11 makePutBodyRequest,
12 removeVideoFromBlacklist,
13 runServer,
14 ServerInfo,
15 setAccessTokensToServers,
16 uploadVideo,
17 userLogin
9639bd17 18} from '../../../../shared/utils'
19import {
20 checkBadCountPagination,
21 checkBadSortPagination,
22 checkBadStartPagination
23} from '../../../../shared/utils/requests/check-api-params'
e5e7f7fe
C
24import { VideoDetails } from '../../../../shared/models/videos'
25import { expect } from 'chai'
792dbaf0
GS
26
27describe('Test video blacklist API validators', function () {
28 let server: ServerInfo
26b7305a 29 let notBlacklistedVideoId: number
e5e7f7fe
C
30 let userAccessToken1 = ''
31 let userAccessToken2 = ''
792dbaf0
GS
32
33 // ---------------------------------------------------------------
34
35 before(async function () {
36 this.timeout(120000)
37
38 await flushTests()
39
40 server = await runServer(1)
41
42 await setAccessTokensToServers([ server ])
43
e5e7f7fe
C
44 {
45 const username = 'user1'
46 const password = 'my super password'
47 await createUser(server.url, server.accessToken, username, password)
48 userAccessToken1 = await userLogin(server, { username, password })
49 }
792dbaf0 50
26b7305a 51 {
e5e7f7fe
C
52 const username = 'user2'
53 const password = 'my super password'
54 await createUser(server.url, server.accessToken, username, password)
55 userAccessToken2 = await userLogin(server, { username, password })
56 }
57
58 {
59 const res = await uploadVideo(server.url, userAccessToken1, {})
26b7305a
C
60 server.video = res.body.video
61 }
62
63 {
64 const res = await uploadVideo(server.url, server.accessToken, {})
65 notBlacklistedVideoId = res.body.video.uuid
66 }
792dbaf0
GS
67 })
68
69 describe('When adding a video in blacklist', function () {
70 const basePath = '/api/v1/videos/'
71
72 it('Should fail with nothing', async function () {
73 const path = basePath + server.video + '/blacklist'
74 const fields = {}
75 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
76 })
77
78 it('Should fail with a wrong video', async function () {
79 const wrongPath = '/api/v1/videos/blabla/blacklist'
80 const fields = {}
81 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
82 })
83
84 it('Should fail with a non authenticated user', async function () {
792dbaf0 85 const path = basePath + server.video + '/blacklist'
11ba2ab3 86 const fields = {}
792dbaf0
GS
87 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
88 })
89
90 it('Should fail with a non admin user', async function () {
792dbaf0 91 const path = basePath + server.video + '/blacklist'
11ba2ab3 92 const fields = {}
e5e7f7fe 93 await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
792dbaf0
GS
94 })
95
26b7305a
C
96 it('Should fail with an invalid reason', async function () {
97 const path = basePath + server.video.uuid + '/blacklist'
98 const fields = { reason: 'a'.repeat(305) }
99
100 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
101 })
102
103 it('Should succeed with the correct params', async function () {
104 const path = basePath + server.video.uuid + '/blacklist'
105 const fields = { }
106
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
108 })
109 })
110
111 describe('When updating a video in blacklist', function () {
112 const basePath = '/api/v1/videos/'
113
114 it('Should fail with a wrong video', async function () {
115 const wrongPath = '/api/v1/videos/blabla/blacklist'
116 const fields = {}
117 await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
118 })
119
120 it('Should fail with a video not blacklisted', async function () {
121 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
122 const fields = {}
123 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
124 })
125
126 it('Should fail with a non authenticated user', async function () {
127 const path = basePath + server.video + '/blacklist'
128 const fields = {}
129 await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
130 })
131
132 it('Should fail with a non admin user', async function () {
133 const path = basePath + server.video + '/blacklist'
11ba2ab3 134 const fields = {}
e5e7f7fe 135 await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
26b7305a
C
136 })
137
138 it('Should fail with an invalid reason', async function () {
139 const path = basePath + server.video.uuid + '/blacklist'
140 const fields = { reason: 'a'.repeat(305) }
141
142 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
143 })
144
145 it('Should succeed with the correct params', async function () {
146 const path = basePath + server.video.uuid + '/blacklist'
147 const fields = { reason: 'hello' }
148
149 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
792dbaf0
GS
150 })
151 })
152
e5e7f7fe
C
153 describe('When getting blacklisted video', function () {
154
155 it('Should fail with a non authenticated user', async function () {
156 await getVideo(server.url, server.video.uuid, 401)
157 })
158
159 it('Should fail with another user', async function () {
160 await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403)
161 })
162
163 it('Should succeed with the owner authenticated user', async function () {
164 const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200)
165 const video: VideoDetails = res.body
166
167 expect(video.blacklisted).to.be.true
168 })
169
170 it('Should succeed with an admin', async function () {
171 const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200)
172 const video: VideoDetails = res.body
173
174 expect(video.blacklisted).to.be.true
175 })
176 })
177
792dbaf0 178 describe('When removing a video in blacklist', function () {
792dbaf0 179 it('Should fail with a non authenticated user', async function () {
26b7305a 180 await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401)
792dbaf0
GS
181 })
182
183 it('Should fail with a non admin user', async function () {
e5e7f7fe 184 await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403)
792dbaf0
GS
185 })
186
187 it('Should fail with an incorrect id', async function () {
11ba2ab3 188 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
792dbaf0
GS
189 })
190
191 it('Should fail with a not blacklisted video', async function () {
192 // The video was not added to the blacklist so it should fail
26b7305a
C
193 await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404)
194 })
195
196 it('Should succeed with the correct params', async function () {
197 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204)
792dbaf0
GS
198 })
199 })
200
201 describe('When listing videos in blacklist', function () {
35bf0c83 202 const basePath = '/api/v1/videos/blacklist/'
792dbaf0
GS
203
204 it('Should fail with a non authenticated user', async function () {
11ba2ab3 205 await getBlacklistedVideosList(server.url, 'fake token', 401)
792dbaf0
GS
206 })
207
208 it('Should fail with a non admin user', async function () {
e5e7f7fe 209 await getBlacklistedVideosList(server.url, userAccessToken2, 403)
792dbaf0
GS
210 })
211
212 it('Should fail with a bad start pagination', async function () {
11ba2ab3 213 await checkBadStartPagination(server.url, basePath, server.accessToken)
792dbaf0
GS
214 })
215
216 it('Should fail with a bad count pagination', async function () {
11ba2ab3 217 await checkBadCountPagination(server.url, basePath, server.accessToken)
792dbaf0
GS
218 })
219
220 it('Should fail with an incorrect sort', async function () {
11ba2ab3 221 await checkBadSortPagination(server.url, basePath, server.accessToken)
792dbaf0
GS
222 })
223 })
224
225 after(async function () {
226 killallServers([ server ])
227
228 // Keep the logs if the test failed
229 if (this['ok']) {
230 await flushTests()
231 }
232 })
233})