diff options
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/index.js | 10 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 8 | ||||
-rw-r--r-- | server/tests/api/check-params/pods.js | 280 | ||||
-rw-r--r-- | server/tests/api/check-params/pods.ts | 259 | ||||
-rw-r--r-- | server/tests/api/check-params/remotes.js | 68 | ||||
-rw-r--r-- | server/tests/api/check-params/remotes.ts | 52 | ||||
-rw-r--r-- | server/tests/api/check-params/request-schedulers.js | 89 | ||||
-rw-r--r-- | server/tests/api/check-params/request-schedulers.ts | 65 | ||||
-rw-r--r-- | server/tests/api/check-params/users.js | 537 | ||||
-rw-r--r-- | server/tests/api/check-params/users.ts | 502 | ||||
-rw-r--r-- | server/tests/api/check-params/video-abuses.js | 179 | ||||
-rw-r--r-- | server/tests/api/check-params/video-abuses.ts | 146 | ||||
-rw-r--r-- | server/tests/api/check-params/video-blacklists.js | 123 | ||||
-rw-r--r-- | server/tests/api/check-params/video-blacklists.ts | 90 | ||||
-rw-r--r-- | server/tests/api/check-params/videos.js | 687 | ||||
-rw-r--r-- | server/tests/api/check-params/videos.ts | 677 |
16 files changed, 1799 insertions, 1973 deletions
diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js deleted file mode 100644 index 1ba16ff32..000000000 --- a/server/tests/api/check-params/index.js +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // Order of the tests we want to execute | ||
4 | require('./pods') | ||
5 | require('./remotes') | ||
6 | require('./users') | ||
7 | require('./request-schedulers') | ||
8 | require('./videos') | ||
9 | require('./video-abuses') | ||
10 | require('./video-blacklists') | ||
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts new file mode 100644 index 000000000..97f2a19d7 --- /dev/null +++ b/server/tests/api/check-params/index.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | // Order of the tests we want to execute | ||
2 | import './pods' | ||
3 | import './remotes' | ||
4 | import './users' | ||
5 | import './request-schedulers' | ||
6 | import './videos' | ||
7 | import './video-abuses' | ||
8 | import './video-blacklists' | ||
diff --git a/server/tests/api/check-params/pods.js b/server/tests/api/check-params/pods.js deleted file mode 100644 index 35ea59093..000000000 --- a/server/tests/api/check-params/pods.js +++ /dev/null | |||
@@ -1,280 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const request = require('supertest') | ||
6 | const series = require('async/series') | ||
7 | |||
8 | const loginUtils = require('../../utils/login') | ||
9 | const requestsUtils = require('../../utils/requests') | ||
10 | const serversUtils = require('../../utils/servers') | ||
11 | const usersUtils = require('../../utils/users') | ||
12 | |||
13 | describe('Test pods API validators', function () { | ||
14 | const path = '/api/v1/pods/' | ||
15 | let server = null | ||
16 | |||
17 | // --------------------------------------------------------------- | ||
18 | |||
19 | before(function (done) { | ||
20 | this.timeout(45000) | ||
21 | |||
22 | series([ | ||
23 | function (next) { | ||
24 | serversUtils.flushTests(next) | ||
25 | }, | ||
26 | function (next) { | ||
27 | serversUtils.runServer(1, function (server1) { | ||
28 | server = server1 | ||
29 | |||
30 | next() | ||
31 | }) | ||
32 | }, | ||
33 | function (next) { | ||
34 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
35 | if (err) throw err | ||
36 | server.accessToken = token | ||
37 | |||
38 | next() | ||
39 | }) | ||
40 | } | ||
41 | ], done) | ||
42 | }) | ||
43 | |||
44 | describe('When managing friends', function () { | ||
45 | let userAccessToken = null | ||
46 | |||
47 | before(function (done) { | ||
48 | usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { | ||
49 | server.user = { | ||
50 | username: 'user1', | ||
51 | password: 'password' | ||
52 | } | ||
53 | |||
54 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
55 | if (err) throw err | ||
56 | |||
57 | userAccessToken = accessToken | ||
58 | |||
59 | done() | ||
60 | }) | ||
61 | }) | ||
62 | }) | ||
63 | |||
64 | describe('When making friends', function () { | ||
65 | const body = { | ||
66 | hosts: [ 'localhost:9002' ] | ||
67 | } | ||
68 | |||
69 | it('Should fail without hosts', function (done) { | ||
70 | request(server.url) | ||
71 | .post(path + '/makefriends') | ||
72 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
73 | .set('Accept', 'application/json') | ||
74 | .expect(400, done) | ||
75 | }) | ||
76 | |||
77 | it('Should fail if hosts is not an array', function (done) { | ||
78 | request(server.url) | ||
79 | .post(path + '/makefriends') | ||
80 | .send({ hosts: 'localhost:9002' }) | ||
81 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
82 | .set('Accept', 'application/json') | ||
83 | .expect(400, done) | ||
84 | }) | ||
85 | |||
86 | it('Should fail if the array is not composed by hosts', function (done) { | ||
87 | request(server.url) | ||
88 | .post(path + '/makefriends') | ||
89 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) | ||
90 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
91 | .set('Accept', 'application/json') | ||
92 | .expect(400, done) | ||
93 | }) | ||
94 | |||
95 | it('Should fail if the array is composed with http schemes', function (done) { | ||
96 | request(server.url) | ||
97 | .post(path + '/makefriends') | ||
98 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) | ||
99 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
100 | .set('Accept', 'application/json') | ||
101 | .expect(400, done) | ||
102 | }) | ||
103 | |||
104 | it('Should fail if hosts are not unique', function (done) { | ||
105 | request(server.url) | ||
106 | .post(path + '/makefriends') | ||
107 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | ||
108 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
109 | .set('Accept', 'application/json') | ||
110 | .expect(400, done) | ||
111 | }) | ||
112 | |||
113 | it('Should fail with an invalid token', function (done) { | ||
114 | request(server.url) | ||
115 | .post(path + '/makefriends') | ||
116 | .send(body) | ||
117 | .set('Authorization', 'Bearer faketoken') | ||
118 | .set('Accept', 'application/json') | ||
119 | .expect(401, done) | ||
120 | }) | ||
121 | |||
122 | it('Should fail if the user is not an administrator', function (done) { | ||
123 | request(server.url) | ||
124 | .post(path + '/makefriends') | ||
125 | .send(body) | ||
126 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
127 | .set('Accept', 'application/json') | ||
128 | .expect(403, done) | ||
129 | }) | ||
130 | }) | ||
131 | |||
132 | describe('When quitting friends', function () { | ||
133 | it('Should fail with an invalid token', function (done) { | ||
134 | request(server.url) | ||
135 | .get(path + '/quitfriends') | ||
136 | .query({ start: 'hello' }) | ||
137 | .set('Authorization', 'Bearer faketoken') | ||
138 | .set('Accept', 'application/json') | ||
139 | .expect(401, done) | ||
140 | }) | ||
141 | |||
142 | it('Should fail if the user is not an administrator', function (done) { | ||
143 | request(server.url) | ||
144 | .get(path + '/quitfriends') | ||
145 | .query({ start: 'hello' }) | ||
146 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
147 | .set('Accept', 'application/json') | ||
148 | .expect(403, done) | ||
149 | }) | ||
150 | }) | ||
151 | |||
152 | describe('When removing one friend', function () { | ||
153 | it('Should fail with an invalid token', function (done) { | ||
154 | request(server.url) | ||
155 | .delete(path + '/1') | ||
156 | .set('Authorization', 'Bearer faketoken') | ||
157 | .set('Accept', 'application/json') | ||
158 | .expect(401, done) | ||
159 | }) | ||
160 | |||
161 | it('Should fail if the user is not an administrator', function (done) { | ||
162 | request(server.url) | ||
163 | .delete(path + '/1') | ||
164 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
165 | .set('Accept', 'application/json') | ||
166 | .expect(403, done) | ||
167 | }) | ||
168 | |||
169 | it('Should fail with an undefined id', function (done) { | ||
170 | request(server.url) | ||
171 | .delete(path + '/' + undefined) | ||
172 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
173 | .set('Accept', 'application/json') | ||
174 | .expect(400, done) | ||
175 | }) | ||
176 | |||
177 | it('Should fail with an invalid id', function (done) { | ||
178 | request(server.url) | ||
179 | .delete(path + '/foobar') | ||
180 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
181 | .set('Accept', 'application/json') | ||
182 | .expect(400, done) | ||
183 | }) | ||
184 | |||
185 | it('Should fail if the pod is not a friend', function (done) { | ||
186 | request(server.url) | ||
187 | .delete(path + '/-1') | ||
188 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
189 | .set('Accept', 'application/json') | ||
190 | .expect(404, done) | ||
191 | }) | ||
192 | |||
193 | it('Should succeed with the correct parameters') | ||
194 | }) | ||
195 | }) | ||
196 | |||
197 | describe('When adding a pod', function () { | ||
198 | it('Should fail with nothing', function (done) { | ||
199 | const data = {} | ||
200 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
201 | }) | ||
202 | |||
203 | it('Should fail without public key', function (done) { | ||
204 | const data = { | ||
205 | email: 'testexample.com', | ||
206 | host: 'coucou.com' | ||
207 | } | ||
208 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
209 | }) | ||
210 | |||
211 | it('Should fail without an email', function (done) { | ||
212 | const data = { | ||
213 | host: 'coucou.com', | ||
214 | publicKey: 'mysuperpublickey' | ||
215 | } | ||
216 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
217 | }) | ||
218 | |||
219 | it('Should fail without an invalid email', function (done) { | ||
220 | const data = { | ||
221 | host: 'coucou.com', | ||
222 | email: 'testexample.com', | ||
223 | publicKey: 'mysuperpublickey' | ||
224 | } | ||
225 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
226 | }) | ||
227 | |||
228 | it('Should fail without a host', function (done) { | ||
229 | const data = { | ||
230 | email: 'testexample.com', | ||
231 | publicKey: 'mysuperpublickey' | ||
232 | } | ||
233 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
234 | }) | ||
235 | |||
236 | it('Should fail with an incorrect host', function (done) { | ||
237 | const data = { | ||
238 | host: 'http://coucou.com', | ||
239 | email: 'testexample.com', | ||
240 | publicKey: 'mysuperpublickey' | ||
241 | } | ||
242 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
243 | data.host = 'http://coucou' | ||
244 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
245 | data.host = 'coucou' | ||
246 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
247 | }) | ||
248 | }) | ||
249 | }) | ||
250 | |||
251 | it('Should succeed with the correct parameters', function (done) { | ||
252 | const data = { | ||
253 | host: 'coucou.com', | ||
254 | email: 'test@example.com', | ||
255 | publicKey: 'mysuperpublickey' | ||
256 | } | ||
257 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) | ||
258 | }) | ||
259 | |||
260 | it('Should fail with a host that already exists', function (done) { | ||
261 | const data = { | ||
262 | host: 'coucou.com', | ||
263 | email: 'test@example.com', | ||
264 | publicKey: 'mysuperpublickey' | ||
265 | } | ||
266 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 409) | ||
267 | }) | ||
268 | }) | ||
269 | |||
270 | after(function (done) { | ||
271 | process.kill(-server.app.pid) | ||
272 | |||
273 | // Keep the logs if the test failed | ||
274 | if (this.ok) { | ||
275 | serversUtils.flushTests(done) | ||
276 | } else { | ||
277 | done() | ||
278 | } | ||
279 | }) | ||
280 | }) | ||
diff --git a/server/tests/api/check-params/pods.ts b/server/tests/api/check-params/pods.ts new file mode 100644 index 000000000..27c080931 --- /dev/null +++ b/server/tests/api/check-params/pods.ts | |||
@@ -0,0 +1,259 @@ | |||
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 | createUser, | ||
11 | loginAndGetAccessToken, | ||
12 | setAccessTokensToServers, | ||
13 | killallServers, | ||
14 | makePostBodyRequest | ||
15 | } from '../../utils' | ||
16 | |||
17 | describe('Test pods API validators', function () { | ||
18 | const path = '/api/v1/pods/' | ||
19 | let server: ServerInfo | ||
20 | |||
21 | // --------------------------------------------------------------- | ||
22 | |||
23 | before(async function () { | ||
24 | this.timeout(45000) | ||
25 | |||
26 | await flushTests() | ||
27 | server = await runServer(1) | ||
28 | |||
29 | await setAccessTokensToServers([ server ]) | ||
30 | }) | ||
31 | |||
32 | describe('When managing friends', function () { | ||
33 | let userAccessToken = null | ||
34 | |||
35 | before(async function () { | ||
36 | await createUser(server.url, server.accessToken, 'user1', 'password') | ||
37 | server.user = { | ||
38 | username: 'user1', | ||
39 | password: 'password' | ||
40 | } | ||
41 | |||
42 | userAccessToken = await loginAndGetAccessToken(server) | ||
43 | }) | ||
44 | |||
45 | describe('When making friends', function () { | ||
46 | const body = { | ||
47 | hosts: [ 'localhost:9002' ] | ||
48 | } | ||
49 | |||
50 | it('Should fail without hosts', async function () { | ||
51 | await request(server.url) | ||
52 | .post(path + '/makefriends') | ||
53 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
54 | .set('Accept', 'application/json') | ||
55 | .expect(400) | ||
56 | }) | ||
57 | |||
58 | it('Should fail if hosts is not an array', async function () { | ||
59 | await request(server.url) | ||
60 | .post(path + '/makefriends') | ||
61 | .send({ hosts: 'localhost:9002' }) | ||
62 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
63 | .set('Accept', 'application/json') | ||
64 | .expect(400) | ||
65 | }) | ||
66 | |||
67 | it('Should fail if the array is not composed by hosts', async function () { | ||
68 | await request(server.url) | ||
69 | .post(path + '/makefriends') | ||
70 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) | ||
71 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
72 | .set('Accept', 'application/json') | ||
73 | .expect(400) | ||
74 | }) | ||
75 | |||
76 | it('Should fail if the array is composed with http schemes', async function () { | ||
77 | await request(server.url) | ||
78 | .post(path + '/makefriends') | ||
79 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) | ||
80 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
81 | .set('Accept', 'application/json') | ||
82 | .expect(400) | ||
83 | }) | ||
84 | |||
85 | it('Should fail if hosts are not unique', async function () { | ||
86 | await request(server.url) | ||
87 | .post(path + '/makefriends') | ||
88 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | ||
89 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
90 | .set('Accept', 'application/json') | ||
91 | .expect(400) | ||
92 | }) | ||
93 | |||
94 | it('Should fail with an invalid token', async function () { | ||
95 | await request(server.url) | ||
96 | .post(path + '/makefriends') | ||
97 | .send(body) | ||
98 | .set('Authorization', 'Bearer faketoken') | ||
99 | .set('Accept', 'application/json') | ||
100 | .expect(401) | ||
101 | }) | ||
102 | |||
103 | it('Should fail if the user is not an administrator', async function () { | ||
104 | await request(server.url) | ||
105 | .post(path + '/makefriends') | ||
106 | .send(body) | ||
107 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
108 | .set('Accept', 'application/json') | ||
109 | .expect(403) | ||
110 | }) | ||
111 | }) | ||
112 | |||
113 | describe('When quitting friends', function () { | ||
114 | it('Should fail with an invalid token', async function () { | ||
115 | await request(server.url) | ||
116 | .get(path + '/quitfriends') | ||
117 | .query({ start: 'hello' }) | ||
118 | .set('Authorization', 'Bearer faketoken') | ||
119 | .set('Accept', 'application/json') | ||
120 | .expect(401) | ||
121 | }) | ||
122 | |||
123 | it('Should fail if the user is not an administrator', async function () { | ||
124 | await request(server.url) | ||
125 | .get(path + '/quitfriends') | ||
126 | .query({ start: 'hello' }) | ||
127 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
128 | .set('Accept', 'application/json') | ||
129 | .expect(403) | ||
130 | }) | ||
131 | }) | ||
132 | |||
133 | describe('When removing one friend', function () { | ||
134 | it('Should fail with an invalid token', async function () { | ||
135 | await request(server.url) | ||
136 | .delete(path + '/1') | ||
137 | .set('Authorization', 'Bearer faketoken') | ||
138 | .set('Accept', 'application/json') | ||
139 | .expect(401) | ||
140 | }) | ||
141 | |||
142 | it('Should fail if the user is not an administrator', async function () { | ||
143 | await request(server.url) | ||
144 | .delete(path + '/1') | ||
145 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
146 | .set('Accept', 'application/json') | ||
147 | .expect(403) | ||
148 | }) | ||
149 | |||
150 | it('Should fail with an undefined id', async function () { | ||
151 | await request(server.url) | ||
152 | .delete(path + '/' + undefined) | ||
153 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
154 | .set('Accept', 'application/json') | ||
155 | .expect(400) | ||
156 | }) | ||
157 | |||
158 | it('Should fail with an invalid id', async function () { | ||
159 | await request(server.url) | ||
160 | .delete(path + '/foobar') | ||
161 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
162 | .set('Accept', 'application/json') | ||
163 | .expect(400) | ||
164 | }) | ||
165 | |||
166 | it('Should fail if the pod is not a friend', async function () { | ||
167 | await request(server.url) | ||
168 | .delete(path + '/-1') | ||
169 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
170 | .set('Accept', 'application/json') | ||
171 | .expect(404) | ||
172 | }) | ||
173 | |||
174 | it('Should succeed with the correct parameters') | ||
175 | }) | ||
176 | }) | ||
177 | |||
178 | describe('When adding a pod', function () { | ||
179 | it('Should fail with nothing', async function () { | ||
180 | const fields = {} | ||
181 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
182 | }) | ||
183 | |||
184 | it('Should fail without public key', async function () { | ||
185 | const fields = { | ||
186 | email: 'test.example.com', | ||
187 | host: 'coucou.com' | ||
188 | } | ||
189 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
190 | }) | ||
191 | |||
192 | it('Should fail without an email', async function () { | ||
193 | const fields = { | ||
194 | host: 'coucou.com', | ||
195 | publicKey: 'my super public key' | ||
196 | } | ||
197 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
198 | }) | ||
199 | |||
200 | it('Should fail without an invalid email', async function () { | ||
201 | const fields = { | ||
202 | host: 'coucou.com', | ||
203 | email: 'test.example.com', | ||
204 | publicKey: 'my super public key' | ||
205 | } | ||
206 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
207 | }) | ||
208 | |||
209 | it('Should fail without a host', async function () { | ||
210 | const fields = { | ||
211 | email: 'test.example.com', | ||
212 | publicKey: 'my super public key' | ||
213 | } | ||
214 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
215 | }) | ||
216 | |||
217 | it('Should fail with an incorrect host', async function () { | ||
218 | const fields = { | ||
219 | host: 'http://coucou.com', | ||
220 | email: 'test.example.com', | ||
221 | publicKey: 'my super public key' | ||
222 | } | ||
223 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
224 | |||
225 | fields.host = 'http://coucou' | ||
226 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
227 | |||
228 | fields.host = 'coucou' | ||
229 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
230 | }) | ||
231 | |||
232 | it('Should succeed with the correct parameters', async function () { | ||
233 | const fields = { | ||
234 | host: 'coucou.com', | ||
235 | email: 'test@example.com', | ||
236 | publicKey: 'my super public key' | ||
237 | } | ||
238 | await makePostBodyRequest({ url: server.url, path, fields, statusCodeExpected: 200 }) | ||
239 | }) | ||
240 | |||
241 | it('Should fail with a host that already exists', async function () { | ||
242 | const fields = { | ||
243 | host: 'coucou.com', | ||
244 | email: 'test@example.com', | ||
245 | publicKey: 'my super public key' | ||
246 | } | ||
247 | await makePostBodyRequest({ url: server.url, path, fields, statusCodeExpected: 409 }) | ||
248 | }) | ||
249 | }) | ||
250 | |||
251 | after(async function () { | ||
252 | killallServers([ server ]) | ||
253 | |||
254 | // Keep the logs if the test failed | ||
255 | if (this['ok']) { | ||
256 | await flushTests() | ||
257 | } | ||
258 | }) | ||
259 | }) | ||
diff --git a/server/tests/api/check-params/remotes.js b/server/tests/api/check-params/remotes.js deleted file mode 100644 index 7cb99c4ae..000000000 --- a/server/tests/api/check-params/remotes.js +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const series = require('async/series') | ||
6 | |||
7 | const loginUtils = require('../../utils/login') | ||
8 | const serversUtils = require('../../utils/servers') | ||
9 | |||
10 | describe('Test remote videos API validators', function () { | ||
11 | let server = null | ||
12 | |||
13 | // --------------------------------------------------------------- | ||
14 | |||
15 | before(function (done) { | ||
16 | this.timeout(20000) | ||
17 | |||
18 | series([ | ||
19 | function (next) { | ||
20 | serversUtils.flushTests(next) | ||
21 | }, | ||
22 | function (next) { | ||
23 | serversUtils.runServer(1, function (server1) { | ||
24 | server = server1 | ||
25 | |||
26 | next() | ||
27 | }) | ||
28 | }, | ||
29 | function (next) { | ||
30 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
31 | if (err) throw err | ||
32 | server.accessToken = token | ||
33 | |||
34 | next() | ||
35 | }) | ||
36 | } | ||
37 | ], done) | ||
38 | }) | ||
39 | |||
40 | describe('When making a secure request', function () { | ||
41 | it('Should check a secure request') | ||
42 | }) | ||
43 | |||
44 | describe('When adding a video', function () { | ||
45 | it('Should check when adding a video') | ||
46 | |||
47 | it('Should not add an existing uuid') | ||
48 | }) | ||
49 | |||
50 | describe('When removing a video', function () { | ||
51 | it('Should check when removing a video') | ||
52 | }) | ||
53 | |||
54 | describe('When reporting abuse on a video', function () { | ||
55 | it('Should check when reporting a video abuse') | ||
56 | }) | ||
57 | |||
58 | after(function (done) { | ||
59 | process.kill(-server.app.pid) | ||
60 | |||
61 | // Keep the logs if the test failed | ||
62 | if (this.ok) { | ||
63 | serversUtils.flushTests(done) | ||
64 | } else { | ||
65 | done() | ||
66 | } | ||
67 | }) | ||
68 | }) | ||
diff --git a/server/tests/api/check-params/remotes.ts b/server/tests/api/check-params/remotes.ts new file mode 100644 index 000000000..b36f1c08b --- /dev/null +++ b/server/tests/api/check-params/remotes.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import { | ||
4 | ServerInfo, | ||
5 | flushTests, | ||
6 | runServer, | ||
7 | setAccessTokensToServers, | ||
8 | killallServers | ||
9 | } from '../../utils' | ||
10 | |||
11 | describe('Test remote videos API validators', function () { | ||
12 | let server: ServerInfo | ||
13 | |||
14 | // --------------------------------------------------------------- | ||
15 | |||
16 | before(async function () { | ||
17 | this.timeout(20000) | ||
18 | |||
19 | await flushTests() | ||
20 | |||
21 | server = await runServer(1) | ||
22 | |||
23 | await setAccessTokensToServers([ server ]) | ||
24 | }) | ||
25 | |||
26 | describe('When making a secure request', async function () { | ||
27 | it('Should check a secure request') | ||
28 | }) | ||
29 | |||
30 | describe('When adding a video', async function () { | ||
31 | it('Should check when adding a video') | ||
32 | |||
33 | it('Should not add an existing uuid') | ||
34 | }) | ||
35 | |||
36 | describe('When removing a video', async function () { | ||
37 | it('Should check when removing a video') | ||
38 | }) | ||
39 | |||
40 | describe('When reporting abuse on a video', async function () { | ||
41 | it('Should check when reporting a video abuse') | ||
42 | }) | ||
43 | |||
44 | after(async function () { | ||
45 | killallServers([ server ]) | ||
46 | |||
47 | // Keep the logs if the test failed | ||
48 | if (this['ok']) { | ||
49 | await flushTests() | ||
50 | } | ||
51 | }) | ||
52 | }) | ||
diff --git a/server/tests/api/check-params/request-schedulers.js b/server/tests/api/check-params/request-schedulers.js deleted file mode 100644 index 9ba0df730..000000000 --- a/server/tests/api/check-params/request-schedulers.js +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const request = require('supertest') | ||
6 | const series = require('async/series') | ||
7 | |||
8 | const loginUtils = require('../../utils/login') | ||
9 | const usersUtils = require('../../utils/users') | ||
10 | const serversUtils = require('../../utils/servers') | ||
11 | |||
12 | describe('Test request schedulers stats API validators', function () { | ||
13 | const path = '/api/v1/request-schedulers/stats' | ||
14 | let server = null | ||
15 | let userAccessToken = null | ||
16 | |||
17 | // --------------------------------------------------------------- | ||
18 | |||
19 | before(function (done) { | ||
20 | this.timeout(20000) | ||
21 | |||
22 | series([ | ||
23 | function (next) { | ||
24 | serversUtils.flushTests(next) | ||
25 | }, | ||
26 | function (next) { | ||
27 | serversUtils.runServer(1, function (server1) { | ||
28 | server = server1 | ||
29 | |||
30 | next() | ||
31 | }) | ||
32 | }, | ||
33 | function (next) { | ||
34 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
35 | if (err) throw err | ||
36 | server.accessToken = token | ||
37 | |||
38 | next() | ||
39 | }) | ||
40 | }, | ||
41 | function (next) { | ||
42 | const username = 'user' | ||
43 | const password = 'my super password' | ||
44 | |||
45 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | ||
46 | }, | ||
47 | function (next) { | ||
48 | const user = { | ||
49 | username: 'user', | ||
50 | password: 'my super password' | ||
51 | } | ||
52 | |||
53 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | ||
54 | if (err) throw err | ||
55 | |||
56 | userAccessToken = accessToken | ||
57 | |||
58 | next() | ||
59 | }) | ||
60 | } | ||
61 | ], done) | ||
62 | }) | ||
63 | |||
64 | it('Should fail with an non authenticated user', function (done) { | ||
65 | request(server.url) | ||
66 | .get(path) | ||
67 | .set('Accept', 'application/json') | ||
68 | .expect(401, done) | ||
69 | }) | ||
70 | |||
71 | it('Should fail with a non admin user', function (done) { | ||
72 | request(server.url) | ||
73 | .get(path) | ||
74 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
75 | .set('Accept', 'application/json') | ||
76 | .expect(403, done) | ||
77 | }) | ||
78 | |||
79 | after(function (done) { | ||
80 | process.kill(-server.app.pid) | ||
81 | |||
82 | // Keep the logs if the test failed | ||
83 | if (this.ok) { | ||
84 | serversUtils.flushTests(done) | ||
85 | } else { | ||
86 | done() | ||
87 | } | ||
88 | }) | ||
89 | }) | ||
diff --git a/server/tests/api/check-params/request-schedulers.ts b/server/tests/api/check-params/request-schedulers.ts new file mode 100644 index 000000000..c39f5947b --- /dev/null +++ b/server/tests/api/check-params/request-schedulers.ts | |||
@@ -0,0 +1,65 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as request from 'supertest' | ||
4 | import 'mocha' | ||
5 | |||
6 | import { | ||
7 | flushTests, | ||
8 | runServer, | ||
9 | createUser, | ||
10 | setAccessTokensToServers, | ||
11 | killallServers, | ||
12 | getUserAccessToken | ||
13 | } from '../../utils' | ||
14 | |||
15 | describe('Test request schedulers stats API validators', function () { | ||
16 | const path = '/api/v1/request-schedulers/stats' | ||
17 | let server = null | ||
18 | let userAccessToken = null | ||
19 | |||
20 | // --------------------------------------------------------------- | ||
21 | |||
22 | before(async function () { | ||
23 | this.timeout(20000) | ||
24 | |||
25 | await flushTests() | ||
26 | |||
27 | server = await runServer(1) | ||
28 | await setAccessTokensToServers([ server ]) | ||
29 | |||
30 | const username = 'user' | ||
31 | const password = 'my super password' | ||
32 | await createUser(server.url, server.accessToken, username, password) | ||
33 | |||
34 | const user = { | ||
35 | username: 'user', | ||
36 | password: 'my super password' | ||
37 | } | ||
38 | |||
39 | userAccessToken = await getUserAccessToken(server, user) | ||
40 | }) | ||
41 | |||
42 | it('Should fail with an non authenticated user', async function () { | ||
43 | await request(server.url) | ||
44 | .get(path) | ||
45 | .set('Accept', 'application/json') | ||
46 | .expect(401) | ||
47 | }) | ||
48 | |||
49 | it('Should fail with a non admin user', async function () { | ||
50 | await request(server.url) | ||
51 | .get(path) | ||
52 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
53 | .set('Accept', 'application/json') | ||
54 | .expect(403) | ||
55 | }) | ||
56 | |||
57 | after(async function () { | ||
58 | killallServers([ server ]) | ||
59 | |||
60 | // Keep the logs if the test failed | ||
61 | if (this['ok']) { | ||
62 | await flushTests() | ||
63 | } | ||
64 | }) | ||
65 | }) | ||
diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js deleted file mode 100644 index 9e7115da1..000000000 --- a/server/tests/api/check-params/users.js +++ /dev/null | |||
@@ -1,537 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const request = require('supertest') | ||
6 | const series = require('async/series') | ||
7 | |||
8 | const loginUtils = require('../../utils/login') | ||
9 | const requestsUtils = require('../../utils/requests') | ||
10 | const serversUtils = require('../../utils/servers') | ||
11 | const usersUtils = require('../../utils/users') | ||
12 | const videosUtils = require('../../utils/videos') | ||
13 | |||
14 | describe('Test users API validators', function () { | ||
15 | const path = '/api/v1/users/' | ||
16 | let userId = null | ||
17 | let rootId = null | ||
18 | let videoId = null | ||
19 | let server = null | ||
20 | let serverWithRegistrationDisabled = null | ||
21 | let userAccessToken = null | ||
22 | |||
23 | // --------------------------------------------------------------- | ||
24 | |||
25 | before(function (done) { | ||
26 | this.timeout(120000) | ||
27 | |||
28 | series([ | ||
29 | function (next) { | ||
30 | serversUtils.flushTests(next) | ||
31 | }, | ||
32 | function (next) { | ||
33 | serversUtils.runServer(1, function (serverCreated) { | ||
34 | server = serverCreated | ||
35 | |||
36 | next() | ||
37 | }) | ||
38 | }, | ||
39 | function (next) { | ||
40 | serversUtils.runServer(2, function (serverCreated) { | ||
41 | serverWithRegistrationDisabled = serverCreated | ||
42 | |||
43 | next() | ||
44 | }) | ||
45 | }, | ||
46 | function (next) { | ||
47 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
48 | if (err) throw err | ||
49 | server.accessToken = token | ||
50 | |||
51 | next() | ||
52 | }) | ||
53 | }, | ||
54 | function (next) { | ||
55 | const username = 'user1' | ||
56 | const password = 'my super password' | ||
57 | |||
58 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | ||
59 | }, | ||
60 | function (next) { | ||
61 | const videoAttributes = {} | ||
62 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next) | ||
63 | }, | ||
64 | function (next) { | ||
65 | videosUtils.getVideosList(server.url, function (err, res) { | ||
66 | if (err) throw err | ||
67 | |||
68 | const videos = res.body.data | ||
69 | videoId = videos[0].id | ||
70 | |||
71 | next() | ||
72 | }) | ||
73 | }, | ||
74 | function (next) { | ||
75 | const user = { | ||
76 | username: 'user1', | ||
77 | password: 'my super password' | ||
78 | } | ||
79 | |||
80 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | ||
81 | if (err) throw err | ||
82 | |||
83 | userAccessToken = accessToken | ||
84 | |||
85 | next() | ||
86 | }) | ||
87 | } | ||
88 | ], done) | ||
89 | }) | ||
90 | |||
91 | describe('When listing users', function () { | ||
92 | it('Should fail with a bad start pagination', function (done) { | ||
93 | request(server.url) | ||
94 | .get(path) | ||
95 | .query({ start: 'hello' }) | ||
96 | .set('Accept', 'application/json') | ||
97 | .expect(400, done) | ||
98 | }) | ||
99 | |||
100 | it('Should fail with a bad count pagination', function (done) { | ||
101 | request(server.url) | ||
102 | .get(path) | ||
103 | .query({ count: 'hello' }) | ||
104 | .set('Accept', 'application/json') | ||
105 | .expect(400, done) | ||
106 | }) | ||
107 | |||
108 | it('Should fail with an incorrect sort', function (done) { | ||
109 | request(server.url) | ||
110 | .get(path) | ||
111 | .query({ sort: 'hello' }) | ||
112 | .set('Accept', 'application/json') | ||
113 | .expect(400, done) | ||
114 | }) | ||
115 | }) | ||
116 | |||
117 | describe('When adding a new user', function () { | ||
118 | it('Should fail with a too small username', function (done) { | ||
119 | const data = { | ||
120 | username: 'ji', | ||
121 | email: 'test@example.com', | ||
122 | password: 'mysuperpassword' | ||
123 | } | ||
124 | |||
125 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
126 | }) | ||
127 | |||
128 | it('Should fail with a too long username', function (done) { | ||
129 | const data = { | ||
130 | username: 'mysuperusernamewhichisverylong', | ||
131 | email: 'test@example.com', | ||
132 | password: 'mysuperpassword' | ||
133 | } | ||
134 | |||
135 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
136 | }) | ||
137 | |||
138 | it('Should fail with an incorrect username', function (done) { | ||
139 | const data = { | ||
140 | username: 'my username', | ||
141 | email: 'test@example.com', | ||
142 | password: 'mysuperpassword' | ||
143 | } | ||
144 | |||
145 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
146 | }) | ||
147 | |||
148 | it('Should fail with a missing email', function (done) { | ||
149 | const data = { | ||
150 | username: 'ji', | ||
151 | password: 'mysuperpassword' | ||
152 | } | ||
153 | |||
154 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
155 | }) | ||
156 | |||
157 | it('Should fail with an invalid email', function (done) { | ||
158 | const data = { | ||
159 | username: 'mysuperusernamewhichisverylong', | ||
160 | email: 'testexample.com', | ||
161 | password: 'mysuperpassword' | ||
162 | } | ||
163 | |||
164 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
165 | }) | ||
166 | |||
167 | it('Should fail with a too small password', function (done) { | ||
168 | const data = { | ||
169 | username: 'myusername', | ||
170 | email: 'test@example.com', | ||
171 | password: 'bla' | ||
172 | } | ||
173 | |||
174 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
175 | }) | ||
176 | |||
177 | it('Should fail with a too long password', function (done) { | ||
178 | const data = { | ||
179 | username: 'myusername', | ||
180 | email: 'test@example.com', | ||
181 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
182 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
183 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
184 | } | ||
185 | |||
186 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
187 | }) | ||
188 | |||
189 | it('Should fail with an non authenticated user', function (done) { | ||
190 | const data = { | ||
191 | username: 'myusername', | ||
192 | email: 'test@example.com', | ||
193 | password: 'my super password' | ||
194 | } | ||
195 | |||
196 | requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) | ||
197 | }) | ||
198 | |||
199 | it('Should fail if we add a user with the same username', function (done) { | ||
200 | const data = { | ||
201 | username: 'user1', | ||
202 | email: 'test@example.com', | ||
203 | password: 'my super password' | ||
204 | } | ||
205 | |||
206 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) | ||
207 | }) | ||
208 | |||
209 | it('Should fail if we add a user with the same email', function (done) { | ||
210 | const data = { | ||
211 | username: 'myusername', | ||
212 | email: 'user1@example.com', | ||
213 | password: 'my super password' | ||
214 | } | ||
215 | |||
216 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) | ||
217 | }) | ||
218 | |||
219 | it('Should succeed with the correct params', function (done) { | ||
220 | const data = { | ||
221 | username: 'user2', | ||
222 | email: 'test@example.com', | ||
223 | password: 'my super password' | ||
224 | } | ||
225 | |||
226 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) | ||
227 | }) | ||
228 | |||
229 | it('Should fail with a non admin user', function (done) { | ||
230 | server.user = { | ||
231 | username: 'user1', | ||
232 | email: 'test@example.com', | ||
233 | password: 'my super password' | ||
234 | } | ||
235 | |||
236 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
237 | if (err) throw err | ||
238 | |||
239 | userAccessToken = accessToken | ||
240 | |||
241 | const data = { | ||
242 | username: 'user3', | ||
243 | email: 'test@example.com', | ||
244 | password: 'my super password' | ||
245 | } | ||
246 | |||
247 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) | ||
248 | }) | ||
249 | }) | ||
250 | }) | ||
251 | |||
252 | describe('When updating a user', function () { | ||
253 | before(function (done) { | ||
254 | usersUtils.getUsersList(server.url, function (err, res) { | ||
255 | if (err) throw err | ||
256 | |||
257 | userId = res.body.data[1].id | ||
258 | rootId = res.body.data[2].id | ||
259 | done() | ||
260 | }) | ||
261 | }) | ||
262 | |||
263 | it('Should fail with a too small password', function (done) { | ||
264 | const data = { | ||
265 | password: 'bla' | ||
266 | } | ||
267 | |||
268 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
269 | }) | ||
270 | |||
271 | it('Should fail with a too long password', function (done) { | ||
272 | const data = { | ||
273 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
274 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
275 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
276 | } | ||
277 | |||
278 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
279 | }) | ||
280 | |||
281 | it('Should fail with an invalid display NSFW attribute', function (done) { | ||
282 | const data = { | ||
283 | displayNSFW: -1 | ||
284 | } | ||
285 | |||
286 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
287 | }) | ||
288 | |||
289 | it('Should fail with an non authenticated user', function (done) { | ||
290 | const data = { | ||
291 | password: 'my super password' | ||
292 | } | ||
293 | |||
294 | requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) | ||
295 | }) | ||
296 | |||
297 | it('Should succeed with the correct params', function (done) { | ||
298 | const data = { | ||
299 | password: 'my super password', | ||
300 | displayNSFW: true | ||
301 | } | ||
302 | |||
303 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) | ||
304 | }) | ||
305 | }) | ||
306 | |||
307 | describe('When getting my information', function () { | ||
308 | it('Should fail with a non authenticated user', function (done) { | ||
309 | request(server.url) | ||
310 | .get(path + 'me') | ||
311 | .set('Authorization', 'Bearer faketoken') | ||
312 | .set('Accept', 'application/json') | ||
313 | .expect(401, done) | ||
314 | }) | ||
315 | |||
316 | it('Should success with the correct parameters', function (done) { | ||
317 | request(server.url) | ||
318 | .get(path + 'me') | ||
319 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
320 | .set('Accept', 'application/json') | ||
321 | .expect(200, done) | ||
322 | }) | ||
323 | }) | ||
324 | |||
325 | describe('When getting my video rating', function () { | ||
326 | it('Should fail with a non authenticated user', function (done) { | ||
327 | request(server.url) | ||
328 | .get(path + 'me/videos/' + videoId + '/rating') | ||
329 | .set('Authorization', 'Bearer faketoken') | ||
330 | .set('Accept', 'application/json') | ||
331 | .expect(401, done) | ||
332 | }) | ||
333 | |||
334 | it('Should fail with an incorrect video uuid', function (done) { | ||
335 | request(server.url) | ||
336 | .get(path + 'me/videos/blabla/rating') | ||
337 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
338 | .set('Accept', 'application/json') | ||
339 | .expect(400, done) | ||
340 | }) | ||
341 | |||
342 | it('Should fail with an unknown video', function (done) { | ||
343 | request(server.url) | ||
344 | .get(path + 'me/videos/4da6fde3-88f7-4d16-b119-108df5630b06/rating') | ||
345 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
346 | .set('Accept', 'application/json') | ||
347 | .expect(404, done) | ||
348 | }) | ||
349 | |||
350 | it('Should success with the correct parameters', function (done) { | ||
351 | request(server.url) | ||
352 | .get(path + 'me/videos/' + videoId + '/rating') | ||
353 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
354 | .set('Accept', 'application/json') | ||
355 | .expect(200, done) | ||
356 | }) | ||
357 | }) | ||
358 | |||
359 | describe('When removing an user', function () { | ||
360 | it('Should fail with an incorrect id', function (done) { | ||
361 | request(server.url) | ||
362 | .delete(path + 'bla-bla') | ||
363 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
364 | .expect(400, done) | ||
365 | }) | ||
366 | |||
367 | it('Should fail with the root user', function (done) { | ||
368 | request(server.url) | ||
369 | .delete(path + rootId) | ||
370 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
371 | .expect(400, done) | ||
372 | }) | ||
373 | |||
374 | it('Should return 404 with a non existing id', function (done) { | ||
375 | request(server.url) | ||
376 | .delete(path + '45') | ||
377 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
378 | .expect(404, done) | ||
379 | }) | ||
380 | }) | ||
381 | |||
382 | describe('When removing an user', function () { | ||
383 | it('Should fail with an incorrect id', function (done) { | ||
384 | request(server.url) | ||
385 | .delete(path + 'bla-bla') | ||
386 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
387 | .expect(400, done) | ||
388 | }) | ||
389 | |||
390 | it('Should fail with the root user', function (done) { | ||
391 | request(server.url) | ||
392 | .delete(path + rootId) | ||
393 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
394 | .expect(400, done) | ||
395 | }) | ||
396 | |||
397 | it('Should return 404 with a non existing id', function (done) { | ||
398 | request(server.url) | ||
399 | .delete(path + '45') | ||
400 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
401 | .expect(404, done) | ||
402 | }) | ||
403 | }) | ||
404 | |||
405 | describe('When register a new user', function () { | ||
406 | const registrationPath = path + '/register' | ||
407 | |||
408 | it('Should fail with a too small username', function (done) { | ||
409 | const data = { | ||
410 | username: 'ji', | ||
411 | email: 'test@example.com', | ||
412 | password: 'mysuperpassword' | ||
413 | } | ||
414 | |||
415 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
416 | }) | ||
417 | |||
418 | it('Should fail with a too long username', function (done) { | ||
419 | const data = { | ||
420 | username: 'mysuperusernamewhichisverylong', | ||
421 | email: 'test@example.com', | ||
422 | password: 'mysuperpassword' | ||
423 | } | ||
424 | |||
425 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
426 | }) | ||
427 | |||
428 | it('Should fail with an incorrect username', function (done) { | ||
429 | const data = { | ||
430 | username: 'my username', | ||
431 | email: 'test@example.com', | ||
432 | password: 'mysuperpassword' | ||
433 | } | ||
434 | |||
435 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
436 | }) | ||
437 | |||
438 | it('Should fail with a missing email', function (done) { | ||
439 | const data = { | ||
440 | username: 'ji', | ||
441 | password: 'mysuperpassword' | ||
442 | } | ||
443 | |||
444 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
445 | }) | ||
446 | |||
447 | it('Should fail with an invalid email', function (done) { | ||
448 | const data = { | ||
449 | username: 'mysuperusernamewhichisverylong', | ||
450 | email: 'testexample.com', | ||
451 | password: 'mysuperpassword' | ||
452 | } | ||
453 | |||
454 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
455 | }) | ||
456 | |||
457 | it('Should fail with a too small password', function (done) { | ||
458 | const data = { | ||
459 | username: 'myusername', | ||
460 | email: 'test@example.com', | ||
461 | password: 'bla' | ||
462 | } | ||
463 | |||
464 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
465 | }) | ||
466 | |||
467 | it('Should fail with a too long password', function (done) { | ||
468 | const data = { | ||
469 | username: 'myusername', | ||
470 | email: 'test@example.com', | ||
471 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
472 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
473 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
474 | } | ||
475 | |||
476 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
477 | }) | ||
478 | |||
479 | it('Should fail if we register a user with the same username', function (done) { | ||
480 | const data = { | ||
481 | username: 'root', | ||
482 | email: 'test@example.com', | ||
483 | password: 'my super password' | ||
484 | } | ||
485 | |||
486 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done, 409) | ||
487 | }) | ||
488 | |||
489 | it('Should fail if we register a user with the same email', function (done) { | ||
490 | const data = { | ||
491 | username: 'myusername', | ||
492 | email: 'admin1@example.com', | ||
493 | password: 'my super password' | ||
494 | } | ||
495 | |||
496 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done, 409) | ||
497 | }) | ||
498 | |||
499 | it('Should succeed with the correct params', function (done) { | ||
500 | const data = { | ||
501 | username: 'user3', | ||
502 | email: 'test3@example.com', | ||
503 | password: 'my super password' | ||
504 | } | ||
505 | |||
506 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done, 204) | ||
507 | }) | ||
508 | |||
509 | it('Should fail on a server with registration disabled', function (done) { | ||
510 | const data = { | ||
511 | username: 'user4', | ||
512 | email: 'test4@example.com', | ||
513 | password: 'my super password 4' | ||
514 | } | ||
515 | |||
516 | requestsUtils.makePostBodyRequest(serverWithRegistrationDisabled.url, registrationPath, serverWithRegistrationDisabled.accessToken, data, done, 403) | ||
517 | }) | ||
518 | }) | ||
519 | |||
520 | describe('When registering multiple users on a server with users limit', function () { | ||
521 | it('Should fail when after 3 registrations', function (done) { | ||
522 | usersUtils.registerUser(server.url, 'user42', 'super password', 403, done) | ||
523 | }) | ||
524 | }) | ||
525 | |||
526 | after(function (done) { | ||
527 | process.kill(-server.app.pid) | ||
528 | process.kill(-serverWithRegistrationDisabled.app.pid) | ||
529 | |||
530 | // Keep the logs if the test failed | ||
531 | if (this.ok) { | ||
532 | serversUtils.flushTests(done) | ||
533 | } else { | ||
534 | done() | ||
535 | } | ||
536 | }) | ||
537 | }) | ||
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts new file mode 100644 index 000000000..643a82afd --- /dev/null +++ b/server/tests/api/check-params/users.ts | |||
@@ -0,0 +1,502 @@ | |||
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 | makePutBodyRequest, | ||
13 | createUser, | ||
14 | loginAndGetAccessToken, | ||
15 | getUsersList, | ||
16 | registerUser, | ||
17 | setAccessTokensToServers, | ||
18 | killallServers, | ||
19 | makePostBodyRequest, | ||
20 | getUserAccessToken | ||
21 | } from '../../utils' | ||
22 | |||
23 | describe('Test users API validators', function () { | ||
24 | const path = '/api/v1/users/' | ||
25 | let userId: number | ||
26 | let rootId: number | ||
27 | let videoId: number | ||
28 | let server: ServerInfo | ||
29 | let serverWithRegistrationDisabled: ServerInfo | ||
30 | let userAccessToken = '' | ||
31 | |||
32 | // --------------------------------------------------------------- | ||
33 | |||
34 | before(async function () { | ||
35 | this.timeout(120000) | ||
36 | |||
37 | await flushTests() | ||
38 | |||
39 | server = await runServer(1) | ||
40 | serverWithRegistrationDisabled = await runServer(2) | ||
41 | |||
42 | await setAccessTokensToServers([ server ]) | ||
43 | |||
44 | const username = 'user1' | ||
45 | const password = 'my super password' | ||
46 | await createUser(server.url, server.accessToken, username, password) | ||
47 | |||
48 | const videoAttributes = {} | ||
49 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
50 | |||
51 | const res = await getVideosList(server.url) | ||
52 | const videos = res.body.data | ||
53 | videoId = videos[0].id | ||
54 | |||
55 | const user = { | ||
56 | username: 'user1', | ||
57 | password: 'my super password' | ||
58 | } | ||
59 | userAccessToken = await getUserAccessToken(server, user) | ||
60 | }) | ||
61 | |||
62 | describe('When listing users', function () { | ||
63 | it('Should fail with a bad start pagination', async function () { | ||
64 | await request(server.url) | ||
65 | .get(path) | ||
66 | .query({ start: 'hello' }) | ||
67 | .set('Accept', 'application/json') | ||
68 | .expect(400) | ||
69 | }) | ||
70 | |||
71 | it('Should fail with a bad count pagination', async function () { | ||
72 | await request(server.url) | ||
73 | .get(path) | ||
74 | .query({ count: 'hello' }) | ||
75 | .set('Accept', 'application/json') | ||
76 | .expect(400) | ||
77 | }) | ||
78 | |||
79 | it('Should fail with an incorrect sort', async function () { | ||
80 | await request(server.url) | ||
81 | .get(path) | ||
82 | .query({ sort: 'hello' }) | ||
83 | .set('Accept', 'application/json') | ||
84 | .expect(400) | ||
85 | }) | ||
86 | }) | ||
87 | |||
88 | describe('When adding a new user', function () { | ||
89 | it('Should fail with a too small username', async function () { | ||
90 | const fields = { | ||
91 | username: 'ji', | ||
92 | email: 'test@example.com', | ||
93 | password: 'my_super_password' | ||
94 | } | ||
95 | |||
96 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
97 | }) | ||
98 | |||
99 | it('Should fail with a too long username', async function () { | ||
100 | const fields = { | ||
101 | username: 'my_super_username_which_is_very_long', | ||
102 | email: 'test@example.com', | ||
103 | password: 'my_super_password' | ||
104 | } | ||
105 | |||
106 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
107 | }) | ||
108 | |||
109 | it('Should fail with an incorrect username', async function () { | ||
110 | const fields = { | ||
111 | username: 'my username', | ||
112 | email: 'test@example.com', | ||
113 | password: 'my_super_password' | ||
114 | } | ||
115 | |||
116 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
117 | }) | ||
118 | |||
119 | it('Should fail with a missing email', async function () { | ||
120 | const fields = { | ||
121 | username: 'ji', | ||
122 | password: 'my_super_password' | ||
123 | } | ||
124 | |||
125 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
126 | }) | ||
127 | |||
128 | it('Should fail with an invalid email', async function () { | ||
129 | const fields = { | ||
130 | username: 'my_super_username_which_is_very_long', | ||
131 | email: 'test_example.com', | ||
132 | password: 'my_super_password' | ||
133 | } | ||
134 | |||
135 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
136 | }) | ||
137 | |||
138 | it('Should fail with a too small password', async function () { | ||
139 | const fields = { | ||
140 | username: 'my_username', | ||
141 | email: 'test@example.com', | ||
142 | password: 'bla' | ||
143 | } | ||
144 | |||
145 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
146 | }) | ||
147 | |||
148 | it('Should fail with a too long password', async function () { | ||
149 | const fields = { | ||
150 | username: 'my_username', | ||
151 | email: 'test@example.com', | ||
152 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
153 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
154 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
155 | } | ||
156 | |||
157 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
158 | }) | ||
159 | |||
160 | it('Should fail with an non authenticated user', async function () { | ||
161 | const fields = { | ||
162 | username: 'my_username', | ||
163 | email: 'test@example.com', | ||
164 | password: 'my super password' | ||
165 | } | ||
166 | |||
167 | await makePostBodyRequest({ url: server.url, path, token: 'super token', fields, statusCodeExpected: 401 }) | ||
168 | }) | ||
169 | |||
170 | it('Should fail if we add a user with the same username', async function () { | ||
171 | const fields = { | ||
172 | username: 'user1', | ||
173 | email: 'test@example.com', | ||
174 | password: 'my super password' | ||
175 | } | ||
176 | |||
177 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | ||
178 | }) | ||
179 | |||
180 | it('Should fail if we add a user with the same email', async function () { | ||
181 | const fields = { | ||
182 | username: 'my_username', | ||
183 | email: 'user1@example.com', | ||
184 | password: 'my super password' | ||
185 | } | ||
186 | |||
187 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | ||
188 | }) | ||
189 | |||
190 | it('Should succeed with the correct params', async function () { | ||
191 | const fields = { | ||
192 | username: 'user2', | ||
193 | email: 'test@example.com', | ||
194 | password: 'my super password' | ||
195 | } | ||
196 | |||
197 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | ||
198 | }) | ||
199 | |||
200 | it('Should fail with a non admin user', async function () { | ||
201 | server.user = { | ||
202 | username: 'user1', | ||
203 | email: 'test@example.com', | ||
204 | password: 'my super password' | ||
205 | } | ||
206 | |||
207 | userAccessToken = await loginAndGetAccessToken(server) | ||
208 | const fields = { | ||
209 | username: 'user3', | ||
210 | email: 'test@example.com', | ||
211 | password: 'my super password' | ||
212 | } | ||
213 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | ||
214 | }) | ||
215 | }) | ||
216 | |||
217 | describe('When updating a user', function () { | ||
218 | before(async function () { | ||
219 | const res = await getUsersList(server.url) | ||
220 | |||
221 | userId = res.body.data[1].id | ||
222 | rootId = res.body.data[2].id | ||
223 | }) | ||
224 | |||
225 | it('Should fail with a too small password', async function () { | ||
226 | const fields = { | ||
227 | password: 'bla' | ||
228 | } | ||
229 | |||
230 | await makePutBodyRequest({ url: server.url, path: path + userId, token: userAccessToken, fields }) | ||
231 | }) | ||
232 | |||
233 | it('Should fail with a too long password', async function () { | ||
234 | const fields = { | ||
235 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
236 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
237 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
238 | } | ||
239 | |||
240 | await makePutBodyRequest({ url: server.url, path: path + userId, token: userAccessToken, fields }) | ||
241 | }) | ||
242 | |||
243 | it('Should fail with an invalid display NSFW attribute', async function () { | ||
244 | const fields = { | ||
245 | displayNSFW: -1 | ||
246 | } | ||
247 | |||
248 | await makePutBodyRequest({ url: server.url, path: path + userId, token: userAccessToken, fields }) | ||
249 | }) | ||
250 | |||
251 | it('Should fail with an non authenticated user', async function () { | ||
252 | const fields = { | ||
253 | password: 'my super password' | ||
254 | } | ||
255 | |||
256 | await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) | ||
257 | }) | ||
258 | |||
259 | it('Should succeed with the correct params', async function () { | ||
260 | const fields = { | ||
261 | password: 'my super password', | ||
262 | displayNSFW: true | ||
263 | } | ||
264 | |||
265 | await makePutBodyRequest({ url: server.url, path: path + userId, token: userAccessToken, fields, statusCodeExpected: 204 }) | ||
266 | }) | ||
267 | }) | ||
268 | |||
269 | describe('When getting my information', function () { | ||
270 | it('Should fail with a non authenticated user', async function () { | ||
271 | await request(server.url) | ||
272 | .get(path + 'me') | ||
273 | .set('Authorization', 'Bearer fake_token') | ||
274 | .set('Accept', 'application/json') | ||
275 | .expect(401) | ||
276 | }) | ||
277 | |||
278 | it('Should success with the correct parameters', async function () { | ||
279 | await request(server.url) | ||
280 | .get(path + 'me') | ||
281 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
282 | .set('Accept', 'application/json') | ||
283 | .expect(200) | ||
284 | }) | ||
285 | }) | ||
286 | |||
287 | describe('When getting my video rating', function () { | ||
288 | it('Should fail with a non authenticated user', async function () { | ||
289 | await request(server.url) | ||
290 | .get(path + 'me/videos/' + videoId + '/rating') | ||
291 | .set('Authorization', 'Bearer fake_token') | ||
292 | .set('Accept', 'application/json') | ||
293 | .expect(401) | ||
294 | }) | ||
295 | |||
296 | it('Should fail with an incorrect video uuid', async function () { | ||
297 | await request(server.url) | ||
298 | .get(path + 'me/videos/blabla/rating') | ||
299 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
300 | .set('Accept', 'application/json') | ||
301 | .expect(400) | ||
302 | }) | ||
303 | |||
304 | it('Should fail with an unknown video', async function () { | ||
305 | await request(server.url) | ||
306 | .get(path + 'me/videos/4da6fde3-88f7-4d16-b119-108df5630b06/rating') | ||
307 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
308 | .set('Accept', 'application/json') | ||
309 | .expect(404) | ||
310 | }) | ||
311 | |||
312 | it('Should success with the correct parameters', async function () { | ||
313 | await request(server.url) | ||
314 | .get(path + 'me/videos/' + videoId + '/rating') | ||
315 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
316 | .set('Accept', 'application/json') | ||
317 | .expect(200) | ||
318 | }) | ||
319 | }) | ||
320 | |||
321 | describe('When removing an user', function () { | ||
322 | it('Should fail with an incorrect id', async function () { | ||
323 | await request(server.url) | ||
324 | .delete(path + 'bla-bla') | ||
325 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
326 | .expect(400) | ||
327 | }) | ||
328 | |||
329 | it('Should fail with the root user', async function () { | ||
330 | await request(server.url) | ||
331 | .delete(path + rootId) | ||
332 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
333 | .expect(400) | ||
334 | }) | ||
335 | |||
336 | it('Should return 404 with a non existing id', async function () { | ||
337 | await request(server.url) | ||
338 | .delete(path + '45') | ||
339 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
340 | .expect(404) | ||
341 | }) | ||
342 | }) | ||
343 | |||
344 | describe('When removing an user', function () { | ||
345 | it('Should fail with an incorrect id', async function () { | ||
346 | await request(server.url) | ||
347 | .delete(path + 'bla-bla') | ||
348 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
349 | .expect(400) | ||
350 | }) | ||
351 | |||
352 | it('Should fail with the root user', async function () { | ||
353 | await request(server.url) | ||
354 | .delete(path + rootId) | ||
355 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
356 | .expect(400) | ||
357 | }) | ||
358 | |||
359 | it('Should return 404 with a non existing id', async function () { | ||
360 | await request(server.url) | ||
361 | .delete(path + '45') | ||
362 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
363 | .expect(404) | ||
364 | }) | ||
365 | }) | ||
366 | |||
367 | describe('When register a new user', function () { | ||
368 | const registrationPath = path + '/register' | ||
369 | |||
370 | it('Should fail with a too small username', async function () { | ||
371 | const fields = { | ||
372 | username: 'ji', | ||
373 | email: 'test@example.com', | ||
374 | password: 'my_super_password' | ||
375 | } | ||
376 | |||
377 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | ||
378 | }) | ||
379 | |||
380 | it('Should fail with a too long username', async function () { | ||
381 | const fields = { | ||
382 | username: 'my_super_username_which_is_very_long', | ||
383 | email: 'test@example.com', | ||
384 | password: 'my_super_password' | ||
385 | } | ||
386 | |||
387 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | ||
388 | }) | ||
389 | |||
390 | it('Should fail with an incorrect username', async function () { | ||
391 | const fields = { | ||
392 | username: 'my username', | ||
393 | email: 'test@example.com', | ||
394 | password: 'my_super_password' | ||
395 | } | ||
396 | |||
397 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | ||
398 | }) | ||
399 | |||
400 | it('Should fail with a missing email', async function () { | ||
401 | const fields = { | ||
402 | username: 'ji', | ||
403 | password: 'my_super_password' | ||
404 | } | ||
405 | |||
406 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | ||
407 | }) | ||
408 | |||
409 | it('Should fail with an invalid email', async function () { | ||
410 | const fields = { | ||
411 | username: 'my_super_username_which_is_very_long', | ||
412 | email: 'test_example.com', | ||
413 | password: 'my_super_password' | ||
414 | } | ||
415 | |||
416 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | ||
417 | }) | ||
418 | |||
419 | it('Should fail with a too small password', async function () { | ||
420 | const fields = { | ||
421 | username: 'my_username', | ||
422 | email: 'test@example.com', | ||
423 | password: 'bla' | ||
424 | } | ||
425 | |||
426 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | ||
427 | }) | ||
428 | |||
429 | it('Should fail with a too long password', async function () { | ||
430 | const fields = { | ||
431 | username: 'my_username', | ||
432 | email: 'test@example.com', | ||
433 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
434 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
435 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
436 | } | ||
437 | |||
438 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | ||
439 | }) | ||
440 | |||
441 | it('Should fail if we register a user with the same username', async function () { | ||
442 | const fields = { | ||
443 | username: 'root', | ||
444 | email: 'test@example.com', | ||
445 | password: 'my super password' | ||
446 | } | ||
447 | |||
448 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 }) | ||
449 | }) | ||
450 | |||
451 | it('Should fail if we register a user with the same email', async function () { | ||
452 | const fields = { | ||
453 | username: 'my_username', | ||
454 | email: 'admin1@example.com', | ||
455 | password: 'my super password' | ||
456 | } | ||
457 | |||
458 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 }) | ||
459 | }) | ||
460 | |||
461 | it('Should succeed with the correct params', async function () { | ||
462 | const fields = { | ||
463 | username: 'user3', | ||
464 | email: 'test3@example.com', | ||
465 | password: 'my super password' | ||
466 | } | ||
467 | |||
468 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 204 }) | ||
469 | }) | ||
470 | |||
471 | it('Should fail on a server with registration disabled', async function () { | ||
472 | const fields = { | ||
473 | username: 'user4', | ||
474 | email: 'test4@example.com', | ||
475 | password: 'my super password 4' | ||
476 | } | ||
477 | |||
478 | await makePostBodyRequest({ | ||
479 | url: serverWithRegistrationDisabled.url, | ||
480 | path: registrationPath, | ||
481 | token: serverWithRegistrationDisabled.accessToken, | ||
482 | fields, | ||
483 | statusCodeExpected: 403 | ||
484 | }) | ||
485 | }) | ||
486 | }) | ||
487 | |||
488 | describe('When registering multiple users on a server with users limit', function () { | ||
489 | it('Should fail when after 3 registrations', async function () { | ||
490 | await registerUser(server.url, 'user42', 'super password', 403) | ||
491 | }) | ||
492 | }) | ||
493 | |||
494 | after(async function () { | ||
495 | killallServers([ server, serverWithRegistrationDisabled ]) | ||
496 | |||
497 | // Keep the logs if the test failed | ||
498 | if (this['ok']) { | ||
499 | await flushTests() | ||
500 | } | ||
501 | }) | ||
502 | }) | ||
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 | |||
5 | const request = require('supertest') | ||
6 | const series = require('async/series') | ||
7 | |||
8 | const loginUtils = require('../../utils/login') | ||
9 | const requestsUtils = require('../../utils/requests') | ||
10 | const serversUtils = require('../../utils/servers') | ||
11 | const usersUtils = require('../../utils/users') | ||
12 | const videosUtils = require('../../utils/videos') | ||
13 | |||
14 | describe('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 | }) | ||
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts new file mode 100644 index 000000000..30d15778d --- /dev/null +++ b/server/tests/api/check-params/video-abuses.ts | |||
@@ -0,0 +1,146 @@ | |||
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 | }) | ||
diff --git a/server/tests/api/check-params/video-blacklists.js b/server/tests/api/check-params/video-blacklists.js deleted file mode 100644 index 53b503e56..000000000 --- a/server/tests/api/check-params/video-blacklists.js +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const series = require('async/series') | ||
6 | |||
7 | const loginUtils = require('../../utils/login') | ||
8 | const requestsUtils = require('../../utils/requests') | ||
9 | const serversUtils = require('../../utils/servers') | ||
10 | const usersUtils = require('../../utils/users') | ||
11 | const videosUtils = require('../../utils/videos') | ||
12 | |||
13 | describe('Test video blacklists API validators', function () { | ||
14 | let server = null | ||
15 | let userAccessToken = null | ||
16 | |||
17 | // --------------------------------------------------------------- | ||
18 | |||
19 | before(function (done) { | ||
20 | this.timeout(120000) | ||
21 | |||
22 | series([ | ||
23 | function (next) { | ||
24 | serversUtils.flushTests(next) | ||
25 | }, | ||
26 | function (next) { | ||
27 | serversUtils.runServer(1, function (server1) { | ||
28 | server = server1 | ||
29 | |||
30 | next() | ||
31 | }) | ||
32 | }, | ||
33 | function (next) { | ||
34 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
35 | if (err) throw err | ||
36 | server.accessToken = token | ||
37 | |||
38 | next() | ||
39 | }) | ||
40 | }, | ||
41 | function (next) { | ||
42 | const username = 'user1' | ||
43 | const password = 'my super password' | ||
44 | |||
45 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | ||
46 | }, | ||
47 | function (next) { | ||
48 | const user = { | ||
49 | username: 'user1', | ||
50 | password: 'my super password' | ||
51 | } | ||
52 | |||
53 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | ||
54 | if (err) throw err | ||
55 | |||
56 | userAccessToken = accessToken | ||
57 | |||
58 | next() | ||
59 | }) | ||
60 | }, | ||
61 | // Upload a video | ||
62 | function (next) { | ||
63 | const videoAttributes = {} | ||
64 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next) | ||
65 | }, | ||
66 | function (next) { | ||
67 | videosUtils.getVideosList(server.url, function (err, res) { | ||
68 | if (err) throw err | ||
69 | |||
70 | const videos = res.body.data | ||
71 | server.video = videos[0] | ||
72 | |||
73 | next() | ||
74 | }) | ||
75 | } | ||
76 | ], done) | ||
77 | }) | ||
78 | |||
79 | describe('When adding a video in blacklist', function () { | ||
80 | const basePath = '/api/v1/videos/' | ||
81 | |||
82 | it('Should fail with nothing', function (done) { | ||
83 | const path = basePath + server.video + '/blacklist' | ||
84 | const data = {} | ||
85 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
86 | }) | ||
87 | |||
88 | it('Should fail with a wrong video', function (done) { | ||
89 | const wrongPath = '/api/v1/videos/blabla/blacklist' | ||
90 | const data = {} | ||
91 | requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done) | ||
92 | }) | ||
93 | |||
94 | it('Should fail with a non authenticated user', function (done) { | ||
95 | const data = {} | ||
96 | const path = basePath + server.video + '/blacklist' | ||
97 | requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) | ||
98 | }) | ||
99 | |||
100 | it('Should fail with a non admin user', function (done) { | ||
101 | const data = {} | ||
102 | const path = basePath + server.video + '/blacklist' | ||
103 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) | ||
104 | }) | ||
105 | |||
106 | it('Should fail with a local video', function (done) { | ||
107 | const data = {} | ||
108 | const path = basePath + server.video.id + '/blacklist' | ||
109 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 403) | ||
110 | }) | ||
111 | }) | ||
112 | |||
113 | after(function (done) { | ||
114 | process.kill(-server.app.pid) | ||
115 | |||
116 | // Keep the logs if the test failed | ||
117 | if (this.ok) { | ||
118 | serversUtils.flushTests(done) | ||
119 | } else { | ||
120 | done() | ||
121 | } | ||
122 | }) | ||
123 | }) | ||
diff --git a/server/tests/api/check-params/video-blacklists.ts b/server/tests/api/check-params/video-blacklists.ts new file mode 100644 index 000000000..d0ad78ff1 --- /dev/null +++ b/server/tests/api/check-params/video-blacklists.ts | |||
@@ -0,0 +1,90 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | |||
5 | import { | ||
6 | ServerInfo, | ||
7 | flushTests, | ||
8 | runServer, | ||
9 | uploadVideo, | ||
10 | getVideosList, | ||
11 | createUser, | ||
12 | setAccessTokensToServers, | ||
13 | killallServers, | ||
14 | makePostBodyRequest, | ||
15 | getUserAccessToken | ||
16 | } from '../../utils' | ||
17 | |||
18 | describe('Test video blacklists API validators', function () { | ||
19 | let server: ServerInfo | ||
20 | let userAccessToken = '' | ||
21 | |||
22 | // --------------------------------------------------------------- | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(120000) | ||
26 | |||
27 | await flushTests() | ||
28 | |||
29 | server = await runServer(1) | ||
30 | |||
31 | await setAccessTokensToServers([ server ]) | ||
32 | |||
33 | const username = 'user1' | ||
34 | const password = 'my super password' | ||
35 | await createUser(server.url, server.accessToken, username, password) | ||
36 | userAccessToken = await getUserAccessToken(server, { username, password }) | ||
37 | |||
38 | // Upload a video | ||
39 | const videoAttributes = {} | ||
40 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
41 | |||
42 | const res = await getVideosList(server.url) | ||
43 | |||
44 | const videos = res.body.data | ||
45 | server.video = videos[0] | ||
46 | }) | ||
47 | |||
48 | describe('When adding a video in blacklist', function () { | ||
49 | const basePath = '/api/v1/videos/' | ||
50 | |||
51 | it('Should fail with nothing', async function () { | ||
52 | const path = basePath + server.video + '/blacklist' | ||
53 | const fields = {} | ||
54 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
55 | }) | ||
56 | |||
57 | it('Should fail with a wrong video', async function () { | ||
58 | const wrongPath = '/api/v1/videos/blabla/blacklist' | ||
59 | const fields = {} | ||
60 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | ||
61 | }) | ||
62 | |||
63 | it('Should fail with a non authenticated user', async function () { | ||
64 | const fields = {} | ||
65 | const path = basePath + server.video + '/blacklist' | ||
66 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | ||
67 | }) | ||
68 | |||
69 | it('Should fail with a non admin user', async function () { | ||
70 | const fields = {} | ||
71 | const path = basePath + server.video + '/blacklist' | ||
72 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | ||
73 | }) | ||
74 | |||
75 | it('Should fail with a local video', async function () { | ||
76 | const fields = {} | ||
77 | const path = basePath + server.video.id + '/blacklist' | ||
78 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) | ||
79 | }) | ||
80 | }) | ||
81 | |||
82 | after(async function () { | ||
83 | killallServers([ server ]) | ||
84 | |||
85 | // Keep the logs if the test failed | ||
86 | if (this['ok']) { | ||
87 | await flushTests() | ||
88 | } | ||
89 | }) | ||
90 | }) | ||
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js deleted file mode 100644 index ce6c49583..000000000 --- a/server/tests/api/check-params/videos.js +++ /dev/null | |||
@@ -1,687 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const expect = chai.expect | ||
7 | const pathUtils = require('path') | ||
8 | const request = require('supertest') | ||
9 | const series = require('async/series') | ||
10 | |||
11 | const loginUtils = require('../../utils/login') | ||
12 | const requestsUtils = require('../../utils/requests') | ||
13 | const serversUtils = require('../../utils/servers') | ||
14 | const videosUtils = require('../../utils/videos') | ||
15 | |||
16 | describe('Test videos API validator', function () { | ||
17 | const path = '/api/v1/videos/' | ||
18 | let server = null | ||
19 | |||
20 | // --------------------------------------------------------------- | ||
21 | |||
22 | before(function (done) { | ||
23 | this.timeout(20000) | ||
24 | |||
25 | series([ | ||
26 | function (next) { | ||
27 | serversUtils.flushTests(next) | ||
28 | }, | ||
29 | function (next) { | ||
30 | serversUtils.runServer(1, function (server1) { | ||
31 | server = server1 | ||
32 | |||
33 | next() | ||
34 | }) | ||
35 | }, | ||
36 | function (next) { | ||
37 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
38 | if (err) throw err | ||
39 | server.accessToken = token | ||
40 | |||
41 | next() | ||
42 | }) | ||
43 | } | ||
44 | ], done) | ||
45 | }) | ||
46 | |||
47 | describe('When listing a video', function () { | ||
48 | it('Should fail with a bad start pagination', function (done) { | ||
49 | request(server.url) | ||
50 | .get(path) | ||
51 | .query({ start: 'hello' }) | ||
52 | .set('Accept', 'application/json') | ||
53 | .expect(400, done) | ||
54 | }) | ||
55 | |||
56 | it('Should fail with a bad count pagination', function (done) { | ||
57 | request(server.url) | ||
58 | .get(path) | ||
59 | .query({ count: 'hello' }) | ||
60 | .set('Accept', 'application/json') | ||
61 | .expect(400, done) | ||
62 | }) | ||
63 | |||
64 | it('Should fail with an incorrect sort', function (done) { | ||
65 | request(server.url) | ||
66 | .get(path) | ||
67 | .query({ sort: 'hello' }) | ||
68 | .set('Accept', 'application/json') | ||
69 | .expect(400, done) | ||
70 | }) | ||
71 | }) | ||
72 | |||
73 | describe('When searching a video', function () { | ||
74 | it('Should fail with nothing', function (done) { | ||
75 | request(server.url) | ||
76 | .get(pathUtils.join(path, 'search')) | ||
77 | .set('Accept', 'application/json') | ||
78 | .expect(400, done) | ||
79 | }) | ||
80 | |||
81 | it('Should fail with a bad start pagination', function (done) { | ||
82 | request(server.url) | ||
83 | .get(pathUtils.join(path, 'search', 'test')) | ||
84 | .query({ start: 'hello' }) | ||
85 | .set('Accept', 'application/json') | ||
86 | .expect(400, done) | ||
87 | }) | ||
88 | |||
89 | it('Should fail with a bad count pagination', function (done) { | ||
90 | request(server.url) | ||
91 | .get(pathUtils.join(path, 'search', 'test')) | ||
92 | .query({ count: 'hello' }) | ||
93 | .set('Accept', 'application/json') | ||
94 | .expect(400, done) | ||
95 | }) | ||
96 | |||
97 | it('Should fail with an incorrect sort', function (done) { | ||
98 | request(server.url) | ||
99 | .get(pathUtils.join(path, 'search', 'test')) | ||
100 | .query({ sort: 'hello' }) | ||
101 | .set('Accept', 'application/json') | ||
102 | .expect(400, done) | ||
103 | }) | ||
104 | }) | ||
105 | |||
106 | describe('When adding a video', function () { | ||
107 | it('Should fail with nothing', function (done) { | ||
108 | const data = {} | ||
109 | const attach = {} | ||
110 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
111 | }) | ||
112 | |||
113 | it('Should fail without name', function (done) { | ||
114 | const data = { | ||
115 | category: 5, | ||
116 | licence: 1, | ||
117 | language: 6, | ||
118 | nsfw: false, | ||
119 | description: 'my super description', | ||
120 | tags: [ 'tag1', 'tag2' ] | ||
121 | } | ||
122 | const attach = { | ||
123 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
124 | } | ||
125 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
126 | }) | ||
127 | |||
128 | it('Should fail with a long name', function (done) { | ||
129 | const data = { | ||
130 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
131 | category: 5, | ||
132 | licence: 1, | ||
133 | language: 6, | ||
134 | nsfw: false, | ||
135 | description: 'my super description', | ||
136 | tags: [ 'tag1', 'tag2' ] | ||
137 | } | ||
138 | const attach = { | ||
139 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
140 | } | ||
141 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
142 | }) | ||
143 | |||
144 | it('Should fail without a category', function (done) { | ||
145 | const data = { | ||
146 | name: 'my super name', | ||
147 | licence: 1, | ||
148 | language: 6, | ||
149 | nsfw: false, | ||
150 | description: 'my super description', | ||
151 | tags: [ 'tag1', 'tag2' ] | ||
152 | } | ||
153 | const attach = { | ||
154 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
155 | } | ||
156 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
157 | }) | ||
158 | |||
159 | it('Should fail with a bad category', function (done) { | ||
160 | const data = { | ||
161 | name: 'my super name', | ||
162 | category: 125, | ||
163 | licence: 1, | ||
164 | language: 6, | ||
165 | nsfw: false, | ||
166 | description: 'my super description', | ||
167 | tags: [ 'tag1', 'tag2' ] | ||
168 | } | ||
169 | const attach = { | ||
170 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
171 | } | ||
172 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
173 | }) | ||
174 | |||
175 | it('Should fail without a licence', function (done) { | ||
176 | const data = { | ||
177 | name: 'my super name', | ||
178 | category: 5, | ||
179 | language: 6, | ||
180 | nsfw: false, | ||
181 | description: 'my super description', | ||
182 | tags: [ 'tag1', 'tag2' ] | ||
183 | } | ||
184 | const attach = { | ||
185 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
186 | } | ||
187 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
188 | }) | ||
189 | |||
190 | it('Should fail with a bad licence', function (done) { | ||
191 | const data = { | ||
192 | name: 'my super name', | ||
193 | category: 5, | ||
194 | licence: 125, | ||
195 | language: 6, | ||
196 | nsfw: false, | ||
197 | description: 'my super description', | ||
198 | tags: [ 'tag1', 'tag2' ] | ||
199 | } | ||
200 | const attach = { | ||
201 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
202 | } | ||
203 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
204 | }) | ||
205 | |||
206 | it('Should fail with a bad language', function (done) { | ||
207 | const data = { | ||
208 | name: 'my super name', | ||
209 | category: 5, | ||
210 | licence: 4, | ||
211 | language: 563, | ||
212 | nsfw: false, | ||
213 | description: 'my super description', | ||
214 | tags: [ 'tag1', 'tag2' ] | ||
215 | } | ||
216 | const attach = { | ||
217 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
218 | } | ||
219 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
220 | }) | ||
221 | |||
222 | it('Should fail without nsfw attribute', function (done) { | ||
223 | const data = { | ||
224 | name: 'my super name', | ||
225 | category: 5, | ||
226 | licence: 4, | ||
227 | language: 6, | ||
228 | description: 'my super description', | ||
229 | tags: [ 'tag1', 'tag2' ] | ||
230 | } | ||
231 | const attach = { | ||
232 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
233 | } | ||
234 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
235 | }) | ||
236 | |||
237 | it('Should fail with a bad nsfw attribue', function (done) { | ||
238 | const data = { | ||
239 | name: 'my super name', | ||
240 | category: 5, | ||
241 | licence: 4, | ||
242 | language: 6, | ||
243 | nsfw: 2, | ||
244 | description: 'my super description', | ||
245 | tags: [ 'tag1', 'tag2' ] | ||
246 | } | ||
247 | const attach = { | ||
248 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
249 | } | ||
250 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
251 | }) | ||
252 | |||
253 | it('Should fail without description', function (done) { | ||
254 | const data = { | ||
255 | name: 'my super name', | ||
256 | category: 5, | ||
257 | licence: 1, | ||
258 | language: 6, | ||
259 | nsfw: false, | ||
260 | tags: [ 'tag1', 'tag2' ] | ||
261 | } | ||
262 | const attach = { | ||
263 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
264 | } | ||
265 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
266 | }) | ||
267 | |||
268 | it('Should fail with a long description', function (done) { | ||
269 | const data = { | ||
270 | name: 'my super name', | ||
271 | category: 5, | ||
272 | licence: 1, | ||
273 | language: 6, | ||
274 | nsfw: false, | ||
275 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
276 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
277 | 'very very very very very very very very very very very very very very very long', | ||
278 | tags: [ 'tag1', 'tag2' ] | ||
279 | } | ||
280 | const attach = { | ||
281 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
282 | } | ||
283 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
284 | }) | ||
285 | |||
286 | it('Should fail with too many tags', function (done) { | ||
287 | const data = { | ||
288 | name: 'my super name', | ||
289 | category: 5, | ||
290 | licence: 1, | ||
291 | language: 6, | ||
292 | nsfw: false, | ||
293 | description: 'my super description', | ||
294 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
295 | } | ||
296 | const attach = { | ||
297 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
298 | } | ||
299 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
300 | }) | ||
301 | |||
302 | it('Should fail with a tag length too low', function (done) { | ||
303 | const data = { | ||
304 | name: 'my super name', | ||
305 | category: 5, | ||
306 | licence: 1, | ||
307 | language: 6, | ||
308 | nsfw: false, | ||
309 | description: 'my super description', | ||
310 | tags: [ 'tag1', 't' ] | ||
311 | } | ||
312 | const attach = { | ||
313 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
314 | } | ||
315 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
316 | }) | ||
317 | |||
318 | it('Should fail with a tag length too big', function (done) { | ||
319 | const data = { | ||
320 | name: 'my super name', | ||
321 | category: 5, | ||
322 | licence: 1, | ||
323 | language: 6, | ||
324 | nsfw: false, | ||
325 | description: 'my super description', | ||
326 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
327 | } | ||
328 | const attach = { | ||
329 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
330 | } | ||
331 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
332 | }) | ||
333 | |||
334 | it('Should fail without an input file', function (done) { | ||
335 | const data = { | ||
336 | name: 'my super name', | ||
337 | category: 5, | ||
338 | licence: 1, | ||
339 | language: 6, | ||
340 | nsfw: false, | ||
341 | description: 'my super description', | ||
342 | tags: [ 'tag1', 'tag2' ] | ||
343 | } | ||
344 | const attach = {} | ||
345 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
346 | }) | ||
347 | |||
348 | it('Should fail without an incorrect input file', function (done) { | ||
349 | const data = { | ||
350 | name: 'my super name', | ||
351 | category: 5, | ||
352 | licence: 1, | ||
353 | language: 6, | ||
354 | nsfw: false, | ||
355 | description: 'my super description', | ||
356 | tags: [ 'tag1', 'tag2' ] | ||
357 | } | ||
358 | const attach = { | ||
359 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | ||
360 | } | ||
361 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
362 | }) | ||
363 | |||
364 | it('Should fail with a too big duration', function (done) { | ||
365 | const data = { | ||
366 | name: 'my super name', | ||
367 | category: 5, | ||
368 | licence: 1, | ||
369 | language: 6, | ||
370 | nsfw: false, | ||
371 | description: 'my super description', | ||
372 | tags: [ 'tag1', 'tag2' ] | ||
373 | } | ||
374 | const attach = { | ||
375 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm') | ||
376 | } | ||
377 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
378 | }) | ||
379 | |||
380 | it('Should succeed with the correct parameters', function (done) { | ||
381 | this.timeout(10000) | ||
382 | |||
383 | const data = { | ||
384 | name: 'my super name', | ||
385 | category: 5, | ||
386 | licence: 1, | ||
387 | language: 6, | ||
388 | nsfw: false, | ||
389 | description: 'my super description', | ||
390 | tags: [ 'tag1', 'tag2' ] | ||
391 | } | ||
392 | const attach = { | ||
393 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
394 | } | ||
395 | |||
396 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | ||
397 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4') | ||
398 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | ||
399 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv') | ||
400 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) | ||
401 | }, false) | ||
402 | }, false) | ||
403 | }) | ||
404 | }) | ||
405 | |||
406 | describe('When updating a video', function () { | ||
407 | let videoId | ||
408 | |||
409 | before(function (done) { | ||
410 | videosUtils.getVideosList(server.url, function (err, res) { | ||
411 | if (err) throw err | ||
412 | |||
413 | videoId = res.body.data[0].id | ||
414 | |||
415 | return done() | ||
416 | }) | ||
417 | }) | ||
418 | |||
419 | it('Should fail with nothing', function (done) { | ||
420 | const data = {} | ||
421 | requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done) | ||
422 | }) | ||
423 | |||
424 | it('Should fail without a valid uuid', function (done) { | ||
425 | const data = { | ||
426 | category: 5, | ||
427 | licence: 2, | ||
428 | language: 6, | ||
429 | nsfw: false, | ||
430 | description: 'my super description', | ||
431 | tags: [ 'tag1', 'tag2' ] | ||
432 | } | ||
433 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) | ||
434 | }) | ||
435 | |||
436 | it('Should fail with an unknown id', function (done) { | ||
437 | const data = { | ||
438 | category: 5, | ||
439 | licence: 2, | ||
440 | language: 6, | ||
441 | nsfw: false, | ||
442 | description: 'my super description', | ||
443 | tags: [ 'tag1', 'tag2' ] | ||
444 | } | ||
445 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404) | ||
446 | }) | ||
447 | |||
448 | it('Should fail with a long name', function (done) { | ||
449 | const data = { | ||
450 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
451 | category: 5, | ||
452 | licence: 2, | ||
453 | language: 6, | ||
454 | nsfw: false, | ||
455 | description: 'my super description', | ||
456 | tags: [ 'tag1', 'tag2' ] | ||
457 | } | ||
458 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
459 | }) | ||
460 | |||
461 | it('Should fail with a bad category', function (done) { | ||
462 | const data = { | ||
463 | name: 'my super name', | ||
464 | category: 128, | ||
465 | licence: 2, | ||
466 | language: 6, | ||
467 | nsfw: false, | ||
468 | description: 'my super description', | ||
469 | tags: [ 'tag1', 'tag2' ] | ||
470 | } | ||
471 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
472 | }) | ||
473 | |||
474 | it('Should fail with a bad licence', function (done) { | ||
475 | const data = { | ||
476 | name: 'my super name', | ||
477 | category: 5, | ||
478 | licence: 128, | ||
479 | language: 6, | ||
480 | nsfw: false, | ||
481 | description: 'my super description', | ||
482 | tags: [ 'tag1', 'tag2' ] | ||
483 | } | ||
484 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
485 | }) | ||
486 | |||
487 | it('Should fail with a bad language', function (done) { | ||
488 | const data = { | ||
489 | name: 'my super name', | ||
490 | category: 5, | ||
491 | licence: 3, | ||
492 | language: 896, | ||
493 | nsfw: false, | ||
494 | description: 'my super description', | ||
495 | tags: [ 'tag1', 'tag2' ] | ||
496 | } | ||
497 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
498 | }) | ||
499 | |||
500 | it('Should fail with a bad nsfw attribute', function (done) { | ||
501 | const data = { | ||
502 | name: 'my super name', | ||
503 | category: 5, | ||
504 | licence: 5, | ||
505 | language: 6, | ||
506 | nsfw: -4, | ||
507 | description: 'my super description', | ||
508 | tags: [ 'tag1', 'tag2' ] | ||
509 | } | ||
510 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
511 | }) | ||
512 | |||
513 | it('Should fail with a long description', function (done) { | ||
514 | const data = { | ||
515 | name: 'my super name', | ||
516 | category: 5, | ||
517 | licence: 2, | ||
518 | language: 6, | ||
519 | nsfw: false, | ||
520 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
521 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
522 | 'very very very very very very very very very very very very very very very long', | ||
523 | tags: [ 'tag1', 'tag2' ] | ||
524 | } | ||
525 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
526 | }) | ||
527 | |||
528 | it('Should fail with too many tags', function (done) { | ||
529 | const data = { | ||
530 | name: 'my super name', | ||
531 | category: 5, | ||
532 | licence: 2, | ||
533 | language: 6, | ||
534 | nsfw: false, | ||
535 | description: 'my super description', | ||
536 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
537 | } | ||
538 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
539 | }) | ||
540 | |||
541 | it('Should fail with a tag length too low', function (done) { | ||
542 | const data = { | ||
543 | name: 'my super name', | ||
544 | category: 5, | ||
545 | licence: 2, | ||
546 | language: 6, | ||
547 | nsfw: false, | ||
548 | description: 'my super description', | ||
549 | tags: [ 'tag1', 't' ] | ||
550 | } | ||
551 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
552 | }) | ||
553 | |||
554 | it('Should fail with a tag length too big', function (done) { | ||
555 | const data = { | ||
556 | name: 'my super name', | ||
557 | category: 5, | ||
558 | licence: 2, | ||
559 | language: 6, | ||
560 | nsfw: false, | ||
561 | description: 'my super description', | ||
562 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
563 | } | ||
564 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
565 | }) | ||
566 | |||
567 | it('Should fail with a video of another user') | ||
568 | |||
569 | it('Should fail with a video of another pod') | ||
570 | }) | ||
571 | |||
572 | describe('When getting a video', function () { | ||
573 | it('Should return the list of the videos with nothing', function (done) { | ||
574 | request(server.url) | ||
575 | .get(path) | ||
576 | .set('Accept', 'application/json') | ||
577 | .expect(200) | ||
578 | .expect('Content-Type', /json/) | ||
579 | .end(function (err, res) { | ||
580 | if (err) throw err | ||
581 | |||
582 | expect(res.body.data).to.be.an('array') | ||
583 | expect(res.body.data.length).to.equal(3) | ||
584 | |||
585 | done() | ||
586 | }) | ||
587 | }) | ||
588 | |||
589 | it('Should fail without a correct uuid', function (done) { | ||
590 | request(server.url) | ||
591 | .get(path + 'coucou') | ||
592 | .set('Accept', 'application/json') | ||
593 | .expect(400, done) | ||
594 | }) | ||
595 | |||
596 | it('Should return 404 with an incorrect video', function (done) { | ||
597 | request(server.url) | ||
598 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
599 | .set('Accept', 'application/json') | ||
600 | .expect(404, done) | ||
601 | }) | ||
602 | |||
603 | it('Should succeed with the correct parameters') | ||
604 | }) | ||
605 | |||
606 | describe('When rating a video', function () { | ||
607 | let videoId | ||
608 | |||
609 | before(function (done) { | ||
610 | videosUtils.getVideosList(server.url, function (err, res) { | ||
611 | if (err) throw err | ||
612 | |||
613 | videoId = res.body.data[0].id | ||
614 | |||
615 | return done() | ||
616 | }) | ||
617 | }) | ||
618 | |||
619 | it('Should fail without a valid uuid', function (done) { | ||
620 | const data = { | ||
621 | rating: 'like' | ||
622 | } | ||
623 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done) | ||
624 | }) | ||
625 | |||
626 | it('Should fail with an unknown id', function (done) { | ||
627 | const data = { | ||
628 | rating: 'like' | ||
629 | } | ||
630 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404) | ||
631 | }) | ||
632 | |||
633 | it('Should fail with a wrong rating', function (done) { | ||
634 | const data = { | ||
635 | rating: 'likes' | ||
636 | } | ||
637 | requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done) | ||
638 | }) | ||
639 | |||
640 | it('Should succeed with the correct parameters', function (done) { | ||
641 | const data = { | ||
642 | rating: 'like' | ||
643 | } | ||
644 | requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204) | ||
645 | }) | ||
646 | }) | ||
647 | |||
648 | describe('When removing a video', function () { | ||
649 | it('Should have 404 with nothing', function (done) { | ||
650 | request(server.url) | ||
651 | .delete(path) | ||
652 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
653 | .expect(400, done) | ||
654 | }) | ||
655 | |||
656 | it('Should fail without a correct uuid', function (done) { | ||
657 | request(server.url) | ||
658 | .delete(path + 'hello') | ||
659 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
660 | .expect(400, done) | ||
661 | }) | ||
662 | |||
663 | it('Should fail with a video which does not exist', function (done) { | ||
664 | request(server.url) | ||
665 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
666 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
667 | .expect(404, done) | ||
668 | }) | ||
669 | |||
670 | it('Should fail with a video of another user') | ||
671 | |||
672 | it('Should fail with a video of another pod') | ||
673 | |||
674 | it('Should succeed with the correct parameters') | ||
675 | }) | ||
676 | |||
677 | after(function (done) { | ||
678 | process.kill(-server.app.pid) | ||
679 | |||
680 | // Keep the logs if the test failed | ||
681 | if (this.ok) { | ||
682 | serversUtils.flushTests(done) | ||
683 | } else { | ||
684 | done() | ||
685 | } | ||
686 | }) | ||
687 | }) | ||
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts new file mode 100644 index 000000000..8d30769d3 --- /dev/null +++ b/server/tests/api/check-params/videos.ts | |||
@@ -0,0 +1,677 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as request from 'supertest' | ||
4 | import { join } from 'path' | ||
5 | import 'mocha' | ||
6 | import * as chai from 'chai' | ||
7 | const expect = chai.expect | ||
8 | |||
9 | import { | ||
10 | ServerInfo, | ||
11 | flushTests, | ||
12 | runServer, | ||
13 | getVideosList, | ||
14 | makePutBodyRequest, | ||
15 | setAccessTokensToServers, | ||
16 | killallServers, | ||
17 | makePostUploadRequest | ||
18 | } from '../../utils' | ||
19 | |||
20 | describe('Test videos API validator', function () { | ||
21 | const path = '/api/v1/videos/' | ||
22 | let server: ServerInfo | ||
23 | |||
24 | // --------------------------------------------------------------- | ||
25 | |||
26 | before(async function () { | ||
27 | this.timeout(20000) | ||
28 | |||
29 | await flushTests() | ||
30 | |||
31 | server = await runServer(1) | ||
32 | |||
33 | await setAccessTokensToServers([ server ]) | ||
34 | }) | ||
35 | |||
36 | describe('When listing a video', function () { | ||
37 | it('Should fail with a bad start pagination', async function () { | ||
38 | await request(server.url) | ||
39 | .get(path) | ||
40 | .query({ start: 'hello' }) | ||
41 | .set('Accept', 'application/json') | ||
42 | .expect(400) | ||
43 | }) | ||
44 | |||
45 | it('Should fail with a bad count pagination', async function () { | ||
46 | await request(server.url) | ||
47 | .get(path) | ||
48 | .query({ count: 'hello' }) | ||
49 | .set('Accept', 'application/json') | ||
50 | .expect(400) | ||
51 | }) | ||
52 | |||
53 | it('Should fail with an incorrect sort', async function () { | ||
54 | await request(server.url) | ||
55 | .get(path) | ||
56 | .query({ sort: 'hello' }) | ||
57 | .set('Accept', 'application/json') | ||
58 | .expect(400) | ||
59 | }) | ||
60 | }) | ||
61 | |||
62 | describe('When searching a video', function () { | ||
63 | it('Should fail with nothing', async function () { | ||
64 | await request(server.url) | ||
65 | .get(join(path, 'search')) | ||
66 | .set('Accept', 'application/json') | ||
67 | .expect(400) | ||
68 | }) | ||
69 | |||
70 | it('Should fail with a bad start pagination', async function () { | ||
71 | await request(server.url) | ||
72 | .get(join(path, 'search', 'test')) | ||
73 | .query({ start: 'hello' }) | ||
74 | .set('Accept', 'application/json') | ||
75 | .expect(400) | ||
76 | }) | ||
77 | |||
78 | it('Should fail with a bad count pagination', async function () { | ||
79 | await request(server.url) | ||
80 | .get(join(path, 'search', 'test')) | ||
81 | .query({ count: 'hello' }) | ||
82 | .set('Accept', 'application/json') | ||
83 | .expect(400) | ||
84 | }) | ||
85 | |||
86 | it('Should fail with an incorrect sort', async function () { | ||
87 | await request(server.url) | ||
88 | .get(join(path, 'search', 'test')) | ||
89 | .query({ sort: 'hello' }) | ||
90 | .set('Accept', 'application/json') | ||
91 | .expect(400) | ||
92 | }) | ||
93 | }) | ||
94 | |||
95 | describe('When adding a video', function () { | ||
96 | it('Should fail with nothing', async function () { | ||
97 | const fields = {} | ||
98 | const attaches = {} | ||
99 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
100 | }) | ||
101 | |||
102 | it('Should fail without name', async function () { | ||
103 | const fields = { | ||
104 | category: 5, | ||
105 | licence: 1, | ||
106 | language: 6, | ||
107 | nsfw: false, | ||
108 | description: 'my super description', | ||
109 | tags: [ 'tag1', 'tag2' ] | ||
110 | } | ||
111 | const attaches = { | ||
112 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
113 | } | ||
114 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
115 | }) | ||
116 | |||
117 | it('Should fail with a long name', async function () { | ||
118 | const fields = { | ||
119 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
120 | category: 5, | ||
121 | licence: 1, | ||
122 | language: 6, | ||
123 | nsfw: false, | ||
124 | description: 'my super description', | ||
125 | tags: [ 'tag1', 'tag2' ] | ||
126 | } | ||
127 | const attaches = { | ||
128 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
129 | } | ||
130 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
131 | }) | ||
132 | |||
133 | it('Should fail without a category', async function () { | ||
134 | const fields = { | ||
135 | name: 'my super name', | ||
136 | licence: 1, | ||
137 | language: 6, | ||
138 | nsfw: false, | ||
139 | description: 'my super description', | ||
140 | tags: [ 'tag1', 'tag2' ] | ||
141 | } | ||
142 | const attaches = { | ||
143 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
144 | } | ||
145 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
146 | }) | ||
147 | |||
148 | it('Should fail with a bad category', async function () { | ||
149 | const fields = { | ||
150 | name: 'my super name', | ||
151 | category: 125, | ||
152 | licence: 1, | ||
153 | language: 6, | ||
154 | nsfw: false, | ||
155 | description: 'my super description', | ||
156 | tags: [ 'tag1', 'tag2' ] | ||
157 | } | ||
158 | const attaches = { | ||
159 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
160 | } | ||
161 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
162 | }) | ||
163 | |||
164 | it('Should fail without a licence', async function () { | ||
165 | const fields = { | ||
166 | name: 'my super name', | ||
167 | category: 5, | ||
168 | language: 6, | ||
169 | nsfw: false, | ||
170 | description: 'my super description', | ||
171 | tags: [ 'tag1', 'tag2' ] | ||
172 | } | ||
173 | const attaches = { | ||
174 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
175 | } | ||
176 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
177 | }) | ||
178 | |||
179 | it('Should fail with a bad licence', async function () { | ||
180 | const fields = { | ||
181 | name: 'my super name', | ||
182 | category: 5, | ||
183 | licence: 125, | ||
184 | language: 6, | ||
185 | nsfw: false, | ||
186 | description: 'my super description', | ||
187 | tags: [ 'tag1', 'tag2' ] | ||
188 | } | ||
189 | const attaches = { | ||
190 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
191 | } | ||
192 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
193 | }) | ||
194 | |||
195 | it('Should fail with a bad language', async function () { | ||
196 | const fields = { | ||
197 | name: 'my super name', | ||
198 | category: 5, | ||
199 | licence: 4, | ||
200 | language: 563, | ||
201 | nsfw: false, | ||
202 | description: 'my super description', | ||
203 | tags: [ 'tag1', 'tag2' ] | ||
204 | } | ||
205 | const attaches = { | ||
206 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
207 | } | ||
208 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
209 | }) | ||
210 | |||
211 | it('Should fail without nsfw attribute', async function () { | ||
212 | const fields = { | ||
213 | name: 'my super name', | ||
214 | category: 5, | ||
215 | licence: 4, | ||
216 | language: 6, | ||
217 | description: 'my super description', | ||
218 | tags: [ 'tag1', 'tag2' ] | ||
219 | } | ||
220 | const attaches = { | ||
221 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
222 | } | ||
223 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
224 | }) | ||
225 | |||
226 | it('Should fail with a bad nsfw attribue', async function () { | ||
227 | const fields = { | ||
228 | name: 'my super name', | ||
229 | category: 5, | ||
230 | licence: 4, | ||
231 | language: 6, | ||
232 | nsfw: 2, | ||
233 | description: 'my super description', | ||
234 | tags: [ 'tag1', 'tag2' ] | ||
235 | } | ||
236 | const attaches = { | ||
237 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
238 | } | ||
239 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
240 | }) | ||
241 | |||
242 | it('Should fail without description', async function () { | ||
243 | const fields = { | ||
244 | name: 'my super name', | ||
245 | category: 5, | ||
246 | licence: 1, | ||
247 | language: 6, | ||
248 | nsfw: false, | ||
249 | tags: [ 'tag1', 'tag2' ] | ||
250 | } | ||
251 | const attaches = { | ||
252 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
253 | } | ||
254 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
255 | }) | ||
256 | |||
257 | it('Should fail with a long description', async function () { | ||
258 | const fields = { | ||
259 | name: 'my super name', | ||
260 | category: 5, | ||
261 | licence: 1, | ||
262 | language: 6, | ||
263 | nsfw: false, | ||
264 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
265 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
266 | 'very very very very very very very very very very very very very very very long', | ||
267 | tags: [ 'tag1', 'tag2' ] | ||
268 | } | ||
269 | const attaches = { | ||
270 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
271 | } | ||
272 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
273 | }) | ||
274 | |||
275 | it('Should fail with too many tags', async function () { | ||
276 | const fields = { | ||
277 | name: 'my super name', | ||
278 | category: 5, | ||
279 | licence: 1, | ||
280 | language: 6, | ||
281 | nsfw: false, | ||
282 | description: 'my super description', | ||
283 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
284 | } | ||
285 | const attaches = { | ||
286 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
287 | } | ||
288 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
289 | }) | ||
290 | |||
291 | it('Should fail with a tag length too low', async function () { | ||
292 | const fields = { | ||
293 | name: 'my super name', | ||
294 | category: 5, | ||
295 | licence: 1, | ||
296 | language: 6, | ||
297 | nsfw: false, | ||
298 | description: 'my super description', | ||
299 | tags: [ 'tag1', 't' ] | ||
300 | } | ||
301 | const attaches = { | ||
302 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
303 | } | ||
304 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
305 | }) | ||
306 | |||
307 | it('Should fail with a tag length too big', async function () { | ||
308 | const fields = { | ||
309 | name: 'my super name', | ||
310 | category: 5, | ||
311 | licence: 1, | ||
312 | language: 6, | ||
313 | nsfw: false, | ||
314 | description: 'my super description', | ||
315 | tags: [ 'my_super_tag_too_long', 'tag1' ] | ||
316 | } | ||
317 | const attaches = { | ||
318 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
319 | } | ||
320 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
321 | }) | ||
322 | |||
323 | it('Should fail without an input file', async function () { | ||
324 | const fields = { | ||
325 | name: 'my super name', | ||
326 | category: 5, | ||
327 | licence: 1, | ||
328 | language: 6, | ||
329 | nsfw: false, | ||
330 | description: 'my super description', | ||
331 | tags: [ 'tag1', 'tag2' ] | ||
332 | } | ||
333 | const attaches = {} | ||
334 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
335 | }) | ||
336 | |||
337 | it('Should fail without an incorrect input file', async function () { | ||
338 | const fields = { | ||
339 | name: 'my super name', | ||
340 | category: 5, | ||
341 | licence: 1, | ||
342 | language: 6, | ||
343 | nsfw: false, | ||
344 | description: 'my super description', | ||
345 | tags: [ 'tag1', 'tag2' ] | ||
346 | } | ||
347 | const attaches = { | ||
348 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | ||
349 | } | ||
350 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
351 | }) | ||
352 | |||
353 | it('Should fail with a too big duration', async function () { | ||
354 | const fields = { | ||
355 | name: 'my super name', | ||
356 | category: 5, | ||
357 | licence: 1, | ||
358 | language: 6, | ||
359 | nsfw: false, | ||
360 | description: 'my super description', | ||
361 | tags: [ 'tag1', 'tag2' ] | ||
362 | } | ||
363 | const attaches = { | ||
364 | 'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm') | ||
365 | } | ||
366 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
367 | }) | ||
368 | |||
369 | it('Should succeed with the correct parameters', async function () { | ||
370 | this.timeout(10000) | ||
371 | |||
372 | const fields = { | ||
373 | name: 'my super name', | ||
374 | category: 5, | ||
375 | licence: 1, | ||
376 | language: 6, | ||
377 | nsfw: false, | ||
378 | description: 'my super description', | ||
379 | tags: [ 'tag1', 'tag2' ] | ||
380 | } | ||
381 | const attaches = { | ||
382 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
383 | } | ||
384 | |||
385 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 }) | ||
386 | |||
387 | attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4') | ||
388 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 }) | ||
389 | |||
390 | attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv') | ||
391 | await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 }) | ||
392 | }) | ||
393 | }) | ||
394 | |||
395 | describe('When updating a video', function () { | ||
396 | let videoId | ||
397 | |||
398 | before(async function () { | ||
399 | const res = await getVideosList(server.url) | ||
400 | videoId = res.body.data[0].id | ||
401 | }) | ||
402 | |||
403 | it('Should fail with nothing', async function () { | ||
404 | const fields = {} | ||
405 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
406 | }) | ||
407 | |||
408 | it('Should fail without a valid uuid', async function () { | ||
409 | const fields = { | ||
410 | category: 5, | ||
411 | licence: 2, | ||
412 | language: 6, | ||
413 | nsfw: false, | ||
414 | description: 'my super description', | ||
415 | tags: [ 'tag1', 'tag2' ] | ||
416 | } | ||
417 | await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields }) | ||
418 | }) | ||
419 | |||
420 | it('Should fail with an unknown id', async function () { | ||
421 | const fields = { | ||
422 | category: 5, | ||
423 | licence: 2, | ||
424 | language: 6, | ||
425 | nsfw: false, | ||
426 | description: 'my super description', | ||
427 | tags: [ 'tag1', 'tag2' ] | ||
428 | } | ||
429 | await makePutBodyRequest({ | ||
430 | url: server.url, | ||
431 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', | ||
432 | token: server.accessToken, | ||
433 | fields, | ||
434 | statusCodeExpected: 404 | ||
435 | }) | ||
436 | }) | ||
437 | |||
438 | it('Should fail with a long name', async function () { | ||
439 | const fields = { | ||
440 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
441 | category: 5, | ||
442 | licence: 2, | ||
443 | language: 6, | ||
444 | nsfw: false, | ||
445 | description: 'my super description', | ||
446 | tags: [ 'tag1', 'tag2' ] | ||
447 | } | ||
448 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
449 | }) | ||
450 | |||
451 | it('Should fail with a bad category', async function () { | ||
452 | const fields = { | ||
453 | name: 'my super name', | ||
454 | category: 128, | ||
455 | licence: 2, | ||
456 | language: 6, | ||
457 | nsfw: false, | ||
458 | description: 'my super description', | ||
459 | tags: [ 'tag1', 'tag2' ] | ||
460 | } | ||
461 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
462 | }) | ||
463 | |||
464 | it('Should fail with a bad licence', async function () { | ||
465 | const fields = { | ||
466 | name: 'my super name', | ||
467 | category: 5, | ||
468 | licence: 128, | ||
469 | language: 6, | ||
470 | nsfw: false, | ||
471 | description: 'my super description', | ||
472 | tags: [ 'tag1', 'tag2' ] | ||
473 | } | ||
474 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
475 | }) | ||
476 | |||
477 | it('Should fail with a bad language', async function () { | ||
478 | const fields = { | ||
479 | name: 'my super name', | ||
480 | category: 5, | ||
481 | licence: 3, | ||
482 | language: 896, | ||
483 | nsfw: false, | ||
484 | description: 'my super description', | ||
485 | tags: [ 'tag1', 'tag2' ] | ||
486 | } | ||
487 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
488 | }) | ||
489 | |||
490 | it('Should fail with a bad nsfw attribute', async function () { | ||
491 | const fields = { | ||
492 | name: 'my super name', | ||
493 | category: 5, | ||
494 | licence: 5, | ||
495 | language: 6, | ||
496 | nsfw: -4, | ||
497 | description: 'my super description', | ||
498 | tags: [ 'tag1', 'tag2' ] | ||
499 | } | ||
500 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
501 | }) | ||
502 | |||
503 | it('Should fail with a long description', async function () { | ||
504 | const fields = { | ||
505 | name: 'my super name', | ||
506 | category: 5, | ||
507 | licence: 2, | ||
508 | language: 6, | ||
509 | nsfw: false, | ||
510 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
511 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
512 | 'very very very very very very very very very very very very very very very long', | ||
513 | tags: [ 'tag1', 'tag2' ] | ||
514 | } | ||
515 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
516 | }) | ||
517 | |||
518 | it('Should fail with too many tags', async function () { | ||
519 | const fields = { | ||
520 | name: 'my super name', | ||
521 | category: 5, | ||
522 | licence: 2, | ||
523 | language: 6, | ||
524 | nsfw: false, | ||
525 | description: 'my super description', | ||
526 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
527 | } | ||
528 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
529 | }) | ||
530 | |||
531 | it('Should fail with a tag length too low', async function () { | ||
532 | const fields = { | ||
533 | name: 'my super name', | ||
534 | category: 5, | ||
535 | licence: 2, | ||
536 | language: 6, | ||
537 | nsfw: false, | ||
538 | description: 'my super description', | ||
539 | tags: [ 'tag1', 't' ] | ||
540 | } | ||
541 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
542 | }) | ||
543 | |||
544 | it('Should fail with a tag length too big', async function () { | ||
545 | const fields = { | ||
546 | name: 'my super name', | ||
547 | category: 5, | ||
548 | licence: 2, | ||
549 | language: 6, | ||
550 | nsfw: false, | ||
551 | description: 'my super description', | ||
552 | tags: [ 'my_super_tag_too_long', 'tag1' ] | ||
553 | } | ||
554 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | ||
555 | }) | ||
556 | |||
557 | it('Should fail with a video of another user') | ||
558 | |||
559 | it('Should fail with a video of another pod') | ||
560 | }) | ||
561 | |||
562 | describe('When getting a video', function () { | ||
563 | it('Should return the list of the videos with nothing', async function () { | ||
564 | const res = await request(server.url) | ||
565 | .get(path) | ||
566 | .set('Accept', 'application/json') | ||
567 | .expect(200) | ||
568 | .expect('Content-Type', /json/) | ||
569 | |||
570 | expect(res.body.data).to.be.an('array') | ||
571 | expect(res.body.data.length).to.equal(3) | ||
572 | }) | ||
573 | |||
574 | it('Should fail without a correct uuid', async function () { | ||
575 | await request(server.url) | ||
576 | .get(path + 'coucou') | ||
577 | .set('Accept', 'application/json') | ||
578 | .expect(400) | ||
579 | }) | ||
580 | |||
581 | it('Should return 404 with an incorrect video', async function () { | ||
582 | await request(server.url) | ||
583 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
584 | .set('Accept', 'application/json') | ||
585 | .expect(404) | ||
586 | }) | ||
587 | |||
588 | it('Should succeed with the correct parameters') | ||
589 | }) | ||
590 | |||
591 | describe('When rating a video', function () { | ||
592 | let videoId | ||
593 | |||
594 | before(async function () { | ||
595 | const res = await getVideosList(server.url) | ||
596 | videoId = res.body.data[0].id | ||
597 | }) | ||
598 | |||
599 | it('Should fail without a valid uuid', async function () { | ||
600 | const fields = { | ||
601 | rating: 'like' | ||
602 | } | ||
603 | await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields }) | ||
604 | }) | ||
605 | |||
606 | it('Should fail with an unknown id', async function () { | ||
607 | const fields = { | ||
608 | rating: 'like' | ||
609 | } | ||
610 | await makePutBodyRequest({ | ||
611 | url: server.url, | ||
612 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', | ||
613 | token: server.accessToken, | ||
614 | fields, | ||
615 | statusCodeExpected: 404 | ||
616 | }) | ||
617 | }) | ||
618 | |||
619 | it('Should fail with a wrong rating', async function () { | ||
620 | const fields = { | ||
621 | rating: 'likes' | ||
622 | } | ||
623 | await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields }) | ||
624 | }) | ||
625 | |||
626 | it('Should succeed with the correct parameters', async function () { | ||
627 | const fields = { | ||
628 | rating: 'like' | ||
629 | } | ||
630 | await makePutBodyRequest({ | ||
631 | url: server.url, | ||
632 | path: path + videoId + '/rate', | ||
633 | token: server.accessToken, | ||
634 | fields, | ||
635 | statusCodeExpected: 204 | ||
636 | }) | ||
637 | }) | ||
638 | }) | ||
639 | |||
640 | describe('When removing a video', function () { | ||
641 | it('Should have 404 with nothing', async function () { | ||
642 | await request(server.url) | ||
643 | .delete(path) | ||
644 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
645 | .expect(400) | ||
646 | }) | ||
647 | |||
648 | it('Should fail without a correct uuid', async function () { | ||
649 | await request(server.url) | ||
650 | .delete(path + 'hello') | ||
651 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
652 | .expect(400) | ||
653 | }) | ||
654 | |||
655 | it('Should fail with a video which does not exist', async function () { | ||
656 | await request(server.url) | ||
657 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
658 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
659 | .expect(404) | ||
660 | }) | ||
661 | |||
662 | it('Should fail with a video of another user') | ||
663 | |||
664 | it('Should fail with a video of another pod') | ||
665 | |||
666 | it('Should succeed with the correct parameters') | ||
667 | }) | ||
668 | |||
669 | after(async function () { | ||
670 | killallServers([ server ]) | ||
671 | |||
672 | // Keep the logs if the test failed | ||
673 | if (this['ok']) { | ||
674 | await flushTests() | ||
675 | } | ||
676 | }) | ||
677 | }) | ||