diff options
Diffstat (limited to 'server/tests/api')
38 files changed, 4396 insertions, 5404 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 | }) | ||
diff --git a/server/tests/api/config.js b/server/tests/api/config.js deleted file mode 100644 index dc3cce052..000000000 --- a/server/tests/api/config.js +++ /dev/null | |||
@@ -1,83 +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 series = require('async/series') | ||
8 | |||
9 | const serversUtils = require('../utils/servers') | ||
10 | const configUtils = require('../utils/config') | ||
11 | const usersUtils = require('../utils/users') | ||
12 | |||
13 | describe('Test config', function () { | ||
14 | let server = null | ||
15 | |||
16 | before(function (done) { | ||
17 | this.timeout(120000) | ||
18 | |||
19 | series([ | ||
20 | function (next) { | ||
21 | serversUtils.flushTests(next) | ||
22 | }, | ||
23 | function (next) { | ||
24 | serversUtils.runServer(1, function (server1) { | ||
25 | server = server1 | ||
26 | next() | ||
27 | }) | ||
28 | } | ||
29 | ], done) | ||
30 | }) | ||
31 | |||
32 | it('Should have a correct config on a server with registration enabled', function (done) { | ||
33 | configUtils.getConfig(server.url, function (err, res) { | ||
34 | if (err) throw err | ||
35 | |||
36 | const data = res.body | ||
37 | |||
38 | expect(data.signup.allowed).to.be.true | ||
39 | |||
40 | done() | ||
41 | }) | ||
42 | }) | ||
43 | |||
44 | it('Should have a correct config on a server with registration enabled and a users limit', function (done) { | ||
45 | series([ | ||
46 | function (next) { | ||
47 | usersUtils.registerUser(server.url, 'user1', 'super password', next) | ||
48 | }, | ||
49 | |||
50 | function (next) { | ||
51 | usersUtils.registerUser(server.url, 'user2', 'super password', next) | ||
52 | }, | ||
53 | |||
54 | function (next) { | ||
55 | usersUtils.registerUser(server.url, 'user3', 'super password', next) | ||
56 | } | ||
57 | |||
58 | ], function (err) { | ||
59 | if (err) throw err | ||
60 | |||
61 | configUtils.getConfig(server.url, function (err, res) { | ||
62 | if (err) throw err | ||
63 | |||
64 | const data = res.body | ||
65 | |||
66 | expect(data.signup.allowed).to.be.false | ||
67 | |||
68 | done() | ||
69 | }) | ||
70 | }) | ||
71 | }) | ||
72 | |||
73 | after(function (done) { | ||
74 | process.kill(-server.app.pid) | ||
75 | |||
76 | // Keep the logs if the test failed | ||
77 | if (this.ok) { | ||
78 | serversUtils.flushTests(done) | ||
79 | } else { | ||
80 | done() | ||
81 | } | ||
82 | }) | ||
83 | }) | ||
diff --git a/server/tests/api/config.ts b/server/tests/api/config.ts new file mode 100644 index 000000000..3dda3b4d7 --- /dev/null +++ b/server/tests/api/config.ts | |||
@@ -0,0 +1,50 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | getConfig, | ||
9 | flushTests, | ||
10 | runServer, | ||
11 | registerUser | ||
12 | } from '../utils' | ||
13 | |||
14 | describe('Test config', function () { | ||
15 | let server = null | ||
16 | |||
17 | before(async function () { | ||
18 | this.timeout(120000) | ||
19 | |||
20 | await flushTests() | ||
21 | server = await runServer(1) | ||
22 | }) | ||
23 | |||
24 | it('Should have a correct config on a server with registration enabled', async function () { | ||
25 | const res = await getConfig(server.url) | ||
26 | const data = res.body | ||
27 | |||
28 | expect(data.signup.allowed).to.be.true | ||
29 | }) | ||
30 | |||
31 | it('Should have a correct config on a server with registration enabled and a users limit', async function () { | ||
32 | await registerUser(server.url, 'user1', 'super password') | ||
33 | await registerUser(server.url, 'user2', 'super password') | ||
34 | await registerUser(server.url, 'user3', 'super password') | ||
35 | |||
36 | const res = await getConfig(server.url) | ||
37 | const data = res.body | ||
38 | |||
39 | expect(data.signup.allowed).to.be.false | ||
40 | }) | ||
41 | |||
42 | after(async function () { | ||
43 | process.kill(-server.app.pid) | ||
44 | |||
45 | // Keep the logs if the test failed | ||
46 | if (this['ok']) { | ||
47 | await flushTests() | ||
48 | } | ||
49 | }) | ||
50 | }) | ||
diff --git a/server/tests/api/friends-advanced.js b/server/tests/api/friends-advanced.js deleted file mode 100644 index 89dc080bc..000000000 --- a/server/tests/api/friends-advanced.js +++ /dev/null | |||
@@ -1,394 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const series = require('async/series') | ||
9 | |||
10 | const loginUtils = require('../utils/login') | ||
11 | const podsUtils = require('../utils/pods') | ||
12 | const serversUtils = require('../utils/servers') | ||
13 | const videosUtils = require('../utils/videos') | ||
14 | |||
15 | describe('Test advanced friends', function () { | ||
16 | let servers = [] | ||
17 | |||
18 | function makeFriends (podNumber, callback) { | ||
19 | const server = servers[podNumber - 1] | ||
20 | return podsUtils.makeFriends(server.url, server.accessToken, callback) | ||
21 | } | ||
22 | |||
23 | function quitFriends (podNumber, callback) { | ||
24 | const server = servers[podNumber - 1] | ||
25 | return podsUtils.quitFriends(server.url, server.accessToken, callback) | ||
26 | } | ||
27 | |||
28 | function removeFriend (podNumber, podNumberToRemove, callback) { | ||
29 | const server = servers[podNumber - 1] | ||
30 | const serverToRemove = servers[podNumberToRemove - 1] | ||
31 | |||
32 | getFriendsList(podNumber, function (err, res) { | ||
33 | if (err) throw err | ||
34 | |||
35 | let friendsList = res.body.data | ||
36 | let podToRemove = friendsList.find((friend) => (friend.host === serverToRemove.host)) | ||
37 | |||
38 | return podsUtils.quitOneFriend(server.url, server.accessToken, podToRemove.id, callback) | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | function getFriendsList (podNumber, end) { | ||
43 | const server = servers[podNumber - 1] | ||
44 | return podsUtils.getFriendsList(server.url, end) | ||
45 | } | ||
46 | |||
47 | function uploadVideo (podNumber, callback) { | ||
48 | const videoAttributes = { | ||
49 | tags: [ 'tag1', 'tag2' ] | ||
50 | } | ||
51 | const server = servers[podNumber - 1] | ||
52 | |||
53 | return videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callback) | ||
54 | } | ||
55 | |||
56 | function getVideos (podNumber, callback) { | ||
57 | return videosUtils.getVideosList(servers[podNumber - 1].url, callback) | ||
58 | } | ||
59 | |||
60 | // --------------------------------------------------------------- | ||
61 | |||
62 | before(function (done) { | ||
63 | this.timeout(120000) | ||
64 | serversUtils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) { | ||
65 | servers = serversRun | ||
66 | |||
67 | each(servers, function (server, callbackEach) { | ||
68 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
69 | if (err) return callbackEach(err) | ||
70 | |||
71 | server.accessToken = accessToken | ||
72 | callbackEach() | ||
73 | }) | ||
74 | }, done) | ||
75 | }) | ||
76 | }) | ||
77 | |||
78 | it('Should make friends with two pod each in a different group', function (done) { | ||
79 | this.timeout(20000) | ||
80 | |||
81 | series([ | ||
82 | // Pod 3 makes friend with the first one | ||
83 | function (next) { | ||
84 | makeFriends(3, next) | ||
85 | }, | ||
86 | // Pod 4 makes friend with the second one | ||
87 | function (next) { | ||
88 | makeFriends(4, next) | ||
89 | }, | ||
90 | // Now if the fifth wants to make friends with the third et the first | ||
91 | function (next) { | ||
92 | makeFriends(5, next) | ||
93 | }, | ||
94 | function (next) { | ||
95 | setTimeout(next, 11000) | ||
96 | }], | ||
97 | function (err) { | ||
98 | if (err) throw err | ||
99 | |||
100 | // It should have 0 friends | ||
101 | getFriendsList(5, function (err, res) { | ||
102 | if (err) throw err | ||
103 | |||
104 | expect(res.body.data.length).to.equal(0) | ||
105 | |||
106 | done() | ||
107 | }) | ||
108 | } | ||
109 | ) | ||
110 | }) | ||
111 | |||
112 | it('Should quit all friends', function (done) { | ||
113 | this.timeout(10000) | ||
114 | |||
115 | series([ | ||
116 | function (next) { | ||
117 | quitFriends(1, next) | ||
118 | }, | ||
119 | function (next) { | ||
120 | quitFriends(2, next) | ||
121 | }], | ||
122 | function (err) { | ||
123 | if (err) throw err | ||
124 | |||
125 | each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { | ||
126 | getFriendsList(i, function (err, res) { | ||
127 | if (err) throw err | ||
128 | |||
129 | expect(res.body.data.length).to.equal(0) | ||
130 | |||
131 | callback() | ||
132 | }) | ||
133 | }, done) | ||
134 | } | ||
135 | ) | ||
136 | }) | ||
137 | |||
138 | it('Should make friends with the pods 1, 2, 3', function (done) { | ||
139 | this.timeout(150000) | ||
140 | |||
141 | series([ | ||
142 | // Pods 1, 2, 3 and 4 become friends | ||
143 | function (next) { | ||
144 | makeFriends(2, next) | ||
145 | }, | ||
146 | function (next) { | ||
147 | makeFriends(1, next) | ||
148 | }, | ||
149 | function (next) { | ||
150 | makeFriends(4, next) | ||
151 | }, | ||
152 | // Check the pods 1, 2, 3 and 4 are friends | ||
153 | function (next) { | ||
154 | each([ 1, 2, 3, 4 ], function (i, callback) { | ||
155 | getFriendsList(i, function (err, res) { | ||
156 | if (err) throw err | ||
157 | |||
158 | expect(res.body.data.length).to.equal(3) | ||
159 | |||
160 | callback() | ||
161 | }) | ||
162 | }, next) | ||
163 | }, | ||
164 | // Kill pod 4 | ||
165 | function (next) { | ||
166 | servers[3].app.kill() | ||
167 | next() | ||
168 | }, | ||
169 | // Expulse pod 4 from pod 1 and 2 | ||
170 | function (next) { | ||
171 | uploadVideo(1, next) | ||
172 | }, | ||
173 | function (next) { | ||
174 | uploadVideo(2, next) | ||
175 | }, | ||
176 | function (next) { | ||
177 | setTimeout(next, 11000) | ||
178 | }, | ||
179 | function (next) { | ||
180 | uploadVideo(1, next) | ||
181 | }, | ||
182 | function (next) { | ||
183 | uploadVideo(2, next) | ||
184 | }, | ||
185 | function (next) { | ||
186 | setTimeout(next, 22000) | ||
187 | }, | ||
188 | // Check the pods 1, 2 expulsed pod 4 | ||
189 | function (next) { | ||
190 | each([ 1, 2 ], function (i, callback) { | ||
191 | getFriendsList(i, function (err, res) { | ||
192 | if (err) throw err | ||
193 | |||
194 | // Pod 4 should not be our friend | ||
195 | const result = res.body.data | ||
196 | expect(result.length).to.equal(2) | ||
197 | for (const pod of result) { | ||
198 | expect(pod.host).not.equal(servers[3].host) | ||
199 | } | ||
200 | |||
201 | callback() | ||
202 | }) | ||
203 | }, next) | ||
204 | }, | ||
205 | // Rerun server 4 | ||
206 | function (next) { | ||
207 | serversUtils.runServer(4, function (server) { | ||
208 | servers[3].app = server.app | ||
209 | next() | ||
210 | }) | ||
211 | }, | ||
212 | function (next) { | ||
213 | getFriendsList(4, function (err, res) { | ||
214 | if (err) throw err | ||
215 | |||
216 | // Pod 4 didn't know pod 1 and 2 removed it | ||
217 | expect(res.body.data.length).to.equal(3) | ||
218 | next() | ||
219 | }) | ||
220 | }, | ||
221 | // Pod 6 asks pod 1, 2 and 3 | ||
222 | function (next) { | ||
223 | makeFriends(6, next) | ||
224 | }, | ||
225 | function (next) { | ||
226 | setTimeout(next, 11000) | ||
227 | }], | ||
228 | function (err) { | ||
229 | if (err) throw err | ||
230 | |||
231 | getFriendsList(6, function (err, res) { | ||
232 | if (err) throw err | ||
233 | |||
234 | // Pod 4 should not be our friend | ||
235 | const result = res.body.data | ||
236 | expect(result.length).to.equal(3) | ||
237 | for (const pod of result) { | ||
238 | expect(pod.host).not.equal(servers[3].host) | ||
239 | } | ||
240 | |||
241 | done() | ||
242 | }) | ||
243 | } | ||
244 | ) | ||
245 | }) | ||
246 | |||
247 | it('Should pod 1 quit friends', function (done) { | ||
248 | this.timeout(25000) | ||
249 | |||
250 | series([ | ||
251 | // Upload a video on server 3 for aditionnal tests | ||
252 | function (next) { | ||
253 | uploadVideo(3, next) | ||
254 | }, | ||
255 | function (next) { | ||
256 | setTimeout(next, 15000) | ||
257 | }, | ||
258 | function (next) { | ||
259 | quitFriends(1, next) | ||
260 | }, | ||
261 | // Remove pod 1 from pod 2 | ||
262 | function (next) { | ||
263 | getVideos(1, function (err, res) { | ||
264 | if (err) throw err | ||
265 | |||
266 | const videos = res.body.data | ||
267 | expect(videos).to.be.an('array') | ||
268 | expect(videos.length).to.equal(2) | ||
269 | |||
270 | next() | ||
271 | }) | ||
272 | }], | ||
273 | function (err) { | ||
274 | if (err) throw err | ||
275 | |||
276 | getVideos(2, function (err, res) { | ||
277 | if (err) throw err | ||
278 | |||
279 | const videos = res.body.data | ||
280 | expect(videos).to.be.an('array') | ||
281 | expect(videos.length).to.equal(3) | ||
282 | done() | ||
283 | }) | ||
284 | } | ||
285 | ) | ||
286 | }) | ||
287 | |||
288 | it('Should make friends between pod 1 and 2 and exchange their videos', function (done) { | ||
289 | this.timeout(20000) | ||
290 | makeFriends(1, function () { | ||
291 | setTimeout(function () { | ||
292 | getVideos(1, function (err, res) { | ||
293 | if (err) throw err | ||
294 | |||
295 | const videos = res.body.data | ||
296 | expect(videos).to.be.an('array') | ||
297 | expect(videos.length).to.equal(5) | ||
298 | |||
299 | done() | ||
300 | }) | ||
301 | }, 11000) | ||
302 | }) | ||
303 | }) | ||
304 | |||
305 | it('Should allow pod 6 to quit pod 1 & 2 and be friend with pod 3', function (done) { | ||
306 | this.timeout(30000) | ||
307 | |||
308 | series([ | ||
309 | // Pod 3 should have 4 friends | ||
310 | function (next) { | ||
311 | getFriendsList(3, function (err, res) { | ||
312 | if (err) throw err | ||
313 | |||
314 | const friendsList = res.body.data | ||
315 | expect(friendsList).to.be.an('array') | ||
316 | expect(friendsList.length).to.equal(4) | ||
317 | |||
318 | next() | ||
319 | }) | ||
320 | }, | ||
321 | // Pod 1, 2, 6 should have 3 friends each | ||
322 | function (next) { | ||
323 | each([ 1, 2, 6 ], function (i, callback) { | ||
324 | getFriendsList(i, function (err, res) { | ||
325 | if (err) throw err | ||
326 | |||
327 | const friendsList = res.body.data | ||
328 | expect(friendsList).to.be.an('array') | ||
329 | expect(friendsList.length).to.equal(3) | ||
330 | |||
331 | callback() | ||
332 | }) | ||
333 | }, next) | ||
334 | }, | ||
335 | function (next) { | ||
336 | removeFriend(6, 1, next) | ||
337 | }, | ||
338 | function (next) { | ||
339 | removeFriend(6, 2, next) | ||
340 | }, | ||
341 | // Pod 6 should now have only 1 friend (and it should be Pod 3) | ||
342 | function (next) { | ||
343 | getFriendsList(6, function (err, res) { | ||
344 | if (err) throw err | ||
345 | |||
346 | const friendsList = res.body.data | ||
347 | expect(friendsList).to.be.an('array') | ||
348 | expect(friendsList.length).to.equal(1) | ||
349 | expect(friendsList[0].host).to.equal(servers[2].host) | ||
350 | |||
351 | next() | ||
352 | }) | ||
353 | }, | ||
354 | // Pod 1 & 2 should not know friend 6 anymore | ||
355 | function (next) { | ||
356 | each([ 1, 2 ], function (i, callback) { | ||
357 | getFriendsList(i, function (err, res) { | ||
358 | if (err) throw err | ||
359 | |||
360 | const friendsList = res.body.data | ||
361 | expect(friendsList).to.be.an('array') | ||
362 | expect(friendsList.length).to.equal(2) | ||
363 | |||
364 | callback() | ||
365 | }) | ||
366 | }, next) | ||
367 | }, | ||
368 | // Pod 3 should know every pod | ||
369 | function (next) { | ||
370 | getFriendsList(3, function (err, res) { | ||
371 | if (err) throw err | ||
372 | |||
373 | const friendsList = res.body.data | ||
374 | expect(friendsList).to.be.an('array') | ||
375 | expect(friendsList.length).to.equal(4) | ||
376 | |||
377 | next() | ||
378 | }) | ||
379 | } | ||
380 | ], done) | ||
381 | }) | ||
382 | |||
383 | after(function (done) { | ||
384 | servers.forEach(function (server) { | ||
385 | process.kill(-server.app.pid) | ||
386 | }) | ||
387 | |||
388 | if (this.ok) { | ||
389 | serversUtils.flushTests(done) | ||
390 | } else { | ||
391 | done() | ||
392 | } | ||
393 | }) | ||
394 | }) | ||
diff --git a/server/tests/api/friends-advanced.ts b/server/tests/api/friends-advanced.ts new file mode 100644 index 000000000..dc5c83c5e --- /dev/null +++ b/server/tests/api/friends-advanced.ts | |||
@@ -0,0 +1,261 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | runServer, | ||
11 | uploadVideo, | ||
12 | quitFriends, | ||
13 | getVideosList, | ||
14 | wait, | ||
15 | setAccessTokensToServers, | ||
16 | flushAndRunMultipleServers, | ||
17 | killallServers, | ||
18 | makeFriends, | ||
19 | getFriendsList, | ||
20 | quitOneFriend | ||
21 | } from '../utils' | ||
22 | |||
23 | describe('Test advanced friends', function () { | ||
24 | let servers: ServerInfo[] = [] | ||
25 | |||
26 | async function makeFriendsWrapper (podNumber: number) { | ||
27 | const server = servers[podNumber - 1] | ||
28 | return await makeFriends(server.url, server.accessToken) | ||
29 | } | ||
30 | |||
31 | async function quitFriendsWrapper (podNumber: number) { | ||
32 | const server = servers[podNumber - 1] | ||
33 | return await quitFriends(server.url, server.accessToken) | ||
34 | } | ||
35 | |||
36 | async function removeFriendWrapper (podNumber: number, podNumberToRemove: number) { | ||
37 | const server = servers[podNumber - 1] | ||
38 | const serverToRemove = servers[podNumberToRemove - 1] | ||
39 | |||
40 | const res = await getFriendsList(server.url) | ||
41 | |||
42 | let friendsList = res.body.data | ||
43 | let podToRemove = friendsList.find(friend => (friend.host === serverToRemove.host)) | ||
44 | |||
45 | return await quitOneFriend(server.url, server.accessToken, podToRemove.id) | ||
46 | } | ||
47 | |||
48 | async function getFriendsListWrapper (podNumber: number) { | ||
49 | const server = servers[podNumber - 1] | ||
50 | return await getFriendsList(server.url) | ||
51 | } | ||
52 | |||
53 | async function uploadVideoWrapper (podNumber: number) { | ||
54 | const videoAttributes = { | ||
55 | tags: [ 'tag1', 'tag2' ] | ||
56 | } | ||
57 | const server = servers[podNumber - 1] | ||
58 | |||
59 | return await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
60 | } | ||
61 | |||
62 | async function getVideosWrapper (podNumber: number) { | ||
63 | return await getVideosList(servers[podNumber - 1].url) | ||
64 | } | ||
65 | |||
66 | // --------------------------------------------------------------- | ||
67 | |||
68 | before(async function () { | ||
69 | this.timeout(120000) | ||
70 | |||
71 | servers = await flushAndRunMultipleServers(6) | ||
72 | await setAccessTokensToServers(servers) | ||
73 | }) | ||
74 | |||
75 | it('Should make friends with two pod each in a different group', async function () { | ||
76 | this.timeout(20000) | ||
77 | |||
78 | // Pod 3 makes friend with the first one | ||
79 | await makeFriendsWrapper(3) | ||
80 | |||
81 | // Pod 4 makes friend with the second one | ||
82 | await makeFriendsWrapper(4) | ||
83 | |||
84 | // Now if the fifth wants to make friends with the third et the first | ||
85 | await makeFriendsWrapper(5) | ||
86 | |||
87 | await wait(11000) | ||
88 | |||
89 | // It should have 0 friends | ||
90 | const res = await getFriendsListWrapper(5) | ||
91 | expect(res.body.data.length).to.equal(0) | ||
92 | }) | ||
93 | |||
94 | it('Should quit all friends', async function () { | ||
95 | this.timeout(10000) | ||
96 | |||
97 | await quitFriendsWrapper(1) | ||
98 | await quitFriendsWrapper(2) | ||
99 | |||
100 | const serverNumbersToTest = [ 1, 2, 3, 4, 5, 6 ] | ||
101 | for (const i of serverNumbersToTest) { | ||
102 | const res = await getFriendsListWrapper(i) | ||
103 | expect(res.body.data.length).to.equal(0) | ||
104 | } | ||
105 | }) | ||
106 | |||
107 | it('Should make friends with the pods 1, 2, 3', async function () { | ||
108 | this.timeout(150000) | ||
109 | |||
110 | // Pods 1, 2, 3 and 4 become friends | ||
111 | await makeFriendsWrapper(2) | ||
112 | await makeFriendsWrapper(1) | ||
113 | await makeFriendsWrapper(4) | ||
114 | |||
115 | // Check the pods 1, 2, 3 and 4 are friends | ||
116 | let serverNumbersToTest = [ 1, 2, 3, 4 ] | ||
117 | for (const i of serverNumbersToTest) { | ||
118 | const res = await getFriendsListWrapper(i) | ||
119 | expect(res.body.data.length).to.equal(3) | ||
120 | } | ||
121 | |||
122 | // Kill pod 4 | ||
123 | servers[3].app.kill() | ||
124 | |||
125 | // Remove pod 4 from pod 1 and 2 | ||
126 | await uploadVideoWrapper(1) | ||
127 | await uploadVideoWrapper(2) | ||
128 | |||
129 | await wait(11000) | ||
130 | |||
131 | await uploadVideoWrapper(1) | ||
132 | await uploadVideoWrapper(2) | ||
133 | |||
134 | await wait(11000) | ||
135 | |||
136 | serverNumbersToTest = [ 1, 2 ] | ||
137 | |||
138 | for (const i of serverNumbersToTest) { | ||
139 | const res = await getFriendsListWrapper(i) | ||
140 | |||
141 | // Pod 4 should not be our friend | ||
142 | const friends = res.body.data | ||
143 | expect(friends.length).to.equal(2) | ||
144 | |||
145 | for (const pod of friends) { | ||
146 | expect(pod.host).not.equal(servers[3].host) | ||
147 | } | ||
148 | } | ||
149 | |||
150 | // Rerun server 4 | ||
151 | const newServer = await runServer(4) | ||
152 | servers[3].app = newServer.app | ||
153 | servers[3].app | ||
154 | |||
155 | const res1 = await getFriendsListWrapper(4) | ||
156 | |||
157 | // Pod 4 didn't know pod 1 and 2 removed it | ||
158 | expect(res1.body.data.length).to.equal(3) | ||
159 | |||
160 | // Pod 6 asks pod 1, 2 and 3 | ||
161 | await makeFriendsWrapper(6) | ||
162 | |||
163 | await wait(11000) | ||
164 | |||
165 | const res2 = await getFriendsListWrapper(6) | ||
166 | |||
167 | // Pod 4 should not be our friend | ||
168 | const friends = res2.body.data | ||
169 | expect(friends.length).to.equal(3) | ||
170 | for (const pod of friends) { | ||
171 | expect(pod.host).not.equal(servers[3].host) | ||
172 | } | ||
173 | }) | ||
174 | |||
175 | it('Should pod 1 quit friends', async function () { | ||
176 | this.timeout(25000) | ||
177 | |||
178 | // Upload a video on server 3 for additional tests | ||
179 | await uploadVideoWrapper(3) | ||
180 | |||
181 | await wait(15000) | ||
182 | |||
183 | await quitFriendsWrapper(1) | ||
184 | |||
185 | // Remove pod 1 from pod 2 | ||
186 | const res1 = await getVideosWrapper(1) | ||
187 | const videos1 = res1.body.data | ||
188 | expect(videos1).to.be.an('array') | ||
189 | expect(videos1.length).to.equal(2) | ||
190 | |||
191 | const res2 = await getVideosWrapper(2) | ||
192 | const videos2 = res2.body.data | ||
193 | expect(videos2).to.be.an('array') | ||
194 | expect(videos2.length).to.equal(3) | ||
195 | }) | ||
196 | |||
197 | it('Should make friends between pod 1 and 2 and exchange their videos', async function () { | ||
198 | this.timeout(20000) | ||
199 | |||
200 | await makeFriendsWrapper(1) | ||
201 | |||
202 | await wait(11000) | ||
203 | |||
204 | const res = await getVideosWrapper(1) | ||
205 | const videos = res.body.data | ||
206 | expect(videos).to.be.an('array') | ||
207 | expect(videos.length).to.equal(5) | ||
208 | }) | ||
209 | |||
210 | it('Should allow pod 6 to quit pod 1 & 2 and be friend with pod 3', async function () { | ||
211 | this.timeout(30000) | ||
212 | |||
213 | // Pod 3 should have 4 friends | ||
214 | const res1 = await getFriendsListWrapper(3) | ||
215 | const friendsList1 = res1.body.data | ||
216 | expect(friendsList1).to.be.an('array') | ||
217 | expect(friendsList1.length).to.equal(4) | ||
218 | |||
219 | // Pod 1, 2, 6 should have 3 friends each | ||
220 | let serverNumbersToTest = [ 1, 2, 6 ] | ||
221 | for (const i of serverNumbersToTest) { | ||
222 | const res = await getFriendsListWrapper(i) | ||
223 | const friendsList = res.body.data | ||
224 | expect(friendsList).to.be.an('array') | ||
225 | expect(friendsList.length).to.equal(3) | ||
226 | } | ||
227 | |||
228 | await removeFriendWrapper(6, 1) | ||
229 | await removeFriendWrapper(6, 2) | ||
230 | |||
231 | // Pod 6 should now have only 1 friend (and it should be Pod 3) | ||
232 | const res2 = await getFriendsListWrapper(6) | ||
233 | const friendsList2 = res2.body.data | ||
234 | expect(friendsList2).to.be.an('array') | ||
235 | expect(friendsList2.length).to.equal(1) | ||
236 | expect(friendsList2[0].host).to.equal(servers[2].host) | ||
237 | |||
238 | // Pod 1 & 2 should not know friend 6 anymore | ||
239 | serverNumbersToTest = [ 1, 2 ] | ||
240 | for (const i of serverNumbersToTest) { | ||
241 | const res = await getFriendsListWrapper(i) | ||
242 | const friendsList = res.body.data | ||
243 | expect(friendsList).to.be.an('array') | ||
244 | expect(friendsList.length).to.equal(2) | ||
245 | } | ||
246 | |||
247 | // Pod 3 should know every pod | ||
248 | const res3 = await getFriendsListWrapper(3) | ||
249 | const friendsList3 = res3.body.data | ||
250 | expect(friendsList3).to.be.an('array') | ||
251 | expect(friendsList3.length).to.equal(4) | ||
252 | }) | ||
253 | |||
254 | after(async function () { | ||
255 | killallServers(servers) | ||
256 | |||
257 | if (this['ok']) { | ||
258 | await flushTests() | ||
259 | } | ||
260 | }) | ||
261 | }) | ||
diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js deleted file mode 100644 index 5f1fdd255..000000000 --- a/server/tests/api/friends-basic.js +++ /dev/null | |||
@@ -1,277 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const series = require('async/series') | ||
9 | |||
10 | const loginUtils = require('../utils/login') | ||
11 | const miscsUtils = require('../utils/miscs') | ||
12 | const podsUtils = require('../utils/pods') | ||
13 | const serversUtils = require('../utils/servers') | ||
14 | |||
15 | describe('Test basic friends', function () { | ||
16 | let servers = [] | ||
17 | |||
18 | function makeFriends (podNumber, callback) { | ||
19 | const server = servers[podNumber - 1] | ||
20 | return podsUtils.makeFriends(server.url, server.accessToken, callback) | ||
21 | } | ||
22 | |||
23 | function testMadeFriends (servers, serverToTest, callback) { | ||
24 | const friends = [] | ||
25 | for (let i = 0; i < servers.length; i++) { | ||
26 | if (servers[i].url === serverToTest.url) continue | ||
27 | friends.push(servers[i].host) | ||
28 | } | ||
29 | |||
30 | podsUtils.getFriendsList(serverToTest.url, function (err, res) { | ||
31 | if (err) throw err | ||
32 | |||
33 | const result = res.body.data | ||
34 | expect(result).to.be.an('array') | ||
35 | expect(result.length).to.equal(2) | ||
36 | |||
37 | const resultHosts = [ result[0].host, result[1].host ] | ||
38 | expect(resultHosts[0]).to.not.equal(resultHosts[1]) | ||
39 | |||
40 | const errorString = 'Friends host do not correspond for ' + serverToTest.host | ||
41 | expect(friends).to.contain(resultHosts[0], errorString) | ||
42 | expect(friends).to.contain(resultHosts[1], errorString) | ||
43 | callback() | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | // --------------------------------------------------------------- | ||
48 | |||
49 | before(function (done) { | ||
50 | this.timeout(120000) | ||
51 | serversUtils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) { | ||
52 | servers = serversRun | ||
53 | |||
54 | each(servers, function (server, callbackEach) { | ||
55 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
56 | if (err) return callbackEach(err) | ||
57 | |||
58 | server.accessToken = accessToken | ||
59 | callbackEach() | ||
60 | }) | ||
61 | }, done) | ||
62 | }) | ||
63 | }) | ||
64 | |||
65 | it('Should not have friends', function (done) { | ||
66 | each(servers, function (server, callback) { | ||
67 | podsUtils.getFriendsList(server.url, function (err, res) { | ||
68 | if (err) throw err | ||
69 | |||
70 | const result = res.body.data | ||
71 | expect(result).to.be.an('array') | ||
72 | expect(result.length).to.equal(0) | ||
73 | callback() | ||
74 | }) | ||
75 | }, done) | ||
76 | }) | ||
77 | |||
78 | it('Should make friends', function (done) { | ||
79 | this.timeout(120000) | ||
80 | |||
81 | series([ | ||
82 | // The second pod make friend with the third | ||
83 | function (next) { | ||
84 | makeFriends(2, next) | ||
85 | }, | ||
86 | // Wait for the request between pods | ||
87 | function (next) { | ||
88 | setTimeout(next, 11000) | ||
89 | }, | ||
90 | // The second pod should have the third as a friend | ||
91 | function (next) { | ||
92 | podsUtils.getFriendsList(servers[1].url, function (err, res) { | ||
93 | if (err) throw err | ||
94 | |||
95 | const result = res.body.data | ||
96 | expect(result).to.be.an('array') | ||
97 | expect(result.length).to.equal(1) | ||
98 | |||
99 | const pod = result[0] | ||
100 | expect(pod.host).to.equal(servers[2].host) | ||
101 | expect(pod.email).to.equal('admin3@example.com') | ||
102 | expect(pod.score).to.equal(20) | ||
103 | expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true | ||
104 | |||
105 | next() | ||
106 | }) | ||
107 | }, | ||
108 | // Same here, the third pod should have the second pod as a friend | ||
109 | function (next) { | ||
110 | podsUtils.getFriendsList(servers[2].url, function (err, res) { | ||
111 | if (err) throw err | ||
112 | |||
113 | const result = res.body.data | ||
114 | expect(result).to.be.an('array') | ||
115 | expect(result.length).to.equal(1) | ||
116 | |||
117 | const pod = result[0] | ||
118 | expect(pod.host).to.equal(servers[1].host) | ||
119 | expect(pod.email).to.equal('admin2@example.com') | ||
120 | expect(pod.score).to.equal(20) | ||
121 | expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true | ||
122 | |||
123 | next() | ||
124 | }) | ||
125 | }, | ||
126 | // Finally the first pod make friend with the second pod | ||
127 | function (next) { | ||
128 | makeFriends(1, next) | ||
129 | }, | ||
130 | // Wait for the request between pods | ||
131 | function (next) { | ||
132 | setTimeout(next, 11000) | ||
133 | } | ||
134 | ], | ||
135 | // Now each pod should be friend with the other ones | ||
136 | function (err) { | ||
137 | if (err) throw err | ||
138 | each(servers, function (server, callback) { | ||
139 | testMadeFriends(servers, server, callback) | ||
140 | }, done) | ||
141 | }) | ||
142 | }) | ||
143 | |||
144 | it('Should not be allowed to make friend again', function (done) { | ||
145 | this.timeout(10000) | ||
146 | const server = servers[1] | ||
147 | podsUtils.makeFriends(server.url, server.accessToken, 409, done) | ||
148 | }) | ||
149 | |||
150 | it('Should quit friends of pod 2', function (done) { | ||
151 | this.timeout(10000) | ||
152 | |||
153 | series([ | ||
154 | // Pod 1 quit friends | ||
155 | function (next) { | ||
156 | const server = servers[1] | ||
157 | podsUtils.quitFriends(server.url, server.accessToken, next) | ||
158 | }, | ||
159 | // Pod 1 should not have friends anymore | ||
160 | function (next) { | ||
161 | podsUtils.getFriendsList(servers[1].url, function (err, res) { | ||
162 | if (err) throw err | ||
163 | |||
164 | const result = res.body.data | ||
165 | expect(result).to.be.an('array') | ||
166 | expect(result.length).to.equal(0) | ||
167 | |||
168 | next() | ||
169 | }) | ||
170 | }, | ||
171 | // Other pods shouldn't have pod 1 too | ||
172 | function (next) { | ||
173 | each([ servers[0].url, servers[2].url ], function (url, callback) { | ||
174 | podsUtils.getFriendsList(url, function (err, res) { | ||
175 | if (err) throw err | ||
176 | |||
177 | const result = res.body.data | ||
178 | expect(result).to.be.an('array') | ||
179 | expect(result.length).to.equal(1) | ||
180 | expect(result[0].host).not.to.be.equal(servers[1].host) | ||
181 | callback() | ||
182 | }) | ||
183 | }, next) | ||
184 | } | ||
185 | ], done) | ||
186 | }) | ||
187 | |||
188 | it('Should allow pod 2 to make friend again', function (done) { | ||
189 | this.timeout(120000) | ||
190 | |||
191 | const server = servers[1] | ||
192 | podsUtils.makeFriends(server.url, server.accessToken, function () { | ||
193 | setTimeout(function () { | ||
194 | each(servers, function (server, callback) { | ||
195 | testMadeFriends(servers, server, callback) | ||
196 | }, done) | ||
197 | }, 11000) | ||
198 | }) | ||
199 | }) | ||
200 | |||
201 | it('Should allow pod 1 to quit only pod 2', function (done) { | ||
202 | series([ | ||
203 | // Pod 1 quits pod 2 | ||
204 | function (next) { | ||
205 | const server = servers[0] | ||
206 | |||
207 | // Get pod 2 id so we can query it | ||
208 | podsUtils.getFriendsList(server.url, function (err, res) { | ||
209 | if (err) throw err | ||
210 | |||
211 | const result = res.body.data | ||
212 | let pod = result.find((friend) => (friend.host === servers[1].host)) | ||
213 | |||
214 | // Remove it from the friends list | ||
215 | podsUtils.quitOneFriend(server.url, server.accessToken, pod.id, next) | ||
216 | }) | ||
217 | }, | ||
218 | |||
219 | // Pod 1 should have only pod 3 in its friends list | ||
220 | function (next) { | ||
221 | podsUtils.getFriendsList(servers[0].url, function (err, res) { | ||
222 | if (err) throw err | ||
223 | |||
224 | const result = res.body.data | ||
225 | expect(result).to.be.an('array') | ||
226 | expect(result.length).to.equal(1) | ||
227 | |||
228 | const pod = result[0] | ||
229 | expect(pod.host).to.equal(servers[2].host) | ||
230 | |||
231 | next() | ||
232 | }) | ||
233 | }, | ||
234 | |||
235 | // Pod 2 should have only pod 3 in its friends list | ||
236 | function (next) { | ||
237 | podsUtils.getFriendsList(servers[1].url, function (err, res) { | ||
238 | if (err) throw err | ||
239 | |||
240 | const result = res.body.data | ||
241 | expect(result).to.be.an('array') | ||
242 | expect(result.length).to.equal(1) | ||
243 | |||
244 | const pod = result[0] | ||
245 | expect(pod.host).to.equal(servers[2].host) | ||
246 | |||
247 | next() | ||
248 | }) | ||
249 | }, | ||
250 | |||
251 | // Pod 3 should have both pods in its friends list | ||
252 | function (next) { | ||
253 | podsUtils.getFriendsList(servers[2].url, function (err, res) { | ||
254 | if (err) throw err | ||
255 | |||
256 | const result = res.body.data | ||
257 | expect(result).to.be.an('array') | ||
258 | expect(result.length).to.equal(2) | ||
259 | |||
260 | next() | ||
261 | }) | ||
262 | } | ||
263 | ], done) | ||
264 | }) | ||
265 | |||
266 | after(function (done) { | ||
267 | servers.forEach(function (server) { | ||
268 | process.kill(-server.app.pid) | ||
269 | }) | ||
270 | |||
271 | if (this.ok) { | ||
272 | serversUtils.flushTests(done) | ||
273 | } else { | ||
274 | done() | ||
275 | } | ||
276 | }) | ||
277 | }) | ||
diff --git a/server/tests/api/friends-basic.ts b/server/tests/api/friends-basic.ts new file mode 100644 index 000000000..13edf6273 --- /dev/null +++ b/server/tests/api/friends-basic.ts | |||
@@ -0,0 +1,203 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | quitFriends, | ||
11 | wait, | ||
12 | setAccessTokensToServers, | ||
13 | flushAndRunMultipleServers, | ||
14 | killallServers, | ||
15 | makeFriends, | ||
16 | getFriendsList, | ||
17 | dateIsValid, | ||
18 | quitOneFriend | ||
19 | } from '../utils' | ||
20 | |||
21 | describe('Test basic friends', function () { | ||
22 | let servers = [] | ||
23 | |||
24 | function makeFriendsWrapper (podNumber: number) { | ||
25 | const server = servers[podNumber - 1] | ||
26 | return makeFriends(server.url, server.accessToken) | ||
27 | } | ||
28 | |||
29 | async function testMadeFriends (servers: ServerInfo[], serverToTest: ServerInfo) { | ||
30 | const friends = [] | ||
31 | for (let i = 0; i < servers.length; i++) { | ||
32 | if (servers[i].url === serverToTest.url) continue | ||
33 | friends.push(servers[i].host) | ||
34 | } | ||
35 | |||
36 | const res = await getFriendsList(serverToTest.url) | ||
37 | |||
38 | const result = res.body.data | ||
39 | expect(result).to.be.an('array') | ||
40 | expect(result.length).to.equal(2) | ||
41 | |||
42 | const resultHosts = [ result[0].host, result[1].host ] | ||
43 | expect(resultHosts[0]).to.not.equal(resultHosts[1]) | ||
44 | |||
45 | const errorString = 'Friends host do not correspond for ' + serverToTest.host | ||
46 | expect(friends).to.contain(resultHosts[0], errorString) | ||
47 | expect(friends).to.contain(resultHosts[1], errorString) | ||
48 | } | ||
49 | |||
50 | // --------------------------------------------------------------- | ||
51 | |||
52 | before(async function () { | ||
53 | this.timeout(120000) | ||
54 | |||
55 | servers = await flushAndRunMultipleServers(3) | ||
56 | |||
57 | await setAccessTokensToServers(servers) | ||
58 | }) | ||
59 | |||
60 | it('Should not have friends', async function () { | ||
61 | for (const server of servers) { | ||
62 | const res = await getFriendsList(server.url) | ||
63 | |||
64 | const result = res.body.data | ||
65 | expect(result).to.be.an('array') | ||
66 | expect(result.length).to.equal(0) | ||
67 | } | ||
68 | }) | ||
69 | |||
70 | it('Should make friends', async function () { | ||
71 | this.timeout(120000) | ||
72 | |||
73 | // The second pod make friend with the third | ||
74 | await makeFriendsWrapper(2) | ||
75 | |||
76 | // Wait for the request between pods | ||
77 | await wait(11000) | ||
78 | |||
79 | // The second pod should have the third as a friend | ||
80 | const res1 = await getFriendsList(servers[1].url) | ||
81 | |||
82 | const friends = res1.body.data | ||
83 | expect(friends).to.be.an('array') | ||
84 | expect(friends.length).to.equal(1) | ||
85 | |||
86 | const pod1 = friends[0] | ||
87 | expect(pod1.host).to.equal(servers[2].host) | ||
88 | expect(pod1.email).to.equal('admin3@example.com') | ||
89 | expect(pod1.score).to.equal(20) | ||
90 | expect(dateIsValid(pod1.createdAt)).to.be.true | ||
91 | |||
92 | // Same here, the third pod should have the second pod as a friend | ||
93 | const res2 = await getFriendsList(servers[2].url) | ||
94 | const result = res2.body.data | ||
95 | expect(result).to.be.an('array') | ||
96 | expect(result.length).to.equal(1) | ||
97 | |||
98 | const pod2 = result[0] | ||
99 | expect(pod2.host).to.equal(servers[1].host) | ||
100 | expect(pod2.email).to.equal('admin2@example.com') | ||
101 | expect(pod2.score).to.equal(20) | ||
102 | expect(dateIsValid(pod2.createdAt)).to.be.true | ||
103 | |||
104 | // Finally the first pod make friend with the second pod | ||
105 | await makeFriendsWrapper(1) | ||
106 | |||
107 | // Wait for the request between pods | ||
108 | await wait(11000) | ||
109 | |||
110 | // Now each pod should be friend with the other ones | ||
111 | for (const server of servers) { | ||
112 | await testMadeFriends(servers, server) | ||
113 | } | ||
114 | }) | ||
115 | |||
116 | it('Should not be allowed to make friend again', async function () { | ||
117 | this.timeout(10000) | ||
118 | |||
119 | const server = servers[1] | ||
120 | await makeFriends(server.url, server.accessToken, 409) | ||
121 | }) | ||
122 | |||
123 | it('Should quit friends of pod 2', async function () { | ||
124 | this.timeout(10000) | ||
125 | |||
126 | // Pod 1 quit friends | ||
127 | await quitFriends(servers[1].url, servers[1].accessToken) | ||
128 | |||
129 | // Pod 1 should not have friends anymore | ||
130 | const res = await getFriendsList(servers[1].url) | ||
131 | const friends = res.body.data | ||
132 | expect(friends).to.be.an('array') | ||
133 | expect(friends).to.have.lengthOf(0) | ||
134 | |||
135 | // Other pods shouldn't have pod 1 too | ||
136 | const serversToTest = [ servers[0].url, servers[2].url ] | ||
137 | for (const url of serversToTest) { | ||
138 | const res = await getFriendsList(url) | ||
139 | const friends = res.body.data | ||
140 | |||
141 | expect(friends).to.be.an('array') | ||
142 | expect(friends.length).to.equal(1) | ||
143 | expect(friends[0].host).not.to.be.equal(servers[1].host) | ||
144 | } | ||
145 | }) | ||
146 | |||
147 | it('Should allow pod 2 to make friend again', async function () { | ||
148 | this.timeout(120000) | ||
149 | |||
150 | const server = servers[1] | ||
151 | await makeFriends(server.url, server.accessToken) | ||
152 | await wait(11000) | ||
153 | |||
154 | for (const server of servers) { | ||
155 | await testMadeFriends(servers, server) | ||
156 | } | ||
157 | }) | ||
158 | |||
159 | it('Should allow pod 1 to quit only pod 2', async function () { | ||
160 | // Pod 1 quits pod 2 | ||
161 | const server = servers[0] | ||
162 | |||
163 | // Get pod 2 id so we can query it | ||
164 | const res1 = await getFriendsList(server.url) | ||
165 | const friends1 = res1.body.data | ||
166 | let pod1 = friends1.find(friend => (friend.host === servers[1].host)) | ||
167 | |||
168 | // Remove it from the friends list | ||
169 | await quitOneFriend(server.url, server.accessToken, pod1.id) | ||
170 | |||
171 | // Pod 1 should have only pod 3 in its friends list | ||
172 | const res2 = await getFriendsList(servers[0].url) | ||
173 | const friends2 = res2.body.data | ||
174 | expect(friends2).to.be.an('array') | ||
175 | expect(friends2.length).to.equal(1) | ||
176 | |||
177 | const pod2 = friends2[0] | ||
178 | expect(pod2.host).to.equal(servers[2].host) | ||
179 | |||
180 | // Pod 2 should have only pod 3 in its friends list | ||
181 | const res3 = await getFriendsList(servers[1].url) | ||
182 | const friends3 = res3.body.data | ||
183 | expect(friends3).to.be.an('array') | ||
184 | expect(friends3.length).to.equal(1) | ||
185 | |||
186 | const pod = friends3[0] | ||
187 | expect(pod.host).to.equal(servers[2].host) | ||
188 | |||
189 | // Pod 3 should have both pods in its friends list | ||
190 | const res4 = await getFriendsList(servers[2].url) | ||
191 | const friends4 = res4.body.data | ||
192 | expect(friends4).to.be.an('array') | ||
193 | expect(friends4.length).to.equal(2) | ||
194 | }) | ||
195 | |||
196 | after(async function () { | ||
197 | killallServers(servers) | ||
198 | |||
199 | if (this['ok']) { | ||
200 | await flushTests() | ||
201 | } | ||
202 | }) | ||
203 | }) | ||
diff --git a/server/tests/api/index.js b/server/tests/api/index.js deleted file mode 100644 index 7404d7d88..000000000 --- a/server/tests/api/index.js +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // Order of the tests we want to execute | ||
4 | require('./config') | ||
5 | require('./check-params') | ||
6 | require('./friends-basic') | ||
7 | require('./users') | ||
8 | require('./single-pod') | ||
9 | require('./video-abuse') | ||
10 | require('./video-blacklist') | ||
11 | require('./multiple-pods') | ||
12 | require('./request-schedulers') | ||
13 | require('./friends-advanced') | ||
14 | require('./video-transcoder') | ||
diff --git a/server/tests/api/index.ts b/server/tests/api/index.ts new file mode 100644 index 000000000..f60d709c8 --- /dev/null +++ b/server/tests/api/index.ts | |||
@@ -0,0 +1,12 @@ | |||
1 | // Order of the tests we want to execute | ||
2 | import './config' | ||
3 | import './check-params' | ||
4 | import './friends-basic' | ||
5 | import './users' | ||
6 | import './single-pod' | ||
7 | import './video-abuse' | ||
8 | import './video-blacklist' | ||
9 | import './multiple-pods' | ||
10 | import './request-schedulers' | ||
11 | import './friends-advanced' | ||
12 | import './video-transcoder' | ||
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js deleted file mode 100644 index b281cc249..000000000 --- a/server/tests/api/multiple-pods.js +++ /dev/null | |||
@@ -1,854 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const eachSeries = require('async/eachSeries') | ||
8 | const expect = chai.expect | ||
9 | const parallel = require('async/parallel') | ||
10 | const series = require('async/series') | ||
11 | const WebTorrent = require('webtorrent') | ||
12 | const webtorrent = new WebTorrent() | ||
13 | |||
14 | const loginUtils = require('../utils/login') | ||
15 | const miscsUtils = require('../utils/miscs') | ||
16 | const podsUtils = require('../utils/pods') | ||
17 | const serversUtils = require('../utils/servers') | ||
18 | const videosUtils = require('../utils/videos') | ||
19 | |||
20 | describe('Test multiple pods', function () { | ||
21 | let servers = [] | ||
22 | const toRemove = [] | ||
23 | let videoUUID = '' | ||
24 | |||
25 | before(function (done) { | ||
26 | this.timeout(120000) | ||
27 | |||
28 | series([ | ||
29 | // Run servers | ||
30 | function (next) { | ||
31 | serversUtils.flushAndRunMultipleServers(3, function (serversRun) { | ||
32 | servers = serversRun | ||
33 | next() | ||
34 | }) | ||
35 | }, | ||
36 | // Get the access tokens | ||
37 | function (next) { | ||
38 | each(servers, function (server, callbackEach) { | ||
39 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
40 | if (err) return callbackEach(err) | ||
41 | |||
42 | server.accessToken = accessToken | ||
43 | callbackEach() | ||
44 | }) | ||
45 | }, next) | ||
46 | }, | ||
47 | // The second pod make friend with the third | ||
48 | function (next) { | ||
49 | const server = servers[1] | ||
50 | podsUtils.makeFriends(server.url, server.accessToken, next) | ||
51 | }, | ||
52 | // Wait for the request between pods | ||
53 | function (next) { | ||
54 | setTimeout(next, 10000) | ||
55 | }, | ||
56 | // Pod 1 make friends too | ||
57 | function (next) { | ||
58 | const server = servers[0] | ||
59 | podsUtils.makeFriends(server.url, server.accessToken, next) | ||
60 | } | ||
61 | ], done) | ||
62 | }) | ||
63 | |||
64 | it('Should not have videos for all pods', function (done) { | ||
65 | each(servers, function (server, callback) { | ||
66 | videosUtils.getVideosList(server.url, function (err, res) { | ||
67 | if (err) throw err | ||
68 | |||
69 | const videos = res.body.data | ||
70 | expect(videos).to.be.an('array') | ||
71 | expect(videos.length).to.equal(0) | ||
72 | |||
73 | callback() | ||
74 | }) | ||
75 | }, done) | ||
76 | }) | ||
77 | |||
78 | describe('Should upload the video and propagate on each pod', function () { | ||
79 | it('Should upload the video on pod 1 and propagate on each pod', function (done) { | ||
80 | // Pod 1 has video transcoding activated | ||
81 | this.timeout(15000) | ||
82 | |||
83 | series([ | ||
84 | function (next) { | ||
85 | const videoAttributes = { | ||
86 | name: 'my super name for pod 1', | ||
87 | category: 5, | ||
88 | licence: 4, | ||
89 | language: 9, | ||
90 | nsfw: true, | ||
91 | description: 'my super description for pod 1', | ||
92 | tags: [ 'tag1p1', 'tag2p1' ], | ||
93 | fixture: 'video_short1.webm' | ||
94 | } | ||
95 | videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, next) | ||
96 | }, | ||
97 | function (next) { | ||
98 | setTimeout(next, 11000) | ||
99 | }], | ||
100 | // All pods should have this video | ||
101 | function (err) { | ||
102 | if (err) throw err | ||
103 | |||
104 | each(servers, function (server, callback) { | ||
105 | let baseMagnet = null | ||
106 | |||
107 | videosUtils.getVideosList(server.url, function (err, res) { | ||
108 | if (err) throw err | ||
109 | |||
110 | const videos = res.body.data | ||
111 | expect(videos).to.be.an('array') | ||
112 | expect(videos.length).to.equal(1) | ||
113 | const video = videos[0] | ||
114 | expect(video.name).to.equal('my super name for pod 1') | ||
115 | expect(video.category).to.equal(5) | ||
116 | expect(video.categoryLabel).to.equal('Sports') | ||
117 | expect(video.licence).to.equal(4) | ||
118 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial') | ||
119 | expect(video.language).to.equal(9) | ||
120 | expect(video.languageLabel).to.equal('Japanese') | ||
121 | expect(video.nsfw).to.be.ok | ||
122 | expect(video.description).to.equal('my super description for pod 1') | ||
123 | expect(video.podHost).to.equal('localhost:9001') | ||
124 | expect(video.duration).to.equal(10) | ||
125 | expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) | ||
126 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
127 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
128 | expect(video.author).to.equal('root') | ||
129 | |||
130 | expect(video.files).to.have.lengthOf(1) | ||
131 | |||
132 | const file = video.files[0] | ||
133 | const magnetUri = file.magnetUri | ||
134 | expect(file.magnetUri).to.exist | ||
135 | expect(file.resolution).to.equal(0) | ||
136 | expect(file.resolutionLabel).to.equal('original') | ||
137 | expect(file.size).to.equal(572456) | ||
138 | |||
139 | if (server.url !== 'http://localhost:9001') { | ||
140 | expect(video.isLocal).to.be.false | ||
141 | } else { | ||
142 | expect(video.isLocal).to.be.true | ||
143 | } | ||
144 | |||
145 | // All pods should have the same magnet Uri | ||
146 | if (baseMagnet === null) { | ||
147 | baseMagnet = magnetUri | ||
148 | } else { | ||
149 | expect(baseMagnet).to.equal(magnetUri) | ||
150 | } | ||
151 | |||
152 | videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) { | ||
153 | if (err) throw err | ||
154 | expect(test).to.equal(true) | ||
155 | |||
156 | callback() | ||
157 | }) | ||
158 | }) | ||
159 | }, done) | ||
160 | } | ||
161 | ) | ||
162 | }) | ||
163 | |||
164 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | ||
165 | this.timeout(60000) | ||
166 | |||
167 | series([ | ||
168 | function (next) { | ||
169 | const videoAttributes = { | ||
170 | name: 'my super name for pod 2', | ||
171 | category: 4, | ||
172 | licence: 3, | ||
173 | language: 11, | ||
174 | nsfw: true, | ||
175 | description: 'my super description for pod 2', | ||
176 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], | ||
177 | fixture: 'video_short2.webm' | ||
178 | } | ||
179 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next) | ||
180 | }, | ||
181 | function (next) { | ||
182 | // Transcoding, so wait more that 22 seconds | ||
183 | setTimeout(next, 42000) | ||
184 | }], | ||
185 | // All pods should have this video | ||
186 | function (err) { | ||
187 | if (err) throw err | ||
188 | |||
189 | each(servers, function (server, callback) { | ||
190 | let baseMagnet = null | ||
191 | |||
192 | videosUtils.getVideosList(server.url, function (err, res) { | ||
193 | if (err) throw err | ||
194 | |||
195 | const videos = res.body.data | ||
196 | expect(videos).to.be.an('array') | ||
197 | expect(videos.length).to.equal(2) | ||
198 | const video = videos[1] | ||
199 | expect(video.name).to.equal('my super name for pod 2') | ||
200 | expect(video.category).to.equal(4) | ||
201 | expect(video.categoryLabel).to.equal('Art') | ||
202 | expect(video.licence).to.equal(3) | ||
203 | expect(video.licenceLabel).to.equal('Attribution - No Derivatives') | ||
204 | expect(video.language).to.equal(11) | ||
205 | expect(video.languageLabel).to.equal('German') | ||
206 | expect(video.nsfw).to.be.true | ||
207 | expect(video.description).to.equal('my super description for pod 2') | ||
208 | expect(video.podHost).to.equal('localhost:9002') | ||
209 | expect(video.duration).to.equal(5) | ||
210 | expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) | ||
211 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
212 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
213 | expect(video.author).to.equal('root') | ||
214 | |||
215 | expect(video.files).to.have.lengthOf(1) | ||
216 | |||
217 | const file = video.files[0] | ||
218 | const magnetUri = file.magnetUri | ||
219 | expect(file.magnetUri).to.exist | ||
220 | expect(file.resolution).to.equal(0) | ||
221 | expect(file.resolutionLabel).to.equal('original') | ||
222 | expect(file.size).to.equal(942961) | ||
223 | |||
224 | if (server.url !== 'http://localhost:9002') { | ||
225 | expect(video.isLocal).to.be.false | ||
226 | } else { | ||
227 | expect(video.isLocal).to.be.true | ||
228 | } | ||
229 | |||
230 | // All pods should have the same magnet Uri | ||
231 | if (baseMagnet === null) { | ||
232 | baseMagnet = magnetUri | ||
233 | } else { | ||
234 | expect(baseMagnet).to.equal(magnetUri) | ||
235 | } | ||
236 | |||
237 | videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) { | ||
238 | if (err) throw err | ||
239 | expect(test).to.equal(true) | ||
240 | |||
241 | callback() | ||
242 | }) | ||
243 | }) | ||
244 | }, done) | ||
245 | } | ||
246 | ) | ||
247 | }) | ||
248 | |||
249 | it('Should upload two videos on pod 3 and propagate on each pod', function (done) { | ||
250 | this.timeout(45000) | ||
251 | |||
252 | series([ | ||
253 | function (next) { | ||
254 | const videoAttributes = { | ||
255 | name: 'my super name for pod 3', | ||
256 | category: 6, | ||
257 | licence: 5, | ||
258 | language: 11, | ||
259 | nsfw: true, | ||
260 | description: 'my super description for pod 3', | ||
261 | tags: [ 'tag1p3' ], | ||
262 | fixture: 'video_short3.webm' | ||
263 | } | ||
264 | videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes, next) | ||
265 | }, | ||
266 | function (next) { | ||
267 | const videoAttributes = { | ||
268 | name: 'my super name for pod 3-2', | ||
269 | category: 7, | ||
270 | licence: 6, | ||
271 | language: 12, | ||
272 | nsfw: false, | ||
273 | description: 'my super description for pod 3-2', | ||
274 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], | ||
275 | fixture: 'video_short.webm' | ||
276 | } | ||
277 | videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes, next) | ||
278 | }, | ||
279 | function (next) { | ||
280 | setTimeout(next, 33000) | ||
281 | }], | ||
282 | function (err) { | ||
283 | if (err) throw err | ||
284 | |||
285 | let baseMagnet = null | ||
286 | // All pods should have this video | ||
287 | each(servers, function (server, callback) { | ||
288 | videosUtils.getVideosList(server.url, function (err, res) { | ||
289 | if (err) throw err | ||
290 | |||
291 | const videos = res.body.data | ||
292 | expect(videos).to.be.an('array') | ||
293 | expect(videos.length).to.equal(4) | ||
294 | |||
295 | // We not sure about the order of the two last uploads | ||
296 | let video1 = null | ||
297 | let video2 = null | ||
298 | if (videos[2].name === 'my super name for pod 3') { | ||
299 | video1 = videos[2] | ||
300 | video2 = videos[3] | ||
301 | } else { | ||
302 | video1 = videos[3] | ||
303 | video2 = videos[2] | ||
304 | } | ||
305 | |||
306 | expect(video1.name).to.equal('my super name for pod 3') | ||
307 | expect(video1.category).to.equal(6) | ||
308 | expect(video1.categoryLabel).to.equal('Travels') | ||
309 | expect(video1.licence).to.equal(5) | ||
310 | expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike') | ||
311 | expect(video1.language).to.equal(11) | ||
312 | expect(video1.languageLabel).to.equal('German') | ||
313 | expect(video1.nsfw).to.be.ok | ||
314 | expect(video1.description).to.equal('my super description for pod 3') | ||
315 | expect(video1.podHost).to.equal('localhost:9003') | ||
316 | expect(video1.duration).to.equal(5) | ||
317 | expect(video1.tags).to.deep.equal([ 'tag1p3' ]) | ||
318 | expect(video1.author).to.equal('root') | ||
319 | expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true | ||
320 | expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true | ||
321 | |||
322 | expect(video1.files).to.have.lengthOf(1) | ||
323 | |||
324 | const file1 = video1.files[0] | ||
325 | const magnetUri1 = file1.magnetUri | ||
326 | expect(file1.magnetUri).to.exist | ||
327 | expect(file1.resolution).to.equal(0) | ||
328 | expect(file1.resolutionLabel).to.equal('original') | ||
329 | expect(file1.size).to.equal(292677) | ||
330 | |||
331 | expect(video2.name).to.equal('my super name for pod 3-2') | ||
332 | expect(video2.category).to.equal(7) | ||
333 | expect(video2.categoryLabel).to.equal('Gaming') | ||
334 | expect(video2.licence).to.equal(6) | ||
335 | expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
336 | expect(video2.language).to.equal(12) | ||
337 | expect(video2.languageLabel).to.equal('Korean') | ||
338 | expect(video2.nsfw).to.be.false | ||
339 | expect(video2.description).to.equal('my super description for pod 3-2') | ||
340 | expect(video2.podHost).to.equal('localhost:9003') | ||
341 | expect(video2.duration).to.equal(5) | ||
342 | expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) | ||
343 | expect(video2.author).to.equal('root') | ||
344 | expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true | ||
345 | expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true | ||
346 | |||
347 | expect(video2.files).to.have.lengthOf(1) | ||
348 | |||
349 | const file2 = video2.files[0] | ||
350 | const magnetUri2 = file2.magnetUri | ||
351 | expect(file2.magnetUri).to.exist | ||
352 | expect(file2.resolution).to.equal(0) | ||
353 | expect(file2.resolutionLabel).to.equal('original') | ||
354 | expect(file2.size).to.equal(218910) | ||
355 | |||
356 | if (server.url !== 'http://localhost:9003') { | ||
357 | expect(video1.isLocal).to.be.false | ||
358 | expect(video2.isLocal).to.be.false | ||
359 | } else { | ||
360 | expect(video1.isLocal).to.be.true | ||
361 | expect(video2.isLocal).to.be.true | ||
362 | } | ||
363 | |||
364 | // All pods should have the same magnet Uri | ||
365 | if (baseMagnet === null) { | ||
366 | baseMagnet = magnetUri2 | ||
367 | } else { | ||
368 | expect(baseMagnet).to.equal(magnetUri2) | ||
369 | } | ||
370 | |||
371 | videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) { | ||
372 | if (err) throw err | ||
373 | expect(test).to.equal(true) | ||
374 | |||
375 | videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) { | ||
376 | if (err) throw err | ||
377 | expect(test).to.equal(true) | ||
378 | |||
379 | callback() | ||
380 | }) | ||
381 | }) | ||
382 | }) | ||
383 | }, done) | ||
384 | } | ||
385 | ) | ||
386 | }) | ||
387 | }) | ||
388 | |||
389 | describe('Should seed the uploaded video', function () { | ||
390 | it('Should add the file 1 by asking pod 3', function (done) { | ||
391 | // Yes, this could be long | ||
392 | this.timeout(200000) | ||
393 | |||
394 | videosUtils.getVideosList(servers[2].url, function (err, res) { | ||
395 | if (err) throw err | ||
396 | |||
397 | const video = res.body.data[0] | ||
398 | toRemove.push(res.body.data[2]) | ||
399 | toRemove.push(res.body.data[3]) | ||
400 | |||
401 | webtorrent.add(video.files[0].magnetUri, function (torrent) { | ||
402 | expect(torrent.files).to.exist | ||
403 | expect(torrent.files.length).to.equal(1) | ||
404 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
405 | |||
406 | done() | ||
407 | }) | ||
408 | }) | ||
409 | }) | ||
410 | |||
411 | it('Should add the file 2 by asking pod 1', function (done) { | ||
412 | // Yes, this could be long | ||
413 | this.timeout(200000) | ||
414 | |||
415 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
416 | if (err) throw err | ||
417 | |||
418 | const video = res.body.data[1] | ||
419 | |||
420 | webtorrent.add(video.files[0].magnetUri, function (torrent) { | ||
421 | expect(torrent.files).to.exist | ||
422 | expect(torrent.files.length).to.equal(1) | ||
423 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
424 | |||
425 | done() | ||
426 | }) | ||
427 | }) | ||
428 | }) | ||
429 | |||
430 | it('Should add the file 3 by asking pod 2', function (done) { | ||
431 | // Yes, this could be long | ||
432 | this.timeout(200000) | ||
433 | |||
434 | videosUtils.getVideosList(servers[1].url, function (err, res) { | ||
435 | if (err) throw err | ||
436 | |||
437 | const video = res.body.data[2] | ||
438 | |||
439 | webtorrent.add(video.files[0].magnetUri, function (torrent) { | ||
440 | expect(torrent.files).to.exist | ||
441 | expect(torrent.files.length).to.equal(1) | ||
442 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
443 | |||
444 | done() | ||
445 | }) | ||
446 | }) | ||
447 | }) | ||
448 | |||
449 | it('Should add the file 3-2 by asking pod 1', function (done) { | ||
450 | // Yes, this could be long | ||
451 | this.timeout(200000) | ||
452 | |||
453 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
454 | if (err) throw err | ||
455 | |||
456 | const video = res.body.data[3] | ||
457 | |||
458 | webtorrent.add(video.files[0].magnetUri, function (torrent) { | ||
459 | expect(torrent.files).to.exist | ||
460 | expect(torrent.files.length).to.equal(1) | ||
461 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
462 | |||
463 | done() | ||
464 | }) | ||
465 | }) | ||
466 | }) | ||
467 | }) | ||
468 | |||
469 | describe('Should update video views, likes and dislikes', function () { | ||
470 | let localVideosPod3 = [] | ||
471 | let remoteVideosPod1 = [] | ||
472 | let remoteVideosPod2 = [] | ||
473 | let remoteVideosPod3 = [] | ||
474 | |||
475 | before(function (done) { | ||
476 | parallel([ | ||
477 | function (callback) { | ||
478 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
479 | if (err) throw err | ||
480 | |||
481 | remoteVideosPod1 = res.body.data.filter(video => video.isLocal === false).map(video => video.id) | ||
482 | |||
483 | callback() | ||
484 | }) | ||
485 | }, | ||
486 | |||
487 | function (callback) { | ||
488 | videosUtils.getVideosList(servers[1].url, function (err, res) { | ||
489 | if (err) throw err | ||
490 | |||
491 | remoteVideosPod2 = res.body.data.filter(video => video.isLocal === false).map(video => video.id) | ||
492 | |||
493 | callback() | ||
494 | }) | ||
495 | }, | ||
496 | |||
497 | function (callback) { | ||
498 | videosUtils.getVideosList(servers[2].url, function (err, res) { | ||
499 | if (err) throw err | ||
500 | |||
501 | localVideosPod3 = res.body.data.filter(video => video.isLocal === true).map(video => video.id) | ||
502 | remoteVideosPod3 = res.body.data.filter(video => video.isLocal === false).map(video => video.id) | ||
503 | |||
504 | callback() | ||
505 | }) | ||
506 | } | ||
507 | ], done) | ||
508 | }) | ||
509 | |||
510 | it('Should view multiple videos on owned servers', function (done) { | ||
511 | this.timeout(30000) | ||
512 | |||
513 | parallel([ | ||
514 | function (callback) { | ||
515 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) | ||
516 | }, | ||
517 | |||
518 | function (callback) { | ||
519 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) | ||
520 | }, | ||
521 | |||
522 | function (callback) { | ||
523 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) | ||
524 | }, | ||
525 | |||
526 | function (callback) { | ||
527 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) | ||
528 | }, | ||
529 | |||
530 | function (callback) { | ||
531 | setTimeout(callback, 22000) | ||
532 | } | ||
533 | ], function (err) { | ||
534 | if (err) throw err | ||
535 | |||
536 | eachSeries(servers, function (server, callback) { | ||
537 | videosUtils.getVideosList(server.url, function (err, res) { | ||
538 | if (err) throw err | ||
539 | |||
540 | const videos = res.body.data | ||
541 | expect(videos.find(video => video.views === 3)).to.exist | ||
542 | expect(videos.find(video => video.views === 1)).to.exist | ||
543 | |||
544 | callback() | ||
545 | }) | ||
546 | }, done) | ||
547 | }) | ||
548 | }) | ||
549 | |||
550 | it('Should view multiple videos on each servers', function (done) { | ||
551 | this.timeout(30000) | ||
552 | |||
553 | parallel([ | ||
554 | function (callback) { | ||
555 | videosUtils.getVideo(servers[0].url, remoteVideosPod1[0], callback) | ||
556 | }, | ||
557 | |||
558 | function (callback) { | ||
559 | videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback) | ||
560 | }, | ||
561 | |||
562 | function (callback) { | ||
563 | videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback) | ||
564 | }, | ||
565 | |||
566 | function (callback) { | ||
567 | videosUtils.getVideo(servers[2].url, remoteVideosPod3[0], callback) | ||
568 | }, | ||
569 | |||
570 | function (callback) { | ||
571 | videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback) | ||
572 | }, | ||
573 | |||
574 | function (callback) { | ||
575 | videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback) | ||
576 | }, | ||
577 | |||
578 | function (callback) { | ||
579 | videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback) | ||
580 | }, | ||
581 | |||
582 | function (callback) { | ||
583 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) | ||
584 | }, | ||
585 | |||
586 | function (callback) { | ||
587 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) | ||
588 | }, | ||
589 | |||
590 | function (callback) { | ||
591 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) | ||
592 | }, | ||
593 | |||
594 | function (callback) { | ||
595 | setTimeout(callback, 22000) | ||
596 | } | ||
597 | ], function (err) { | ||
598 | if (err) throw err | ||
599 | |||
600 | let baseVideos = null | ||
601 | eachSeries(servers, function (server, callback) { | ||
602 | videosUtils.getVideosList(server.url, function (err, res) { | ||
603 | if (err) throw err | ||
604 | |||
605 | const videos = res.body.data | ||
606 | |||
607 | // Initialize base videos for future comparisons | ||
608 | if (baseVideos === null) { | ||
609 | baseVideos = videos | ||
610 | return callback() | ||
611 | } | ||
612 | |||
613 | baseVideos.forEach(baseVideo => { | ||
614 | const sameVideo = videos.find(video => video.name === baseVideo.name) | ||
615 | expect(baseVideo.views).to.equal(sameVideo.views) | ||
616 | }) | ||
617 | |||
618 | callback() | ||
619 | }) | ||
620 | }, done) | ||
621 | }) | ||
622 | }) | ||
623 | |||
624 | it('Should like and dislikes videos on different services', function (done) { | ||
625 | this.timeout(30000) | ||
626 | |||
627 | parallel([ | ||
628 | function (callback) { | ||
629 | videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback) | ||
630 | }, | ||
631 | |||
632 | function (callback) { | ||
633 | videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike', callback) | ||
634 | }, | ||
635 | |||
636 | function (callback) { | ||
637 | videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback) | ||
638 | }, | ||
639 | |||
640 | function (callback) { | ||
641 | videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like', callback) | ||
642 | }, | ||
643 | |||
644 | function (callback) { | ||
645 | videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike', callback) | ||
646 | }, | ||
647 | |||
648 | function (callback) { | ||
649 | videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike', callback) | ||
650 | }, | ||
651 | |||
652 | function (callback) { | ||
653 | videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like', callback) | ||
654 | }, | ||
655 | |||
656 | function (callback) { | ||
657 | setTimeout(callback, 22000) | ||
658 | } | ||
659 | ], function (err) { | ||
660 | if (err) throw err | ||
661 | |||
662 | let baseVideos = null | ||
663 | eachSeries(servers, function (server, callback) { | ||
664 | videosUtils.getVideosList(server.url, function (err, res) { | ||
665 | if (err) throw err | ||
666 | |||
667 | const videos = res.body.data | ||
668 | |||
669 | // Initialize base videos for future comparisons | ||
670 | if (baseVideos === null) { | ||
671 | baseVideos = videos | ||
672 | return callback() | ||
673 | } | ||
674 | |||
675 | baseVideos.forEach(baseVideo => { | ||
676 | const sameVideo = videos.find(video => video.name === baseVideo.name) | ||
677 | expect(baseVideo.likes).to.equal(sameVideo.likes) | ||
678 | expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) | ||
679 | }) | ||
680 | |||
681 | callback() | ||
682 | }) | ||
683 | }, done) | ||
684 | }) | ||
685 | }) | ||
686 | }) | ||
687 | |||
688 | describe('Should manipulate these videos', function () { | ||
689 | it('Should update the video 3 by asking pod 3', function (done) { | ||
690 | this.timeout(15000) | ||
691 | |||
692 | const attributes = { | ||
693 | name: 'my super video updated', | ||
694 | category: 10, | ||
695 | licence: 7, | ||
696 | language: 13, | ||
697 | nsfw: true, | ||
698 | description: 'my super description updated', | ||
699 | tags: [ 'tagup1', 'tagup2' ] | ||
700 | } | ||
701 | videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes, function (err) { | ||
702 | if (err) throw err | ||
703 | |||
704 | setTimeout(done, 11000) | ||
705 | }) | ||
706 | }) | ||
707 | |||
708 | it('Should have the video 3 updated on each pod', function (done) { | ||
709 | this.timeout(200000) | ||
710 | |||
711 | each(servers, function (server, callback) { | ||
712 | // Avoid "duplicate torrent" errors | ||
713 | const webtorrent = new WebTorrent() | ||
714 | |||
715 | videosUtils.getVideosList(server.url, function (err, res) { | ||
716 | if (err) throw err | ||
717 | |||
718 | const videos = res.body.data | ||
719 | const videoUpdated = videos.find(function (video) { | ||
720 | return video.name === 'my super video updated' | ||
721 | }) | ||
722 | |||
723 | expect(!!videoUpdated).to.be.true | ||
724 | expect(videoUpdated.category).to.equal(10) | ||
725 | expect(videoUpdated.categoryLabel).to.equal('Entertainment') | ||
726 | expect(videoUpdated.licence).to.equal(7) | ||
727 | expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication') | ||
728 | expect(videoUpdated.language).to.equal(13) | ||
729 | expect(videoUpdated.languageLabel).to.equal('French') | ||
730 | expect(videoUpdated.nsfw).to.be.ok | ||
731 | expect(videoUpdated.description).to.equal('my super description updated') | ||
732 | expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | ||
733 | expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true | ||
734 | |||
735 | const file = videoUpdated.files[0] | ||
736 | const magnetUri = file.magnetUri | ||
737 | expect(file.magnetUri).to.exist | ||
738 | expect(file.resolution).to.equal(0) | ||
739 | expect(file.resolutionLabel).to.equal('original') | ||
740 | expect(file.size).to.equal(292677) | ||
741 | |||
742 | videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) { | ||
743 | if (err) throw err | ||
744 | expect(test).to.equal(true) | ||
745 | |||
746 | webtorrent.add(videoUpdated.files[0].magnetUri, function (torrent) { | ||
747 | expect(torrent.files).to.exist | ||
748 | expect(torrent.files.length).to.equal(1) | ||
749 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
750 | |||
751 | callback() | ||
752 | }) | ||
753 | }) | ||
754 | }) | ||
755 | }, done) | ||
756 | }) | ||
757 | |||
758 | it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) { | ||
759 | this.timeout(15000) | ||
760 | |||
761 | series([ | ||
762 | function (next) { | ||
763 | videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next) | ||
764 | }, | ||
765 | function (next) { | ||
766 | videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next) | ||
767 | }], | ||
768 | function (err) { | ||
769 | if (err) throw err | ||
770 | setTimeout(done, 11000) | ||
771 | } | ||
772 | ) | ||
773 | }) | ||
774 | |||
775 | it('Should have videos 1 and 3 on each pod', function (done) { | ||
776 | each(servers, function (server, callback) { | ||
777 | videosUtils.getVideosList(server.url, function (err, res) { | ||
778 | if (err) throw err | ||
779 | |||
780 | const videos = res.body.data | ||
781 | expect(videos).to.be.an('array') | ||
782 | expect(videos.length).to.equal(2) | ||
783 | expect(videos[0].name).not.to.equal(videos[1].name) | ||
784 | expect(videos[0].name).not.to.equal(toRemove[0].name) | ||
785 | expect(videos[1].name).not.to.equal(toRemove[0].name) | ||
786 | expect(videos[0].name).not.to.equal(toRemove[1].name) | ||
787 | expect(videos[1].name).not.to.equal(toRemove[1].name) | ||
788 | |||
789 | videoUUID = videos.find(video => video.name === 'my super name for pod 1').uuid | ||
790 | |||
791 | callback() | ||
792 | }) | ||
793 | }, done) | ||
794 | }) | ||
795 | |||
796 | it('Should get the same video by UUID on each pod', function (done) { | ||
797 | let baseVideo = null | ||
798 | each(servers, function (server, callback) { | ||
799 | videosUtils.getVideo(server.url, videoUUID, function (err, res) { | ||
800 | if (err) throw err | ||
801 | |||
802 | const video = res.body | ||
803 | |||
804 | if (baseVideo === null) { | ||
805 | baseVideo = video | ||
806 | return callback() | ||
807 | } | ||
808 | |||
809 | expect(baseVideo.name).to.equal(video.name) | ||
810 | expect(baseVideo.uuid).to.equal(video.uuid) | ||
811 | expect(baseVideo.category).to.equal(video.category) | ||
812 | expect(baseVideo.language).to.equal(video.language) | ||
813 | expect(baseVideo.licence).to.equal(video.licence) | ||
814 | expect(baseVideo.category).to.equal(video.category) | ||
815 | expect(baseVideo.nsfw).to.equal(video.nsfw) | ||
816 | expect(baseVideo.author).to.equal(video.author) | ||
817 | expect(baseVideo.tags).to.deep.equal(video.tags) | ||
818 | |||
819 | callback() | ||
820 | }) | ||
821 | }, done) | ||
822 | }) | ||
823 | |||
824 | it('Should get the preview from each pod', function (done) { | ||
825 | each(servers, function (server, callback) { | ||
826 | videosUtils.getVideo(server.url, videoUUID, function (err, res) { | ||
827 | if (err) throw err | ||
828 | |||
829 | const video = res.body | ||
830 | |||
831 | videosUtils.testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath, function (err, test) { | ||
832 | if (err) throw err | ||
833 | expect(test).to.equal(true) | ||
834 | |||
835 | callback() | ||
836 | }) | ||
837 | }) | ||
838 | }, done) | ||
839 | }) | ||
840 | }) | ||
841 | |||
842 | after(function (done) { | ||
843 | servers.forEach(function (server) { | ||
844 | process.kill(-server.app.pid) | ||
845 | }) | ||
846 | |||
847 | // Keep the logs if the test failed | ||
848 | if (this.ok) { | ||
849 | serversUtils.flushTests(done) | ||
850 | } else { | ||
851 | done() | ||
852 | } | ||
853 | }) | ||
854 | }) | ||
diff --git a/server/tests/api/multiple-pods.ts b/server/tests/api/multiple-pods.ts new file mode 100644 index 000000000..7117ab290 --- /dev/null +++ b/server/tests/api/multiple-pods.ts | |||
@@ -0,0 +1,627 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | |||
6 | import { | ||
7 | dateIsValid, | ||
8 | flushAndRunMultipleServers, | ||
9 | flushTests, | ||
10 | getVideo, | ||
11 | getVideosList, | ||
12 | killallServers, | ||
13 | makeFriends, | ||
14 | rateVideo, | ||
15 | removeVideo, | ||
16 | ServerInfo, | ||
17 | setAccessTokensToServers, | ||
18 | testVideoImage, | ||
19 | updateVideo, | ||
20 | uploadVideo, | ||
21 | wait, | ||
22 | webtorrentAdd | ||
23 | } from '../utils' | ||
24 | |||
25 | const expect = chai.expect | ||
26 | |||
27 | describe('Test multiple pods', function () { | ||
28 | let servers: ServerInfo[] = [] | ||
29 | const toRemove = [] | ||
30 | let videoUUID = '' | ||
31 | |||
32 | before(async function () { | ||
33 | this.timeout(120000) | ||
34 | |||
35 | servers = await flushAndRunMultipleServers(3) | ||
36 | |||
37 | // Get the access tokens | ||
38 | await setAccessTokensToServers(servers) | ||
39 | |||
40 | // The second pod make friend with the third | ||
41 | await makeFriends(servers[1].url, servers[1].accessToken) | ||
42 | |||
43 | // Wait for the request between pods | ||
44 | await wait(10000) | ||
45 | |||
46 | // Pod 1 make friends too | ||
47 | await makeFriends(servers[0].url, servers[0].accessToken) | ||
48 | }) | ||
49 | |||
50 | it('Should not have videos for all pods', async function () { | ||
51 | for (const server of servers) { | ||
52 | const res = await getVideosList(server.url) | ||
53 | const videos = res.body.data | ||
54 | expect(videos).to.be.an('array') | ||
55 | expect(videos.length).to.equal(0) | ||
56 | } | ||
57 | }) | ||
58 | |||
59 | describe('Should upload the video and propagate on each pod', function () { | ||
60 | it('Should upload the video on pod 1 and propagate on each pod', async function () { | ||
61 | // Pod 1 has video transcoding activated | ||
62 | this.timeout(15000) | ||
63 | |||
64 | const videoAttributes = { | ||
65 | name: 'my super name for pod 1', | ||
66 | category: 5, | ||
67 | licence: 4, | ||
68 | language: 9, | ||
69 | nsfw: true, | ||
70 | description: 'my super description for pod 1', | ||
71 | tags: [ 'tag1p1', 'tag2p1' ], | ||
72 | fixture: 'video_short1.webm' | ||
73 | } | ||
74 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | ||
75 | |||
76 | await wait(11000) | ||
77 | |||
78 | // All pods should have this video | ||
79 | for (const server of servers) { | ||
80 | let baseMagnet = null | ||
81 | |||
82 | const res = await getVideosList(server.url) | ||
83 | |||
84 | const videos = res.body.data | ||
85 | expect(videos).to.be.an('array') | ||
86 | expect(videos.length).to.equal(1) | ||
87 | const video = videos[0] | ||
88 | expect(video.name).to.equal('my super name for pod 1') | ||
89 | expect(video.category).to.equal(5) | ||
90 | expect(video.categoryLabel).to.equal('Sports') | ||
91 | expect(video.licence).to.equal(4) | ||
92 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial') | ||
93 | expect(video.language).to.equal(9) | ||
94 | expect(video.languageLabel).to.equal('Japanese') | ||
95 | expect(video.nsfw).to.be.ok | ||
96 | expect(video.description).to.equal('my super description for pod 1') | ||
97 | expect(video.podHost).to.equal('localhost:9001') | ||
98 | expect(video.duration).to.equal(10) | ||
99 | expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) | ||
100 | expect(dateIsValid(video.createdAt)).to.be.true | ||
101 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
102 | expect(video.author).to.equal('root') | ||
103 | |||
104 | expect(video.files).to.have.lengthOf(1) | ||
105 | |||
106 | const file = video.files[0] | ||
107 | const magnetUri = file.magnetUri | ||
108 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
109 | expect(file.resolution).to.equal(0) | ||
110 | expect(file.resolutionLabel).to.equal('original') | ||
111 | expect(file.size).to.equal(572456) | ||
112 | |||
113 | if (server.url !== 'http://localhost:9001') { | ||
114 | expect(video.isLocal).to.be.false | ||
115 | } else { | ||
116 | expect(video.isLocal).to.be.true | ||
117 | } | ||
118 | |||
119 | // All pods should have the same magnet Uri | ||
120 | if (baseMagnet === null) { | ||
121 | baseMagnet = magnetUri | ||
122 | } else { | ||
123 | expect(baseMagnet).to.equal(magnetUri) | ||
124 | } | ||
125 | |||
126 | const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath) | ||
127 | expect(test).to.equal(true) | ||
128 | } | ||
129 | }) | ||
130 | |||
131 | it('Should upload the video on pod 2 and propagate on each pod', async function () { | ||
132 | this.timeout(60000) | ||
133 | |||
134 | const videoAttributes = { | ||
135 | name: 'my super name for pod 2', | ||
136 | category: 4, | ||
137 | licence: 3, | ||
138 | language: 11, | ||
139 | nsfw: true, | ||
140 | description: 'my super description for pod 2', | ||
141 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], | ||
142 | fixture: 'video_short2.webm' | ||
143 | } | ||
144 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
145 | |||
146 | // Transcoding, so wait more that 22 seconds | ||
147 | await wait(42000) | ||
148 | |||
149 | // All pods should have this video | ||
150 | for (const server of servers) { | ||
151 | let baseMagnet = null | ||
152 | |||
153 | const res = await getVideosList(server.url) | ||
154 | |||
155 | const videos = res.body.data | ||
156 | expect(videos).to.be.an('array') | ||
157 | expect(videos.length).to.equal(2) | ||
158 | const video = videos[1] | ||
159 | expect(video.name).to.equal('my super name for pod 2') | ||
160 | expect(video.category).to.equal(4) | ||
161 | expect(video.categoryLabel).to.equal('Art') | ||
162 | expect(video.licence).to.equal(3) | ||
163 | expect(video.licenceLabel).to.equal('Attribution - No Derivatives') | ||
164 | expect(video.language).to.equal(11) | ||
165 | expect(video.languageLabel).to.equal('German') | ||
166 | expect(video.nsfw).to.be.true | ||
167 | expect(video.description).to.equal('my super description for pod 2') | ||
168 | expect(video.podHost).to.equal('localhost:9002') | ||
169 | expect(video.duration).to.equal(5) | ||
170 | expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) | ||
171 | expect(dateIsValid(video.createdAt)).to.be.true | ||
172 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
173 | expect(video.author).to.equal('root') | ||
174 | |||
175 | expect(video.files).to.have.lengthOf(1) | ||
176 | |||
177 | const file = video.files[0] | ||
178 | const magnetUri = file.magnetUri | ||
179 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
180 | expect(file.resolution).to.equal(0) | ||
181 | expect(file.resolutionLabel).to.equal('original') | ||
182 | expect(file.size).to.equal(942961) | ||
183 | |||
184 | if (server.url !== 'http://localhost:9002') { | ||
185 | expect(video.isLocal).to.be.false | ||
186 | } else { | ||
187 | expect(video.isLocal).to.be.true | ||
188 | } | ||
189 | |||
190 | // All pods should have the same magnet Uri | ||
191 | if (baseMagnet === null) { | ||
192 | baseMagnet = magnetUri | ||
193 | } else { | ||
194 | expect(baseMagnet).to.equal(magnetUri) | ||
195 | } | ||
196 | |||
197 | const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath) | ||
198 | expect(test).to.equal(true) | ||
199 | } | ||
200 | }) | ||
201 | |||
202 | it('Should upload two videos on pod 3 and propagate on each pod', async function () { | ||
203 | this.timeout(45000) | ||
204 | |||
205 | const videoAttributes1 = { | ||
206 | name: 'my super name for pod 3', | ||
207 | category: 6, | ||
208 | licence: 5, | ||
209 | language: 11, | ||
210 | nsfw: true, | ||
211 | description: 'my super description for pod 3', | ||
212 | tags: [ 'tag1p3' ], | ||
213 | fixture: 'video_short3.webm' | ||
214 | } | ||
215 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) | ||
216 | |||
217 | const videoAttributes2 = { | ||
218 | name: 'my super name for pod 3-2', | ||
219 | category: 7, | ||
220 | licence: 6, | ||
221 | language: 12, | ||
222 | nsfw: false, | ||
223 | description: 'my super description for pod 3-2', | ||
224 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], | ||
225 | fixture: 'video_short.webm' | ||
226 | } | ||
227 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) | ||
228 | |||
229 | await wait(33000) | ||
230 | |||
231 | let baseMagnet = null | ||
232 | // All pods should have this video | ||
233 | for (const server of servers) { | ||
234 | const res = await getVideosList(server.url) | ||
235 | |||
236 | const videos = res.body.data | ||
237 | expect(videos).to.be.an('array') | ||
238 | expect(videos.length).to.equal(4) | ||
239 | |||
240 | // We not sure about the order of the two last uploads | ||
241 | let video1 = null | ||
242 | let video2 = null | ||
243 | if (videos[2].name === 'my super name for pod 3') { | ||
244 | video1 = videos[2] | ||
245 | video2 = videos[3] | ||
246 | } else { | ||
247 | video1 = videos[3] | ||
248 | video2 = videos[2] | ||
249 | } | ||
250 | |||
251 | expect(video1.name).to.equal('my super name for pod 3') | ||
252 | expect(video1.category).to.equal(6) | ||
253 | expect(video1.categoryLabel).to.equal('Travels') | ||
254 | expect(video1.licence).to.equal(5) | ||
255 | expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike') | ||
256 | expect(video1.language).to.equal(11) | ||
257 | expect(video1.languageLabel).to.equal('German') | ||
258 | expect(video1.nsfw).to.be.ok | ||
259 | expect(video1.description).to.equal('my super description for pod 3') | ||
260 | expect(video1.podHost).to.equal('localhost:9003') | ||
261 | expect(video1.duration).to.equal(5) | ||
262 | expect(video1.tags).to.deep.equal([ 'tag1p3' ]) | ||
263 | expect(video1.author).to.equal('root') | ||
264 | expect(dateIsValid(video1.createdAt)).to.be.true | ||
265 | expect(dateIsValid(video1.updatedAt)).to.be.true | ||
266 | |||
267 | expect(video1.files).to.have.lengthOf(1) | ||
268 | |||
269 | const file1 = video1.files[0] | ||
270 | expect(file1.magnetUri).to.have.lengthOf.above(2) | ||
271 | expect(file1.resolution).to.equal(0) | ||
272 | expect(file1.resolutionLabel).to.equal('original') | ||
273 | expect(file1.size).to.equal(292677) | ||
274 | |||
275 | expect(video2.name).to.equal('my super name for pod 3-2') | ||
276 | expect(video2.category).to.equal(7) | ||
277 | expect(video2.categoryLabel).to.equal('Gaming') | ||
278 | expect(video2.licence).to.equal(6) | ||
279 | expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
280 | expect(video2.language).to.equal(12) | ||
281 | expect(video2.languageLabel).to.equal('Korean') | ||
282 | expect(video2.nsfw).to.be.false | ||
283 | expect(video2.description).to.equal('my super description for pod 3-2') | ||
284 | expect(video2.podHost).to.equal('localhost:9003') | ||
285 | expect(video2.duration).to.equal(5) | ||
286 | expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) | ||
287 | expect(video2.author).to.equal('root') | ||
288 | expect(dateIsValid(video2.createdAt)).to.be.true | ||
289 | expect(dateIsValid(video2.updatedAt)).to.be.true | ||
290 | |||
291 | expect(video2.files).to.have.lengthOf(1) | ||
292 | |||
293 | const file2 = video2.files[0] | ||
294 | const magnetUri2 = file2.magnetUri | ||
295 | expect(file2.magnetUri).to.have.lengthOf.above(2) | ||
296 | expect(file2.resolution).to.equal(0) | ||
297 | expect(file2.resolutionLabel).to.equal('original') | ||
298 | expect(file2.size).to.equal(218910) | ||
299 | |||
300 | if (server.url !== 'http://localhost:9003') { | ||
301 | expect(video1.isLocal).to.be.false | ||
302 | expect(video2.isLocal).to.be.false | ||
303 | } else { | ||
304 | expect(video1.isLocal).to.be.true | ||
305 | expect(video2.isLocal).to.be.true | ||
306 | } | ||
307 | |||
308 | // All pods should have the same magnet Uri | ||
309 | if (baseMagnet === null) { | ||
310 | baseMagnet = magnetUri2 | ||
311 | } else { | ||
312 | expect(baseMagnet).to.equal(magnetUri2) | ||
313 | } | ||
314 | |||
315 | const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath) | ||
316 | expect(test1).to.equal(true) | ||
317 | |||
318 | const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath) | ||
319 | expect(test2).to.equal(true) | ||
320 | } | ||
321 | }) | ||
322 | }) | ||
323 | |||
324 | describe('Should seed the uploaded video', function () { | ||
325 | it('Should add the file 1 by asking pod 3', async function () { | ||
326 | // Yes, this could be long | ||
327 | this.timeout(200000) | ||
328 | |||
329 | const res = await getVideosList(servers[2].url) | ||
330 | |||
331 | const video = res.body.data[0] | ||
332 | toRemove.push(res.body.data[2]) | ||
333 | toRemove.push(res.body.data[3]) | ||
334 | |||
335 | const torrent = await webtorrentAdd(video.files[0].magnetUri) | ||
336 | expect(torrent.files).to.be.an('array') | ||
337 | expect(torrent.files.length).to.equal(1) | ||
338 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
339 | }) | ||
340 | |||
341 | it('Should add the file 2 by asking pod 1', async function () { | ||
342 | // Yes, this could be long | ||
343 | this.timeout(200000) | ||
344 | |||
345 | const res = await getVideosList(servers[0].url) | ||
346 | |||
347 | const video = res.body.data[1] | ||
348 | |||
349 | const torrent = await webtorrentAdd(video.files[0].magnetUri) | ||
350 | expect(torrent.files).to.be.an('array') | ||
351 | expect(torrent.files.length).to.equal(1) | ||
352 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
353 | }) | ||
354 | |||
355 | it('Should add the file 3 by asking pod 2', async function () { | ||
356 | // Yes, this could be long | ||
357 | this.timeout(200000) | ||
358 | |||
359 | const res = await getVideosList(servers[1].url) | ||
360 | |||
361 | const video = res.body.data[2] | ||
362 | |||
363 | const torrent = await webtorrentAdd(video.files[0].magnetUri) | ||
364 | expect(torrent.files).to.be.an('array') | ||
365 | expect(torrent.files.length).to.equal(1) | ||
366 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
367 | }) | ||
368 | |||
369 | it('Should add the file 3-2 by asking pod 1', async function () { | ||
370 | // Yes, this could be long | ||
371 | this.timeout(200000) | ||
372 | |||
373 | const res = await getVideosList(servers[0].url) | ||
374 | |||
375 | const video = res.body.data[3] | ||
376 | |||
377 | const torrent = await webtorrentAdd(video.files[0].magnetUri) | ||
378 | expect(torrent.files).to.be.an('array') | ||
379 | expect(torrent.files.length).to.equal(1) | ||
380 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
381 | }) | ||
382 | }) | ||
383 | |||
384 | describe('Should update video views, likes and dislikes', function () { | ||
385 | let localVideosPod3 = [] | ||
386 | let remoteVideosPod1 = [] | ||
387 | let remoteVideosPod2 = [] | ||
388 | let remoteVideosPod3 = [] | ||
389 | |||
390 | before(async function () { | ||
391 | const res1 = await getVideosList(servers[0].url) | ||
392 | remoteVideosPod1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.id) | ||
393 | |||
394 | const res2 = await getVideosList(servers[1].url) | ||
395 | remoteVideosPod2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.id) | ||
396 | |||
397 | const res3 = await getVideosList(servers[2].url) | ||
398 | localVideosPod3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.id) | ||
399 | remoteVideosPod3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.id) | ||
400 | }) | ||
401 | |||
402 | it('Should view multiple videos on owned servers', async function () { | ||
403 | this.timeout(30000) | ||
404 | |||
405 | const tasks: Promise<any>[] = [] | ||
406 | tasks.push(getVideo(servers[2].url, localVideosPod3[0])) | ||
407 | tasks.push(getVideo(servers[2].url, localVideosPod3[0])) | ||
408 | tasks.push(getVideo(servers[2].url, localVideosPod3[0])) | ||
409 | tasks.push(getVideo(servers[2].url, localVideosPod3[1])) | ||
410 | |||
411 | await Promise.all(tasks) | ||
412 | |||
413 | await wait(22000) | ||
414 | |||
415 | for (const server of servers) { | ||
416 | const res = await getVideosList(server.url) | ||
417 | |||
418 | const videos = res.body.data | ||
419 | expect(videos.find(video => video.views === 3)).to.be.an('object') | ||
420 | expect(videos.find(video => video.views === 1)).to.be.an('object') | ||
421 | } | ||
422 | }) | ||
423 | |||
424 | it('Should view multiple videos on each servers', async function () { | ||
425 | this.timeout(30000) | ||
426 | |||
427 | const tasks: Promise<any>[] = [] | ||
428 | tasks.push(getVideo(servers[0].url, remoteVideosPod1[0])) | ||
429 | tasks.push(getVideo(servers[1].url, remoteVideosPod2[0])) | ||
430 | tasks.push(getVideo(servers[1].url, remoteVideosPod2[0])) | ||
431 | tasks.push(getVideo(servers[2].url, remoteVideosPod3[0])) | ||
432 | tasks.push(getVideo(servers[2].url, remoteVideosPod3[1])) | ||
433 | tasks.push(getVideo(servers[2].url, remoteVideosPod3[1])) | ||
434 | tasks.push(getVideo(servers[2].url, remoteVideosPod3[1])) | ||
435 | tasks.push(getVideo(servers[2].url, localVideosPod3[1])) | ||
436 | tasks.push(getVideo(servers[2].url, localVideosPod3[1])) | ||
437 | tasks.push(getVideo(servers[2].url, localVideosPod3[1])) | ||
438 | |||
439 | await Promise.all(tasks) | ||
440 | |||
441 | await wait(22000) | ||
442 | |||
443 | let baseVideos = null | ||
444 | |||
445 | for (const server of servers) { | ||
446 | const res = await getVideosList(server.url) | ||
447 | |||
448 | const videos = res.body.data | ||
449 | |||
450 | // Initialize base videos for future comparisons | ||
451 | if (baseVideos === null) { | ||
452 | baseVideos = videos | ||
453 | return | ||
454 | } | ||
455 | |||
456 | for (const baseVideo of baseVideos) { | ||
457 | const sameVideo = videos.find(video => video.name === baseVideo.name) | ||
458 | expect(baseVideo.views).to.equal(sameVideo.views) | ||
459 | } | ||
460 | } | ||
461 | }) | ||
462 | |||
463 | it('Should like and dislikes videos on different services', async function () { | ||
464 | this.timeout(30000) | ||
465 | |||
466 | const tasks: Promise<any>[] = [] | ||
467 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like')) | ||
468 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike')) | ||
469 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like')) | ||
470 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like')) | ||
471 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike')) | ||
472 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike')) | ||
473 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like')) | ||
474 | |||
475 | await Promise.all(tasks) | ||
476 | |||
477 | await wait(22000) | ||
478 | |||
479 | let baseVideos = null | ||
480 | for (const server of servers) { | ||
481 | const res = await getVideosList(server.url) | ||
482 | |||
483 | const videos = res.body.data | ||
484 | |||
485 | // Initialize base videos for future comparisons | ||
486 | if (baseVideos === null) { | ||
487 | baseVideos = videos | ||
488 | return | ||
489 | } | ||
490 | |||
491 | baseVideos.forEach(baseVideo => { | ||
492 | const sameVideo = videos.find(video => video.name === baseVideo.name) | ||
493 | expect(baseVideo.likes).to.equal(sameVideo.likes) | ||
494 | expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) | ||
495 | }) | ||
496 | } | ||
497 | }) | ||
498 | }) | ||
499 | |||
500 | describe('Should manipulate these videos', function () { | ||
501 | it('Should update the video 3 by asking pod 3', async function () { | ||
502 | this.timeout(15000) | ||
503 | |||
504 | const attributes = { | ||
505 | name: 'my super video updated', | ||
506 | category: 10, | ||
507 | licence: 7, | ||
508 | language: 13, | ||
509 | nsfw: true, | ||
510 | description: 'my super description updated', | ||
511 | tags: [ 'tag_up_1', 'tag_up_2' ] | ||
512 | } | ||
513 | |||
514 | await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) | ||
515 | |||
516 | await wait(11000) | ||
517 | }) | ||
518 | |||
519 | it('Should have the video 3 updated on each pod', async function () { | ||
520 | this.timeout(200000) | ||
521 | |||
522 | for (const server of servers) { | ||
523 | const res = await getVideosList(server.url) | ||
524 | |||
525 | const videos = res.body.data | ||
526 | const videoUpdated = videos.find(video => video.name === 'my super video updated') | ||
527 | |||
528 | expect(!!videoUpdated).to.be.true | ||
529 | expect(videoUpdated.category).to.equal(10) | ||
530 | expect(videoUpdated.categoryLabel).to.equal('Entertainment') | ||
531 | expect(videoUpdated.licence).to.equal(7) | ||
532 | expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication') | ||
533 | expect(videoUpdated.language).to.equal(13) | ||
534 | expect(videoUpdated.languageLabel).to.equal('French') | ||
535 | expect(videoUpdated.nsfw).to.be.ok | ||
536 | expect(videoUpdated.description).to.equal('my super description updated') | ||
537 | expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ]) | ||
538 | expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true | ||
539 | |||
540 | const file = videoUpdated.files[0] | ||
541 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
542 | expect(file.resolution).to.equal(0) | ||
543 | expect(file.resolutionLabel).to.equal('original') | ||
544 | expect(file.size).to.equal(292677) | ||
545 | |||
546 | const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath) | ||
547 | expect(test).to.equal(true) | ||
548 | |||
549 | // Avoid "duplicate torrent" errors | ||
550 | const refreshWebTorrent = true | ||
551 | const torrent = await webtorrentAdd(videoUpdated.files[0].magnetUri, refreshWebTorrent) | ||
552 | expect(torrent.files).to.be.an('array') | ||
553 | expect(torrent.files.length).to.equal(1) | ||
554 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
555 | } | ||
556 | }) | ||
557 | |||
558 | it('Should remove the videos 3 and 3-2 by asking pod 3', async function () { | ||
559 | this.timeout(15000) | ||
560 | |||
561 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) | ||
562 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) | ||
563 | |||
564 | await wait(11000) | ||
565 | }) | ||
566 | |||
567 | it('Should have videos 1 and 3 on each pod', async function () { | ||
568 | for (const server of servers) { | ||
569 | const res = await getVideosList(server.url) | ||
570 | |||
571 | const videos = res.body.data | ||
572 | expect(videos).to.be.an('array') | ||
573 | expect(videos.length).to.equal(2) | ||
574 | expect(videos[0].name).not.to.equal(videos[1].name) | ||
575 | expect(videos[0].name).not.to.equal(toRemove[0].name) | ||
576 | expect(videos[1].name).not.to.equal(toRemove[0].name) | ||
577 | expect(videos[0].name).not.to.equal(toRemove[1].name) | ||
578 | expect(videos[1].name).not.to.equal(toRemove[1].name) | ||
579 | |||
580 | videoUUID = videos.find(video => video.name === 'my super name for pod 1').uuid | ||
581 | } | ||
582 | }) | ||
583 | |||
584 | it('Should get the same video by UUID on each pod', async function () { | ||
585 | let baseVideo = null | ||
586 | for (const server of servers) { | ||
587 | const res = await getVideo(server.url, videoUUID) | ||
588 | |||
589 | const video = res.body | ||
590 | |||
591 | if (baseVideo === null) { | ||
592 | baseVideo = video | ||
593 | return | ||
594 | } | ||
595 | |||
596 | expect(baseVideo.name).to.equal(video.name) | ||
597 | expect(baseVideo.uuid).to.equal(video.uuid) | ||
598 | expect(baseVideo.category).to.equal(video.category) | ||
599 | expect(baseVideo.language).to.equal(video.language) | ||
600 | expect(baseVideo.licence).to.equal(video.licence) | ||
601 | expect(baseVideo.category).to.equal(video.category) | ||
602 | expect(baseVideo.nsfw).to.equal(video.nsfw) | ||
603 | expect(baseVideo.author).to.equal(video.author) | ||
604 | expect(baseVideo.tags).to.deep.equal(video.tags) | ||
605 | } | ||
606 | }) | ||
607 | |||
608 | it('Should get the preview from each pod', async function () { | ||
609 | for (const server of servers) { | ||
610 | const res = await getVideo(server.url, videoUUID) | ||
611 | const video = res.body | ||
612 | |||
613 | const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath) | ||
614 | expect(test).to.equal(true) | ||
615 | } | ||
616 | }) | ||
617 | }) | ||
618 | |||
619 | after(async function () { | ||
620 | killallServers(servers) | ||
621 | |||
622 | // Keep the logs if the test failed | ||
623 | if (this['ok']) { | ||
624 | await flushTests() | ||
625 | } | ||
626 | }) | ||
627 | }) | ||
diff --git a/server/tests/api/request-schedulers.js b/server/tests/api/request-schedulers.js deleted file mode 100644 index c5ea72a6a..000000000 --- a/server/tests/api/request-schedulers.js +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const request = require('supertest') | ||
9 | |||
10 | const loginUtils = require('../utils/login') | ||
11 | const podsUtils = require('../utils/pods') | ||
12 | const serversUtils = require('../utils/servers') | ||
13 | const videosUtils = require('../utils/videos') | ||
14 | |||
15 | describe('Test requests schedulers stats', function () { | ||
16 | const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ] | ||
17 | const path = '/api/v1/request-schedulers/stats' | ||
18 | let servers = [] | ||
19 | |||
20 | function uploadVideo (server, callback) { | ||
21 | const videoAttributes = { | ||
22 | tags: [ 'tag1', 'tag2' ] | ||
23 | } | ||
24 | |||
25 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callback) | ||
26 | } | ||
27 | |||
28 | function getRequestsStats (server, callback) { | ||
29 | request(server.url) | ||
30 | .get(path) | ||
31 | .set('Accept', 'application/json') | ||
32 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
33 | .expect(200) | ||
34 | .end(callback) | ||
35 | } | ||
36 | |||
37 | // --------------------------------------------------------------- | ||
38 | |||
39 | before(function (done) { | ||
40 | this.timeout(120000) | ||
41 | serversUtils.flushAndRunMultipleServers(2, function (serversRun, urlsRun) { | ||
42 | servers = serversRun | ||
43 | |||
44 | each(servers, function (server, callbackEach) { | ||
45 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
46 | if (err) return callbackEach(err) | ||
47 | |||
48 | server.accessToken = accessToken | ||
49 | callbackEach() | ||
50 | }) | ||
51 | }, function (err) { | ||
52 | if (err) throw err | ||
53 | |||
54 | const server1 = servers[0] | ||
55 | podsUtils.makeFriends(server1.url, server1.accessToken, done) | ||
56 | }) | ||
57 | }) | ||
58 | }) | ||
59 | |||
60 | it('Should have a correct timer', function (done) { | ||
61 | const server = servers[0] | ||
62 | |||
63 | getRequestsStats(server, function (err, res) { | ||
64 | if (err) throw err | ||
65 | |||
66 | const requestSchedulers = res.body | ||
67 | for (const requestSchedulerName of requestSchedulerNames) { | ||
68 | const requestScheduler = requestSchedulers[requestSchedulerName] | ||
69 | |||
70 | expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0) | ||
71 | expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000) | ||
72 | } | ||
73 | |||
74 | done() | ||
75 | }) | ||
76 | }) | ||
77 | |||
78 | it('Should have the correct total request', function (done) { | ||
79 | this.timeout(15000) | ||
80 | |||
81 | const server = servers[0] | ||
82 | // Ensure the requests of pod 1 won't be made | ||
83 | servers[1].app.kill() | ||
84 | |||
85 | uploadVideo(server, function (err) { | ||
86 | if (err) throw err | ||
87 | |||
88 | setTimeout(function () { | ||
89 | getRequestsStats(server, function (err, res) { | ||
90 | if (err) throw err | ||
91 | |||
92 | const requestSchedulers = res.body | ||
93 | const requestScheduler = requestSchedulers.requestScheduler | ||
94 | expect(requestScheduler.totalRequests).to.equal(1) | ||
95 | |||
96 | done() | ||
97 | }) | ||
98 | }, 1000) | ||
99 | }) | ||
100 | }) | ||
101 | |||
102 | after(function (done) { | ||
103 | process.kill(-servers[0].app.pid) | ||
104 | |||
105 | if (this.ok) { | ||
106 | serversUtils.flushTests(done) | ||
107 | } else { | ||
108 | done() | ||
109 | } | ||
110 | }) | ||
111 | }) | ||
diff --git a/server/tests/api/request-schedulers.ts b/server/tests/api/request-schedulers.ts new file mode 100644 index 000000000..2358ed8f7 --- /dev/null +++ b/server/tests/api/request-schedulers.ts | |||
@@ -0,0 +1,89 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as request from 'supertest' | ||
4 | import 'mocha' | ||
5 | import * as chai from 'chai' | ||
6 | const expect = chai.expect | ||
7 | |||
8 | import { | ||
9 | ServerInfo, | ||
10 | flushTests, | ||
11 | uploadVideo, | ||
12 | makeFriends, | ||
13 | wait, | ||
14 | setAccessTokensToServers, | ||
15 | flushAndRunMultipleServers | ||
16 | } from '../utils' | ||
17 | |||
18 | describe('Test requests schedulers stats', function () { | ||
19 | const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ] | ||
20 | const path = '/api/v1/request-schedulers/stats' | ||
21 | let servers: ServerInfo[] = [] | ||
22 | |||
23 | function uploadVideoWrapper (server: ServerInfo) { | ||
24 | const videoAttributes = { | ||
25 | tags: [ 'tag1', 'tag2' ] | ||
26 | } | ||
27 | |||
28 | return uploadVideo(server.url, server.accessToken, videoAttributes) | ||
29 | } | ||
30 | |||
31 | function getRequestsStats (server: ServerInfo) { | ||
32 | return request(server.url) | ||
33 | .get(path) | ||
34 | .set('Accept', 'application/json') | ||
35 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
36 | .expect(200) | ||
37 | } | ||
38 | |||
39 | // --------------------------------------------------------------- | ||
40 | |||
41 | before(async function () { | ||
42 | this.timeout(120000) | ||
43 | |||
44 | servers = await flushAndRunMultipleServers(2) | ||
45 | |||
46 | await setAccessTokensToServers(servers) | ||
47 | |||
48 | await makeFriends(servers[0].url, servers[0].accessToken) | ||
49 | }) | ||
50 | |||
51 | it('Should have a correct timer', async function () { | ||
52 | const server = servers[0] | ||
53 | |||
54 | const res = await getRequestsStats(server) | ||
55 | |||
56 | const requestSchedulers = res.body | ||
57 | for (const requestSchedulerName of requestSchedulerNames) { | ||
58 | const requestScheduler = requestSchedulers[requestSchedulerName] | ||
59 | |||
60 | expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0) | ||
61 | expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000) | ||
62 | } | ||
63 | }) | ||
64 | |||
65 | it('Should have the correct total request', async function () { | ||
66 | this.timeout(15000) | ||
67 | |||
68 | const server = servers[0] | ||
69 | // Ensure the requests of pod 1 won't be made | ||
70 | servers[1].app.kill() | ||
71 | |||
72 | await uploadVideoWrapper(server) | ||
73 | |||
74 | await wait(1000) | ||
75 | |||
76 | const res = await getRequestsStats(server) | ||
77 | const requestSchedulers = res.body | ||
78 | const requestScheduler = requestSchedulers.requestScheduler | ||
79 | expect(requestScheduler.totalRequests).to.equal(1) | ||
80 | }) | ||
81 | |||
82 | after(async function () { | ||
83 | process.kill(-servers[0].app.pid) | ||
84 | |||
85 | if (this['ok']) { | ||
86 | await flushTests() | ||
87 | } | ||
88 | }) | ||
89 | }) | ||
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js deleted file mode 100644 index 6933d18dd..000000000 --- a/server/tests/api/single-pod.js +++ /dev/null | |||
@@ -1,841 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const fs = require('fs') | ||
9 | const keyBy = require('lodash/keyBy') | ||
10 | const pathUtils = require('path') | ||
11 | const series = require('async/series') | ||
12 | const webtorrent = new (require('webtorrent'))() | ||
13 | |||
14 | const loginUtils = require('../utils/login') | ||
15 | const miscsUtils = require('../utils/miscs') | ||
16 | const serversUtils = require('../utils/servers') | ||
17 | const videosUtils = require('../utils/videos') | ||
18 | |||
19 | describe('Test a single pod', function () { | ||
20 | let server = null | ||
21 | let videoId = -1 | ||
22 | let videoUUID = '' | ||
23 | let videosListBase = null | ||
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 (server1) { | ||
34 | server = server1 | ||
35 | next() | ||
36 | }) | ||
37 | }, | ||
38 | function (next) { | ||
39 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
40 | if (err) throw err | ||
41 | server.accessToken = token | ||
42 | next() | ||
43 | }) | ||
44 | } | ||
45 | ], done) | ||
46 | }) | ||
47 | |||
48 | it('Should list video categories', function (done) { | ||
49 | videosUtils.getVideoCategories(server.url, function (err, res) { | ||
50 | if (err) throw err | ||
51 | |||
52 | const categories = res.body | ||
53 | expect(Object.keys(categories)).to.have.length.above(10) | ||
54 | |||
55 | expect(categories[11]).to.equal('News') | ||
56 | |||
57 | done() | ||
58 | }) | ||
59 | }) | ||
60 | |||
61 | it('Should list video licences', function (done) { | ||
62 | videosUtils.getVideoLicences(server.url, function (err, res) { | ||
63 | if (err) throw err | ||
64 | |||
65 | const licences = res.body | ||
66 | expect(Object.keys(licences)).to.have.length.above(5) | ||
67 | |||
68 | expect(licences[3]).to.equal('Attribution - No Derivatives') | ||
69 | |||
70 | done() | ||
71 | }) | ||
72 | }) | ||
73 | |||
74 | it('Should list video languages', function (done) { | ||
75 | videosUtils.getVideoLanguages(server.url, function (err, res) { | ||
76 | if (err) throw err | ||
77 | |||
78 | const languages = res.body | ||
79 | expect(Object.keys(languages)).to.have.length.above(5) | ||
80 | |||
81 | expect(languages[3]).to.equal('Mandarin') | ||
82 | |||
83 | done() | ||
84 | }) | ||
85 | }) | ||
86 | |||
87 | it('Should not have videos', function (done) { | ||
88 | videosUtils.getVideosList(server.url, function (err, res) { | ||
89 | if (err) throw err | ||
90 | |||
91 | expect(res.body.total).to.equal(0) | ||
92 | expect(res.body.data).to.be.an('array') | ||
93 | expect(res.body.data.length).to.equal(0) | ||
94 | |||
95 | done() | ||
96 | }) | ||
97 | }) | ||
98 | |||
99 | it('Should upload the video', function (done) { | ||
100 | const videoAttributes = { | ||
101 | name: 'my super name', | ||
102 | category: 2, | ||
103 | nsfw: true, | ||
104 | licence: 6, | ||
105 | tags: [ 'tag1', 'tag2', 'tag3' ] | ||
106 | } | ||
107 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, done) | ||
108 | }) | ||
109 | |||
110 | it('Should seed the uploaded video', function (done) { | ||
111 | // Yes, this could be long | ||
112 | this.timeout(60000) | ||
113 | |||
114 | videosUtils.getVideosList(server.url, function (err, res) { | ||
115 | if (err) throw err | ||
116 | |||
117 | expect(res.body.total).to.equal(1) | ||
118 | expect(res.body.data).to.be.an('array') | ||
119 | expect(res.body.data.length).to.equal(1) | ||
120 | |||
121 | const video = res.body.data[0] | ||
122 | expect(video.name).to.equal('my super name') | ||
123 | expect(video.category).to.equal(2) | ||
124 | expect(video.categoryLabel).to.equal('Films') | ||
125 | expect(video.licence).to.equal(6) | ||
126 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
127 | expect(video.language).to.equal(3) | ||
128 | expect(video.languageLabel).to.equal('Mandarin') | ||
129 | expect(video.nsfw).to.be.ok | ||
130 | expect(video.description).to.equal('my super description') | ||
131 | expect(video.podHost).to.equal('localhost:9001') | ||
132 | expect(video.author).to.equal('root') | ||
133 | expect(video.isLocal).to.be.true | ||
134 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
135 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
136 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
137 | |||
138 | expect(video.files).to.have.lengthOf(1) | ||
139 | |||
140 | const file = video.files[0] | ||
141 | const magnetUri = file.magnetUri | ||
142 | expect(file.magnetUri).to.exist | ||
143 | expect(file.resolution).to.equal(0) | ||
144 | expect(file.resolutionLabel).to.equal('original') | ||
145 | expect(file.size).to.equal(218910) | ||
146 | |||
147 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | ||
148 | if (err) throw err | ||
149 | expect(test).to.equal(true) | ||
150 | |||
151 | videoId = video.id | ||
152 | videoUUID = video.uuid | ||
153 | |||
154 | webtorrent.add(magnetUri, function (torrent) { | ||
155 | expect(torrent.files).to.exist | ||
156 | expect(torrent.files.length).to.equal(1) | ||
157 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
158 | |||
159 | done() | ||
160 | }) | ||
161 | }) | ||
162 | }) | ||
163 | }) | ||
164 | |||
165 | it('Should get the video', function (done) { | ||
166 | // Yes, this could be long | ||
167 | this.timeout(60000) | ||
168 | |||
169 | videosUtils.getVideo(server.url, videoId, function (err, res) { | ||
170 | if (err) throw err | ||
171 | |||
172 | const video = res.body | ||
173 | expect(video.name).to.equal('my super name') | ||
174 | expect(video.category).to.equal(2) | ||
175 | expect(video.categoryLabel).to.equal('Films') | ||
176 | expect(video.licence).to.equal(6) | ||
177 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
178 | expect(video.language).to.equal(3) | ||
179 | expect(video.languageLabel).to.equal('Mandarin') | ||
180 | expect(video.nsfw).to.be.ok | ||
181 | expect(video.description).to.equal('my super description') | ||
182 | expect(video.podHost).to.equal('localhost:9001') | ||
183 | expect(video.author).to.equal('root') | ||
184 | expect(video.isLocal).to.be.true | ||
185 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
186 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
187 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
188 | |||
189 | expect(video.files).to.have.lengthOf(1) | ||
190 | |||
191 | const file = video.files[0] | ||
192 | const magnetUri = file.magnetUri | ||
193 | expect(file.magnetUri).to.exist | ||
194 | expect(file.resolution).to.equal(0) | ||
195 | expect(file.resolutionLabel).to.equal('original') | ||
196 | expect(file.size).to.equal(218910) | ||
197 | |||
198 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | ||
199 | if (err) throw err | ||
200 | expect(test).to.equal(true) | ||
201 | |||
202 | // Wait the async views increment | ||
203 | setTimeout(done, 500) | ||
204 | }) | ||
205 | }) | ||
206 | }) | ||
207 | |||
208 | it('Should get the video by UUID', function (done) { | ||
209 | // Yes, this could be long | ||
210 | this.timeout(60000) | ||
211 | |||
212 | videosUtils.getVideo(server.url, videoUUID, function (err, res) { | ||
213 | if (err) throw err | ||
214 | |||
215 | const video = res.body | ||
216 | expect(video.name).to.equal('my super name') | ||
217 | |||
218 | // Wait the async views increment | ||
219 | setTimeout(done, 500) | ||
220 | }) | ||
221 | }) | ||
222 | |||
223 | it('Should have the views updated', function (done) { | ||
224 | videosUtils.getVideo(server.url, videoId, function (err, res) { | ||
225 | if (err) throw err | ||
226 | |||
227 | const video = res.body | ||
228 | expect(video.views).to.equal(2) | ||
229 | |||
230 | done() | ||
231 | }) | ||
232 | }) | ||
233 | |||
234 | it('Should search the video by name by default', function (done) { | ||
235 | videosUtils.searchVideo(server.url, 'my', function (err, res) { | ||
236 | if (err) throw err | ||
237 | |||
238 | expect(res.body.total).to.equal(1) | ||
239 | expect(res.body.data).to.be.an('array') | ||
240 | expect(res.body.data.length).to.equal(1) | ||
241 | |||
242 | const video = res.body.data[0] | ||
243 | expect(video.name).to.equal('my super name') | ||
244 | expect(video.category).to.equal(2) | ||
245 | expect(video.categoryLabel).to.equal('Films') | ||
246 | expect(video.licence).to.equal(6) | ||
247 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
248 | expect(video.language).to.equal(3) | ||
249 | expect(video.languageLabel).to.equal('Mandarin') | ||
250 | expect(video.nsfw).to.be.ok | ||
251 | expect(video.description).to.equal('my super description') | ||
252 | expect(video.podHost).to.equal('localhost:9001') | ||
253 | expect(video.author).to.equal('root') | ||
254 | expect(video.isLocal).to.be.true | ||
255 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
256 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
257 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
258 | |||
259 | expect(video.files).to.have.lengthOf(1) | ||
260 | |||
261 | const file = video.files[0] | ||
262 | const magnetUri = file.magnetUri | ||
263 | expect(file.magnetUri).to.exist | ||
264 | expect(file.resolution).to.equal(0) | ||
265 | expect(file.resolutionLabel).to.equal('original') | ||
266 | expect(file.size).to.equal(218910) | ||
267 | |||
268 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | ||
269 | if (err) throw err | ||
270 | expect(test).to.equal(true) | ||
271 | |||
272 | done() | ||
273 | }) | ||
274 | }) | ||
275 | }) | ||
276 | |||
277 | // Not implemented yet | ||
278 | // it('Should search the video by podHost', function (done) { | ||
279 | // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) { | ||
280 | // if (err) throw err | ||
281 | |||
282 | // expect(res.body.total).to.equal(1) | ||
283 | // expect(res.body.data).to.be.an('array') | ||
284 | // expect(res.body.data.length).to.equal(1) | ||
285 | |||
286 | // const video = res.body.data[0] | ||
287 | // expect(video.name).to.equal('my super name') | ||
288 | // expect(video.description).to.equal('my super description') | ||
289 | // expect(video.podHost).to.equal('localhost:9001') | ||
290 | // expect(video.author).to.equal('root') | ||
291 | // expect(video.isLocal).to.be.true | ||
292 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
293 | // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
294 | // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
295 | |||
296 | // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | ||
297 | // if (err) throw err | ||
298 | // expect(test).to.equal(true) | ||
299 | |||
300 | // done() | ||
301 | // }) | ||
302 | // }) | ||
303 | // }) | ||
304 | |||
305 | it('Should search the video by tag', function (done) { | ||
306 | videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { | ||
307 | if (err) throw err | ||
308 | |||
309 | expect(res.body.total).to.equal(1) | ||
310 | expect(res.body.data).to.be.an('array') | ||
311 | expect(res.body.data.length).to.equal(1) | ||
312 | |||
313 | const video = res.body.data[0] | ||
314 | expect(video.name).to.equal('my super name') | ||
315 | expect(video.category).to.equal(2) | ||
316 | expect(video.categoryLabel).to.equal('Films') | ||
317 | expect(video.licence).to.equal(6) | ||
318 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
319 | expect(video.language).to.equal(3) | ||
320 | expect(video.languageLabel).to.equal('Mandarin') | ||
321 | expect(video.nsfw).to.be.ok | ||
322 | expect(video.description).to.equal('my super description') | ||
323 | expect(video.podHost).to.equal('localhost:9001') | ||
324 | expect(video.author).to.equal('root') | ||
325 | expect(video.isLocal).to.be.true | ||
326 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
327 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
328 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
329 | |||
330 | expect(video.files).to.have.lengthOf(1) | ||
331 | |||
332 | const file = video.files[0] | ||
333 | const magnetUri = file.magnetUri | ||
334 | expect(file.magnetUri).to.exist | ||
335 | expect(file.resolution).to.equal(0) | ||
336 | expect(file.resolutionLabel).to.equal('original') | ||
337 | expect(file.size).to.equal(218910) | ||
338 | |||
339 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | ||
340 | if (err) throw err | ||
341 | expect(test).to.equal(true) | ||
342 | |||
343 | done() | ||
344 | }) | ||
345 | }) | ||
346 | }) | ||
347 | |||
348 | it('Should not find a search by name by default', function (done) { | ||
349 | videosUtils.searchVideo(server.url, 'hello', function (err, res) { | ||
350 | if (err) throw err | ||
351 | |||
352 | expect(res.body.total).to.equal(0) | ||
353 | expect(res.body.data).to.be.an('array') | ||
354 | expect(res.body.data.length).to.equal(0) | ||
355 | |||
356 | done() | ||
357 | }) | ||
358 | }) | ||
359 | |||
360 | it('Should not find a search by author', function (done) { | ||
361 | videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) { | ||
362 | if (err) throw err | ||
363 | |||
364 | expect(res.body.total).to.equal(0) | ||
365 | expect(res.body.data).to.be.an('array') | ||
366 | expect(res.body.data.length).to.equal(0) | ||
367 | |||
368 | done() | ||
369 | }) | ||
370 | }) | ||
371 | |||
372 | it('Should not find a search by tag', function (done) { | ||
373 | videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) { | ||
374 | if (err) throw err | ||
375 | |||
376 | expect(res.body.total).to.equal(0) | ||
377 | expect(res.body.data).to.be.an('array') | ||
378 | expect(res.body.data.length).to.equal(0) | ||
379 | |||
380 | done() | ||
381 | }) | ||
382 | }) | ||
383 | |||
384 | it('Should remove the video', function (done) { | ||
385 | videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) { | ||
386 | if (err) throw err | ||
387 | |||
388 | fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) { | ||
389 | if (err) throw err | ||
390 | |||
391 | expect(files.length).to.equal(0) | ||
392 | |||
393 | fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) { | ||
394 | if (err) throw err | ||
395 | |||
396 | expect(files.length).to.equal(0) | ||
397 | |||
398 | done() | ||
399 | }) | ||
400 | }) | ||
401 | }) | ||
402 | }) | ||
403 | |||
404 | it('Should not have videos', function (done) { | ||
405 | videosUtils.getVideosList(server.url, function (err, res) { | ||
406 | if (err) throw err | ||
407 | |||
408 | expect(res.body.total).to.equal(0) | ||
409 | expect(res.body.data).to.be.an('array') | ||
410 | expect(res.body.data.length).to.equal(0) | ||
411 | |||
412 | done() | ||
413 | }) | ||
414 | }) | ||
415 | |||
416 | it('Should upload 6 videos', function (done) { | ||
417 | this.timeout(25000) | ||
418 | const videos = [ | ||
419 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | ||
420 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | ||
421 | ] | ||
422 | each(videos, function (video, callbackEach) { | ||
423 | const videoAttributes = { | ||
424 | name: video + ' name', | ||
425 | description: video + ' description', | ||
426 | category: 2, | ||
427 | licence: 1, | ||
428 | language: 1, | ||
429 | nsfw: true, | ||
430 | tags: [ 'tag1', 'tag2', 'tag3' ], | ||
431 | fixture: video | ||
432 | } | ||
433 | |||
434 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callbackEach) | ||
435 | }, done) | ||
436 | }) | ||
437 | |||
438 | it('Should have the correct durations', function (done) { | ||
439 | videosUtils.getVideosList(server.url, function (err, res) { | ||
440 | if (err) throw err | ||
441 | |||
442 | expect(res.body.total).to.equal(6) | ||
443 | const videos = res.body.data | ||
444 | expect(videos).to.be.an('array') | ||
445 | expect(videos.length).to.equal(6) | ||
446 | |||
447 | const videosByName = keyBy(videos, 'name') | ||
448 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | ||
449 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | ||
450 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | ||
451 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | ||
452 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | ||
453 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | ||
454 | |||
455 | done() | ||
456 | }) | ||
457 | }) | ||
458 | |||
459 | it('Should have the correct thumbnails', function (done) { | ||
460 | videosUtils.getVideosList(server.url, function (err, res) { | ||
461 | if (err) throw err | ||
462 | |||
463 | const videos = res.body.data | ||
464 | // For the next test | ||
465 | videosListBase = videos | ||
466 | |||
467 | each(videos, function (video, callbackEach) { | ||
468 | if (err) throw err | ||
469 | const videoName = video.name.replace(' name', '') | ||
470 | |||
471 | videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) { | ||
472 | if (err) throw err | ||
473 | |||
474 | expect(test).to.equal(true) | ||
475 | callbackEach() | ||
476 | }) | ||
477 | }, done) | ||
478 | }) | ||
479 | }) | ||
480 | |||
481 | it('Should list only the two first videos', function (done) { | ||
482 | videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) { | ||
483 | if (err) throw err | ||
484 | |||
485 | const videos = res.body.data | ||
486 | expect(res.body.total).to.equal(6) | ||
487 | expect(videos.length).to.equal(2) | ||
488 | expect(videos[0].name).to.equal(videosListBase[0].name) | ||
489 | expect(videos[1].name).to.equal(videosListBase[1].name) | ||
490 | |||
491 | done() | ||
492 | }) | ||
493 | }) | ||
494 | |||
495 | it('Should list only the next three videos', function (done) { | ||
496 | videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) { | ||
497 | if (err) throw err | ||
498 | |||
499 | const videos = res.body.data | ||
500 | expect(res.body.total).to.equal(6) | ||
501 | expect(videos.length).to.equal(3) | ||
502 | expect(videos[0].name).to.equal(videosListBase[2].name) | ||
503 | expect(videos[1].name).to.equal(videosListBase[3].name) | ||
504 | expect(videos[2].name).to.equal(videosListBase[4].name) | ||
505 | |||
506 | done() | ||
507 | }) | ||
508 | }) | ||
509 | |||
510 | it('Should list the last video', function (done) { | ||
511 | videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) { | ||
512 | if (err) throw err | ||
513 | |||
514 | const videos = res.body.data | ||
515 | expect(res.body.total).to.equal(6) | ||
516 | expect(videos.length).to.equal(1) | ||
517 | expect(videos[0].name).to.equal(videosListBase[5].name) | ||
518 | |||
519 | done() | ||
520 | }) | ||
521 | }) | ||
522 | |||
523 | it('Should search the first video', function (done) { | ||
524 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) { | ||
525 | if (err) throw err | ||
526 | |||
527 | const videos = res.body.data | ||
528 | expect(res.body.total).to.equal(4) | ||
529 | expect(videos.length).to.equal(1) | ||
530 | expect(videos[0].name).to.equal('video_short1.webm name') | ||
531 | |||
532 | done() | ||
533 | }) | ||
534 | }) | ||
535 | |||
536 | it('Should search the last two videos', function (done) { | ||
537 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) { | ||
538 | if (err) throw err | ||
539 | |||
540 | const videos = res.body.data | ||
541 | expect(res.body.total).to.equal(4) | ||
542 | expect(videos.length).to.equal(2) | ||
543 | expect(videos[0].name).to.equal('video_short3.webm name') | ||
544 | expect(videos[1].name).to.equal('video_short.webm name') | ||
545 | |||
546 | done() | ||
547 | }) | ||
548 | }) | ||
549 | |||
550 | it('Should search all the webm videos', function (done) { | ||
551 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) { | ||
552 | if (err) throw err | ||
553 | |||
554 | const videos = res.body.data | ||
555 | expect(res.body.total).to.equal(4) | ||
556 | expect(videos.length).to.equal(4) | ||
557 | |||
558 | done() | ||
559 | }) | ||
560 | }) | ||
561 | |||
562 | it('Should search all the root author videos', function (done) { | ||
563 | videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) { | ||
564 | if (err) throw err | ||
565 | |||
566 | const videos = res.body.data | ||
567 | expect(res.body.total).to.equal(6) | ||
568 | expect(videos.length).to.equal(6) | ||
569 | |||
570 | done() | ||
571 | }) | ||
572 | }) | ||
573 | |||
574 | // Not implemented yet | ||
575 | // it('Should search all the 9001 port videos', function (done) { | ||
576 | // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) { | ||
577 | // if (err) throw err | ||
578 | |||
579 | // const videos = res.body.data | ||
580 | // expect(res.body.total).to.equal(6) | ||
581 | // expect(videos.length).to.equal(6) | ||
582 | |||
583 | // done() | ||
584 | // }) | ||
585 | // }) | ||
586 | |||
587 | // it('Should search all the localhost videos', function (done) { | ||
588 | // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) { | ||
589 | // if (err) throw err | ||
590 | |||
591 | // const videos = res.body.data | ||
592 | // expect(res.body.total).to.equal(6) | ||
593 | // expect(videos.length).to.equal(6) | ||
594 | |||
595 | // done() | ||
596 | // }) | ||
597 | // }) | ||
598 | |||
599 | it('Should search the right magnetUri video', function (done) { | ||
600 | const video = videosListBase[0] | ||
601 | videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.files[0].magnetUri), 'magnetUri', 0, 15, function (err, res) { | ||
602 | if (err) throw err | ||
603 | |||
604 | const videos = res.body.data | ||
605 | expect(res.body.total).to.equal(1) | ||
606 | expect(videos.length).to.equal(1) | ||
607 | expect(videos[0].name).to.equal(video.name) | ||
608 | |||
609 | done() | ||
610 | }) | ||
611 | }) | ||
612 | |||
613 | it('Should list and sort by name in descending order', function (done) { | ||
614 | videosUtils.getVideosListSort(server.url, '-name', function (err, res) { | ||
615 | if (err) throw err | ||
616 | |||
617 | const videos = res.body.data | ||
618 | expect(res.body.total).to.equal(6) | ||
619 | expect(videos.length).to.equal(6) | ||
620 | expect(videos[0].name).to.equal('video_short.webm name') | ||
621 | expect(videos[1].name).to.equal('video_short.ogv name') | ||
622 | expect(videos[2].name).to.equal('video_short.mp4 name') | ||
623 | expect(videos[3].name).to.equal('video_short3.webm name') | ||
624 | expect(videos[4].name).to.equal('video_short2.webm name') | ||
625 | expect(videos[5].name).to.equal('video_short1.webm name') | ||
626 | |||
627 | done() | ||
628 | }) | ||
629 | }) | ||
630 | |||
631 | it('Should search and sort by name in ascending order', function (done) { | ||
632 | videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { | ||
633 | if (err) throw err | ||
634 | |||
635 | const videos = res.body.data | ||
636 | expect(res.body.total).to.equal(4) | ||
637 | expect(videos.length).to.equal(4) | ||
638 | |||
639 | expect(videos[0].name).to.equal('video_short1.webm name') | ||
640 | expect(videos[1].name).to.equal('video_short2.webm name') | ||
641 | expect(videos[2].name).to.equal('video_short3.webm name') | ||
642 | expect(videos[3].name).to.equal('video_short.webm name') | ||
643 | |||
644 | videoId = videos[2].id | ||
645 | |||
646 | done() | ||
647 | }) | ||
648 | }) | ||
649 | |||
650 | it('Should update a video', function (done) { | ||
651 | const attributes = { | ||
652 | name: 'my super video updated', | ||
653 | category: 4, | ||
654 | licence: 2, | ||
655 | language: 5, | ||
656 | nsfw: false, | ||
657 | description: 'my super description updated', | ||
658 | tags: [ 'tagup1', 'tagup2' ] | ||
659 | } | ||
660 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, done) | ||
661 | }) | ||
662 | |||
663 | it('Should have the video updated', function (done) { | ||
664 | this.timeout(60000) | ||
665 | |||
666 | videosUtils.getVideo(server.url, videoId, function (err, res) { | ||
667 | if (err) throw err | ||
668 | |||
669 | const video = res.body | ||
670 | |||
671 | expect(video.name).to.equal('my super video updated') | ||
672 | expect(video.category).to.equal(4) | ||
673 | expect(video.categoryLabel).to.equal('Art') | ||
674 | expect(video.licence).to.equal(2) | ||
675 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
676 | expect(video.language).to.equal(5) | ||
677 | expect(video.languageLabel).to.equal('Arabic') | ||
678 | expect(video.nsfw).to.be.ok | ||
679 | expect(video.description).to.equal('my super description updated') | ||
680 | expect(video.podHost).to.equal('localhost:9001') | ||
681 | expect(video.author).to.equal('root') | ||
682 | expect(video.isLocal).to.be.true | ||
683 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | ||
684 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
685 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
686 | |||
687 | expect(video.files).to.have.lengthOf(1) | ||
688 | |||
689 | const file = video.files[0] | ||
690 | const magnetUri = file.magnetUri | ||
691 | expect(file.magnetUri).to.exist | ||
692 | expect(file.resolution).to.equal(0) | ||
693 | expect(file.resolutionLabel).to.equal('original') | ||
694 | expect(file.size).to.equal(292677) | ||
695 | |||
696 | videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) { | ||
697 | if (err) throw err | ||
698 | expect(test).to.equal(true) | ||
699 | |||
700 | webtorrent.add(magnetUri, function (torrent) { | ||
701 | expect(torrent.files).to.exist | ||
702 | expect(torrent.files.length).to.equal(1) | ||
703 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
704 | |||
705 | done() | ||
706 | }) | ||
707 | }) | ||
708 | }) | ||
709 | }) | ||
710 | |||
711 | it('Should update only the tags of a video', function (done) { | ||
712 | const attributes = { | ||
713 | tags: [ 'tag1', 'tag2', 'supertag' ] | ||
714 | } | ||
715 | |||
716 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) { | ||
717 | if (err) throw err | ||
718 | |||
719 | videosUtils.getVideo(server.url, videoId, function (err, res) { | ||
720 | if (err) throw err | ||
721 | |||
722 | const video = res.body | ||
723 | |||
724 | expect(video.name).to.equal('my super video updated') | ||
725 | expect(video.category).to.equal(4) | ||
726 | expect(video.categoryLabel).to.equal('Art') | ||
727 | expect(video.licence).to.equal(2) | ||
728 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
729 | expect(video.language).to.equal(5) | ||
730 | expect(video.languageLabel).to.equal('Arabic') | ||
731 | expect(video.nsfw).to.be.ok | ||
732 | expect(video.description).to.equal('my super description updated') | ||
733 | expect(video.podHost).to.equal('localhost:9001') | ||
734 | expect(video.author).to.equal('root') | ||
735 | expect(video.isLocal).to.be.true | ||
736 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | ||
737 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
738 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
739 | |||
740 | expect(video.files).to.have.lengthOf(1) | ||
741 | |||
742 | const file = video.files[0] | ||
743 | const magnetUri = file.magnetUri | ||
744 | expect(file.magnetUri).to.exist | ||
745 | expect(file.resolution).to.equal(0) | ||
746 | expect(file.resolutionLabel).to.equal('original') | ||
747 | expect(file.size).to.equal(292677) | ||
748 | |||
749 | done() | ||
750 | }) | ||
751 | }) | ||
752 | }) | ||
753 | |||
754 | it('Should update only the description of a video', function (done) { | ||
755 | const attributes = { | ||
756 | description: 'hello everybody' | ||
757 | } | ||
758 | |||
759 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) { | ||
760 | if (err) throw err | ||
761 | |||
762 | videosUtils.getVideo(server.url, videoId, function (err, res) { | ||
763 | if (err) throw err | ||
764 | |||
765 | const video = res.body | ||
766 | |||
767 | expect(video.name).to.equal('my super video updated') | ||
768 | expect(video.category).to.equal(4) | ||
769 | expect(video.categoryLabel).to.equal('Art') | ||
770 | expect(video.licence).to.equal(2) | ||
771 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
772 | expect(video.language).to.equal(5) | ||
773 | expect(video.languageLabel).to.equal('Arabic') | ||
774 | expect(video.nsfw).to.be.ok | ||
775 | expect(video.description).to.equal('hello everybody') | ||
776 | expect(video.podHost).to.equal('localhost:9001') | ||
777 | expect(video.author).to.equal('root') | ||
778 | expect(video.isLocal).to.be.true | ||
779 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | ||
780 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | ||
781 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
782 | |||
783 | expect(video.files).to.have.lengthOf(1) | ||
784 | |||
785 | const file = video.files[0] | ||
786 | const magnetUri = file.magnetUri | ||
787 | expect(file.magnetUri).to.exist | ||
788 | expect(file.resolution).to.equal(0) | ||
789 | expect(file.resolutionLabel).to.equal('original') | ||
790 | expect(file.size).to.equal(292677) | ||
791 | |||
792 | done() | ||
793 | }) | ||
794 | }) | ||
795 | }) | ||
796 | |||
797 | it('Should like a video', function (done) { | ||
798 | videosUtils.rateVideo(server.url, server.accessToken, videoId, 'like', function (err) { | ||
799 | if (err) throw err | ||
800 | |||
801 | videosUtils.getVideo(server.url, videoId, function (err, res) { | ||
802 | if (err) throw err | ||
803 | |||
804 | const video = res.body | ||
805 | |||
806 | expect(video.likes).to.equal(1) | ||
807 | expect(video.dislikes).to.equal(0) | ||
808 | |||
809 | done() | ||
810 | }) | ||
811 | }) | ||
812 | }) | ||
813 | |||
814 | it('Should dislike the same video', function (done) { | ||
815 | videosUtils.rateVideo(server.url, server.accessToken, videoId, 'dislike', function (err) { | ||
816 | if (err) throw err | ||
817 | |||
818 | videosUtils.getVideo(server.url, videoId, function (err, res) { | ||
819 | if (err) throw err | ||
820 | |||
821 | const video = res.body | ||
822 | |||
823 | expect(video.likes).to.equal(0) | ||
824 | expect(video.dislikes).to.equal(1) | ||
825 | |||
826 | done() | ||
827 | }) | ||
828 | }) | ||
829 | }) | ||
830 | |||
831 | after(function (done) { | ||
832 | process.kill(-server.app.pid) | ||
833 | |||
834 | // Keep the logs if the test failed | ||
835 | if (this.ok) { | ||
836 | serversUtils.flushTests(done) | ||
837 | } else { | ||
838 | done() | ||
839 | } | ||
840 | }) | ||
841 | }) | ||
diff --git a/server/tests/api/single-pod.ts b/server/tests/api/single-pod.ts new file mode 100644 index 000000000..83c981f9b --- /dev/null +++ b/server/tests/api/single-pod.ts | |||
@@ -0,0 +1,683 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import { keyBy } from 'lodash' | ||
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 | uploadVideo, | ||
14 | getVideosList, | ||
15 | rateVideo, | ||
16 | removeVideo, | ||
17 | wait, | ||
18 | setAccessTokensToServers, | ||
19 | searchVideo, | ||
20 | killallServers, | ||
21 | dateIsValid, | ||
22 | getVideoCategories, | ||
23 | getVideoLicences, | ||
24 | getVideoLanguages, | ||
25 | testVideoImage, | ||
26 | webtorrentAdd, | ||
27 | getVideo, | ||
28 | readdirPromise, | ||
29 | getVideosListPagination, | ||
30 | searchVideoWithPagination, | ||
31 | getVideosListSort, | ||
32 | searchVideoWithSort, | ||
33 | updateVideo | ||
34 | } from '../utils' | ||
35 | |||
36 | describe('Test a single pod', function () { | ||
37 | let server: ServerInfo = null | ||
38 | let videoId = -1 | ||
39 | let videoUUID = '' | ||
40 | let videosListBase: any[] = null | ||
41 | |||
42 | before(async function () { | ||
43 | this.timeout(120000) | ||
44 | |||
45 | await flushTests() | ||
46 | |||
47 | server = await runServer(1) | ||
48 | |||
49 | await setAccessTokensToServers([ server ]) | ||
50 | }) | ||
51 | |||
52 | it('Should list video categories', async function () { | ||
53 | const res = await getVideoCategories(server.url) | ||
54 | |||
55 | const categories = res.body | ||
56 | expect(Object.keys(categories)).to.have.length.above(10) | ||
57 | |||
58 | expect(categories[11]).to.equal('News') | ||
59 | }) | ||
60 | |||
61 | it('Should list video licences', async function () { | ||
62 | const res = await getVideoLicences(server.url) | ||
63 | |||
64 | const licences = res.body | ||
65 | expect(Object.keys(licences)).to.have.length.above(5) | ||
66 | |||
67 | expect(licences[3]).to.equal('Attribution - No Derivatives') | ||
68 | }) | ||
69 | |||
70 | it('Should list video languages', async function () { | ||
71 | const res = await getVideoLanguages(server.url) | ||
72 | |||
73 | const languages = res.body | ||
74 | expect(Object.keys(languages)).to.have.length.above(5) | ||
75 | |||
76 | expect(languages[3]).to.equal('Mandarin') | ||
77 | }) | ||
78 | |||
79 | it('Should not have videos', async function () { | ||
80 | const res = await getVideosList(server.url) | ||
81 | |||
82 | expect(res.body.total).to.equal(0) | ||
83 | expect(res.body.data).to.be.an('array') | ||
84 | expect(res.body.data.length).to.equal(0) | ||
85 | }) | ||
86 | |||
87 | it('Should upload the video', async function () { | ||
88 | const videoAttributes = { | ||
89 | name: 'my super name', | ||
90 | category: 2, | ||
91 | nsfw: true, | ||
92 | licence: 6, | ||
93 | tags: [ 'tag1', 'tag2', 'tag3' ] | ||
94 | } | ||
95 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
96 | }) | ||
97 | |||
98 | it('Should seed the uploaded video', async function () { | ||
99 | // Yes, this could be long | ||
100 | this.timeout(60000) | ||
101 | |||
102 | const res = await getVideosList(server.url) | ||
103 | |||
104 | expect(res.body.total).to.equal(1) | ||
105 | expect(res.body.data).to.be.an('array') | ||
106 | expect(res.body.data.length).to.equal(1) | ||
107 | |||
108 | const video = res.body.data[0] | ||
109 | expect(video.name).to.equal('my super name') | ||
110 | expect(video.category).to.equal(2) | ||
111 | expect(video.categoryLabel).to.equal('Films') | ||
112 | expect(video.licence).to.equal(6) | ||
113 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
114 | expect(video.language).to.equal(3) | ||
115 | expect(video.languageLabel).to.equal('Mandarin') | ||
116 | expect(video.nsfw).to.be.ok | ||
117 | expect(video.description).to.equal('my super description') | ||
118 | expect(video.podHost).to.equal('localhost:9001') | ||
119 | expect(video.author).to.equal('root') | ||
120 | expect(video.isLocal).to.be.true | ||
121 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
122 | expect(dateIsValid(video.createdAt)).to.be.true | ||
123 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
124 | |||
125 | expect(video.files).to.have.lengthOf(1) | ||
126 | |||
127 | const file = video.files[0] | ||
128 | const magnetUri = file.magnetUri | ||
129 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
130 | expect(file.resolution).to.equal(0) | ||
131 | expect(file.resolutionLabel).to.equal('original') | ||
132 | expect(file.size).to.equal(218910) | ||
133 | |||
134 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
135 | expect(test).to.equal(true) | ||
136 | |||
137 | videoId = video.id | ||
138 | videoUUID = video.uuid | ||
139 | |||
140 | const torrent = await webtorrentAdd(magnetUri) | ||
141 | expect(torrent.files).to.be.an('array') | ||
142 | expect(torrent.files.length).to.equal(1) | ||
143 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
144 | }) | ||
145 | |||
146 | it('Should get the video', async function () { | ||
147 | // Yes, this could be long | ||
148 | this.timeout(60000) | ||
149 | |||
150 | const res = await getVideo(server.url, videoId) | ||
151 | |||
152 | const video = res.body | ||
153 | expect(video.name).to.equal('my super name') | ||
154 | expect(video.category).to.equal(2) | ||
155 | expect(video.categoryLabel).to.equal('Films') | ||
156 | expect(video.licence).to.equal(6) | ||
157 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
158 | expect(video.language).to.equal(3) | ||
159 | expect(video.languageLabel).to.equal('Mandarin') | ||
160 | expect(video.nsfw).to.be.ok | ||
161 | expect(video.description).to.equal('my super description') | ||
162 | expect(video.podHost).to.equal('localhost:9001') | ||
163 | expect(video.author).to.equal('root') | ||
164 | expect(video.isLocal).to.be.true | ||
165 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
166 | expect(dateIsValid(video.createdAt)).to.be.true | ||
167 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
168 | |||
169 | expect(video.files).to.have.lengthOf(1) | ||
170 | |||
171 | const file = video.files[0] | ||
172 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
173 | expect(file.resolution).to.equal(0) | ||
174 | expect(file.resolutionLabel).to.equal('original') | ||
175 | expect(file.size).to.equal(218910) | ||
176 | |||
177 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
178 | expect(test).to.equal(true) | ||
179 | |||
180 | // Wait the async views increment | ||
181 | await wait(500) | ||
182 | }) | ||
183 | |||
184 | it('Should get the video by UUID', async function () { | ||
185 | // Yes, this could be long | ||
186 | this.timeout(60000) | ||
187 | |||
188 | const res = await getVideo(server.url, videoUUID) | ||
189 | |||
190 | const video = res.body | ||
191 | expect(video.name).to.equal('my super name') | ||
192 | |||
193 | // Wait the async views increment | ||
194 | await wait(500) | ||
195 | }) | ||
196 | |||
197 | it('Should have the views updated', async function () { | ||
198 | const res = await getVideo(server.url, videoId) | ||
199 | |||
200 | const video = res.body | ||
201 | expect(video.views).to.equal(2) | ||
202 | }) | ||
203 | |||
204 | it('Should search the video by name by default', async function () { | ||
205 | const res = await searchVideo(server.url, 'my') | ||
206 | |||
207 | expect(res.body.total).to.equal(1) | ||
208 | expect(res.body.data).to.be.an('array') | ||
209 | expect(res.body.data.length).to.equal(1) | ||
210 | |||
211 | const video = res.body.data[0] | ||
212 | expect(video.name).to.equal('my super name') | ||
213 | expect(video.category).to.equal(2) | ||
214 | expect(video.categoryLabel).to.equal('Films') | ||
215 | expect(video.licence).to.equal(6) | ||
216 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
217 | expect(video.language).to.equal(3) | ||
218 | expect(video.languageLabel).to.equal('Mandarin') | ||
219 | expect(video.nsfw).to.be.ok | ||
220 | expect(video.description).to.equal('my super description') | ||
221 | expect(video.podHost).to.equal('localhost:9001') | ||
222 | expect(video.author).to.equal('root') | ||
223 | expect(video.isLocal).to.be.true | ||
224 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
225 | expect(dateIsValid(video.createdAt)).to.be.true | ||
226 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
227 | |||
228 | expect(video.files).to.have.lengthOf(1) | ||
229 | |||
230 | const file = video.files[0] | ||
231 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
232 | expect(file.resolution).to.equal(0) | ||
233 | expect(file.resolutionLabel).to.equal('original') | ||
234 | expect(file.size).to.equal(218910) | ||
235 | |||
236 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
237 | expect(test).to.equal(true) | ||
238 | }) | ||
239 | |||
240 | // Not implemented yet | ||
241 | // it('Should search the video by podHost', async function () { | ||
242 | // const res = await videosUtils.searchVideo(server.url, '9001', 'host') | ||
243 | |||
244 | // expect(res.body.total).to.equal(1) | ||
245 | // expect(res.body.data).to.be.an('array') | ||
246 | // expect(res.body.data.length).to.equal(1) | ||
247 | |||
248 | // const video = res.body.data[0] | ||
249 | // expect(video.name).to.equal('my super name') | ||
250 | // expect(video.description).to.equal('my super description') | ||
251 | // expect(video.podHost).to.equal('localhost:9001') | ||
252 | // expect(video.author).to.equal('root') | ||
253 | // expect(video.isLocal).to.be.true | ||
254 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
255 | // expect(dateIsValid(video.createdAt)).to.be.true | ||
256 | // expect(dateIsValid(video.updatedAt)).to.be.true | ||
257 | |||
258 | // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
259 | // expect(test).to.equal(true) | ||
260 | |||
261 | // done() | ||
262 | // }) | ||
263 | // }) | ||
264 | // }) | ||
265 | |||
266 | it('Should search the video by tag', async function () { | ||
267 | const res = await searchVideo(server.url, 'tag1', 'tags') | ||
268 | |||
269 | expect(res.body.total).to.equal(1) | ||
270 | expect(res.body.data).to.be.an('array') | ||
271 | expect(res.body.data.length).to.equal(1) | ||
272 | |||
273 | const video = res.body.data[0] | ||
274 | expect(video.name).to.equal('my super name') | ||
275 | expect(video.category).to.equal(2) | ||
276 | expect(video.categoryLabel).to.equal('Films') | ||
277 | expect(video.licence).to.equal(6) | ||
278 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
279 | expect(video.language).to.equal(3) | ||
280 | expect(video.languageLabel).to.equal('Mandarin') | ||
281 | expect(video.nsfw).to.be.ok | ||
282 | expect(video.description).to.equal('my super description') | ||
283 | expect(video.podHost).to.equal('localhost:9001') | ||
284 | expect(video.author).to.equal('root') | ||
285 | expect(video.isLocal).to.be.true | ||
286 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
287 | expect(dateIsValid(video.createdAt)).to.be.true | ||
288 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
289 | |||
290 | expect(video.files).to.have.lengthOf(1) | ||
291 | |||
292 | const file = video.files[0] | ||
293 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
294 | expect(file.resolution).to.equal(0) | ||
295 | expect(file.resolutionLabel).to.equal('original') | ||
296 | expect(file.size).to.equal(218910) | ||
297 | |||
298 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
299 | expect(test).to.equal(true) | ||
300 | }) | ||
301 | |||
302 | it('Should not find a search by name by default', async function () { | ||
303 | const res = await searchVideo(server.url, 'hello') | ||
304 | |||
305 | expect(res.body.total).to.equal(0) | ||
306 | expect(res.body.data).to.be.an('array') | ||
307 | expect(res.body.data.length).to.equal(0) | ||
308 | }) | ||
309 | |||
310 | it('Should not find a search by author', async function () { | ||
311 | const res = await searchVideo(server.url, 'hello', 'author') | ||
312 | |||
313 | expect(res.body.total).to.equal(0) | ||
314 | expect(res.body.data).to.be.an('array') | ||
315 | expect(res.body.data.length).to.equal(0) | ||
316 | }) | ||
317 | |||
318 | it('Should not find a search by tag', async function () { | ||
319 | const res = await searchVideo(server.url, 'hello', 'tags') | ||
320 | |||
321 | expect(res.body.total).to.equal(0) | ||
322 | expect(res.body.data).to.be.an('array') | ||
323 | expect(res.body.data.length).to.equal(0) | ||
324 | }) | ||
325 | |||
326 | it('Should remove the video', async function () { | ||
327 | await removeVideo(server.url, server.accessToken, videoId) | ||
328 | |||
329 | const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/')) | ||
330 | expect(files1).to.have.lengthOf(0) | ||
331 | |||
332 | const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/')) | ||
333 | expect(files2).to.have.lengthOf(0) | ||
334 | }) | ||
335 | |||
336 | it('Should not have videos', async function () { | ||
337 | const res = await getVideosList(server.url) | ||
338 | |||
339 | expect(res.body.total).to.equal(0) | ||
340 | expect(res.body.data).to.be.an('array') | ||
341 | expect(res.body.data).to.have.lengthOf(0) | ||
342 | }) | ||
343 | |||
344 | it('Should upload 6 videos', async function () { | ||
345 | this.timeout(25000) | ||
346 | |||
347 | const videos = [ | ||
348 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | ||
349 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | ||
350 | ] | ||
351 | |||
352 | const tasks: Promise<any>[] = [] | ||
353 | for (const video of videos) { | ||
354 | const videoAttributes = { | ||
355 | name: video + ' name', | ||
356 | description: video + ' description', | ||
357 | category: 2, | ||
358 | licence: 1, | ||
359 | language: 1, | ||
360 | nsfw: true, | ||
361 | tags: [ 'tag1', 'tag2', 'tag3' ], | ||
362 | fixture: video | ||
363 | } | ||
364 | |||
365 | const p = uploadVideo(server.url, server.accessToken, videoAttributes) | ||
366 | tasks.push(p) | ||
367 | } | ||
368 | |||
369 | await Promise.all(tasks) | ||
370 | }) | ||
371 | |||
372 | it('Should have the correct durations', async function () { | ||
373 | const res = await getVideosList(server.url) | ||
374 | |||
375 | expect(res.body.total).to.equal(6) | ||
376 | const videos = res.body.data | ||
377 | expect(videos).to.be.an('array') | ||
378 | expect(videos).to.have.lengthOf(6) | ||
379 | |||
380 | const videosByName = keyBy<{ duration: number }>(videos, 'name') | ||
381 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | ||
382 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | ||
383 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | ||
384 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | ||
385 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | ||
386 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | ||
387 | }) | ||
388 | |||
389 | it('Should have the correct thumbnails', async function () { | ||
390 | const res = await getVideosList(server.url) | ||
391 | |||
392 | const videos = res.body.data | ||
393 | // For the next test | ||
394 | videosListBase = videos | ||
395 | |||
396 | for (const video of videos) { | ||
397 | const videoName = video.name.replace(' name', '') | ||
398 | const test = await testVideoImage(server.url, videoName, video.thumbnailPath) | ||
399 | |||
400 | expect(test).to.equal(true) | ||
401 | } | ||
402 | }) | ||
403 | |||
404 | it('Should list only the two first videos', async function () { | ||
405 | const res = await getVideosListPagination(server.url, 0, 2, 'name') | ||
406 | |||
407 | const videos = res.body.data | ||
408 | expect(res.body.total).to.equal(6) | ||
409 | expect(videos.length).to.equal(2) | ||
410 | expect(videos[0].name).to.equal(videosListBase[0].name) | ||
411 | expect(videos[1].name).to.equal(videosListBase[1].name) | ||
412 | }) | ||
413 | |||
414 | it('Should list only the next three videos', async function () { | ||
415 | const res = await getVideosListPagination(server.url, 2, 3, 'name') | ||
416 | |||
417 | const videos = res.body.data | ||
418 | expect(res.body.total).to.equal(6) | ||
419 | expect(videos.length).to.equal(3) | ||
420 | expect(videos[0].name).to.equal(videosListBase[2].name) | ||
421 | expect(videos[1].name).to.equal(videosListBase[3].name) | ||
422 | expect(videos[2].name).to.equal(videosListBase[4].name) | ||
423 | }) | ||
424 | |||
425 | it('Should list the last video', async function () { | ||
426 | const res = await getVideosListPagination(server.url, 5, 6, 'name') | ||
427 | |||
428 | const videos = res.body.data | ||
429 | expect(res.body.total).to.equal(6) | ||
430 | expect(videos.length).to.equal(1) | ||
431 | expect(videos[0].name).to.equal(videosListBase[5].name) | ||
432 | }) | ||
433 | |||
434 | it('Should search the first video', async function () { | ||
435 | const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name') | ||
436 | |||
437 | const videos = res.body.data | ||
438 | expect(res.body.total).to.equal(4) | ||
439 | expect(videos.length).to.equal(1) | ||
440 | expect(videos[0].name).to.equal('video_short1.webm name') | ||
441 | }) | ||
442 | |||
443 | it('Should search the last two videos', async function () { | ||
444 | const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name') | ||
445 | |||
446 | const videos = res.body.data | ||
447 | expect(res.body.total).to.equal(4) | ||
448 | expect(videos.length).to.equal(2) | ||
449 | expect(videos[0].name).to.equal('video_short3.webm name') | ||
450 | expect(videos[1].name).to.equal('video_short.webm name') | ||
451 | }) | ||
452 | |||
453 | it('Should search all the webm videos', async function () { | ||
454 | const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15) | ||
455 | |||
456 | const videos = res.body.data | ||
457 | expect(res.body.total).to.equal(4) | ||
458 | expect(videos.length).to.equal(4) | ||
459 | }) | ||
460 | |||
461 | it('Should search all the root author videos', async function () { | ||
462 | const res = await searchVideoWithPagination(server.url, 'root', 'author', 0, 15) | ||
463 | |||
464 | const videos = res.body.data | ||
465 | expect(res.body.total).to.equal(6) | ||
466 | expect(videos.length).to.equal(6) | ||
467 | }) | ||
468 | |||
469 | // Not implemented yet | ||
470 | // it('Should search all the 9001 port videos', async function () { | ||
471 | // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15) | ||
472 | |||
473 | // const videos = res.body.data | ||
474 | // expect(res.body.total).to.equal(6) | ||
475 | // expect(videos.length).to.equal(6) | ||
476 | |||
477 | // done() | ||
478 | // }) | ||
479 | // }) | ||
480 | |||
481 | // it('Should search all the localhost videos', async function () { | ||
482 | // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15) | ||
483 | |||
484 | // const videos = res.body.data | ||
485 | // expect(res.body.total).to.equal(6) | ||
486 | // expect(videos.length).to.equal(6) | ||
487 | |||
488 | // done() | ||
489 | // }) | ||
490 | // }) | ||
491 | |||
492 | it('Should search the right magnetUri video', async function () { | ||
493 | const video = videosListBase[0] | ||
494 | const res = await searchVideoWithPagination(server.url, encodeURIComponent(video.files[0].magnetUri), 'magnetUri', 0, 15) | ||
495 | |||
496 | const videos = res.body.data | ||
497 | expect(res.body.total).to.equal(1) | ||
498 | expect(videos.length).to.equal(1) | ||
499 | expect(videos[0].name).to.equal(video.name) | ||
500 | }) | ||
501 | |||
502 | it('Should list and sort by name in descending order', async function () { | ||
503 | const res = await getVideosListSort(server.url, '-name') | ||
504 | |||
505 | const videos = res.body.data | ||
506 | expect(res.body.total).to.equal(6) | ||
507 | expect(videos.length).to.equal(6) | ||
508 | expect(videos[0].name).to.equal('video_short.webm name') | ||
509 | expect(videos[1].name).to.equal('video_short.ogv name') | ||
510 | expect(videos[2].name).to.equal('video_short.mp4 name') | ||
511 | expect(videos[3].name).to.equal('video_short3.webm name') | ||
512 | expect(videos[4].name).to.equal('video_short2.webm name') | ||
513 | expect(videos[5].name).to.equal('video_short1.webm name') | ||
514 | }) | ||
515 | |||
516 | it('Should search and sort by name in ascending order', async function () { | ||
517 | const res = await searchVideoWithSort(server.url, 'webm', 'name') | ||
518 | |||
519 | const videos = res.body.data | ||
520 | expect(res.body.total).to.equal(4) | ||
521 | expect(videos.length).to.equal(4) | ||
522 | |||
523 | expect(videos[0].name).to.equal('video_short1.webm name') | ||
524 | expect(videos[1].name).to.equal('video_short2.webm name') | ||
525 | expect(videos[2].name).to.equal('video_short3.webm name') | ||
526 | expect(videos[3].name).to.equal('video_short.webm name') | ||
527 | |||
528 | videoId = videos[2].id | ||
529 | }) | ||
530 | |||
531 | it('Should update a video', async function () { | ||
532 | const attributes = { | ||
533 | name: 'my super video updated', | ||
534 | category: 4, | ||
535 | licence: 2, | ||
536 | language: 5, | ||
537 | nsfw: false, | ||
538 | description: 'my super description updated', | ||
539 | tags: [ 'tagup1', 'tagup2' ] | ||
540 | } | ||
541 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
542 | }) | ||
543 | |||
544 | it('Should have the video updated', async function () { | ||
545 | this.timeout(60000) | ||
546 | |||
547 | const res = await getVideo(server.url, videoId) | ||
548 | |||
549 | const video = res.body | ||
550 | |||
551 | expect(video.name).to.equal('my super video updated') | ||
552 | expect(video.category).to.equal(4) | ||
553 | expect(video.categoryLabel).to.equal('Art') | ||
554 | expect(video.licence).to.equal(2) | ||
555 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
556 | expect(video.language).to.equal(5) | ||
557 | expect(video.languageLabel).to.equal('Arabic') | ||
558 | expect(video.nsfw).to.be.ok | ||
559 | expect(video.description).to.equal('my super description updated') | ||
560 | expect(video.podHost).to.equal('localhost:9001') | ||
561 | expect(video.author).to.equal('root') | ||
562 | expect(video.isLocal).to.be.true | ||
563 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | ||
564 | expect(dateIsValid(video.createdAt)).to.be.true | ||
565 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
566 | |||
567 | expect(video.files).to.have.lengthOf(1) | ||
568 | |||
569 | const file = video.files[0] | ||
570 | const magnetUri = file.magnetUri | ||
571 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
572 | expect(file.resolution).to.equal(0) | ||
573 | expect(file.resolutionLabel).to.equal('original') | ||
574 | expect(file.size).to.equal(292677) | ||
575 | |||
576 | const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath) | ||
577 | expect(test).to.equal(true) | ||
578 | |||
579 | const torrent = await webtorrentAdd(magnetUri) | ||
580 | expect(torrent.files).to.be.an('array') | ||
581 | expect(torrent.files.length).to.equal(1) | ||
582 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
583 | }) | ||
584 | |||
585 | it('Should update only the tags of a video', async function () { | ||
586 | const attributes = { | ||
587 | tags: [ 'tag1', 'tag2', 'supertag' ] | ||
588 | } | ||
589 | |||
590 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
591 | |||
592 | const res = await getVideo(server.url, videoId) | ||
593 | const video = res.body | ||
594 | |||
595 | expect(video.name).to.equal('my super video updated') | ||
596 | expect(video.category).to.equal(4) | ||
597 | expect(video.categoryLabel).to.equal('Art') | ||
598 | expect(video.licence).to.equal(2) | ||
599 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
600 | expect(video.language).to.equal(5) | ||
601 | expect(video.languageLabel).to.equal('Arabic') | ||
602 | expect(video.nsfw).to.be.ok | ||
603 | expect(video.description).to.equal('my super description updated') | ||
604 | expect(video.podHost).to.equal('localhost:9001') | ||
605 | expect(video.author).to.equal('root') | ||
606 | expect(video.isLocal).to.be.true | ||
607 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | ||
608 | expect(dateIsValid(video.createdAt)).to.be.true | ||
609 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
610 | |||
611 | expect(video.files).to.have.lengthOf(1) | ||
612 | |||
613 | const file = video.files[0] | ||
614 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
615 | expect(file.resolution).to.equal(0) | ||
616 | expect(file.resolutionLabel).to.equal('original') | ||
617 | expect(file.size).to.equal(292677) | ||
618 | }) | ||
619 | |||
620 | it('Should update only the description of a video', async function () { | ||
621 | const attributes = { | ||
622 | description: 'hello everybody' | ||
623 | } | ||
624 | |||
625 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
626 | |||
627 | const res = await getVideo(server.url, videoId) | ||
628 | const video = res.body | ||
629 | |||
630 | expect(video.name).to.equal('my super video updated') | ||
631 | expect(video.category).to.equal(4) | ||
632 | expect(video.categoryLabel).to.equal('Art') | ||
633 | expect(video.licence).to.equal(2) | ||
634 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
635 | expect(video.language).to.equal(5) | ||
636 | expect(video.languageLabel).to.equal('Arabic') | ||
637 | expect(video.nsfw).to.be.ok | ||
638 | expect(video.description).to.equal('hello everybody') | ||
639 | expect(video.podHost).to.equal('localhost:9001') | ||
640 | expect(video.author).to.equal('root') | ||
641 | expect(video.isLocal).to.be.true | ||
642 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | ||
643 | expect(dateIsValid(video.createdAt)).to.be.true | ||
644 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
645 | |||
646 | expect(video.files).to.have.lengthOf(1) | ||
647 | |||
648 | const file = video.files[0] | ||
649 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
650 | expect(file.resolution).to.equal(0) | ||
651 | expect(file.resolutionLabel).to.equal('original') | ||
652 | expect(file.size).to.equal(292677) | ||
653 | }) | ||
654 | |||
655 | it('Should like a video', async function () { | ||
656 | await rateVideo(server.url, server.accessToken, videoId, 'like') | ||
657 | |||
658 | const res = await getVideo(server.url, videoId) | ||
659 | const video = res.body | ||
660 | |||
661 | expect(video.likes).to.equal(1) | ||
662 | expect(video.dislikes).to.equal(0) | ||
663 | }) | ||
664 | |||
665 | it('Should dislike the same video', async function () { | ||
666 | await rateVideo(server.url, server.accessToken, videoId, 'dislike') | ||
667 | |||
668 | const res = await getVideo(server.url, videoId) | ||
669 | const video = res.body | ||
670 | |||
671 | expect(video.likes).to.equal(0) | ||
672 | expect(video.dislikes).to.equal(1) | ||
673 | }) | ||
674 | |||
675 | after(async function () { | ||
676 | killallServers([ server ]) | ||
677 | |||
678 | // Keep the logs if the test failed | ||
679 | if (this['ok']) { | ||
680 | await flushTests() | ||
681 | } | ||
682 | }) | ||
683 | }) | ||
diff --git a/server/tests/api/users.js b/server/tests/api/users.js deleted file mode 100644 index dacecf295..000000000 --- a/server/tests/api/users.js +++ /dev/null | |||
@@ -1,409 +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 series = require('async/series') | ||
8 | |||
9 | const loginUtils = require('../utils/login') | ||
10 | const podsUtils = require('../utils/pods') | ||
11 | const serversUtils = require('../utils/servers') | ||
12 | const usersUtils = require('../utils/users') | ||
13 | const requestsUtils = require('../utils/requests') | ||
14 | const videosUtils = require('../utils/videos') | ||
15 | |||
16 | describe('Test users', function () { | ||
17 | let server = null | ||
18 | let accessToken = null | ||
19 | let accessTokenUser = null | ||
20 | let videoId = null | ||
21 | let userId = null | ||
22 | |||
23 | before(function (done) { | ||
24 | this.timeout(120000) | ||
25 | |||
26 | series([ | ||
27 | function (next) { | ||
28 | serversUtils.flushTests(next) | ||
29 | }, | ||
30 | function (next) { | ||
31 | serversUtils.runServer(1, function (server1) { | ||
32 | server = server1 | ||
33 | next() | ||
34 | }) | ||
35 | } | ||
36 | ], done) | ||
37 | }) | ||
38 | |||
39 | it('Should create a new client') | ||
40 | |||
41 | it('Should return the first client') | ||
42 | |||
43 | it('Should remove the last client') | ||
44 | |||
45 | it('Should not login with an invalid client id', function (done) { | ||
46 | const client = { id: 'client', password: server.client.secret } | ||
47 | loginUtils.login(server.url, client, server.user, 400, function (err, res) { | ||
48 | if (err) throw err | ||
49 | |||
50 | expect(res.body.error).to.equal('invalid_client') | ||
51 | done() | ||
52 | }) | ||
53 | }) | ||
54 | |||
55 | it('Should not login with an invalid client password', function (done) { | ||
56 | const client = { id: server.client.id, password: 'coucou' } | ||
57 | loginUtils.login(server.url, client, server.user, 400, function (err, res) { | ||
58 | if (err) throw err | ||
59 | |||
60 | expect(res.body.error).to.equal('invalid_client') | ||
61 | done() | ||
62 | }) | ||
63 | }) | ||
64 | |||
65 | it('Should not login with an invalid username', function (done) { | ||
66 | const user = { username: 'captain crochet', password: server.user.password } | ||
67 | loginUtils.login(server.url, server.client, user, 400, function (err, res) { | ||
68 | if (err) throw err | ||
69 | |||
70 | expect(res.body.error).to.equal('invalid_grant') | ||
71 | done() | ||
72 | }) | ||
73 | }) | ||
74 | |||
75 | it('Should not login with an invalid password', function (done) { | ||
76 | const user = { username: server.user.username, password: 'mewthree' } | ||
77 | loginUtils.login(server.url, server.client, user, 400, function (err, res) { | ||
78 | if (err) throw err | ||
79 | |||
80 | expect(res.body.error).to.equal('invalid_grant') | ||
81 | done() | ||
82 | }) | ||
83 | }) | ||
84 | |||
85 | it('Should not be able to upload a video', function (done) { | ||
86 | accessToken = 'mysupertoken' | ||
87 | |||
88 | const videoAttributes = {} | ||
89 | videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 401, done) | ||
90 | }) | ||
91 | |||
92 | it('Should not be able to make friends', function (done) { | ||
93 | accessToken = 'mysupertoken' | ||
94 | podsUtils.makeFriends(server.url, accessToken, 401, done) | ||
95 | }) | ||
96 | |||
97 | it('Should not be able to quit friends', function (done) { | ||
98 | accessToken = 'mysupertoken' | ||
99 | podsUtils.quitFriends(server.url, accessToken, 401, done) | ||
100 | }) | ||
101 | |||
102 | it('Should be able to login', function (done) { | ||
103 | loginUtils.login(server.url, server.client, server.user, 200, function (err, res) { | ||
104 | if (err) throw err | ||
105 | |||
106 | accessToken = res.body.access_token | ||
107 | done() | ||
108 | }) | ||
109 | }) | ||
110 | |||
111 | it('Should upload the video with the correct token', function (done) { | ||
112 | const videoAttributes = {} | ||
113 | videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 204, function (err, res) { | ||
114 | if (err) throw err | ||
115 | |||
116 | videosUtils.getVideosList(server.url, function (err, res) { | ||
117 | if (err) throw err | ||
118 | |||
119 | const video = res.body.data[0] | ||
120 | expect(video.author).to.equal('root') | ||
121 | |||
122 | videoId = video.id | ||
123 | done() | ||
124 | }) | ||
125 | }) | ||
126 | }) | ||
127 | |||
128 | it('Should upload the video again with the correct token', function (done) { | ||
129 | const videoAttributes = {} | ||
130 | videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 204, done) | ||
131 | }) | ||
132 | |||
133 | it('Should retrieve a video rating', function (done) { | ||
134 | videosUtils.rateVideo(server.url, accessToken, videoId, 'like', function (err) { | ||
135 | if (err) throw err | ||
136 | |||
137 | usersUtils.getUserVideoRating(server.url, accessToken, videoId, function (err, res) { | ||
138 | if (err) throw err | ||
139 | |||
140 | const rating = res.body | ||
141 | |||
142 | expect(rating.videoId).to.equal(videoId) | ||
143 | expect(rating.rating).to.equal('like') | ||
144 | |||
145 | done() | ||
146 | }) | ||
147 | }) | ||
148 | }) | ||
149 | |||
150 | it('Should not be able to remove the video with an incorrect token', function (done) { | ||
151 | videosUtils.removeVideo(server.url, 'bad_token', videoId, 401, done) | ||
152 | }) | ||
153 | |||
154 | it('Should not be able to remove the video with the token of another account') | ||
155 | |||
156 | it('Should be able to remove the video with the correct token', function (done) { | ||
157 | videosUtils.removeVideo(server.url, accessToken, videoId, done) | ||
158 | }) | ||
159 | |||
160 | it('Should logout (revoke token)') | ||
161 | |||
162 | it('Should not be able to get the user informations') | ||
163 | |||
164 | it('Should not be able to upload a video') | ||
165 | |||
166 | it('Should not be able to remove a video') | ||
167 | |||
168 | it('Should not be able to rate a video', function (done) { | ||
169 | const path = '/api/v1/videos/' | ||
170 | const data = { | ||
171 | rating: 'likes' | ||
172 | } | ||
173 | |||
174 | requestsUtils.makePutBodyRequest(server.url, path + videoId, 'wrong token', data, done, 401) | ||
175 | }) | ||
176 | |||
177 | it('Should be able to login again') | ||
178 | |||
179 | it('Should have an expired access token') | ||
180 | |||
181 | it('Should refresh the token') | ||
182 | |||
183 | it('Should be able to upload a video again') | ||
184 | |||
185 | it('Should be able to create a new user', function (done) { | ||
186 | usersUtils.createUser(server.url, accessToken, 'user_1', 'super password', done) | ||
187 | }) | ||
188 | |||
189 | it('Should be able to login with this user', function (done) { | ||
190 | server.user = { | ||
191 | username: 'user_1', | ||
192 | password: 'super password' | ||
193 | } | ||
194 | |||
195 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
196 | if (err) throw err | ||
197 | |||
198 | accessTokenUser = token | ||
199 | |||
200 | done() | ||
201 | }) | ||
202 | }) | ||
203 | |||
204 | it('Should be able to get the user informations', function (done) { | ||
205 | usersUtils.getUserInformation(server.url, accessTokenUser, function (err, res) { | ||
206 | if (err) throw err | ||
207 | |||
208 | const user = res.body | ||
209 | |||
210 | expect(user.username).to.equal('user_1') | ||
211 | expect(user.email).to.equal('user_1@example.com') | ||
212 | expect(user.displayNSFW).to.be.false | ||
213 | expect(user.id).to.exist | ||
214 | |||
215 | done() | ||
216 | }) | ||
217 | }) | ||
218 | |||
219 | it('Should be able to upload a video with this user', function (done) { | ||
220 | this.timeout(5000) | ||
221 | |||
222 | const videoAttributes = {} | ||
223 | videosUtils.uploadVideo(server.url, accessTokenUser, videoAttributes, done) | ||
224 | }) | ||
225 | |||
226 | it('Should list all the users', function (done) { | ||
227 | usersUtils.getUsersList(server.url, function (err, res) { | ||
228 | if (err) throw err | ||
229 | |||
230 | const result = res.body | ||
231 | const total = result.total | ||
232 | const users = result.data | ||
233 | |||
234 | expect(total).to.equal(2) | ||
235 | expect(users).to.be.an('array') | ||
236 | expect(users.length).to.equal(2) | ||
237 | |||
238 | const user = users[0] | ||
239 | expect(user.username).to.equal('user_1') | ||
240 | expect(user.email).to.equal('user_1@example.com') | ||
241 | expect(user.displayNSFW).to.be.false | ||
242 | |||
243 | const rootUser = users[1] | ||
244 | expect(rootUser.username).to.equal('root') | ||
245 | expect(rootUser.email).to.equal('admin1@example.com') | ||
246 | expect(rootUser.displayNSFW).to.be.false | ||
247 | |||
248 | userId = user.id | ||
249 | |||
250 | done() | ||
251 | }) | ||
252 | }) | ||
253 | |||
254 | it('Should list only the first user by username asc', function (done) { | ||
255 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, 'username', function (err, res) { | ||
256 | if (err) throw err | ||
257 | |||
258 | const result = res.body | ||
259 | const total = result.total | ||
260 | const users = result.data | ||
261 | |||
262 | expect(total).to.equal(2) | ||
263 | expect(users.length).to.equal(1) | ||
264 | |||
265 | const user = users[0] | ||
266 | expect(user.username).to.equal('root') | ||
267 | expect(user.email).to.equal('admin1@example.com') | ||
268 | expect(user.displayNSFW).to.be.false | ||
269 | |||
270 | done() | ||
271 | }) | ||
272 | }) | ||
273 | |||
274 | it('Should list only the first user by username desc', function (done) { | ||
275 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-username', function (err, res) { | ||
276 | if (err) throw err | ||
277 | |||
278 | const result = res.body | ||
279 | const total = result.total | ||
280 | const users = result.data | ||
281 | |||
282 | expect(total).to.equal(2) | ||
283 | expect(users.length).to.equal(1) | ||
284 | |||
285 | const user = users[0] | ||
286 | expect(user.username).to.equal('user_1') | ||
287 | expect(user.email).to.equal('user_1@example.com') | ||
288 | expect(user.displayNSFW).to.be.false | ||
289 | |||
290 | done() | ||
291 | }) | ||
292 | }) | ||
293 | |||
294 | it('Should list only the second user by createdAt desc', function (done) { | ||
295 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdAt', function (err, res) { | ||
296 | if (err) throw err | ||
297 | |||
298 | const result = res.body | ||
299 | const total = result.total | ||
300 | const users = result.data | ||
301 | |||
302 | expect(total).to.equal(2) | ||
303 | expect(users.length).to.equal(1) | ||
304 | |||
305 | const user = users[0] | ||
306 | expect(user.username).to.equal('user_1') | ||
307 | expect(user.email).to.equal('user_1@example.com') | ||
308 | expect(user.displayNSFW).to.be.false | ||
309 | |||
310 | done() | ||
311 | }) | ||
312 | }) | ||
313 | |||
314 | it('Should list all the users by createdAt asc', function (done) { | ||
315 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdAt', function (err, res) { | ||
316 | if (err) throw err | ||
317 | |||
318 | const result = res.body | ||
319 | const total = result.total | ||
320 | const users = result.data | ||
321 | |||
322 | expect(total).to.equal(2) | ||
323 | expect(users.length).to.equal(2) | ||
324 | |||
325 | expect(users[0].username).to.equal('root') | ||
326 | expect(users[0].email).to.equal('admin1@example.com') | ||
327 | expect(users[0].displayNSFW).to.be.false | ||
328 | |||
329 | expect(users[1].username).to.equal('user_1') | ||
330 | expect(users[1].email).to.equal('user_1@example.com') | ||
331 | expect(users[1].displayNSFW).to.be.false | ||
332 | |||
333 | done() | ||
334 | }) | ||
335 | }) | ||
336 | |||
337 | it('Should update the user password', function (done) { | ||
338 | usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', null, function (err, res) { | ||
339 | if (err) throw err | ||
340 | |||
341 | server.user.password = 'new password' | ||
342 | loginUtils.login(server.url, server.client, server.user, 200, done) | ||
343 | }) | ||
344 | }) | ||
345 | |||
346 | it('Should be able to change the NSFW display attribute', function (done) { | ||
347 | usersUtils.updateUser(server.url, userId, accessTokenUser, null, true, function (err, res) { | ||
348 | if (err) throw err | ||
349 | |||
350 | usersUtils.getUserInformation(server.url, accessTokenUser, function (err, res) { | ||
351 | if (err) throw err | ||
352 | |||
353 | const user = res.body | ||
354 | |||
355 | expect(user.username).to.equal('user_1') | ||
356 | expect(user.email).to.equal('user_1@example.com') | ||
357 | expect(user.displayNSFW).to.be.ok | ||
358 | expect(user.id).to.exist | ||
359 | |||
360 | done() | ||
361 | }) | ||
362 | }) | ||
363 | }) | ||
364 | |||
365 | it('Should be able to remove this user', function (done) { | ||
366 | usersUtils.removeUser(server.url, userId, accessToken, done) | ||
367 | }) | ||
368 | |||
369 | it('Should not be able to login with this user', function (done) { | ||
370 | // server.user is already set to user 1 | ||
371 | loginUtils.login(server.url, server.client, server.user, 400, done) | ||
372 | }) | ||
373 | |||
374 | it('Should not have videos of this user', function (done) { | ||
375 | videosUtils.getVideosList(server.url, function (err, res) { | ||
376 | if (err) throw err | ||
377 | |||
378 | expect(res.body.total).to.equal(1) | ||
379 | const video = res.body.data[0] | ||
380 | expect(video.author).to.equal('root') | ||
381 | |||
382 | done() | ||
383 | }) | ||
384 | }) | ||
385 | |||
386 | it('Should register a new user', function (done) { | ||
387 | usersUtils.registerUser(server.url, 'user_15', 'my super password', done) | ||
388 | }) | ||
389 | |||
390 | it('Should be able to login with this registered user', function (done) { | ||
391 | server.user = { | ||
392 | username: 'user_15', | ||
393 | password: 'my super password' | ||
394 | } | ||
395 | |||
396 | loginUtils.loginAndGetAccessToken(server, done) | ||
397 | }) | ||
398 | |||
399 | after(function (done) { | ||
400 | process.kill(-server.app.pid) | ||
401 | |||
402 | // Keep the logs if the test failed | ||
403 | if (this.ok) { | ||
404 | serversUtils.flushTests(done) | ||
405 | } else { | ||
406 | done() | ||
407 | } | ||
408 | }) | ||
409 | }) | ||
diff --git a/server/tests/api/users.ts b/server/tests/api/users.ts new file mode 100644 index 000000000..fd3b51123 --- /dev/null +++ b/server/tests/api/users.ts | |||
@@ -0,0 +1,343 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | runServer, | ||
11 | login, | ||
12 | uploadVideo, | ||
13 | makeFriends, | ||
14 | quitFriends, | ||
15 | getVideosList, | ||
16 | rateVideo, | ||
17 | getUserVideoRating, | ||
18 | removeVideo, | ||
19 | makePutBodyRequest, | ||
20 | createUser, | ||
21 | loginAndGetAccessToken, | ||
22 | getUserInformation, | ||
23 | getUsersList, | ||
24 | getUsersListPaginationAndSort, | ||
25 | updateUser, | ||
26 | registerUser, | ||
27 | removeUser | ||
28 | } from '../utils' | ||
29 | import { killallServers } from '../utils/servers' | ||
30 | |||
31 | describe('Test users', function () { | ||
32 | let server: ServerInfo | ||
33 | let accessToken: string | ||
34 | let accessTokenUser: string | ||
35 | let videoId: number | ||
36 | let userId: number | ||
37 | |||
38 | before(async function () { | ||
39 | this.timeout(120000) | ||
40 | |||
41 | await flushTests() | ||
42 | server = await runServer(1) | ||
43 | }) | ||
44 | |||
45 | it('Should create a new client') | ||
46 | |||
47 | it('Should return the first client') | ||
48 | |||
49 | it('Should remove the last client') | ||
50 | |||
51 | it('Should not login with an invalid client id', async function () { | ||
52 | const client = { id: 'client', secret: server.client.secret } | ||
53 | const res = await login(server.url, client, server.user, 400) | ||
54 | |||
55 | expect(res.body.error).to.equal('invalid_client') | ||
56 | }) | ||
57 | |||
58 | it('Should not login with an invalid client secret', async function () { | ||
59 | const client = { id: server.client.id, secret: 'coucou' } | ||
60 | const res = await login(server.url, client, server.user, 400) | ||
61 | |||
62 | expect(res.body.error).to.equal('invalid_client') | ||
63 | }) | ||
64 | |||
65 | it('Should not login with an invalid username', async function () { | ||
66 | const user = { username: 'captain crochet', password: server.user.password } | ||
67 | const res = await login(server.url, server.client, user, 400) | ||
68 | |||
69 | expect(res.body.error).to.equal('invalid_grant') | ||
70 | }) | ||
71 | |||
72 | it('Should not login with an invalid password', async function () { | ||
73 | const user = { username: server.user.username, password: 'mewthree' } | ||
74 | const res = await login(server.url, server.client, user, 400) | ||
75 | |||
76 | expect(res.body.error).to.equal('invalid_grant') | ||
77 | }) | ||
78 | |||
79 | it('Should not be able to upload a video', async function () { | ||
80 | accessToken = 'my_super_token' | ||
81 | |||
82 | const videoAttributes = {} | ||
83 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | ||
84 | }) | ||
85 | |||
86 | it('Should not be able to make friends', async function () { | ||
87 | accessToken = 'my_super_token' | ||
88 | await makeFriends(server.url, accessToken, 401) | ||
89 | }) | ||
90 | |||
91 | it('Should not be able to quit friends', async function () { | ||
92 | accessToken = 'my_super_token' | ||
93 | await quitFriends(server.url, accessToken, 401) | ||
94 | }) | ||
95 | |||
96 | it('Should be able to login', async function () { | ||
97 | const res = await login(server.url, server.client, server.user, 200) | ||
98 | |||
99 | accessToken = res.body.access_token | ||
100 | }) | ||
101 | |||
102 | it('Should upload the video with the correct token', async function () { | ||
103 | const videoAttributes = {} | ||
104 | await uploadVideo(server.url, accessToken, videoAttributes, 204) | ||
105 | const res = await getVideosList(server.url) | ||
106 | const video = res.body.data[0] | ||
107 | |||
108 | expect(video.author).to.equal('root') | ||
109 | videoId = video.id | ||
110 | }) | ||
111 | |||
112 | it('Should upload the video again with the correct token', async function () { | ||
113 | const videoAttributes = {} | ||
114 | await uploadVideo(server.url, accessToken, videoAttributes, 204) | ||
115 | }) | ||
116 | |||
117 | it('Should retrieve a video rating', async function () { | ||
118 | await rateVideo(server.url, accessToken, videoId, 'like') | ||
119 | const res = await getUserVideoRating(server.url, accessToken, videoId) | ||
120 | const rating = res.body | ||
121 | |||
122 | expect(rating.videoId).to.equal(videoId) | ||
123 | expect(rating.rating).to.equal('like') | ||
124 | }) | ||
125 | |||
126 | it('Should not be able to remove the video with an incorrect token', async function () { | ||
127 | await removeVideo(server.url, 'bad_token', videoId, 401) | ||
128 | }) | ||
129 | |||
130 | it('Should not be able to remove the video with the token of another account') | ||
131 | |||
132 | it('Should be able to remove the video with the correct token', async function () { | ||
133 | await removeVideo(server.url, accessToken, videoId) | ||
134 | }) | ||
135 | |||
136 | it('Should logout (revoke token)') | ||
137 | |||
138 | it('Should not be able to get the user information') | ||
139 | |||
140 | it('Should not be able to upload a video') | ||
141 | |||
142 | it('Should not be able to remove a video') | ||
143 | |||
144 | it('Should not be able to rate a video', async function () { | ||
145 | const path = '/api/v1/videos/' | ||
146 | const data = { | ||
147 | rating: 'likes' | ||
148 | } | ||
149 | |||
150 | const options = { | ||
151 | url: server.url, | ||
152 | path: path + videoId, | ||
153 | token: 'wrong token', | ||
154 | fields: data, | ||
155 | statusCodeExpected: 401 | ||
156 | } | ||
157 | await makePutBodyRequest(options) | ||
158 | }) | ||
159 | |||
160 | it('Should be able to login again') | ||
161 | |||
162 | it('Should have an expired access token') | ||
163 | |||
164 | it('Should refresh the token') | ||
165 | |||
166 | it('Should be able to upload a video again') | ||
167 | |||
168 | it('Should be able to create a new user', async function () { | ||
169 | await createUser(server.url, accessToken, 'user_1', 'super password') | ||
170 | }) | ||
171 | |||
172 | it('Should be able to login with this user', async function () { | ||
173 | server.user = { | ||
174 | username: 'user_1', | ||
175 | password: 'super password' | ||
176 | } | ||
177 | |||
178 | accessTokenUser = await loginAndGetAccessToken(server) | ||
179 | }) | ||
180 | |||
181 | it('Should be able to get the user information', async function () { | ||
182 | const res = await getUserInformation(server.url, accessTokenUser) | ||
183 | const user = res.body | ||
184 | |||
185 | expect(user.username).to.equal('user_1') | ||
186 | expect(user.email).to.equal('user_1@example.com') | ||
187 | expect(user.displayNSFW).to.be.false | ||
188 | expect(user.id).to.be.a('number') | ||
189 | }) | ||
190 | |||
191 | it('Should be able to upload a video with this user', async function () { | ||
192 | this.timeout(5000) | ||
193 | |||
194 | const videoAttributes = {} | ||
195 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | ||
196 | }) | ||
197 | |||
198 | it('Should list all the users', async function () { | ||
199 | const res = await getUsersList(server.url) | ||
200 | const result = res.body | ||
201 | const total = result.total | ||
202 | const users = result.data | ||
203 | |||
204 | expect(total).to.equal(2) | ||
205 | expect(users).to.be.an('array') | ||
206 | expect(users.length).to.equal(2) | ||
207 | |||
208 | const user = users[0] | ||
209 | expect(user.username).to.equal('user_1') | ||
210 | expect(user.email).to.equal('user_1@example.com') | ||
211 | expect(user.displayNSFW).to.be.false | ||
212 | |||
213 | const rootUser = users[1] | ||
214 | expect(rootUser.username).to.equal('root') | ||
215 | expect(rootUser.email).to.equal('admin1@example.com') | ||
216 | expect(rootUser.displayNSFW).to.be.false | ||
217 | |||
218 | userId = user.id | ||
219 | }) | ||
220 | |||
221 | it('Should list only the first user by username asc', async function () { | ||
222 | const res = await getUsersListPaginationAndSort(server.url, 0, 1, 'username') | ||
223 | |||
224 | const result = res.body | ||
225 | const total = result.total | ||
226 | const users = result.data | ||
227 | |||
228 | expect(total).to.equal(2) | ||
229 | expect(users.length).to.equal(1) | ||
230 | |||
231 | const user = users[0] | ||
232 | expect(user.username).to.equal('root') | ||
233 | expect(user.email).to.equal('admin1@example.com') | ||
234 | expect(user.displayNSFW).to.be.false | ||
235 | }) | ||
236 | |||
237 | it('Should list only the first user by username desc', async function () { | ||
238 | const res = await getUsersListPaginationAndSort(server.url, 0, 1, '-username') | ||
239 | const result = res.body | ||
240 | const total = result.total | ||
241 | const users = result.data | ||
242 | |||
243 | expect(total).to.equal(2) | ||
244 | expect(users.length).to.equal(1) | ||
245 | |||
246 | const user = users[0] | ||
247 | expect(user.username).to.equal('user_1') | ||
248 | expect(user.email).to.equal('user_1@example.com') | ||
249 | expect(user.displayNSFW).to.be.false | ||
250 | }) | ||
251 | |||
252 | it('Should list only the second user by createdAt desc', async function () { | ||
253 | const res = await getUsersListPaginationAndSort(server.url, 0, 1, '-createdAt') | ||
254 | const result = res.body | ||
255 | const total = result.total | ||
256 | const users = result.data | ||
257 | |||
258 | expect(total).to.equal(2) | ||
259 | expect(users.length).to.equal(1) | ||
260 | |||
261 | const user = users[0] | ||
262 | expect(user.username).to.equal('user_1') | ||
263 | expect(user.email).to.equal('user_1@example.com') | ||
264 | expect(user.displayNSFW).to.be.false | ||
265 | }) | ||
266 | |||
267 | it('Should list all the users by createdAt asc', async function () { | ||
268 | const res = await getUsersListPaginationAndSort(server.url, 0, 2, 'createdAt') | ||
269 | const result = res.body | ||
270 | const total = result.total | ||
271 | const users = result.data | ||
272 | |||
273 | expect(total).to.equal(2) | ||
274 | expect(users.length).to.equal(2) | ||
275 | |||
276 | expect(users[0].username).to.equal('root') | ||
277 | expect(users[0].email).to.equal('admin1@example.com') | ||
278 | expect(users[0].displayNSFW).to.be.false | ||
279 | |||
280 | expect(users[1].username).to.equal('user_1') | ||
281 | expect(users[1].email).to.equal('user_1@example.com') | ||
282 | expect(users[1].displayNSFW).to.be.false | ||
283 | }) | ||
284 | |||
285 | it('Should update the user password', async function () { | ||
286 | await updateUser(server.url, userId, accessTokenUser, 'new password', null) | ||
287 | server.user.password = 'new password' | ||
288 | |||
289 | await login(server.url, server.client, server.user, 200) | ||
290 | }) | ||
291 | |||
292 | it('Should be able to change the NSFW display attribute', async function () { | ||
293 | await updateUser(server.url, userId, accessTokenUser, null, true) | ||
294 | |||
295 | const res = await getUserInformation(server.url, accessTokenUser) | ||
296 | const user = res.body | ||
297 | |||
298 | expect(user.username).to.equal('user_1') | ||
299 | expect(user.email).to.equal('user_1@example.com') | ||
300 | expect(user.displayNSFW).to.be.ok | ||
301 | expect(user.id).to.be.a('number') | ||
302 | }) | ||
303 | |||
304 | it('Should be able to remove this user', async function () { | ||
305 | await removeUser(server.url, userId, accessToken) | ||
306 | }) | ||
307 | |||
308 | it('Should not be able to login with this user', async function () { | ||
309 | // server.user is already set to user 1 | ||
310 | await login(server.url, server.client, server.user, 400) | ||
311 | }) | ||
312 | |||
313 | it('Should not have videos of this user', async function () { | ||
314 | const res = await getVideosList(server.url) | ||
315 | |||
316 | expect(res.body.total).to.equal(1) | ||
317 | |||
318 | const video = res.body.data[0] | ||
319 | expect(video.author).to.equal('root') | ||
320 | }) | ||
321 | |||
322 | it('Should register a new user', async function () { | ||
323 | await registerUser(server.url, 'user_15', 'my super password') | ||
324 | }) | ||
325 | |||
326 | it('Should be able to login with this registered user', async function () { | ||
327 | server.user = { | ||
328 | username: 'user_15', | ||
329 | password: 'my super password' | ||
330 | } | ||
331 | |||
332 | await loginAndGetAccessToken(server) | ||
333 | }) | ||
334 | |||
335 | after(async function () { | ||
336 | killallServers([ server ]) | ||
337 | |||
338 | // Keep the logs if the test failed | ||
339 | if (this['ok']) { | ||
340 | await flushTests() | ||
341 | } | ||
342 | }) | ||
343 | }) | ||
diff --git a/server/tests/api/video-abuse.js b/server/tests/api/video-abuse.js deleted file mode 100644 index be35a361d..000000000 --- a/server/tests/api/video-abuse.js +++ /dev/null | |||
@@ -1,193 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const series = require('async/series') | ||
9 | |||
10 | const loginUtils = require('../utils/login') | ||
11 | const podsUtils = require('../utils/pods') | ||
12 | const serversUtils = require('../utils/servers') | ||
13 | const videosUtils = require('../utils/videos') | ||
14 | const videoAbusesUtils = require('../utils/video-abuses') | ||
15 | |||
16 | describe('Test video abuses', function () { | ||
17 | let servers = [] | ||
18 | |||
19 | before(function (done) { | ||
20 | this.timeout(100000) | ||
21 | |||
22 | series([ | ||
23 | // Run servers | ||
24 | function (next) { | ||
25 | serversUtils.flushAndRunMultipleServers(2, function (serversRun) { | ||
26 | servers = serversRun | ||
27 | next() | ||
28 | }) | ||
29 | }, | ||
30 | // Get the access tokens | ||
31 | function (next) { | ||
32 | each(servers, function (server, callbackEach) { | ||
33 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
34 | if (err) return callbackEach(err) | ||
35 | |||
36 | server.accessToken = accessToken | ||
37 | callbackEach() | ||
38 | }) | ||
39 | }, next) | ||
40 | }, | ||
41 | // Pod 1 makes friend with pod 2 | ||
42 | function (next) { | ||
43 | const server = servers[0] | ||
44 | podsUtils.makeFriends(server.url, server.accessToken, next) | ||
45 | }, | ||
46 | // Upload some videos on each pods | ||
47 | function (next) { | ||
48 | const videoAttributes = { | ||
49 | name: 'my super name for pod 1', | ||
50 | description: 'my super description for pod 1' | ||
51 | } | ||
52 | videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, next) | ||
53 | }, | ||
54 | function (next) { | ||
55 | const videoAttributes = { | ||
56 | name: 'my super name for pod 2', | ||
57 | description: 'my super description for pod 2' | ||
58 | } | ||
59 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next) | ||
60 | }, | ||
61 | // Wait videos propagation | ||
62 | function (next) { | ||
63 | setTimeout(next, 22000) | ||
64 | }, | ||
65 | function (next) { | ||
66 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
67 | if (err) throw err | ||
68 | |||
69 | const videos = res.body.data | ||
70 | |||
71 | expect(videos.length).to.equal(2) | ||
72 | |||
73 | servers[0].video = videos.find(function (video) { return video.name === 'my super name for pod 1' }) | ||
74 | servers[1].video = videos.find(function (video) { return video.name === 'my super name for pod 2' }) | ||
75 | |||
76 | next() | ||
77 | }) | ||
78 | } | ||
79 | ], done) | ||
80 | }) | ||
81 | |||
82 | it('Should not have video abuses', function (done) { | ||
83 | videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) { | ||
84 | if (err) throw err | ||
85 | |||
86 | expect(res.body.total).to.equal(0) | ||
87 | expect(res.body.data).to.be.an('array') | ||
88 | expect(res.body.data.length).to.equal(0) | ||
89 | |||
90 | done() | ||
91 | }) | ||
92 | }) | ||
93 | |||
94 | it('Should report abuse on a local video', function (done) { | ||
95 | this.timeout(15000) | ||
96 | |||
97 | const reason = 'my super bad reason' | ||
98 | videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason, function (err) { | ||
99 | if (err) throw err | ||
100 | |||
101 | // We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2 | ||
102 | setTimeout(done, 11000) | ||
103 | }) | ||
104 | }) | ||
105 | |||
106 | it('Should have 1 video abuses on pod 1 and 0 on pod 2', function (done) { | ||
107 | videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) { | ||
108 | if (err) throw err | ||
109 | |||
110 | expect(res.body.total).to.equal(1) | ||
111 | expect(res.body.data).to.be.an('array') | ||
112 | expect(res.body.data.length).to.equal(1) | ||
113 | |||
114 | const abuse = res.body.data[0] | ||
115 | expect(abuse.reason).to.equal('my super bad reason') | ||
116 | expect(abuse.reporterUsername).to.equal('root') | ||
117 | expect(abuse.reporterPodHost).to.equal('localhost:9001') | ||
118 | expect(abuse.videoId).to.equal(servers[0].video.id) | ||
119 | |||
120 | videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) { | ||
121 | if (err) throw err | ||
122 | |||
123 | expect(res.body.total).to.equal(0) | ||
124 | expect(res.body.data).to.be.an('array') | ||
125 | expect(res.body.data.length).to.equal(0) | ||
126 | |||
127 | done() | ||
128 | }) | ||
129 | }) | ||
130 | }) | ||
131 | |||
132 | it('Should report abuse on a remote video', function (done) { | ||
133 | this.timeout(15000) | ||
134 | |||
135 | const reason = 'my super bad reason 2' | ||
136 | videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason, function (err) { | ||
137 | if (err) throw err | ||
138 | |||
139 | // We wait requests propagation | ||
140 | setTimeout(done, 11000) | ||
141 | }) | ||
142 | }) | ||
143 | |||
144 | it('Should have 2 video abuse on pod 1 and 1 on pod 2', function (done) { | ||
145 | videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) { | ||
146 | if (err) throw err | ||
147 | |||
148 | expect(res.body.total).to.equal(2) | ||
149 | expect(res.body.data).to.be.an('array') | ||
150 | expect(res.body.data.length).to.equal(2) | ||
151 | |||
152 | let abuse = res.body.data[0] | ||
153 | expect(abuse.reason).to.equal('my super bad reason') | ||
154 | expect(abuse.reporterUsername).to.equal('root') | ||
155 | expect(abuse.reporterPodHost).to.equal('localhost:9001') | ||
156 | expect(abuse.videoId).to.equal(servers[0].video.id) | ||
157 | |||
158 | abuse = res.body.data[1] | ||
159 | expect(abuse.reason).to.equal('my super bad reason 2') | ||
160 | expect(abuse.reporterUsername).to.equal('root') | ||
161 | expect(abuse.reporterPodHost).to.equal('localhost:9001') | ||
162 | expect(abuse.videoId).to.equal(servers[1].video.id) | ||
163 | |||
164 | videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) { | ||
165 | if (err) throw err | ||
166 | |||
167 | expect(res.body.total).to.equal(1) | ||
168 | expect(res.body.data).to.be.an('array') | ||
169 | expect(res.body.data.length).to.equal(1) | ||
170 | |||
171 | let abuse = res.body.data[0] | ||
172 | expect(abuse.reason).to.equal('my super bad reason 2') | ||
173 | expect(abuse.reporterUsername).to.equal('root') | ||
174 | expect(abuse.reporterPodHost).to.equal('localhost:9001') | ||
175 | |||
176 | done() | ||
177 | }) | ||
178 | }) | ||
179 | }) | ||
180 | |||
181 | after(function (done) { | ||
182 | servers.forEach(function (server) { | ||
183 | process.kill(-server.app.pid) | ||
184 | }) | ||
185 | |||
186 | // Keep the logs if the test failed | ||
187 | if (this.ok) { | ||
188 | serversUtils.flushTests(done) | ||
189 | } else { | ||
190 | done() | ||
191 | } | ||
192 | }) | ||
193 | }) | ||
diff --git a/server/tests/api/video-abuse.ts b/server/tests/api/video-abuse.ts new file mode 100644 index 000000000..f2a2c322a --- /dev/null +++ b/server/tests/api/video-abuse.ts | |||
@@ -0,0 +1,145 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushAndRunMultipleServers, | ||
10 | uploadVideo, | ||
11 | makeFriends, | ||
12 | getVideosList, | ||
13 | wait, | ||
14 | setAccessTokensToServers, | ||
15 | getVideoAbusesList, | ||
16 | reportVideoAbuse, | ||
17 | killallServers, | ||
18 | flushTests | ||
19 | } from '../utils' | ||
20 | |||
21 | describe('Test video abuses', function () { | ||
22 | let servers: ServerInfo[] = [] | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(100000) | ||
26 | |||
27 | // Run servers | ||
28 | servers = await flushAndRunMultipleServers(2) | ||
29 | |||
30 | // Get the access tokens | ||
31 | await setAccessTokensToServers(servers) | ||
32 | |||
33 | // Pod 1 makes friend with pod 2 | ||
34 | await makeFriends(servers[0].url, servers[0].accessToken) | ||
35 | |||
36 | // Upload some videos on each pods | ||
37 | const video1Attributes = { | ||
38 | name: 'my super name for pod 1', | ||
39 | description: 'my super description for pod 1' | ||
40 | } | ||
41 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | ||
42 | |||
43 | const video2Attributes = { | ||
44 | name: 'my super name for pod 2', | ||
45 | description: 'my super description for pod 2' | ||
46 | } | ||
47 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | ||
48 | |||
49 | // Wait videos propagation | ||
50 | await wait(22000) | ||
51 | |||
52 | const res = await getVideosList(servers[0].url) | ||
53 | const videos = res.body.data | ||
54 | |||
55 | expect(videos.length).to.equal(2) | ||
56 | |||
57 | servers[0].video = videos.find(video => video.name === 'my super name for pod 1') | ||
58 | servers[1].video = videos.find(video => video.name === 'my super name for pod 2') | ||
59 | }) | ||
60 | |||
61 | it('Should not have video abuses', async function () { | ||
62 | const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | ||
63 | |||
64 | expect(res.body.total).to.equal(0) | ||
65 | expect(res.body.data).to.be.an('array') | ||
66 | expect(res.body.data.length).to.equal(0) | ||
67 | }) | ||
68 | |||
69 | it('Should report abuse on a local video', async function () { | ||
70 | this.timeout(15000) | ||
71 | |||
72 | const reason = 'my super bad reason' | ||
73 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) | ||
74 | |||
75 | // We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2 | ||
76 | await wait(11000) | ||
77 | }) | ||
78 | |||
79 | it('Should have 1 video abuses on pod 1 and 0 on pod 2', async function () { | ||
80 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | ||
81 | |||
82 | expect(res1.body.total).to.equal(1) | ||
83 | expect(res1.body.data).to.be.an('array') | ||
84 | expect(res1.body.data.length).to.equal(1) | ||
85 | |||
86 | const abuse = res1.body.data[0] | ||
87 | expect(abuse.reason).to.equal('my super bad reason') | ||
88 | expect(abuse.reporterUsername).to.equal('root') | ||
89 | expect(abuse.reporterPodHost).to.equal('localhost:9001') | ||
90 | expect(abuse.videoId).to.equal(servers[0].video.id) | ||
91 | |||
92 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | ||
93 | expect(res2.body.total).to.equal(0) | ||
94 | expect(res2.body.data).to.be.an('array') | ||
95 | expect(res2.body.data.length).to.equal(0) | ||
96 | }) | ||
97 | |||
98 | it('Should report abuse on a remote video', async function () { | ||
99 | this.timeout(15000) | ||
100 | |||
101 | const reason = 'my super bad reason 2' | ||
102 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) | ||
103 | |||
104 | // We wait requests propagation | ||
105 | await wait(11000) | ||
106 | }) | ||
107 | |||
108 | it('Should have 2 video abuse on pod 1 and 1 on pod 2', async function () { | ||
109 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | ||
110 | expect(res1.body.total).to.equal(2) | ||
111 | expect(res1.body.data).to.be.an('array') | ||
112 | expect(res1.body.data.length).to.equal(2) | ||
113 | |||
114 | const abuse1 = res1.body.data[0] | ||
115 | expect(abuse1.reason).to.equal('my super bad reason') | ||
116 | expect(abuse1.reporterUsername).to.equal('root') | ||
117 | expect(abuse1.reporterPodHost).to.equal('localhost:9001') | ||
118 | expect(abuse1.videoId).to.equal(servers[0].video.id) | ||
119 | |||
120 | const abuse2 = res1.body.data[1] | ||
121 | expect(abuse2.reason).to.equal('my super bad reason 2') | ||
122 | expect(abuse2.reporterUsername).to.equal('root') | ||
123 | expect(abuse2.reporterPodHost).to.equal('localhost:9001') | ||
124 | expect(abuse2.videoId).to.equal(servers[1].video.id) | ||
125 | |||
126 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | ||
127 | expect(res2.body.total).to.equal(1) | ||
128 | expect(res2.body.data).to.be.an('array') | ||
129 | expect(res2.body.data.length).to.equal(1) | ||
130 | |||
131 | const abuse3 = res2.body.data[0] | ||
132 | expect(abuse3.reason).to.equal('my super bad reason 2') | ||
133 | expect(abuse3.reporterUsername).to.equal('root') | ||
134 | expect(abuse3.reporterPodHost).to.equal('localhost:9001') | ||
135 | }) | ||
136 | |||
137 | after(async function () { | ||
138 | killallServers(servers) | ||
139 | |||
140 | // Keep the logs if the test failed | ||
141 | if (this['ok']) { | ||
142 | await flushTests() | ||
143 | } | ||
144 | }) | ||
145 | }) | ||
diff --git a/server/tests/api/video-blacklist.js b/server/tests/api/video-blacklist.js deleted file mode 100644 index 79a2fec8d..000000000 --- a/server/tests/api/video-blacklist.js +++ /dev/null | |||
@@ -1,138 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const series = require('async/series') | ||
9 | |||
10 | const loginUtils = require('../utils/login') | ||
11 | const podsUtils = require('../utils/pods') | ||
12 | const serversUtils = require('../utils/servers') | ||
13 | const videosUtils = require('../utils/videos') | ||
14 | const videoBlacklistsUtils = require('../utils/video-blacklists') | ||
15 | |||
16 | describe('Test video blacklists', function () { | ||
17 | let servers = [] | ||
18 | |||
19 | before(function (done) { | ||
20 | this.timeout(120000) | ||
21 | |||
22 | series([ | ||
23 | // Run servers | ||
24 | function (next) { | ||
25 | serversUtils.flushAndRunMultipleServers(2, function (serversRun) { | ||
26 | servers = serversRun | ||
27 | next() | ||
28 | }) | ||
29 | }, | ||
30 | // Get the access tokens | ||
31 | function (next) { | ||
32 | each(servers, function (server, callbackEach) { | ||
33 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
34 | if (err) return callbackEach(err) | ||
35 | |||
36 | server.accessToken = accessToken | ||
37 | callbackEach() | ||
38 | }) | ||
39 | }, next) | ||
40 | }, | ||
41 | // Pod 1 makes friend with pod 2 | ||
42 | function (next) { | ||
43 | const server = servers[0] | ||
44 | podsUtils.makeFriends(server.url, server.accessToken, next) | ||
45 | }, | ||
46 | // Upload a video on pod 2 | ||
47 | function (next) { | ||
48 | const videoAttributes = { | ||
49 | name: 'my super name for pod 2', | ||
50 | description: 'my super description for pod 2' | ||
51 | } | ||
52 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next) | ||
53 | }, | ||
54 | // Wait videos propagation | ||
55 | function (next) { | ||
56 | setTimeout(next, 22000) | ||
57 | }, | ||
58 | function (next) { | ||
59 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
60 | if (err) throw err | ||
61 | |||
62 | const videos = res.body.data | ||
63 | |||
64 | expect(videos.length).to.equal(1) | ||
65 | |||
66 | servers[0].remoteVideo = videos.find(function (video) { return video.name === 'my super name for pod 2' }) | ||
67 | |||
68 | next() | ||
69 | }) | ||
70 | } | ||
71 | ], done) | ||
72 | }) | ||
73 | |||
74 | it('Should blacklist a remote video on pod 1', function (done) { | ||
75 | videoBlacklistsUtils.addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id, done) | ||
76 | }) | ||
77 | |||
78 | it('Should not have the video blacklisted in videos list on pod 1', function (done) { | ||
79 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
80 | if (err) throw err | ||
81 | |||
82 | expect(res.body.total).to.equal(0) | ||
83 | expect(res.body.data).to.be.an('array') | ||
84 | expect(res.body.data.length).to.equal(0) | ||
85 | |||
86 | done() | ||
87 | }) | ||
88 | }) | ||
89 | |||
90 | it('Should not have the video blacklisted in videos search on pod 1', function (done) { | ||
91 | videosUtils.searchVideo(servers[0].url, 'name', function (err, res) { | ||
92 | if (err) throw err | ||
93 | |||
94 | expect(res.body.total).to.equal(0) | ||
95 | expect(res.body.data).to.be.an('array') | ||
96 | expect(res.body.data.length).to.equal(0) | ||
97 | |||
98 | done() | ||
99 | }) | ||
100 | }) | ||
101 | |||
102 | it('Should have the blacklisted video in videos list on pod 2', function (done) { | ||
103 | videosUtils.getVideosList(servers[1].url, function (err, res) { | ||
104 | if (err) throw err | ||
105 | |||
106 | expect(res.body.total).to.equal(1) | ||
107 | expect(res.body.data).to.be.an('array') | ||
108 | expect(res.body.data.length).to.equal(1) | ||
109 | |||
110 | done() | ||
111 | }) | ||
112 | }) | ||
113 | |||
114 | it('Should have the video blacklisted in videos search on pod 2', function (done) { | ||
115 | videosUtils.searchVideo(servers[1].url, 'name', function (err, res) { | ||
116 | if (err) throw err | ||
117 | |||
118 | expect(res.body.total).to.equal(1) | ||
119 | expect(res.body.data).to.be.an('array') | ||
120 | expect(res.body.data.length).to.equal(1) | ||
121 | |||
122 | done() | ||
123 | }) | ||
124 | }) | ||
125 | |||
126 | after(function (done) { | ||
127 | servers.forEach(function (server) { | ||
128 | process.kill(-server.app.pid) | ||
129 | }) | ||
130 | |||
131 | // Keep the logs if the test failed | ||
132 | if (this.ok) { | ||
133 | serversUtils.flushTests(done) | ||
134 | } else { | ||
135 | done() | ||
136 | } | ||
137 | }) | ||
138 | }) | ||
diff --git a/server/tests/api/video-blacklist.ts b/server/tests/api/video-blacklist.ts new file mode 100644 index 000000000..e789611d0 --- /dev/null +++ b/server/tests/api/video-blacklist.ts | |||
@@ -0,0 +1,98 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | uploadVideo, | ||
11 | makeFriends, | ||
12 | getVideosList, | ||
13 | wait, | ||
14 | setAccessTokensToServers, | ||
15 | flushAndRunMultipleServers, | ||
16 | addVideoToBlacklist, | ||
17 | searchVideo, | ||
18 | killallServers | ||
19 | } from '../utils' | ||
20 | |||
21 | describe('Test video blacklists', function () { | ||
22 | let servers: ServerInfo[] = [] | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(120000) | ||
26 | |||
27 | // Run servers | ||
28 | servers = await flushAndRunMultipleServers(2) | ||
29 | |||
30 | // Get the access tokens | ||
31 | await setAccessTokensToServers(servers) | ||
32 | |||
33 | // Pod 1 makes friend with pod 2 | ||
34 | await makeFriends(servers[0].url, servers[0].accessToken) | ||
35 | |||
36 | // Upload a video on pod 2 | ||
37 | const videoAttributes = { | ||
38 | name: 'my super name for pod 2', | ||
39 | description: 'my super description for pod 2' | ||
40 | } | ||
41 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
42 | |||
43 | // Wait videos propagation | ||
44 | await wait(22000) | ||
45 | |||
46 | const res = await getVideosList(servers[0].url) | ||
47 | const videos = res.body.data | ||
48 | |||
49 | expect(videos.length).to.equal(1) | ||
50 | |||
51 | servers[0].remoteVideo = videos.find(video => video.name === 'my super name for pod 2') | ||
52 | }) | ||
53 | |||
54 | it('Should blacklist a remote video on pod 1', async function () { | ||
55 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id) | ||
56 | }) | ||
57 | |||
58 | it('Should not have the video blacklisted in videos list on pod 1', async function () { | ||
59 | const res = await getVideosList(servers[0].url) | ||
60 | |||
61 | expect(res.body.total).to.equal(0) | ||
62 | expect(res.body.data).to.be.an('array') | ||
63 | expect(res.body.data.length).to.equal(0) | ||
64 | }) | ||
65 | |||
66 | it('Should not have the video blacklisted in videos search on pod 1', async function () { | ||
67 | const res = await searchVideo(servers[0].url, 'name') | ||
68 | |||
69 | expect(res.body.total).to.equal(0) | ||
70 | expect(res.body.data).to.be.an('array') | ||
71 | expect(res.body.data.length).to.equal(0) | ||
72 | }) | ||
73 | |||
74 | it('Should have the blacklisted video in videos list on pod 2', async function () { | ||
75 | const res = await getVideosList(servers[1].url) | ||
76 | |||
77 | expect(res.body.total).to.equal(1) | ||
78 | expect(res.body.data).to.be.an('array') | ||
79 | expect(res.body.data.length).to.equal(1) | ||
80 | }) | ||
81 | |||
82 | it('Should have the video blacklisted in videos search on pod 2', async function () { | ||
83 | const res = await searchVideo(servers[1].url, 'name') | ||
84 | |||
85 | expect(res.body.total).to.equal(1) | ||
86 | expect(res.body.data).to.be.an('array') | ||
87 | expect(res.body.data.length).to.equal(1) | ||
88 | }) | ||
89 | |||
90 | after(async function () { | ||
91 | killallServers(servers) | ||
92 | |||
93 | // Keep the logs if the test failed | ||
94 | if (this['ok']) { | ||
95 | await flushTests() | ||
96 | } | ||
97 | }) | ||
98 | }) | ||
diff --git a/server/tests/api/video-transcoder.js b/server/tests/api/video-transcoder.js deleted file mode 100644 index c7af3cf11..000000000 --- a/server/tests/api/video-transcoder.js +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const series = require('async/series') | ||
9 | const webtorrent = new (require('webtorrent'))() | ||
10 | |||
11 | const loginUtils = require('../utils/login') | ||
12 | const serversUtils = require('../utils/servers') | ||
13 | const videosUtils = require('../utils/videos') | ||
14 | |||
15 | describe('Test video transcoding', function () { | ||
16 | let servers = [] | ||
17 | |||
18 | before(function (done) { | ||
19 | this.timeout(30000) | ||
20 | |||
21 | series([ | ||
22 | // Run servers | ||
23 | function (next) { | ||
24 | serversUtils.flushAndRunMultipleServers(2, function (serversRun) { | ||
25 | servers = serversRun | ||
26 | next() | ||
27 | }) | ||
28 | }, | ||
29 | // Get the access tokens | ||
30 | function (next) { | ||
31 | each(servers, function (server, callbackEach) { | ||
32 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
33 | if (err) return callbackEach(err) | ||
34 | |||
35 | server.accessToken = accessToken | ||
36 | callbackEach() | ||
37 | }) | ||
38 | }, next) | ||
39 | } | ||
40 | ], done) | ||
41 | }) | ||
42 | |||
43 | it('Should not transcode video on server 1', function (done) { | ||
44 | this.timeout(60000) | ||
45 | |||
46 | const videoAttributes = { | ||
47 | name: 'my super name for pod 1', | ||
48 | description: 'my super description for pod 1', | ||
49 | fixture: 'video_short.webm' | ||
50 | } | ||
51 | videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, function (err) { | ||
52 | if (err) throw err | ||
53 | |||
54 | setTimeout(function () { | ||
55 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
56 | if (err) throw err | ||
57 | |||
58 | const video = res.body.data[0] | ||
59 | const magnetUri = video.files[0].magnetUri | ||
60 | expect(magnetUri).to.match(/\.webm/) | ||
61 | |||
62 | webtorrent.add(magnetUri, function (torrent) { | ||
63 | expect(torrent.files).to.exist | ||
64 | expect(torrent.files.length).to.equal(1) | ||
65 | expect(torrent.files[0].path).match(/\.webm$/) | ||
66 | |||
67 | done() | ||
68 | }) | ||
69 | }) | ||
70 | }, 30000) | ||
71 | }) | ||
72 | }) | ||
73 | |||
74 | it('Should transcode video on server 2', function (done) { | ||
75 | this.timeout(60000) | ||
76 | |||
77 | const videoAttributes = { | ||
78 | name: 'my super name for pod 2', | ||
79 | description: 'my super description for pod 2', | ||
80 | fixture: 'video_short.webm' | ||
81 | } | ||
82 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, function (err) { | ||
83 | if (err) throw err | ||
84 | |||
85 | setTimeout(function () { | ||
86 | videosUtils.getVideosList(servers[1].url, function (err, res) { | ||
87 | if (err) throw err | ||
88 | |||
89 | const video = res.body.data[0] | ||
90 | const magnetUri = video.files[0].magnetUri | ||
91 | expect(magnetUri).to.match(/\.mp4/) | ||
92 | |||
93 | webtorrent.add(magnetUri, function (torrent) { | ||
94 | expect(torrent.files).to.exist | ||
95 | expect(torrent.files.length).to.equal(1) | ||
96 | expect(torrent.files[0].path).match(/\.mp4$/) | ||
97 | |||
98 | done() | ||
99 | }) | ||
100 | }) | ||
101 | }, 30000) | ||
102 | }) | ||
103 | }) | ||
104 | |||
105 | after(function (done) { | ||
106 | servers.forEach(function (server) { | ||
107 | process.kill(-server.app.pid) | ||
108 | }) | ||
109 | |||
110 | // Keep the logs if the test failed | ||
111 | if (this.ok) { | ||
112 | serversUtils.flushTests(done) | ||
113 | } else { | ||
114 | done() | ||
115 | } | ||
116 | }) | ||
117 | }) | ||
diff --git a/server/tests/api/video-transcoder.ts b/server/tests/api/video-transcoder.ts new file mode 100644 index 000000000..228cef007 --- /dev/null +++ b/server/tests/api/video-transcoder.ts | |||
@@ -0,0 +1,86 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | uploadVideo, | ||
11 | getVideosList, | ||
12 | wait, | ||
13 | setAccessTokensToServers, | ||
14 | flushAndRunMultipleServers, | ||
15 | killallServers, | ||
16 | webtorrentAdd | ||
17 | } from '../utils' | ||
18 | |||
19 | describe('Test video transcoding', function () { | ||
20 | let servers: ServerInfo[] = [] | ||
21 | |||
22 | before(async function () { | ||
23 | this.timeout(30000) | ||
24 | |||
25 | // Run servers | ||
26 | servers = await flushAndRunMultipleServers(2) | ||
27 | |||
28 | await setAccessTokensToServers(servers) | ||
29 | }) | ||
30 | |||
31 | it('Should not transcode video on server 1', async function () { | ||
32 | this.timeout(60000) | ||
33 | |||
34 | const videoAttributes = { | ||
35 | name: 'my super name for pod 1', | ||
36 | description: 'my super description for pod 1', | ||
37 | fixture: 'video_short.webm' | ||
38 | } | ||
39 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | ||
40 | |||
41 | await wait(30000) | ||
42 | |||
43 | const res = await getVideosList(servers[0].url) | ||
44 | const video = res.body.data[0] | ||
45 | const magnetUri = video.files[0].magnetUri | ||
46 | expect(magnetUri).to.match(/\.webm/) | ||
47 | |||
48 | const torrent = await webtorrentAdd(magnetUri) | ||
49 | expect(torrent.files).to.be.an('array') | ||
50 | expect(torrent.files.length).to.equal(1) | ||
51 | expect(torrent.files[0].path).match(/\.webm$/) | ||
52 | }) | ||
53 | |||
54 | it('Should transcode video on server 2', async function () { | ||
55 | this.timeout(60000) | ||
56 | |||
57 | const videoAttributes = { | ||
58 | name: 'my super name for pod 2', | ||
59 | description: 'my super description for pod 2', | ||
60 | fixture: 'video_short.webm' | ||
61 | } | ||
62 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
63 | |||
64 | await wait(30000) | ||
65 | |||
66 | const res = await getVideosList(servers[1].url) | ||
67 | |||
68 | const video = res.body.data[0] | ||
69 | const magnetUri = video.files[0].magnetUri | ||
70 | expect(magnetUri).to.match(/\.mp4/) | ||
71 | |||
72 | const torrent = await webtorrentAdd(magnetUri) | ||
73 | expect(torrent.files).to.be.an('array') | ||
74 | expect(torrent.files.length).to.equal(1) | ||
75 | expect(torrent.files[0].path).match(/\.mp4$/) | ||
76 | }) | ||
77 | |||
78 | after(async function () { | ||
79 | killallServers(servers) | ||
80 | |||
81 | // Keep the logs if the test failed | ||
82 | if (this['ok']) { | ||
83 | await flushTests() | ||
84 | } | ||
85 | }) | ||
86 | }) | ||