aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-abuses.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-abuses.ts')
-rw-r--r--server/tests/api/check-params/video-abuses.ts84
1 files changed, 28 insertions, 56 deletions
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts
index e994ccd49..68e2ce786 100644
--- a/server/tests/api/check-params/video-abuses.ts
+++ b/server/tests/api/check-params/video-abuses.ts
@@ -1,20 +1,12 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as request from 'supertest'
4import 'mocha' 3import 'mocha'
5 4
6import { 5import {
7 ServerInfo, 6 createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
8 flushTests, 7 uploadVideo, userLogin
9 runServer,
10 uploadVideo,
11 getVideosList,
12 createUser,
13 setAccessTokensToServers,
14 killallServers,
15 makePostBodyRequest,
16 userLogin
17} from '../../utils' 8} from '../../utils'
9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
18 10
19describe('Test video abuses API validators', function () { 11describe('Test video abuses API validators', function () {
20 let server: ServerInfo 12 let server: ServerInfo
@@ -34,63 +26,42 @@ describe('Test video abuses API validators', function () {
34 const username = 'user1' 26 const username = 'user1'
35 const password = 'my super password' 27 const password = 'my super password'
36 await createUser(server.url, server.accessToken, username, password) 28 await createUser(server.url, server.accessToken, username, password)
37
38 userAccessToken = await userLogin(server, { username, password }) 29 userAccessToken = await userLogin(server, { username, password })
39 30
40 // Upload a video 31 const res = await uploadVideo(server.url, server.accessToken, {})
41 const videoAttributes = {} 32 server.video = res.body.video
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 }) 33 })
48 34
49 describe('When listing video abuses', function () { 35 describe('When listing video abuses', function () {
50 const path = '/api/v1/videos/abuse' 36 const path = '/api/v1/videos/abuse'
51 37
52 it('Should fail with a bad start pagination', async function () { 38 it('Should fail with a bad start pagination', async function () {
53 await request(server.url) 39 await checkBadStartPagination(server.url, path, server.accessToken)
54 .get(path)
55 .query({ start: 'hello' })
56 .set('Authorization', 'Bearer ' + server.accessToken)
57 .set('Accept', 'application/json')
58 .expect(400)
59 }) 40 })
60 41
61 it('Should fail with a bad count pagination', async function () { 42 it('Should fail with a bad count pagination', async function () {
62 await request(server.url) 43 await checkBadCountPagination(server.url, path, server.accessToken)
63 .get(path)
64 .query({ count: 'hello' })
65 .set('Accept', 'application/json')
66 .set('Authorization', 'Bearer ' + server.accessToken)
67 .expect(400)
68 }) 44 })
69 45
70 it('Should fail with an incorrect sort', async function () { 46 it('Should fail with an incorrect sort', async function () {
71 await request(server.url) 47 await checkBadSortPagination(server.url, path, server.accessToken)
72 .get(path)
73 .query({ sort: 'hello' })
74 .set('Accept', 'application/json')
75 .set('Authorization', 'Bearer ' + server.accessToken)
76 .expect(400)
77 }) 48 })
78 49
79 it('Should fail with a non authenticated user', async function () { 50 it('Should fail with a non authenticated user', async function () {
80 await request(server.url) 51 await makeGetRequest({
81 .get(path) 52 url: server.url,
82 .query({ sort: 'hello' }) 53 path,
83 .set('Accept', 'application/json') 54 statusCodeExpected: 401
84 .expect(401) 55 })
85 }) 56 })
86 57
87 it('Should fail with a non admin user', async function () { 58 it('Should fail with a non admin user', async function () {
88 await request(server.url) 59 await makeGetRequest({
89 .get(path) 60 url: server.url,
90 .query({ sort: 'hello' }) 61 path,
91 .set('Accept', 'application/json') 62 token: userAccessToken,
92 .set('Authorization', 'Bearer ' + userAccessToken) 63 statusCodeExpected: 403
93 .expect(403) 64 })
94 }) 65 })
95 }) 66 })
96 67
@@ -105,32 +76,33 @@ describe('Test video abuses API validators', function () {
105 76
106 it('Should fail with a wrong video', async function () { 77 it('Should fail with a wrong video', async function () {
107 const wrongPath = '/api/v1/videos/blabla/abuse' 78 const wrongPath = '/api/v1/videos/blabla/abuse'
108 const fields = {} 79 const fields = {
80 reason: 'my super reason'
81 }
109 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) 82 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
110 }) 83 })
111 84
112 it('Should fail with a non authenticated user', async function () { 85 it('Should fail with a non authenticated user', async function () {
113 const fields = {}
114 const path = basePath + server.video.id + '/abuse' 86 const path = basePath + server.video.id + '/abuse'
87 const fields = {
88 reason: 'my super reason'
89 }
115 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 90 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
116 }) 91 })
117 92
118 it('Should fail with a reason too short', async function () { 93 it('Should fail with a reason too short', async function () {
94 const path = basePath + server.video.id + '/abuse'
119 const fields = { 95 const fields = {
120 reason: 'h' 96 reason: 'h'
121 } 97 }
122 const path = basePath + server.video.id + '/abuse'
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
124 }) 99 })
125 100
126 it('Should fail with a reason too big', async function () { 101 it('Should fail with a reason too big', async function () {
102 const path = basePath + server.video.id + '/abuse'
127 const fields = { 103 const fields = {
128 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + 104 reason: 'super'.repeat(61)
129 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
130 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
131 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
132 } 105 }
133 const path = basePath + server.video.id + '/abuse'
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 106 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 }) 107 })
136 }) 108 })