diff options
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/index.js | 9 | ||||
-rw-r--r-- | server/tests/api/check-params/pods.js | 204 | ||||
-rw-r--r-- | server/tests/api/check-params/remotes.js | 64 | ||||
-rw-r--r-- | server/tests/api/check-params/requests.js | 87 | ||||
-rw-r--r-- | server/tests/api/check-params/users.js | 284 | ||||
-rw-r--r-- | server/tests/api/check-params/video-abuses.js | 180 | ||||
-rw-r--r-- | server/tests/api/check-params/videos.js | 460 |
7 files changed, 1288 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js new file mode 100644 index 000000000..d0824f08a --- /dev/null +++ b/server/tests/api/check-params/index.js | |||
@@ -0,0 +1,9 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // Order of the tests we want to execute | ||
4 | require('./pods') | ||
5 | require('./remotes') | ||
6 | require('./users') | ||
7 | require('./requests') | ||
8 | require('./videos') | ||
9 | require('./video-abuses') | ||
diff --git a/server/tests/api/check-params/pods.js b/server/tests/api/check-params/pods.js new file mode 100644 index 000000000..2f85af644 --- /dev/null +++ b/server/tests/api/check-params/pods.js | |||
@@ -0,0 +1,204 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | const series = require('async/series') | ||
5 | |||
6 | const loginUtils = require('../../utils/login') | ||
7 | const requestsUtils = require('../../utils/requests') | ||
8 | const serversUtils = require('../../utils/servers') | ||
9 | const usersUtils = require('../../utils/users') | ||
10 | |||
11 | describe('Test pods API validators', function () { | ||
12 | const path = '/api/v1/pods/' | ||
13 | let server = null | ||
14 | |||
15 | // --------------------------------------------------------------- | ||
16 | |||
17 | before(function (done) { | ||
18 | this.timeout(20000) | ||
19 | |||
20 | series([ | ||
21 | function (next) { | ||
22 | serversUtils.flushTests(next) | ||
23 | }, | ||
24 | function (next) { | ||
25 | serversUtils.runServer(1, function (server1) { | ||
26 | server = server1 | ||
27 | |||
28 | next() | ||
29 | }) | ||
30 | }, | ||
31 | function (next) { | ||
32 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
33 | if (err) throw err | ||
34 | server.accessToken = token | ||
35 | |||
36 | next() | ||
37 | }) | ||
38 | } | ||
39 | ], done) | ||
40 | }) | ||
41 | |||
42 | describe('When making friends', function () { | ||
43 | let userAccessToken = null | ||
44 | |||
45 | before(function (done) { | ||
46 | usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { | ||
47 | server.user = { | ||
48 | username: 'user1', | ||
49 | password: 'password' | ||
50 | } | ||
51 | |||
52 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
53 | if (err) throw err | ||
54 | |||
55 | userAccessToken = accessToken | ||
56 | |||
57 | done() | ||
58 | }) | ||
59 | }) | ||
60 | }) | ||
61 | |||
62 | describe('When making friends', function () { | ||
63 | const body = { | ||
64 | hosts: [ 'localhost:9002' ] | ||
65 | } | ||
66 | |||
67 | it('Should fail without hosts', function (done) { | ||
68 | request(server.url) | ||
69 | .post(path + '/makefriends') | ||
70 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
71 | .set('Accept', 'application/json') | ||
72 | .expect(400, done) | ||
73 | }) | ||
74 | |||
75 | it('Should fail if hosts is not an array', function (done) { | ||
76 | request(server.url) | ||
77 | .post(path + '/makefriends') | ||
78 | .send({ hosts: 'localhost:9002' }) | ||
79 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
80 | .set('Accept', 'application/json') | ||
81 | .expect(400, done) | ||
82 | }) | ||
83 | |||
84 | it('Should fail if the array is not composed by hosts', function (done) { | ||
85 | request(server.url) | ||
86 | .post(path + '/makefriends') | ||
87 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) | ||
88 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
89 | .set('Accept', 'application/json') | ||
90 | .expect(400, done) | ||
91 | }) | ||
92 | |||
93 | it('Should fail if the array is composed with http schemes', function (done) { | ||
94 | request(server.url) | ||
95 | .post(path + '/makefriends') | ||
96 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) | ||
97 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
98 | .set('Accept', 'application/json') | ||
99 | .expect(400, done) | ||
100 | }) | ||
101 | |||
102 | it('Should fail if hosts are not unique', function (done) { | ||
103 | request(server.url) | ||
104 | .post(path + '/makefriends') | ||
105 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | ||
106 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
107 | .set('Accept', 'application/json') | ||
108 | .expect(400, done) | ||
109 | }) | ||
110 | |||
111 | it('Should fail with a invalid token', function (done) { | ||
112 | request(server.url) | ||
113 | .post(path + '/makefriends') | ||
114 | .send(body) | ||
115 | .set('Authorization', 'Bearer faketoken') | ||
116 | .set('Accept', 'application/json') | ||
117 | .expect(401, done) | ||
118 | }) | ||
119 | |||
120 | it('Should fail if the user is not an administrator', function (done) { | ||
121 | request(server.url) | ||
122 | .post(path + '/makefriends') | ||
123 | .send(body) | ||
124 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
125 | .set('Accept', 'application/json') | ||
126 | .expect(403, done) | ||
127 | }) | ||
128 | }) | ||
129 | |||
130 | describe('When quitting friends', function () { | ||
131 | it('Should fail with a invalid token', function (done) { | ||
132 | request(server.url) | ||
133 | .get(path + '/quitfriends') | ||
134 | .query({ start: 'hello' }) | ||
135 | .set('Authorization', 'Bearer faketoken') | ||
136 | .set('Accept', 'application/json') | ||
137 | .expect(401, done) | ||
138 | }) | ||
139 | |||
140 | it('Should fail if the user is not an administrator', function (done) { | ||
141 | request(server.url) | ||
142 | .get(path + '/quitfriends') | ||
143 | .query({ start: 'hello' }) | ||
144 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
145 | .set('Accept', 'application/json') | ||
146 | .expect(403, done) | ||
147 | }) | ||
148 | }) | ||
149 | }) | ||
150 | |||
151 | describe('When adding a pod', function () { | ||
152 | it('Should fail with nothing', function (done) { | ||
153 | const data = {} | ||
154 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
155 | }) | ||
156 | |||
157 | it('Should fail without public key', function (done) { | ||
158 | const data = { | ||
159 | host: 'coucou.com' | ||
160 | } | ||
161 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
162 | }) | ||
163 | |||
164 | it('Should fail without an host', function (done) { | ||
165 | const data = { | ||
166 | publicKey: 'mysuperpublickey' | ||
167 | } | ||
168 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
169 | }) | ||
170 | |||
171 | it('Should fail with an incorrect host', function (done) { | ||
172 | const data = { | ||
173 | host: 'http://coucou.com', | ||
174 | publicKey: 'mysuperpublickey' | ||
175 | } | ||
176 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
177 | data.host = 'http://coucou' | ||
178 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
179 | data.host = 'coucou' | ||
180 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
181 | }) | ||
182 | }) | ||
183 | }) | ||
184 | |||
185 | it('Should succeed with the correct parameters', function (done) { | ||
186 | const data = { | ||
187 | host: 'coucou.com', | ||
188 | publicKey: 'mysuperpublickey' | ||
189 | } | ||
190 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) | ||
191 | }) | ||
192 | }) | ||
193 | |||
194 | after(function (done) { | ||
195 | process.kill(-server.app.pid) | ||
196 | |||
197 | // Keep the logs if the test failed | ||
198 | if (this.ok) { | ||
199 | serversUtils.flushTests(done) | ||
200 | } else { | ||
201 | done() | ||
202 | } | ||
203 | }) | ||
204 | }) | ||
diff --git a/server/tests/api/check-params/remotes.js b/server/tests/api/check-params/remotes.js new file mode 100644 index 000000000..c1ab9fb2b --- /dev/null +++ b/server/tests/api/check-params/remotes.js | |||
@@ -0,0 +1,64 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const series = require('async/series') | ||
4 | |||
5 | const loginUtils = require('../../utils/login') | ||
6 | const serversUtils = require('../../utils/servers') | ||
7 | |||
8 | describe('Test remote videos API validators', function () { | ||
9 | let server = null | ||
10 | |||
11 | // --------------------------------------------------------------- | ||
12 | |||
13 | before(function (done) { | ||
14 | this.timeout(20000) | ||
15 | |||
16 | series([ | ||
17 | function (next) { | ||
18 | serversUtils.flushTests(next) | ||
19 | }, | ||
20 | function (next) { | ||
21 | serversUtils.runServer(1, function (server1) { | ||
22 | server = server1 | ||
23 | |||
24 | next() | ||
25 | }) | ||
26 | }, | ||
27 | function (next) { | ||
28 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
29 | if (err) throw err | ||
30 | server.accessToken = token | ||
31 | |||
32 | next() | ||
33 | }) | ||
34 | } | ||
35 | ], done) | ||
36 | }) | ||
37 | |||
38 | describe('When making a secure request', function () { | ||
39 | it('Should check a secure request') | ||
40 | }) | ||
41 | |||
42 | describe('When adding a video', function () { | ||
43 | it('Should check when adding a video') | ||
44 | }) | ||
45 | |||
46 | describe('When removing a video', function () { | ||
47 | it('Should check when removing a video') | ||
48 | }) | ||
49 | |||
50 | describe('When reporting abuse on a video', function () { | ||
51 | it('Should check when reporting a video abuse') | ||
52 | }) | ||
53 | |||
54 | after(function (done) { | ||
55 | process.kill(-server.app.pid) | ||
56 | |||
57 | // Keep the logs if the test failed | ||
58 | if (this.ok) { | ||
59 | serversUtils.flushTests(done) | ||
60 | } else { | ||
61 | done() | ||
62 | } | ||
63 | }) | ||
64 | }) | ||
diff --git a/server/tests/api/check-params/requests.js b/server/tests/api/check-params/requests.js new file mode 100644 index 000000000..08f58db43 --- /dev/null +++ b/server/tests/api/check-params/requests.js | |||
@@ -0,0 +1,87 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | const series = require('async/series') | ||
5 | |||
6 | const loginUtils = require('../../utils/login') | ||
7 | const usersUtils = require('../../utils/users') | ||
8 | const serversUtils = require('../../utils/servers') | ||
9 | |||
10 | describe('Test requests API validators', function () { | ||
11 | const path = '/api/v1/requests/stats' | ||
12 | let server = null | ||
13 | let userAccessToken = null | ||
14 | |||
15 | // --------------------------------------------------------------- | ||
16 | |||
17 | before(function (done) { | ||
18 | this.timeout(20000) | ||
19 | |||
20 | series([ | ||
21 | function (next) { | ||
22 | serversUtils.flushTests(next) | ||
23 | }, | ||
24 | function (next) { | ||
25 | serversUtils.runServer(1, function (server1) { | ||
26 | server = server1 | ||
27 | |||
28 | next() | ||
29 | }) | ||
30 | }, | ||
31 | function (next) { | ||
32 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
33 | if (err) throw err | ||
34 | server.accessToken = token | ||
35 | |||
36 | next() | ||
37 | }) | ||
38 | }, | ||
39 | function (next) { | ||
40 | const username = 'user' | ||
41 | const password = 'my super password' | ||
42 | |||
43 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | ||
44 | }, | ||
45 | function (next) { | ||
46 | const user = { | ||
47 | username: 'user', | ||
48 | password: 'my super password' | ||
49 | } | ||
50 | |||
51 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | ||
52 | if (err) throw err | ||
53 | |||
54 | userAccessToken = accessToken | ||
55 | |||
56 | next() | ||
57 | }) | ||
58 | } | ||
59 | ], done) | ||
60 | }) | ||
61 | |||
62 | it('Should fail with an non authenticated user', function (done) { | ||
63 | request(server.url) | ||
64 | .get(path) | ||
65 | .set('Accept', 'application/json') | ||
66 | .expect(401, done) | ||
67 | }) | ||
68 | |||
69 | it('Should fail with a non admin user', function (done) { | ||
70 | request(server.url) | ||
71 | .get(path) | ||
72 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
73 | .set('Accept', 'application/json') | ||
74 | .expect(403, done) | ||
75 | }) | ||
76 | |||
77 | after(function (done) { | ||
78 | process.kill(-server.app.pid) | ||
79 | |||
80 | // Keep the logs if the test failed | ||
81 | if (this.ok) { | ||
82 | serversUtils.flushTests(done) | ||
83 | } else { | ||
84 | done() | ||
85 | } | ||
86 | }) | ||
87 | }) | ||
diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js new file mode 100644 index 000000000..c1fcf34a4 --- /dev/null +++ b/server/tests/api/check-params/users.js | |||
@@ -0,0 +1,284 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | const series = require('async/series') | ||
5 | |||
6 | const loginUtils = require('../../utils/login') | ||
7 | const requestsUtils = require('../../utils/requests') | ||
8 | const serversUtils = require('../../utils/servers') | ||
9 | const usersUtils = require('../../utils/users') | ||
10 | |||
11 | describe('Test users API validators', function () { | ||
12 | const path = '/api/v1/users/' | ||
13 | let userId = null | ||
14 | let rootId = null | ||
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 | ], done) | ||
63 | }) | ||
64 | |||
65 | describe('When listing users', function () { | ||
66 | it('Should fail with a bad start pagination', function (done) { | ||
67 | request(server.url) | ||
68 | .get(path) | ||
69 | .query({ start: 'hello' }) | ||
70 | .set('Accept', 'application/json') | ||
71 | .expect(400, done) | ||
72 | }) | ||
73 | |||
74 | it('Should fail with a bad count pagination', function (done) { | ||
75 | request(server.url) | ||
76 | .get(path) | ||
77 | .query({ count: 'hello' }) | ||
78 | .set('Accept', 'application/json') | ||
79 | .expect(400, done) | ||
80 | }) | ||
81 | |||
82 | it('Should fail with an incorrect sort', function (done) { | ||
83 | request(server.url) | ||
84 | .get(path) | ||
85 | .query({ sort: 'hello' }) | ||
86 | .set('Accept', 'application/json') | ||
87 | .expect(400, done) | ||
88 | }) | ||
89 | }) | ||
90 | |||
91 | describe('When adding a new user', function () { | ||
92 | it('Should fail with a too small username', function (done) { | ||
93 | const data = { | ||
94 | username: 'ji', | ||
95 | password: 'mysuperpassword' | ||
96 | } | ||
97 | |||
98 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
99 | }) | ||
100 | |||
101 | it('Should fail with a too long username', function (done) { | ||
102 | const data = { | ||
103 | username: 'mysuperusernamewhichisverylong', | ||
104 | password: 'mysuperpassword' | ||
105 | } | ||
106 | |||
107 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
108 | }) | ||
109 | |||
110 | it('Should fail with an incorrect username', function (done) { | ||
111 | const data = { | ||
112 | username: 'my username', | ||
113 | password: 'mysuperpassword' | ||
114 | } | ||
115 | |||
116 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
117 | }) | ||
118 | |||
119 | it('Should fail with a too small password', function (done) { | ||
120 | const data = { | ||
121 | username: 'myusername', | ||
122 | password: 'bla' | ||
123 | } | ||
124 | |||
125 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
126 | }) | ||
127 | |||
128 | it('Should fail with a too long password', function (done) { | ||
129 | const data = { | ||
130 | username: 'myusername', | ||
131 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
132 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
133 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
134 | } | ||
135 | |||
136 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
137 | }) | ||
138 | |||
139 | it('Should fail with an non authenticated user', function (done) { | ||
140 | const data = { | ||
141 | username: 'myusername', | ||
142 | password: 'my super password' | ||
143 | } | ||
144 | |||
145 | requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) | ||
146 | }) | ||
147 | |||
148 | it('Should fail if we add a user with the same username', function (done) { | ||
149 | const data = { | ||
150 | username: 'user1', | ||
151 | password: 'my super password' | ||
152 | } | ||
153 | |||
154 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) | ||
155 | }) | ||
156 | |||
157 | it('Should succeed with the correct params', function (done) { | ||
158 | const data = { | ||
159 | username: 'user2', | ||
160 | password: 'my super password' | ||
161 | } | ||
162 | |||
163 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) | ||
164 | }) | ||
165 | |||
166 | it('Should fail with a non admin user', function (done) { | ||
167 | server.user = { | ||
168 | username: 'user1', | ||
169 | password: 'my super password' | ||
170 | } | ||
171 | |||
172 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
173 | if (err) throw err | ||
174 | |||
175 | userAccessToken = accessToken | ||
176 | |||
177 | const data = { | ||
178 | username: 'user3', | ||
179 | password: 'my super password' | ||
180 | } | ||
181 | |||
182 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) | ||
183 | }) | ||
184 | }) | ||
185 | }) | ||
186 | |||
187 | describe('When updating a user', function () { | ||
188 | before(function (done) { | ||
189 | usersUtils.getUsersList(server.url, function (err, res) { | ||
190 | if (err) throw err | ||
191 | |||
192 | userId = res.body.data[1].id | ||
193 | rootId = res.body.data[2].id | ||
194 | done() | ||
195 | }) | ||
196 | }) | ||
197 | |||
198 | it('Should fail with a too small password', function (done) { | ||
199 | const data = { | ||
200 | password: 'bla' | ||
201 | } | ||
202 | |||
203 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
204 | }) | ||
205 | |||
206 | it('Should fail with a too long password', function (done) { | ||
207 | const data = { | ||
208 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
209 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
210 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
211 | } | ||
212 | |||
213 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
214 | }) | ||
215 | |||
216 | it('Should fail with an non authenticated user', function (done) { | ||
217 | const data = { | ||
218 | password: 'my super password' | ||
219 | } | ||
220 | |||
221 | requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) | ||
222 | }) | ||
223 | |||
224 | it('Should succeed with the correct params', function (done) { | ||
225 | const data = { | ||
226 | password: 'my super password' | ||
227 | } | ||
228 | |||
229 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) | ||
230 | }) | ||
231 | }) | ||
232 | |||
233 | describe('When getting my information', function () { | ||
234 | it('Should fail with a non authenticated user', function (done) { | ||
235 | request(server.url) | ||
236 | .get(path + 'me') | ||
237 | .set('Authorization', 'Bearer faketoken') | ||
238 | .set('Accept', 'application/json') | ||
239 | .expect(401, done) | ||
240 | }) | ||
241 | |||
242 | it('Should success with the correct parameters', function (done) { | ||
243 | request(server.url) | ||
244 | .get(path + 'me') | ||
245 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
246 | .set('Accept', 'application/json') | ||
247 | .expect(200, done) | ||
248 | }) | ||
249 | }) | ||
250 | |||
251 | describe('When removing an user', function () { | ||
252 | it('Should fail with an incorrect id', function (done) { | ||
253 | request(server.url) | ||
254 | .delete(path + 'bla-bla') | ||
255 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
256 | .expect(400, done) | ||
257 | }) | ||
258 | |||
259 | it('Should fail with the root user', function (done) { | ||
260 | request(server.url) | ||
261 | .delete(path + rootId) | ||
262 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
263 | .expect(400, done) | ||
264 | }) | ||
265 | |||
266 | it('Should return 404 with a non existing id', function (done) { | ||
267 | request(server.url) | ||
268 | .delete(path + '45') | ||
269 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
270 | .expect(404, done) | ||
271 | }) | ||
272 | }) | ||
273 | |||
274 | after(function (done) { | ||
275 | process.kill(-server.app.pid) | ||
276 | |||
277 | // Keep the logs if the test failed | ||
278 | if (this.ok) { | ||
279 | serversUtils.flushTests(done) | ||
280 | } else { | ||
281 | done() | ||
282 | } | ||
283 | }) | ||
284 | }) | ||
diff --git a/server/tests/api/check-params/video-abuses.js b/server/tests/api/check-params/video-abuses.js new file mode 100644 index 000000000..8cb4ccdc1 --- /dev/null +++ b/server/tests/api/check-params/video-abuses.js | |||
@@ -0,0 +1,180 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | const series = require('async/series') | ||
5 | |||
6 | const loginUtils = require('../../utils/login') | ||
7 | const requestsUtils = require('../../utils/requests') | ||
8 | const serversUtils = require('../../utils/servers') | ||
9 | const usersUtils = require('../../utils/users') | ||
10 | const videosUtils = require('../../utils/videos') | ||
11 | |||
12 | describe('Test video abuses API validators', function () { | ||
13 | let server = null | ||
14 | let userAccessToken = null | ||
15 | |||
16 | // --------------------------------------------------------------- | ||
17 | |||
18 | before(function (done) { | ||
19 | this.timeout(20000) | ||
20 | |||
21 | series([ | ||
22 | function (next) { | ||
23 | serversUtils.flushTests(next) | ||
24 | }, | ||
25 | function (next) { | ||
26 | serversUtils.runServer(1, function (server1) { | ||
27 | server = server1 | ||
28 | |||
29 | next() | ||
30 | }) | ||
31 | }, | ||
32 | function (next) { | ||
33 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
34 | if (err) throw err | ||
35 | server.accessToken = token | ||
36 | |||
37 | next() | ||
38 | }) | ||
39 | }, | ||
40 | function (next) { | ||
41 | const username = 'user1' | ||
42 | const password = 'my super password' | ||
43 | |||
44 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | ||
45 | }, | ||
46 | function (next) { | ||
47 | const user = { | ||
48 | username: 'user1', | ||
49 | password: 'my super password' | ||
50 | } | ||
51 | |||
52 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | ||
53 | if (err) throw err | ||
54 | |||
55 | userAccessToken = accessToken | ||
56 | |||
57 | next() | ||
58 | }) | ||
59 | }, | ||
60 | // Upload some videos on each pods | ||
61 | function (next) { | ||
62 | const name = 'my super name for pod' | ||
63 | const description = 'my super description for pod' | ||
64 | const tags = [ 'tag' ] | ||
65 | const file = 'video_short2.webm' | ||
66 | videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next) | ||
67 | }, | ||
68 | function (next) { | ||
69 | videosUtils.getVideosList(server.url, function (err, res) { | ||
70 | if (err) throw err | ||
71 | |||
72 | const videos = res.body.data | ||
73 | server.video = videos[0] | ||
74 | |||
75 | next() | ||
76 | }) | ||
77 | } | ||
78 | ], done) | ||
79 | }) | ||
80 | |||
81 | describe('When listing video abuses', function () { | ||
82 | const path = '/api/v1/videos/abuse' | ||
83 | |||
84 | it('Should fail with a bad start pagination', function (done) { | ||
85 | request(server.url) | ||
86 | .get(path) | ||
87 | .query({ start: 'hello' }) | ||
88 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
89 | .set('Accept', 'application/json') | ||
90 | .expect(400, done) | ||
91 | }) | ||
92 | |||
93 | it('Should fail with a bad count pagination', function (done) { | ||
94 | request(server.url) | ||
95 | .get(path) | ||
96 | .query({ count: 'hello' }) | ||
97 | .set('Accept', 'application/json') | ||
98 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
99 | .expect(400, done) | ||
100 | }) | ||
101 | |||
102 | it('Should fail with an incorrect sort', function (done) { | ||
103 | request(server.url) | ||
104 | .get(path) | ||
105 | .query({ sort: 'hello' }) | ||
106 | .set('Accept', 'application/json') | ||
107 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
108 | .expect(400, done) | ||
109 | }) | ||
110 | |||
111 | it('Should fail with a non authenticated user', function (done) { | ||
112 | request(server.url) | ||
113 | .get(path) | ||
114 | .query({ sort: 'hello' }) | ||
115 | .set('Accept', 'application/json') | ||
116 | .expect(401, done) | ||
117 | }) | ||
118 | |||
119 | it('Should fail with a non admin user', function (done) { | ||
120 | request(server.url) | ||
121 | .get(path) | ||
122 | .query({ sort: 'hello' }) | ||
123 | .set('Accept', 'application/json') | ||
124 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
125 | .expect(403, done) | ||
126 | }) | ||
127 | }) | ||
128 | |||
129 | describe('When reporting a video abuse', function () { | ||
130 | const basePath = '/api/v1/videos/' | ||
131 | |||
132 | it('Should fail with nothing', function (done) { | ||
133 | const path = basePath + server.video + '/abuse' | ||
134 | const data = {} | ||
135 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
136 | }) | ||
137 | |||
138 | it('Should fail with a wrong video', function (done) { | ||
139 | const wrongPath = '/api/v1/videos/blabla/abuse' | ||
140 | const data = {} | ||
141 | requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done) | ||
142 | }) | ||
143 | |||
144 | it('Should fail with a non authenticated user', function (done) { | ||
145 | const data = {} | ||
146 | const path = basePath + server.video + '/abuse' | ||
147 | requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) | ||
148 | }) | ||
149 | |||
150 | it('Should fail with a reason too short', function (done) { | ||
151 | const data = { | ||
152 | reason: 'h' | ||
153 | } | ||
154 | const path = basePath + server.video + '/abuse' | ||
155 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
156 | }) | ||
157 | |||
158 | it('Should fail with a reason too big', function (done) { | ||
159 | const data = { | ||
160 | reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + | ||
161 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + | ||
162 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + | ||
163 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' | ||
164 | } | ||
165 | const path = basePath + server.video + '/abuse' | ||
166 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
167 | }) | ||
168 | }) | ||
169 | |||
170 | after(function (done) { | ||
171 | process.kill(-server.app.pid) | ||
172 | |||
173 | // Keep the logs if the test failed | ||
174 | if (this.ok) { | ||
175 | serversUtils.flushTests(done) | ||
176 | } else { | ||
177 | done() | ||
178 | } | ||
179 | }) | ||
180 | }) | ||
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js new file mode 100644 index 000000000..fac903715 --- /dev/null +++ b/server/tests/api/check-params/videos.js | |||
@@ -0,0 +1,460 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const chai = require('chai') | ||
4 | const expect = chai.expect | ||
5 | const pathUtils = require('path') | ||
6 | const request = require('supertest') | ||
7 | const series = require('async/series') | ||
8 | |||
9 | const loginUtils = require('../../utils/login') | ||
10 | const requestsUtils = require('../../utils/requests') | ||
11 | const serversUtils = require('../../utils/servers') | ||
12 | const videosUtils = require('../../utils/videos') | ||
13 | |||
14 | describe('Test videos API validator', function () { | ||
15 | const path = '/api/v1/videos/' | ||
16 | let server = 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 | ], done) | ||
43 | }) | ||
44 | |||
45 | describe('When listing a video', function () { | ||
46 | it('Should fail with a bad start pagination', function (done) { | ||
47 | request(server.url) | ||
48 | .get(path) | ||
49 | .query({ start: 'hello' }) | ||
50 | .set('Accept', 'application/json') | ||
51 | .expect(400, done) | ||
52 | }) | ||
53 | |||
54 | it('Should fail with a bad count pagination', function (done) { | ||
55 | request(server.url) | ||
56 | .get(path) | ||
57 | .query({ count: 'hello' }) | ||
58 | .set('Accept', 'application/json') | ||
59 | .expect(400, done) | ||
60 | }) | ||
61 | |||
62 | it('Should fail with an incorrect sort', function (done) { | ||
63 | request(server.url) | ||
64 | .get(path) | ||
65 | .query({ sort: 'hello' }) | ||
66 | .set('Accept', 'application/json') | ||
67 | .expect(400, done) | ||
68 | }) | ||
69 | }) | ||
70 | |||
71 | describe('When searching a video', function () { | ||
72 | it('Should fail with nothing', function (done) { | ||
73 | request(server.url) | ||
74 | .get(pathUtils.join(path, 'search')) | ||
75 | .set('Accept', 'application/json') | ||
76 | .expect(400, done) | ||
77 | }) | ||
78 | |||
79 | it('Should fail with a bad start pagination', function (done) { | ||
80 | request(server.url) | ||
81 | .get(pathUtils.join(path, 'search', 'test')) | ||
82 | .query({ start: 'hello' }) | ||
83 | .set('Accept', 'application/json') | ||
84 | .expect(400, done) | ||
85 | }) | ||
86 | |||
87 | it('Should fail with a bad count pagination', function (done) { | ||
88 | request(server.url) | ||
89 | .get(pathUtils.join(path, 'search', 'test')) | ||
90 | .query({ count: 'hello' }) | ||
91 | .set('Accept', 'application/json') | ||
92 | .expect(400, done) | ||
93 | }) | ||
94 | |||
95 | it('Should fail with an incorrect sort', function (done) { | ||
96 | request(server.url) | ||
97 | .get(pathUtils.join(path, 'search', 'test')) | ||
98 | .query({ sort: 'hello' }) | ||
99 | .set('Accept', 'application/json') | ||
100 | .expect(400, done) | ||
101 | }) | ||
102 | }) | ||
103 | |||
104 | describe('When adding a video', function () { | ||
105 | it('Should fail with nothing', function (done) { | ||
106 | const data = {} | ||
107 | const attach = {} | ||
108 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
109 | }) | ||
110 | |||
111 | it('Should fail without name', function (done) { | ||
112 | const data = { | ||
113 | description: 'my super description', | ||
114 | tags: [ 'tag1', 'tag2' ] | ||
115 | } | ||
116 | const attach = { | ||
117 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
118 | } | ||
119 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
120 | }) | ||
121 | |||
122 | it('Should fail with a long name', function (done) { | ||
123 | const data = { | ||
124 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
125 | description: 'my super description', | ||
126 | tags: [ 'tag1', 'tag2' ] | ||
127 | } | ||
128 | const attach = { | ||
129 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
130 | } | ||
131 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
132 | }) | ||
133 | |||
134 | it('Should fail without description', function (done) { | ||
135 | const data = { | ||
136 | name: 'my super name', | ||
137 | tags: [ 'tag1', 'tag2' ] | ||
138 | } | ||
139 | const attach = { | ||
140 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
141 | } | ||
142 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
143 | }) | ||
144 | |||
145 | it('Should fail with a long description', function (done) { | ||
146 | const data = { | ||
147 | name: 'my super name', | ||
148 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
149 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
150 | 'very very very very very very very very very very very very very very very long', | ||
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 without tags', function (done) { | ||
160 | const data = { | ||
161 | name: 'my super name', | ||
162 | description: 'my super description' | ||
163 | } | ||
164 | const attach = { | ||
165 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
166 | } | ||
167 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
168 | }) | ||
169 | |||
170 | it('Should fail with too many tags', function (done) { | ||
171 | const data = { | ||
172 | name: 'my super name', | ||
173 | description: 'my super description', | ||
174 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
175 | } | ||
176 | const attach = { | ||
177 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
178 | } | ||
179 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
180 | }) | ||
181 | |||
182 | it('Should fail with not enough tags', function (done) { | ||
183 | const data = { | ||
184 | name: 'my super name', | ||
185 | description: 'my super description', | ||
186 | tags: [ ] | ||
187 | } | ||
188 | const attach = { | ||
189 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
190 | } | ||
191 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
192 | }) | ||
193 | |||
194 | it('Should fail with a tag length too low', function (done) { | ||
195 | const data = { | ||
196 | name: 'my super name', | ||
197 | description: 'my super description', | ||
198 | tags: [ 'tag1', 't' ] | ||
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 tag length too big', function (done) { | ||
207 | const data = { | ||
208 | name: 'my super name', | ||
209 | description: 'my super description', | ||
210 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
211 | } | ||
212 | const attach = { | ||
213 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
214 | } | ||
215 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
216 | }) | ||
217 | |||
218 | it('Should fail with malformed tags', function (done) { | ||
219 | const data = { | ||
220 | name: 'my super name', | ||
221 | description: 'my super description', | ||
222 | tags: [ 'my tag' ] | ||
223 | } | ||
224 | const attach = { | ||
225 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
226 | } | ||
227 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
228 | }) | ||
229 | |||
230 | it('Should fail without an input file', function (done) { | ||
231 | const data = { | ||
232 | name: 'my super name', | ||
233 | description: 'my super description', | ||
234 | tags: [ 'tag1', 'tag2' ] | ||
235 | } | ||
236 | const attach = {} | ||
237 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
238 | }) | ||
239 | |||
240 | it('Should fail without an incorrect input file', function (done) { | ||
241 | const data = { | ||
242 | name: 'my super name', | ||
243 | description: 'my super description', | ||
244 | tags: [ 'tag1', 'tag2' ] | ||
245 | } | ||
246 | const attach = { | ||
247 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | ||
248 | } | ||
249 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
250 | }) | ||
251 | |||
252 | it('Should fail with a too big duration', function (done) { | ||
253 | const data = { | ||
254 | name: 'my super name', | ||
255 | description: 'my super description', | ||
256 | tags: [ 'tag1', 'tag2' ] | ||
257 | } | ||
258 | const attach = { | ||
259 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm') | ||
260 | } | ||
261 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
262 | }) | ||
263 | |||
264 | it('Should succeed with the correct parameters', function (done) { | ||
265 | const data = { | ||
266 | name: 'my super name', | ||
267 | description: 'my super description', | ||
268 | tags: [ 'tag1', 'tag2' ] | ||
269 | } | ||
270 | const attach = { | ||
271 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
272 | } | ||
273 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | ||
274 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4') | ||
275 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | ||
276 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv') | ||
277 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) | ||
278 | }, false) | ||
279 | }, false) | ||
280 | }) | ||
281 | }) | ||
282 | |||
283 | describe('When updating a video', function () { | ||
284 | let videoId | ||
285 | |||
286 | before(function (done) { | ||
287 | videosUtils.getVideosList(server.url, function (err, res) { | ||
288 | if (err) throw err | ||
289 | |||
290 | videoId = res.body.data[0].id | ||
291 | |||
292 | return done() | ||
293 | }) | ||
294 | }) | ||
295 | |||
296 | it('Should fail with nothing', function (done) { | ||
297 | const data = {} | ||
298 | requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done) | ||
299 | }) | ||
300 | |||
301 | it('Should fail without a valid uuid', function (done) { | ||
302 | const data = { | ||
303 | description: 'my super description', | ||
304 | tags: [ 'tag1', 'tag2' ] | ||
305 | } | ||
306 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) | ||
307 | }) | ||
308 | |||
309 | it('Should fail with an unknown id', function (done) { | ||
310 | const data = { | ||
311 | description: 'my super description', | ||
312 | tags: [ 'tag1', 'tag2' ] | ||
313 | } | ||
314 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404) | ||
315 | }) | ||
316 | |||
317 | it('Should fail with a long name', function (done) { | ||
318 | const data = { | ||
319 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
320 | description: 'my super description', | ||
321 | tags: [ 'tag1', 'tag2' ] | ||
322 | } | ||
323 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
324 | }) | ||
325 | |||
326 | it('Should fail with a long description', function (done) { | ||
327 | const data = { | ||
328 | name: 'my super name', | ||
329 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
330 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
331 | 'very very very very very very very very very very very very very very very long', | ||
332 | tags: [ 'tag1', 'tag2' ] | ||
333 | } | ||
334 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
335 | }) | ||
336 | |||
337 | it('Should fail with too many tags', function (done) { | ||
338 | const data = { | ||
339 | name: 'my super name', | ||
340 | description: 'my super description', | ||
341 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
342 | } | ||
343 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
344 | }) | ||
345 | |||
346 | it('Should fail with not enough tags', function (done) { | ||
347 | const data = { | ||
348 | name: 'my super name', | ||
349 | description: 'my super description', | ||
350 | tags: [ ] | ||
351 | } | ||
352 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
353 | }) | ||
354 | |||
355 | it('Should fail with a tag length too low', function (done) { | ||
356 | const data = { | ||
357 | name: 'my super name', | ||
358 | description: 'my super description', | ||
359 | tags: [ 'tag1', 't' ] | ||
360 | } | ||
361 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
362 | }) | ||
363 | |||
364 | it('Should fail with a tag length too big', function (done) { | ||
365 | const data = { | ||
366 | name: 'my super name', | ||
367 | description: 'my super description', | ||
368 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
369 | } | ||
370 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
371 | }) | ||
372 | |||
373 | it('Should fail with malformed tags', function (done) { | ||
374 | const data = { | ||
375 | name: 'my super name', | ||
376 | description: 'my super description', | ||
377 | tags: [ 'my tag' ] | ||
378 | } | ||
379 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
380 | }) | ||
381 | |||
382 | it('Should fail with a video of another user') | ||
383 | |||
384 | it('Should fail with a video of another pod') | ||
385 | }) | ||
386 | |||
387 | describe('When getting a video', function () { | ||
388 | it('Should return the list of the videos with nothing', function (done) { | ||
389 | request(server.url) | ||
390 | .get(path) | ||
391 | .set('Accept', 'application/json') | ||
392 | .expect(200) | ||
393 | .expect('Content-Type', /json/) | ||
394 | .end(function (err, res) { | ||
395 | if (err) throw err | ||
396 | |||
397 | expect(res.body.data).to.be.an('array') | ||
398 | expect(res.body.data.length).to.equal(3) | ||
399 | |||
400 | done() | ||
401 | }) | ||
402 | }) | ||
403 | |||
404 | it('Should fail without a correct uuid', function (done) { | ||
405 | request(server.url) | ||
406 | .get(path + 'coucou') | ||
407 | .set('Accept', 'application/json') | ||
408 | .expect(400, done) | ||
409 | }) | ||
410 | |||
411 | it('Should return 404 with an incorrect video', function (done) { | ||
412 | request(server.url) | ||
413 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
414 | .set('Accept', 'application/json') | ||
415 | .expect(404, done) | ||
416 | }) | ||
417 | |||
418 | it('Should succeed with the correct parameters') | ||
419 | }) | ||
420 | |||
421 | describe('When removing a video', function () { | ||
422 | it('Should have 404 with nothing', function (done) { | ||
423 | request(server.url) | ||
424 | .delete(path) | ||
425 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
426 | .expect(400, done) | ||
427 | }) | ||
428 | |||
429 | it('Should fail without a correct uuid', function (done) { | ||
430 | request(server.url) | ||
431 | .delete(path + 'hello') | ||
432 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
433 | .expect(400, done) | ||
434 | }) | ||
435 | |||
436 | it('Should fail with a video which does not exist', function (done) { | ||
437 | request(server.url) | ||
438 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
439 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
440 | .expect(404, done) | ||
441 | }) | ||
442 | |||
443 | it('Should fail with a video of another user') | ||
444 | |||
445 | it('Should fail with a video of another pod') | ||
446 | |||
447 | it('Should succeed with the correct parameters') | ||
448 | }) | ||
449 | |||
450 | after(function (done) { | ||
451 | process.kill(-server.app.pid) | ||
452 | |||
453 | // Keep the logs if the test failed | ||
454 | if (this.ok) { | ||
455 | serversUtils.flushTests(done) | ||
456 | } else { | ||
457 | done() | ||
458 | } | ||
459 | }) | ||
460 | }) | ||