]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/video-abuses.ts
Add oembed endpoint
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-abuses.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as request from 'supertest'
4 import 'mocha'
5
6 import {
7 ServerInfo,
8 flushTests,
9 runServer,
10 uploadVideo,
11 getVideosList,
12 createUser,
13 setAccessTokensToServers,
14 killallServers,
15 makePostBodyRequest,
16 getUserAccessToken
17 } from '../../utils'
18
19 describe('Test video abuses API validators', function () {
20 let server: ServerInfo
21 let userAccessToken = ''
22
23 // ---------------------------------------------------------------
24
25 before(async function () {
26 this.timeout(20000)
27
28 await flushTests()
29
30 server = await runServer(1)
31
32 await setAccessTokensToServers([ server ])
33
34 const username = 'user1'
35 const password = 'my super password'
36 await createUser(server.url, server.accessToken, username, password)
37
38 userAccessToken = await getUserAccessToken(server, { username, password })
39
40 // Upload a video
41 const videoAttributes = {}
42 await uploadVideo(server.url, server.accessToken, videoAttributes)
43
44 const res = await getVideosList(server.url)
45 const videos = res.body.data
46 server.video = videos[0]
47 })
48
49 describe('When listing video abuses', function () {
50 const path = '/api/v1/videos/abuse'
51
52 it('Should fail with a bad start pagination', async function () {
53 await request(server.url)
54 .get(path)
55 .query({ start: 'hello' })
56 .set('Authorization', 'Bearer ' + server.accessToken)
57 .set('Accept', 'application/json')
58 .expect(400)
59 })
60
61 it('Should fail with a bad count pagination', async function () {
62 await request(server.url)
63 .get(path)
64 .query({ count: 'hello' })
65 .set('Accept', 'application/json')
66 .set('Authorization', 'Bearer ' + server.accessToken)
67 .expect(400)
68 })
69
70 it('Should fail with an incorrect sort', async function () {
71 await request(server.url)
72 .get(path)
73 .query({ sort: 'hello' })
74 .set('Accept', 'application/json')
75 .set('Authorization', 'Bearer ' + server.accessToken)
76 .expect(400)
77 })
78
79 it('Should fail with a non authenticated user', async function () {
80 await request(server.url)
81 .get(path)
82 .query({ sort: 'hello' })
83 .set('Accept', 'application/json')
84 .expect(401)
85 })
86
87 it('Should fail with a non admin user', async function () {
88 await request(server.url)
89 .get(path)
90 .query({ sort: 'hello' })
91 .set('Accept', 'application/json')
92 .set('Authorization', 'Bearer ' + userAccessToken)
93 .expect(403)
94 })
95 })
96
97 describe('When reporting a video abuse', function () {
98 const basePath = '/api/v1/videos/'
99
100 it('Should fail with nothing', async function () {
101 const path = basePath + server.video.id + '/abuse'
102 const fields = {}
103 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
104 })
105
106 it('Should fail with a wrong video', async function () {
107 const wrongPath = '/api/v1/videos/blabla/abuse'
108 const fields = {}
109 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields})
110 })
111
112 it('Should fail with a non authenticated user', async function () {
113 const fields = {}
114 const path = basePath + server.video.id + '/abuse'
115 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
116 })
117
118 it('Should fail with a reason too short', async function () {
119 const fields = {
120 reason: 'h'
121 }
122 const path = basePath + server.video.id + '/abuse'
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
124 })
125
126 it('Should fail with a reason too big', async function () {
127 const fields = {
128 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
129 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
130 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
131 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
132 }
133 const path = basePath + server.video.id + '/abuse'
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 })
136 })
137
138 after(async function () {
139 killallServers([ server ])
140
141 // Keep the logs if the test failed
142 if (this['ok']) {
143 await flushTests()
144 }
145 })
146 })