]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-abuses.ts
Replace current state when changing page
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-abuses.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
0e1dc3e7
C
3import 'mocha'
4
5import {
11ba2ab3
C
6 createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
7 uploadVideo, userLogin
0e1dc3e7 8} from '../../utils'
11ba2ab3 9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
0e1dc3e7
C
10
11describe('Test video abuses API validators', function () {
12 let server: ServerInfo
13 let userAccessToken = ''
14
15 // ---------------------------------------------------------------
16
17 before(async function () {
e212f887 18 this.timeout(30000)
0e1dc3e7
C
19
20 await flushTests()
21
22 server = await runServer(1)
23
24 await setAccessTokensToServers([ server ])
25
26 const username = 'user1'
27 const password = 'my super password'
28 await createUser(server.url, server.accessToken, username, password)
eec63bbc 29 userAccessToken = await userLogin(server, { username, password })
0e1dc3e7 30
11ba2ab3
C
31 const res = await uploadVideo(server.url, server.accessToken, {})
32 server.video = res.body.video
0e1dc3e7
C
33 })
34
35 describe('When listing video abuses', function () {
36 const path = '/api/v1/videos/abuse'
37
38 it('Should fail with a bad start pagination', async function () {
11ba2ab3 39 await checkBadStartPagination(server.url, path, server.accessToken)
0e1dc3e7
C
40 })
41
42 it('Should fail with a bad count pagination', async function () {
11ba2ab3 43 await checkBadCountPagination(server.url, path, server.accessToken)
0e1dc3e7
C
44 })
45
46 it('Should fail with an incorrect sort', async function () {
11ba2ab3 47 await checkBadSortPagination(server.url, path, server.accessToken)
0e1dc3e7
C
48 })
49
50 it('Should fail with a non authenticated user', async function () {
11ba2ab3
C
51 await makeGetRequest({
52 url: server.url,
53 path,
54 statusCodeExpected: 401
55 })
0e1dc3e7
C
56 })
57
58 it('Should fail with a non admin user', async function () {
11ba2ab3
C
59 await makeGetRequest({
60 url: server.url,
61 path,
62 token: userAccessToken,
63 statusCodeExpected: 403
64 })
0e1dc3e7
C
65 })
66 })
67
68 describe('When reporting a video abuse', function () {
69 const basePath = '/api/v1/videos/'
70
71 it('Should fail with nothing', async function () {
72 const path = basePath + server.video.id + '/abuse'
73 const fields = {}
74 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
75 })
76
77 it('Should fail with a wrong video', async function () {
78 const wrongPath = '/api/v1/videos/blabla/abuse'
11ba2ab3
C
79 const fields = {
80 reason: 'my super reason'
81 }
53abc4c2 82 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
0e1dc3e7
C
83 })
84
85 it('Should fail with a non authenticated user', async function () {
0e1dc3e7 86 const path = basePath + server.video.id + '/abuse'
11ba2ab3
C
87 const fields = {
88 reason: 'my super reason'
89 }
0e1dc3e7
C
90 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
91 })
92
93 it('Should fail with a reason too short', async function () {
11ba2ab3 94 const path = basePath + server.video.id + '/abuse'
0e1dc3e7
C
95 const fields = {
96 reason: 'h'
97 }
0e1dc3e7
C
98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
99 })
100
101 it('Should fail with a reason too big', async function () {
11ba2ab3 102 const path = basePath + server.video.id + '/abuse'
0e1dc3e7 103 const fields = {
11ba2ab3 104 reason: 'super'.repeat(61)
0e1dc3e7 105 }
0e1dc3e7
C
106 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
107 })
108 })
109
110 after(async function () {
111 killallServers([ server ])
112
113 // Keep the logs if the test failed
114 if (this['ok']) {
115 await flushTests()
116 }
117 })
118})