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