]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/video-abuses.ts
e643cb95e529acf6f25cb5d47ef728dd40ae94c3
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-abuses.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4
5 import {
6 cleanupTests,
7 createUser,
8 deleteVideoAbuse,
9 flushAndRunServer,
10 makeGetRequest,
11 makePostBodyRequest,
12 ServerInfo,
13 setAccessTokensToServers,
14 updateVideoAbuse,
15 uploadVideo,
16 userLogin
17 } from '../../../../shared/extra-utils'
18 import {
19 checkBadCountPagination,
20 checkBadSortPagination,
21 checkBadStartPagination
22 } from '../../../../shared/extra-utils/requests/check-api-params'
23 import { VideoAbuseState } from '../../../../shared/models/videos'
24
25 describe('Test video abuses API validators', function () {
26 let server: ServerInfo
27 let userAccessToken = ''
28 let videoAbuseId: number
29
30 // ---------------------------------------------------------------
31
32 before(async function () {
33 this.timeout(30000)
34
35 server = await flushAndRunServer(1)
36
37 await setAccessTokensToServers([ server ])
38
39 const username = 'user1'
40 const password = 'my super password'
41 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
42 userAccessToken = await userLogin(server, { username, password })
43
44 const res = await uploadVideo(server.url, server.accessToken, {})
45 server.video = res.body.video
46 })
47
48 describe('When listing video abuses', function () {
49 const path = '/api/v1/videos/abuse'
50
51 it('Should fail with a bad start pagination', async function () {
52 await checkBadStartPagination(server.url, path, server.accessToken)
53 })
54
55 it('Should fail with a bad count pagination', async function () {
56 await checkBadCountPagination(server.url, path, server.accessToken)
57 })
58
59 it('Should fail with an incorrect sort', async function () {
60 await checkBadSortPagination(server.url, path, server.accessToken)
61 })
62
63 it('Should fail with a non authenticated user', async function () {
64 await makeGetRequest({
65 url: server.url,
66 path,
67 statusCodeExpected: 401
68 })
69 })
70
71 it('Should fail with a non admin user', async function () {
72 await makeGetRequest({
73 url: server.url,
74 path,
75 token: userAccessToken,
76 statusCodeExpected: 403
77 })
78 })
79
80 it('Should fail with a bad id filter', async function () {
81 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 'toto' } })
82 })
83
84 it('Should fail with a bad state filter', async function () {
85 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 'toto' } })
86 })
87
88 it('Should fail with a bad videoIs filter', async function () {
89 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { videoIs: 'toto' } })
90 })
91
92 it('Should succeed with the correct params', async function () {
93 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 13 }, statusCodeExpected: 200 })
94 })
95 })
96
97 describe('When reporting a video abuse', function () {
98 const basePath = '/api/v1/videos/'
99 let path: string
100
101 before(() => {
102 path = basePath + server.video.id + '/abuse'
103 })
104
105 it('Should fail with nothing', async function () {
106 const fields = {}
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
108 })
109
110 it('Should fail with a wrong video', async function () {
111 const wrongPath = '/api/v1/videos/blabla/abuse'
112 const fields = { reason: 'my super reason' }
113
114 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
115 })
116
117 it('Should fail with a non authenticated user', async function () {
118 const fields = { reason: 'my super reason' }
119
120 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
121 })
122
123 it('Should fail with a reason too short', async function () {
124 const fields = { reason: 'h' }
125
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
127 })
128
129 it('Should fail with a too big reason', async function () {
130 const fields = { reason: 'super'.repeat(605) }
131
132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
133 })
134
135 it('Should succeed with the correct parameters', async function () {
136 const fields = { reason: 'super reason' }
137
138 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
139 videoAbuseId = res.body.videoAbuse.id
140 })
141 })
142
143 describe('When updating a video abuse', function () {
144 const basePath = '/api/v1/videos/'
145 // eslint-disable-next-line @typescript-eslint/no-unused-vars
146 let path: string
147
148 before(() => {
149 path = basePath + server.video.id + '/abuse/' + videoAbuseId
150 })
151
152 it('Should fail with a non authenticated user', async function () {
153 await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
154 })
155
156 it('Should fail with a non admin user', async function () {
157 await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
158 })
159
160 it('Should fail with a bad video id or bad video abuse id', async function () {
161 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404)
162 await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404)
163 })
164
165 it('Should fail with a bad state', async function () {
166 const body = { state: 5 }
167 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
168 })
169
170 it('Should fail with a bad moderation comment', async function () {
171 const body = { moderationComment: 'b'.repeat(3001) }
172 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
173 })
174
175 it('Should succeed with the correct params', async function () {
176 const body = { state: VideoAbuseState.ACCEPTED }
177 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body)
178 })
179 })
180
181 describe('When deleting a video abuse', function () {
182 const basePath = '/api/v1/videos/'
183 // eslint-disable-next-line @typescript-eslint/no-unused-vars
184 let path: string
185
186 before(() => {
187 path = basePath + server.video.id + '/abuse/' + videoAbuseId
188 })
189
190 it('Should fail with a non authenticated user', async function () {
191 await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
192 })
193
194 it('Should fail with a non admin user', async function () {
195 await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
196 })
197
198 it('Should fail with a bad video id or bad video abuse id', async function () {
199 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404)
200 await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404)
201 })
202
203 it('Should succeed with the correct params', async function () {
204 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
205 })
206 })
207
208 after(async function () {
209 await cleanupTests([ server ])
210 })
211 })