1 /* tslint:disable:no-unused-expression */
14 setAccessTokensToServers,
18 } from '../../../../shared/utils'
20 checkBadCountPagination,
21 checkBadSortPagination,
22 checkBadStartPagination
23 } from '../../../../shared/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 () {
38 server = await runServer(1)
40 await setAccessTokensToServers([ server ])
42 const username = 'user1'
43 const password = 'my super password'
44 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
45 userAccessToken = await userLogin(server, { username, password })
47 const res = await uploadVideo(server.url, server.accessToken, {})
48 server.video = res.body.video
51 describe('When listing video abuses', function () {
52 const path = '/api/v1/videos/abuse'
54 it('Should fail with a bad start pagination', async function () {
55 await checkBadStartPagination(server.url, path, server.accessToken)
58 it('Should fail with a bad count pagination', async function () {
59 await checkBadCountPagination(server.url, path, server.accessToken)
62 it('Should fail with an incorrect sort', async function () {
63 await checkBadSortPagination(server.url, path, server.accessToken)
66 it('Should fail with a non authenticated user', async function () {
67 await makeGetRequest({
70 statusCodeExpected: 401
74 it('Should fail with a non admin user', async function () {
75 await makeGetRequest({
78 token: userAccessToken,
79 statusCodeExpected: 403
84 describe('When reporting a video abuse', function () {
85 const basePath = '/api/v1/videos/'
89 path = basePath + server.video.id + '/abuse'
92 it('Should fail with nothing', async function () {
94 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
97 it('Should fail with a wrong video', async function () {
98 const wrongPath = '/api/v1/videos/blabla/abuse'
99 const fields = { reason: 'my super reason' }
101 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
104 it('Should fail with a non authenticated user', async function () {
105 const fields = { reason: 'my super reason' }
107 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
110 it('Should fail with a reason too short', async function () {
111 const fields = { reason: 'h' }
113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
116 it('Should fail with a too big reason', async function () {
117 const fields = { reason: 'super'.repeat(605) }
119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
122 it('Should succeed with the correct parameters', async function () {
123 const fields = { reason: 'super reason' }
125 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
126 videoAbuseId = res.body.videoAbuse.id
130 describe('When updating a video abuse', function () {
131 const basePath = '/api/v1/videos/'
135 path = basePath + server.video.id + '/abuse/' + videoAbuseId
138 it('Should fail with a non authenticated user', async function () {
139 await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
142 it('Should fail with a non admin user', async function () {
143 await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
146 it('Should fail with a bad video id or bad video abuse id', async function () {
147 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404)
148 await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404)
151 it('Should fail with a bad state', async function () {
152 const body = { state: 5 }
153 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
156 it('Should fail with a bad moderation comment', async function () {
157 const body = { moderationComment: 'b'.repeat(3001) }
158 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
161 it('Should succeed with the correct params', async function () {
162 const body = { state: VideoAbuseState.ACCEPTED }
163 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body)
167 describe('When deleting a video abuse', function () {
168 const basePath = '/api/v1/videos/'
172 path = basePath + server.video.id + '/abuse/' + videoAbuseId
175 it('Should fail with a non authenticated user', async function () {
176 await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
179 it('Should fail with a non admin user', async function () {
180 await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
183 it('Should fail with a bad video id or bad video abuse id', async function () {
184 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404)
185 await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404)
188 it('Should succeed with the correct params', async function () {
189 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
193 after(async function () {
194 killallServers([ server ])
196 // Keep the logs if the test failed