aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-abuses.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-abuses.js')
-rw-r--r--server/tests/api/check-params/video-abuses.js179
1 files changed, 0 insertions, 179 deletions
diff --git a/server/tests/api/check-params/video-abuses.js b/server/tests/api/check-params/video-abuses.js
deleted file mode 100644
index 8c520aab4..000000000
--- a/server/tests/api/check-params/video-abuses.js
+++ /dev/null
@@ -1,179 +0,0 @@
1/* eslint-disable no-unused-expressions */
2
3'use strict'
4
5const request = require('supertest')
6const series = require('async/series')
7
8const loginUtils = require('../../utils/login')
9const requestsUtils = require('../../utils/requests')
10const serversUtils = require('../../utils/servers')
11const usersUtils = require('../../utils/users')
12const videosUtils = require('../../utils/videos')
13
14describe('Test video abuses API validators', function () {
15 let server = null
16 let userAccessToken = null
17
18 // ---------------------------------------------------------------
19
20 before(function (done) {
21 this.timeout(20000)
22
23 series([
24 function (next) {
25 serversUtils.flushTests(next)
26 },
27 function (next) {
28 serversUtils.runServer(1, function (server1) {
29 server = server1
30
31 next()
32 })
33 },
34 function (next) {
35 loginUtils.loginAndGetAccessToken(server, function (err, token) {
36 if (err) throw err
37 server.accessToken = token
38
39 next()
40 })
41 },
42 function (next) {
43 const username = 'user1'
44 const password = 'my super password'
45
46 usersUtils.createUser(server.url, server.accessToken, username, password, next)
47 },
48 function (next) {
49 const user = {
50 username: 'user1',
51 password: 'my super password'
52 }
53
54 loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
55 if (err) throw err
56
57 userAccessToken = accessToken
58
59 next()
60 })
61 },
62 // Upload some videos on each pods
63 function (next) {
64 const videoAttributes = {}
65 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next)
66 },
67 function (next) {
68 videosUtils.getVideosList(server.url, function (err, res) {
69 if (err) throw err
70
71 const videos = res.body.data
72 server.video = videos[0]
73
74 next()
75 })
76 }
77 ], done)
78 })
79
80 describe('When listing video abuses', function () {
81 const path = '/api/v1/videos/abuse'
82
83 it('Should fail with a bad start pagination', function (done) {
84 request(server.url)
85 .get(path)
86 .query({ start: 'hello' })
87 .set('Authorization', 'Bearer ' + server.accessToken)
88 .set('Accept', 'application/json')
89 .expect(400, done)
90 })
91
92 it('Should fail with a bad count pagination', function (done) {
93 request(server.url)
94 .get(path)
95 .query({ count: 'hello' })
96 .set('Accept', 'application/json')
97 .set('Authorization', 'Bearer ' + server.accessToken)
98 .expect(400, done)
99 })
100
101 it('Should fail with an incorrect sort', function (done) {
102 request(server.url)
103 .get(path)
104 .query({ sort: 'hello' })
105 .set('Accept', 'application/json')
106 .set('Authorization', 'Bearer ' + server.accessToken)
107 .expect(400, done)
108 })
109
110 it('Should fail with a non authenticated user', function (done) {
111 request(server.url)
112 .get(path)
113 .query({ sort: 'hello' })
114 .set('Accept', 'application/json')
115 .expect(401, done)
116 })
117
118 it('Should fail with a non admin user', function (done) {
119 request(server.url)
120 .get(path)
121 .query({ sort: 'hello' })
122 .set('Accept', 'application/json')
123 .set('Authorization', 'Bearer ' + userAccessToken)
124 .expect(403, done)
125 })
126 })
127
128 describe('When reporting a video abuse', function () {
129 const basePath = '/api/v1/videos/'
130
131 it('Should fail with nothing', function (done) {
132 const path = basePath + server.video.id + '/abuse'
133 const data = {}
134 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
135 })
136
137 it('Should fail with a wrong video', function (done) {
138 const wrongPath = '/api/v1/videos/blabla/abuse'
139 const data = {}
140 requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done)
141 })
142
143 it('Should fail with a non authenticated user', function (done) {
144 const data = {}
145 const path = basePath + server.video.id + '/abuse'
146 requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
147 })
148
149 it('Should fail with a reason too short', function (done) {
150 const data = {
151 reason: 'h'
152 }
153 const path = basePath + server.video.id + '/abuse'
154 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
155 })
156
157 it('Should fail with a reason too big', function (done) {
158 const data = {
159 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
160 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
161 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
162 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
163 }
164 const path = basePath + server.video.id + '/abuse'
165 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
166 })
167 })
168
169 after(function (done) {
170 process.kill(-server.app.pid)
171
172 // Keep the logs if the test failed
173 if (this.ok) {
174 serversUtils.flushTests(done)
175 } else {
176 done()
177 }
178 })
179})