1 /* tslint:disable:no-unused-expression */
13 setAccessTokensToServers,
17 } from '../../../../shared/extra-utils'
19 checkBadCountPagination,
20 checkBadSortPagination,
21 checkBadStartPagination
22 } from '../../../../shared/extra-utils/requests/check-api-params'
23 import { VideoAbuseState } from '../../../../shared/models/videos'
25 describe('Test video abuses API validators', function () {
26 let server: ServerInfo
27 let userAccessToken = ''
28 let videoAbuseId: number
30 // ---------------------------------------------------------------
32 before(async function () {
35 server = await flushAndRunServer(1)
37 await setAccessTokensToServers([ server ])
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 })
44 const res = await uploadVideo(server.url, server.accessToken, {})
45 server.video = res.body.video
48 describe('When listing video abuses', function () {
49 const path = '/api/v1/videos/abuse'
51 it('Should fail with a bad start pagination', async function () {
52 await checkBadStartPagination(server.url, path, server.accessToken)
55 it('Should fail with a bad count pagination', async function () {
56 await checkBadCountPagination(server.url, path, server.accessToken)
59 it('Should fail with an incorrect sort', async function () {
60 await checkBadSortPagination(server.url, path, server.accessToken)
63 it('Should fail with a non authenticated user', async function () {
64 await makeGetRequest({
67 statusCodeExpected: 401
71 it('Should fail with a non admin user', async function () {
72 await makeGetRequest({
75 token: userAccessToken,
76 statusCodeExpected: 403
81 describe('When reporting a video abuse', function () {
82 const basePath = '/api/v1/videos/'
86 path = basePath + server.video.id + '/abuse'
89 it('Should fail with nothing', async function () {
91 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
94 it('Should fail with a wrong video', async function () {
95 const wrongPath = '/api/v1/videos/blabla/abuse'
96 const fields = { reason: 'my super reason' }
98 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
101 it('Should fail with a non authenticated user', async function () {
102 const fields = { reason: 'my super reason' }
104 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
107 it('Should fail with a reason too short', async function () {
108 const fields = { reason: 'h' }
110 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
113 it('Should fail with a too big reason', async function () {
114 const fields = { reason: 'super'.repeat(605) }
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
119 it('Should succeed with the correct parameters', async function () {
120 const fields = { reason: 'super reason' }
122 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
123 videoAbuseId = res.body.videoAbuse.id
127 describe('When updating a video abuse', function () {
128 const basePath = '/api/v1/videos/'
132 path = basePath + server.video.id + '/abuse/' + videoAbuseId
135 it('Should fail with a non authenticated user', async function () {
136 await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
139 it('Should fail with a non admin user', async function () {
140 await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
143 it('Should fail with a bad video id or bad video abuse id', async function () {
144 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404)
145 await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404)
148 it('Should fail with a bad state', async function () {
149 const body = { state: 5 }
150 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
153 it('Should fail with a bad moderation comment', async function () {
154 const body = { moderationComment: 'b'.repeat(3001) }
155 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
158 it('Should succeed with the correct params', async function () {
159 const body = { state: VideoAbuseState.ACCEPTED }
160 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body)
164 describe('When deleting a video abuse', function () {
165 const basePath = '/api/v1/videos/'
169 path = basePath + server.video.id + '/abuse/' + videoAbuseId
172 it('Should fail with a non authenticated user', async function () {
173 await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
176 it('Should fail with a non admin user', async function () {
177 await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
180 it('Should fail with a bad video id or bad video abuse id', async function () {
181 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404)
182 await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404)
185 it('Should succeed with the correct params', async function () {
186 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
190 after(async function () {
191 await cleanupTests([ server ])