diff options
Diffstat (limited to 'test/api/checkParams.js')
-rw-r--r-- | test/api/checkParams.js | 301 |
1 files changed, 0 insertions, 301 deletions
diff --git a/test/api/checkParams.js b/test/api/checkParams.js deleted file mode 100644 index 11fc68ff9..000000000 --- a/test/api/checkParams.js +++ /dev/null | |||
@@ -1,301 +0,0 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var async = require('async') | ||
5 | var chai = require('chai') | ||
6 | var expect = chai.expect | ||
7 | var request = require('supertest') | ||
8 | |||
9 | var utils = require('./utils') | ||
10 | |||
11 | describe('Test parameters validator', function () { | ||
12 | var app = null | ||
13 | var url = '' | ||
14 | |||
15 | function makePostRequest (path, fields, attach, done, fail) { | ||
16 | var status_code = 400 | ||
17 | if (fail !== undefined && fail === false) status_code = 200 | ||
18 | |||
19 | var req = request(url) | ||
20 | .post(path) | ||
21 | .set('Accept', 'application/json') | ||
22 | |||
23 | Object.keys(fields).forEach(function (field) { | ||
24 | var value = fields[field] | ||
25 | req.field(field, value) | ||
26 | }) | ||
27 | |||
28 | req.expect(status_code, done) | ||
29 | } | ||
30 | |||
31 | function makePostBodyRequest (path, fields, done, fail) { | ||
32 | var status_code = 400 | ||
33 | if (fail !== undefined && fail === false) status_code = 200 | ||
34 | |||
35 | request(url) | ||
36 | .post(path) | ||
37 | .set('Accept', 'application/json') | ||
38 | .send(fields) | ||
39 | .expect(status_code, done) | ||
40 | } | ||
41 | |||
42 | // --------------------------------------------------------------- | ||
43 | |||
44 | before(function (done) { | ||
45 | this.timeout(20000) | ||
46 | |||
47 | async.series([ | ||
48 | function (next) { | ||
49 | utils.flushTests(next) | ||
50 | }, | ||
51 | function (next) { | ||
52 | utils.runServer(1, function (app1, url1) { | ||
53 | app = app1 | ||
54 | url = url1 | ||
55 | next() | ||
56 | }) | ||
57 | } | ||
58 | ], done) | ||
59 | }) | ||
60 | |||
61 | describe('Of the pods API', function () { | ||
62 | var path = '/api/v1/pods/' | ||
63 | |||
64 | describe('When adding a pod', function () { | ||
65 | it('Should fail with nothing', function (done) { | ||
66 | var data = {} | ||
67 | makePostBodyRequest(path, data, done) | ||
68 | }) | ||
69 | |||
70 | it('Should fail without public key', function (done) { | ||
71 | var data = { | ||
72 | data: { | ||
73 | url: 'http://coucou.com' | ||
74 | } | ||
75 | } | ||
76 | makePostBodyRequest(path, data, done) | ||
77 | }) | ||
78 | |||
79 | it('Should fail without an url', function (done) { | ||
80 | var data = { | ||
81 | data: { | ||
82 | publicKey: 'mysuperpublickey' | ||
83 | } | ||
84 | } | ||
85 | makePostBodyRequest(path, data, done) | ||
86 | }) | ||
87 | |||
88 | it('Should fail with an incorrect url', function (done) { | ||
89 | var data = { | ||
90 | data: { | ||
91 | url: 'coucou.com', | ||
92 | publicKey: 'mysuperpublickey' | ||
93 | } | ||
94 | } | ||
95 | makePostBodyRequest(path, data, function () { | ||
96 | data.data.url = 'http://coucou' | ||
97 | makePostBodyRequest(path, data, function () { | ||
98 | data.data.url = 'coucou' | ||
99 | makePostBodyRequest(path, data, done) | ||
100 | }) | ||
101 | }) | ||
102 | }) | ||
103 | |||
104 | it('Should succeed with the correct parameters', function (done) { | ||
105 | var data = { | ||
106 | data: { | ||
107 | url: 'http://coucou.com', | ||
108 | publicKey: 'mysuperpublickey' | ||
109 | } | ||
110 | } | ||
111 | makePostBodyRequest(path, data, done, false) | ||
112 | }) | ||
113 | }) | ||
114 | }) | ||
115 | |||
116 | describe('Of the videos API', function () { | ||
117 | var path = '/api/v1/videos/' | ||
118 | |||
119 | describe('When searching a video', function () { | ||
120 | it('Should fail with nothing', function (done) { | ||
121 | request(url) | ||
122 | .get(path + '/search/') | ||
123 | .set('Accept', 'application/json') | ||
124 | .expect(400, done) | ||
125 | }) | ||
126 | }) | ||
127 | |||
128 | describe('When adding a video', function () { | ||
129 | it('Should fail with nothing', function (done) { | ||
130 | var data = {} | ||
131 | var attach = {} | ||
132 | makePostRequest(path, data, attach, done) | ||
133 | }) | ||
134 | |||
135 | it('Should fail without name', function (done) { | ||
136 | var data = { | ||
137 | description: 'my super description' | ||
138 | } | ||
139 | var attach = { | ||
140 | 'input_video': __dirname + '/fixtures/video_short.webm' | ||
141 | } | ||
142 | makePostRequest(path, data, attach, done) | ||
143 | }) | ||
144 | |||
145 | it('Should fail with a long name', function (done) { | ||
146 | var data = { | ||
147 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
148 | description: 'my super description' | ||
149 | } | ||
150 | var attach = { | ||
151 | 'input_video': __dirname + '/fixtures/video_short.webm' | ||
152 | } | ||
153 | makePostRequest(path, data, attach, done) | ||
154 | }) | ||
155 | |||
156 | it('Should fail without description', function (done) { | ||
157 | var data = { | ||
158 | name: 'my super name' | ||
159 | } | ||
160 | var attach = { | ||
161 | 'input_video': __dirname + '/fixtures/video_short.webm' | ||
162 | } | ||
163 | makePostRequest(path, data, attach, done) | ||
164 | }) | ||
165 | |||
166 | it('Should fail with a long description', function (done) { | ||
167 | var data = { | ||
168 | name: 'my super name', | ||
169 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
170 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
171 | 'very very very very very very very very very very very very very very very long' | ||
172 | } | ||
173 | var attach = { | ||
174 | 'input_video': __dirname + '/fixtures/video_short.webm' | ||
175 | } | ||
176 | makePostRequest(path, data, attach, done) | ||
177 | }) | ||
178 | |||
179 | it('Should fail without an input file', function (done) { | ||
180 | var data = { | ||
181 | name: 'my super name', | ||
182 | description: 'my super description' | ||
183 | } | ||
184 | var attach = {} | ||
185 | makePostRequest(path, data, attach, done) | ||
186 | }) | ||
187 | |||
188 | it('Should fail without an incorrect input file', function (done) { | ||
189 | var data = { | ||
190 | name: 'my super name', | ||
191 | description: 'my super description' | ||
192 | } | ||
193 | var attach = { | ||
194 | 'input_video': __dirname + '/../fixtures/video_short_fake.webm' | ||
195 | } | ||
196 | makePostRequest(path, data, attach, done) | ||
197 | }) | ||
198 | |||
199 | it('Should succeed with the correct parameters', function (done) { | ||
200 | var data = { | ||
201 | name: 'my super name', | ||
202 | description: 'my super description' | ||
203 | } | ||
204 | var attach = { | ||
205 | 'input_video': __dirname + '/fixtures/video_short.webm' | ||
206 | } | ||
207 | makePostRequest(path, data, attach, function () { | ||
208 | attach.input_video = __dirname + '/fixtures/video_short.mp4' | ||
209 | makePostRequest(path, data, attach, function () { | ||
210 | attach.input_video = __dirname + '/fixtures/video_short.ogv' | ||
211 | makePostRequest(path, data, attach, done, true) | ||
212 | }, true) | ||
213 | }, true) | ||
214 | }) | ||
215 | }) | ||
216 | |||
217 | describe('When getting a video', function () { | ||
218 | it('Should return the list of the videos with nothing', function (done) { | ||
219 | request(url) | ||
220 | .get(path) | ||
221 | .set('Accept', 'application/json') | ||
222 | .expect(200) | ||
223 | .expect('Content-Type', /json/) | ||
224 | .end(function (err, res) { | ||
225 | if (err) throw err | ||
226 | |||
227 | expect(res.body).to.be.an('array') | ||
228 | expect(res.body.length).to.equal(0) | ||
229 | |||
230 | done() | ||
231 | }) | ||
232 | }) | ||
233 | |||
234 | it('Should fail without a mongodb id', function (done) { | ||
235 | request(url) | ||
236 | .get(path + 'coucou') | ||
237 | .set('Accept', 'application/json') | ||
238 | .expect(400, done) | ||
239 | }) | ||
240 | |||
241 | it('Should return 404 with an incorrect video', function (done) { | ||
242 | request(url) | ||
243 | .get(path + '123456789012345678901234') | ||
244 | .set('Accept', 'application/json') | ||
245 | .expect(404, done) | ||
246 | }) | ||
247 | |||
248 | it('Should succeed with the correct parameters') | ||
249 | }) | ||
250 | |||
251 | describe('When removing a video', function () { | ||
252 | it('Should have 404 with nothing', function (done) { | ||
253 | request(url) | ||
254 | .delete(path) | ||
255 | .expect(404, done) | ||
256 | }) | ||
257 | |||
258 | it('Should fail without a mongodb id', function (done) { | ||
259 | request(url) | ||
260 | .delete(path + 'hello') | ||
261 | .expect(400, done) | ||
262 | }) | ||
263 | |||
264 | it('Should fail with a video which does not exist', function (done) { | ||
265 | request(url) | ||
266 | .delete(path + '123456789012345678901234') | ||
267 | .expect(404, done) | ||
268 | }) | ||
269 | |||
270 | it('Should fail with a video of another pod') | ||
271 | |||
272 | it('Should succeed with the correct parameters') | ||
273 | }) | ||
274 | }) | ||
275 | |||
276 | describe('Of the remote videos API', function () { | ||
277 | describe('When making a secure request', function () { | ||
278 | it('Should check a secure request') | ||
279 | }) | ||
280 | |||
281 | describe('When adding a video', function () { | ||
282 | it('Should check when adding a video') | ||
283 | }) | ||
284 | |||
285 | describe('When removing a video', function () { | ||
286 | it('Should check when removing a video') | ||
287 | }) | ||
288 | }) | ||
289 | |||
290 | after(function (done) { | ||
291 | process.kill(-app.pid) | ||
292 | |||
293 | // Keep the logs if the test failed | ||
294 | if (this.ok) { | ||
295 | utils.flushTests(done) | ||
296 | } else { | ||
297 | done() | ||
298 | } | ||
299 | }) | ||
300 | }) | ||
301 | })() | ||