1 /* tslint:disable:no-unused-expression */
14 setAccessTokensToServers,
19 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
20 import { VideoAbuseState } from '../../../../shared/models/videos'
22 describe('Test video abuses API validators', function () {
23 let server: ServerInfo
24 let userAccessToken = ''
25 let videoAbuseId: number
27 // ---------------------------------------------------------------
29 before(async function () {
34 server = await runServer(1)
36 await setAccessTokensToServers([ server ])
38 const username = 'user1'
39 const password = 'my super password'
40 await createUser(server.url, server.accessToken, username, password)
41 userAccessToken = await userLogin(server, { username, password })
43 const res = await uploadVideo(server.url, server.accessToken, {})
44 server.video = res.body.video
47 describe('When listing video abuses', function () {
48 const path = '/api/v1/videos/abuse'
50 it('Should fail with a bad start pagination', async function () {
51 await checkBadStartPagination(server.url, path, server.accessToken)
54 it('Should fail with a bad count pagination', async function () {
55 await checkBadCountPagination(server.url, path, server.accessToken)
58 it('Should fail with an incorrect sort', async function () {
59 await checkBadSortPagination(server.url, path, server.accessToken)
62 it('Should fail with a non authenticated user', async function () {
63 await makeGetRequest({
66 statusCodeExpected: 401
70 it('Should fail with a non admin user', async function () {
71 await makeGetRequest({
74 token: userAccessToken,
75 statusCodeExpected: 403
80 describe('When reporting a video abuse', function () {
81 const basePath = '/api/v1/videos/'
85 path = basePath + server.video.id + '/abuse'
88 it('Should fail with nothing', async function () {
90 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
93 it('Should fail with a wrong video', async function () {
94 const wrongPath = '/api/v1/videos/blabla/abuse'
95 const fields = { reason: 'my super reason' }
97 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
100 it('Should fail with a non authenticated user', async function () {
101 const fields = { reason: 'my super reason' }
103 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
106 it('Should fail with a reason too short', async function () {
107 const fields = { reason: 'h' }
109 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
112 it('Should fail with a reason too big', async function () {
113 const fields = { reason: 'super'.repeat(61) }
115 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
118 it('Should succeed with the correct parameters', async function () {
119 const fields = { reason: 'super reason' }
121 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
122 videoAbuseId = res.body.videoAbuse.id
126 describe('When updating a video abuse', function () {
127 const basePath = '/api/v1/videos/'
131 path = basePath + server.video.id + '/abuse/' + videoAbuseId
134 it('Should fail with a non authenticated user', async function () {
135 await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
138 it('Should fail with a non admin user', async function () {
139 await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
142 it('Should fail with a bad video id or bad video abuse id', async function () {
143 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404)
144 await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404)
147 it('Should fail with a bad state', async function () {
148 const body = { state: 5 }
149 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
152 it('Should fail with a bad moderation comment', async function () {
153 const body = { moderationComment: 'b'.repeat(305) }
154 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
157 it('Should succeed with the correct params', async function () {
158 const body = { state: VideoAbuseState.ACCEPTED }
159 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body)
163 describe('When deleting a video abuse', function () {
164 const basePath = '/api/v1/videos/'
168 path = basePath + server.video.id + '/abuse/' + videoAbuseId
171 it('Should fail with a non authenticated user', async function () {
172 await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
175 it('Should fail with a non admin user', async function () {
176 await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
179 it('Should fail with a bad video id or bad video abuse id', async function () {
180 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404)
181 await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404)
184 it('Should succeed with the correct params', async function () {
185 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
189 after(async function () {
190 killallServers([ server ])
192 // Keep the logs if the test failed