aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/video-abuses.ts30
-rw-r--r--server/tests/api/videos/video-abuse.ts43
2 files changed, 63 insertions, 10 deletions
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts
index a3fe00ffb..557bf20eb 100644
--- a/server/tests/api/check-params/video-abuses.ts
+++ b/server/tests/api/check-params/video-abuses.ts
@@ -20,7 +20,7 @@ import {
20 checkBadSortPagination, 20 checkBadSortPagination,
21 checkBadStartPagination 21 checkBadStartPagination
22} from '../../../../shared/extra-utils/requests/check-api-params' 22} from '../../../../shared/extra-utils/requests/check-api-params'
23import { VideoAbuseState } from '../../../../shared/models/videos' 23import { VideoAbuseState, VideoAbuseCreate } from '../../../../shared/models/videos'
24 24
25describe('Test video abuses API validators', function () { 25describe('Test video abuses API validators', function () {
26 let server: ServerInfo 26 let server: ServerInfo
@@ -132,12 +132,36 @@ describe('Test video abuses API validators', function () {
132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
133 }) 133 })
134 134
135 it('Should succeed with the correct parameters', async function () { 135 it('Should succeed with the correct parameters (basic)', async function () {
136 const fields = { reason: 'super reason' } 136 const fields = { reason: 'my super reason' }
137 137
138 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 }) 138 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
139 videoAbuseId = res.body.videoAbuse.id 139 videoAbuseId = res.body.videoAbuse.id
140 }) 140 })
141
142 it('Should fail with a wrong predefined reason', async function () {
143 const fields = { reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
144
145 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
146 })
147
148 it('Should fail with negative timestamps', async function () {
149 const fields = { reason: 'my super reason', startAt: -1 }
150
151 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
152 })
153
154 it('Should fail mith misordered startAt/endAt', async function () {
155 const fields = { reason: 'my super reason', startAt: 5, endAt: 1 }
156
157 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
158 })
159
160 it('Should succeed with the corret parameters (advanced)', async function () {
161 const fields: VideoAbuseCreate = { reason: 'my super reason', predefinedReasons: [ 'serverRules' ], startAt: 1, endAt: 5 }
162
163 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
164 })
141 }) 165 })
142 166
143 describe('When updating a video abuse', function () { 167 describe('When updating a video abuse', function () {
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts
index a96be97f6..7383bd991 100644
--- a/server/tests/api/videos/video-abuse.ts
+++ b/server/tests/api/videos/video-abuse.ts
@@ -2,7 +2,7 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos' 5import { VideoAbuse, VideoAbuseState, VideoAbusePredefinedReasonsString } from '../../../../shared/models/videos'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 deleteVideoAbuse, 8 deleteVideoAbuse,
@@ -291,6 +291,32 @@ describe('Test video abuses', function () {
291 } 291 }
292 }) 292 })
293 293
294 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
295 this.timeout(10000)
296
297 const reason5 = 'my super bad reason 5'
298 const predefinedReasons5: VideoAbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
299 const createdAbuse = (await reportVideoAbuse(
300 servers[0].url,
301 servers[0].accessToken,
302 servers[0].video.id,
303 reason5,
304 predefinedReasons5,
305 1,
306 5
307 )).body.videoAbuse as VideoAbuse
308
309 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
310
311 {
312 const abuse = (res.body.data as VideoAbuse[]).find(a => a.id === createdAbuse.id)
313 expect(abuse.reason).to.equals(reason5)
314 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
315 expect(abuse.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
316 expect(abuse.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
317 }
318 })
319
294 it('Should delete the video abuse', async function () { 320 it('Should delete the video abuse', async function () {
295 this.timeout(10000) 321 this.timeout(10000)
296 322
@@ -307,7 +333,7 @@ describe('Test video abuses', function () {
307 333
308 { 334 {
309 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 335 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
310 expect(res.body.total).to.equal(5) 336 expect(res.body.total).to.equal(6)
311 } 337 }
312 }) 338 })
313 339
@@ -328,25 +354,28 @@ describe('Test video abuses', function () {
328 expect(await list({ id: 56 })).to.have.lengthOf(0) 354 expect(await list({ id: 56 })).to.have.lengthOf(0)
329 expect(await list({ id: 1 })).to.have.lengthOf(1) 355 expect(await list({ id: 1 })).to.have.lengthOf(1)
330 356
331 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(3) 357 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
332 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0) 358 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
333 359
334 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1) 360 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
335 361
336 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(3) 362 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
337 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0) 363 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
338 364
339 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1) 365 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
340 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(4) 366 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
341 367
342 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(3) 368 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(4)
343 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0) 369 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
344 370
345 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1) 371 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
346 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0) 372 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
347 373
348 expect(await list({ state: VideoAbuseState.ACCEPTED })).to.have.lengthOf(0) 374 expect(await list({ state: VideoAbuseState.ACCEPTED })).to.have.lengthOf(0)
349 expect(await list({ state: VideoAbuseState.PENDING })).to.have.lengthOf(5) 375 expect(await list({ state: VideoAbuseState.PENDING })).to.have.lengthOf(6)
376
377 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
378 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
350 }) 379 })
351 380
352 after(async function () { 381 after(async function () {