1 /* tslint:disable:no-unused-expression */
14 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
20 checkBadCountPagination,
21 checkBadSortPagination,
22 checkBadStartPagination
23 } from '../../../../shared/extra-utils/requests/check-api-params'
24 import { VideoAbuseState } from '../../../../shared/models/videos'
26 describe('Test video abuses API validators', function () {
27 let server: ServerInfo
28 let userAccessToken = ''
29 let videoAbuseId: number
31 // ---------------------------------------------------------------
33 before(async function () {
36 server = await flushAndRunServer(1)
38 await setAccessTokensToServers([ server ])
40 const username = 'user1'
41 const password = 'my super password'
42 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
43 userAccessToken = await userLogin(server, { username, password })
45 const res = await uploadVideo(server.url, server.accessToken, {})
46 server.video = res.body.video
49 describe('When listing video abuses', function () {
50 const path = '/api/v1/videos/abuse'
52 it('Should fail with a bad start pagination', async function () {
53 await checkBadStartPagination(server.url, path, server.accessToken)
56 it('Should fail with a bad count pagination', async function () {
57 await checkBadCountPagination(server.url, path, server.accessToken)
60 it('Should fail with an incorrect sort', async function () {
61 await checkBadSortPagination(server.url, path, server.accessToken)
64 it('Should fail with a non authenticated user', async function () {
65 await makeGetRequest({
68 statusCodeExpected: 401
72 it('Should fail with a non admin user', async function () {
73 await makeGetRequest({
76 token: userAccessToken,
77 statusCodeExpected: 403
82 describe('When reporting a video abuse', function () {
83 const basePath = '/api/v1/videos/'
87 path = basePath + server.video.id + '/abuse'
90 it('Should fail with nothing', async function () {
92 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
95 it('Should fail with a wrong video', async function () {
96 const wrongPath = '/api/v1/videos/blabla/abuse'
97 const fields = { reason: 'my super reason' }
99 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
102 it('Should fail with a non authenticated user', async function () {
103 const fields = { reason: 'my super reason' }
105 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
108 it('Should fail with a reason too short', async function () {
109 const fields = { reason: 'h' }
111 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
114 it('Should fail with a too big reason', async function () {
115 const fields = { reason: 'super'.repeat(605) }
117 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 it('Should succeed with the correct parameters', async function () {
121 const fields = { reason: 'super reason' }
123 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
124 videoAbuseId = res.body.videoAbuse.id
128 describe('When updating a video abuse', function () {
129 const basePath = '/api/v1/videos/'
133 path = basePath + server.video.id + '/abuse/' + videoAbuseId
136 it('Should fail with a non authenticated user', async function () {
137 await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
140 it('Should fail with a non admin user', async function () {
141 await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
144 it('Should fail with a bad video id or bad video abuse id', async function () {
145 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404)
146 await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404)
149 it('Should fail with a bad state', async function () {
150 const body = { state: 5 }
151 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
154 it('Should fail with a bad moderation comment', async function () {
155 const body = { moderationComment: 'b'.repeat(3001) }
156 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
159 it('Should succeed with the correct params', async function () {
160 const body = { state: VideoAbuseState.ACCEPTED }
161 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body)
165 describe('When deleting a video abuse', function () {
166 const basePath = '/api/v1/videos/'
170 path = basePath + server.video.id + '/abuse/' + videoAbuseId
173 it('Should fail with a non authenticated user', async function () {
174 await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
177 it('Should fail with a non admin user', async function () {
178 await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
181 it('Should fail with a bad video id or bad video abuse id', async function () {
182 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404)
183 await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404)
186 it('Should succeed with the correct params', async function () {
187 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
192 killallServers([ server ])