1 | (function() {
|
2 | var chai, format, schemas, tv4;
|
3 |
|
4 | chai = require('chai');
|
5 |
|
6 | schemas = require('../../schema/schemas.js');
|
7 |
|
8 | tv4 = require('tv4');
|
9 |
|
10 | format = require('../../schema/format');
|
11 |
|
12 | describe('Test network protocol schema on events', function() {
|
13 | before(function() {
|
14 | var networkSchema, sharedSchema;
|
15 | sharedSchema = schemas.shared;
|
16 | networkSchema = schemas.network;
|
17 | tv4.addSchema('/shared/', sharedSchema);
|
18 | tv4.addSchema('/network/', networkSchema);
|
19 | return format(tv4);
|
20 | });
|
21 | describe('output', function() {
|
22 | describe('stopped', function() {
|
23 | var schema;
|
24 | schema = '/network/output/stopped';
|
25 | it('should have schema', function() {
|
26 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
27 | });
|
28 | it('should validate event with required fields', function() {
|
29 | var event, res;
|
30 | event = {
|
31 | protocol: 'network',
|
32 | command: 'stopped',
|
33 | payload: {
|
34 | time: '2016-05-29 13:26:01Z-1:00',
|
35 | uptime: 1000,
|
36 | graph: 'mygraph'
|
37 | }
|
38 | };
|
39 | res = tv4.validate(event, schema);
|
40 | return chai.expect(res).to.be["true"];
|
41 | });
|
42 | it('should invalidate event with invalid date', function() {
|
43 | var event, res;
|
44 | event = {
|
45 | protocol: 'network',
|
46 | command: 'stopped',
|
47 | payload: {
|
48 | time: '5:00PM',
|
49 | uptime: 1000,
|
50 | graph: 'mygraph'
|
51 | }
|
52 | };
|
53 | res = tv4.validate(event, schema);
|
54 | return chai.expect(res).to.be["false"];
|
55 | });
|
56 | return it('should invalidate event with extra fields', function() {
|
57 | var event, res;
|
58 | event = {
|
59 | hello: true,
|
60 | protocol: 'network',
|
61 | command: 'stopped',
|
62 | payload: {
|
63 | time: '5:00PM',
|
64 | uptime: 1000,
|
65 | graph: 'mygraph'
|
66 | }
|
67 | };
|
68 | res = tv4.validate(event, schema);
|
69 | return chai.expect(res).to.be["false"];
|
70 | });
|
71 | });
|
72 | describe('started', function() {
|
73 | var schema;
|
74 | schema = '/network/output/started';
|
75 | it('should have schema', function() {
|
76 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
77 | });
|
78 | return it('should validate event with required fields', function() {
|
79 | var event, res;
|
80 | event = {
|
81 | protocol: 'network',
|
82 | command: 'started',
|
83 | payload: {
|
84 | time: '2016-05-29T13:26:01Z+1:00',
|
85 | graph: 'mygraph'
|
86 | }
|
87 | };
|
88 | res = tv4.validate(event, schema);
|
89 | return chai.expect(res).to.be["true"];
|
90 | });
|
91 | });
|
92 | describe('status', function() {
|
93 | var schema;
|
94 | schema = '/network/output/status';
|
95 | it('should have schema', function() {
|
96 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
97 | });
|
98 | return it('should validate event with required fields', function() {
|
99 | var event, res;
|
100 | event = {
|
101 | protocol: 'network',
|
102 | command: 'status',
|
103 | payload: {
|
104 | running: true,
|
105 | uptime: 1000,
|
106 | graph: 'mygraph'
|
107 | }
|
108 | };
|
109 | res = tv4.validate(event, schema);
|
110 | return chai.expect(res).to.be["true"];
|
111 | });
|
112 | });
|
113 | describe('output', function() {
|
114 | var schema;
|
115 | schema = '/network/output/output';
|
116 | it('should have schema', function() {
|
117 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
118 | });
|
119 | it('should validate event with required fields', function() {
|
120 | var event, res;
|
121 | event = {
|
122 | protocol: 'network',
|
123 | command: 'output',
|
124 | payload: {
|
125 | message: 'hello',
|
126 | type: 'message'
|
127 | }
|
128 | };
|
129 | res = tv4.validate(event, schema);
|
130 | return chai.expect(res).to.be["true"];
|
131 | });
|
132 | return it('should invalidate event with invalid type', function() {
|
133 | var event, res;
|
134 | event = {
|
135 | protocol: 'network',
|
136 | command: 'output',
|
137 | payload: {
|
138 | message: 'hello',
|
139 | type: 'hello'
|
140 | }
|
141 | };
|
142 | res = tv4.validate(event, schema);
|
143 | return chai.expect(res).to.be["false"];
|
144 | });
|
145 | });
|
146 | describe('error', function() {
|
147 | var schema;
|
148 | schema = '/network/output/error';
|
149 | it('should have schema', function() {
|
150 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
151 | });
|
152 | return it('should validate event with required fields', function() {
|
153 | var event, res;
|
154 | event = {
|
155 | protocol: 'network',
|
156 | command: 'error',
|
157 | payload: {
|
158 | message: 'oops'
|
159 | }
|
160 | };
|
161 | res = tv4.validate(event, schema);
|
162 | return chai.expect(res).to.be["true"];
|
163 | });
|
164 | });
|
165 | describe('processerror', function() {
|
166 | var schema;
|
167 | schema = '/network/output/processerror';
|
168 | it('should have schema', function() {
|
169 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
170 | });
|
171 | return it('should validate event with required fields', function() {
|
172 | var event, res;
|
173 | event = {
|
174 | protocol: 'network',
|
175 | command: 'processerror',
|
176 | payload: {
|
177 | id: 'node1',
|
178 | error: 'BigError',
|
179 | graph: 'mygraph'
|
180 | }
|
181 | };
|
182 | res = tv4.validate(event, schema);
|
183 | return chai.expect(res).to.be["true"];
|
184 | });
|
185 | });
|
186 | describe('icon', function() {
|
187 | var schema;
|
188 | schema = '/network/output/icon';
|
189 | it('should have schema', function() {
|
190 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
191 | });
|
192 | return it('should validate event with required fields', function() {
|
193 | var event, res;
|
194 | event = {
|
195 | protocol: 'network',
|
196 | command: 'icon',
|
197 | payload: {
|
198 | id: 'node1',
|
199 | icon: 'amazingicon',
|
200 | graph: 'mygraph'
|
201 | }
|
202 | };
|
203 | res = tv4.validate(event, schema);
|
204 | return chai.expect(res).to.be["true"];
|
205 | });
|
206 | });
|
207 | describe('connect', function() {
|
208 | var schema;
|
209 | schema = '/network/output/connect';
|
210 | it('should have schema', function() {
|
211 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
212 | });
|
213 | return it('should validate event with required fields', function() {
|
214 | var event, res;
|
215 | event = {
|
216 | protocol: 'network',
|
217 | command: 'connect',
|
218 | payload: {
|
219 | id: 'node1 OUT -> IN node2',
|
220 | src: {
|
221 | node: 'node1',
|
222 | port: 'out'
|
223 | },
|
224 | tgt: {
|
225 | node: 'node2',
|
226 | port: 'in'
|
227 | },
|
228 | graph: 'mygraph'
|
229 | }
|
230 | };
|
231 | res = tv4.validate(event, schema);
|
232 | return chai.expect(res).to.be["true"];
|
233 | });
|
234 | });
|
235 | describe('begingroup', function() {
|
236 | var schema;
|
237 | schema = '/network/output/begingroup';
|
238 | it('should have schema', function() {
|
239 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
240 | });
|
241 | it('should validate event with required fields', function() {
|
242 | var event, res;
|
243 | event = {
|
244 | protocol: 'network',
|
245 | command: 'begingroup',
|
246 | payload: {
|
247 | id: 'node1 OUT -> IN node2',
|
248 | src: {
|
249 | node: 'node1',
|
250 | port: 'out'
|
251 | },
|
252 | tgt: {
|
253 | node: 'node2',
|
254 | port: 'in'
|
255 | },
|
256 | group: 'group1',
|
257 | graph: 'mygraph'
|
258 | }
|
259 | };
|
260 | res = tv4.validate(event, schema);
|
261 | return chai.expect(res).to.be["true"];
|
262 | });
|
263 | it('should invalidate event without required fields', function() {
|
264 | var event, res;
|
265 | event = {
|
266 | protocol: 'network',
|
267 | command: 'begingroup',
|
268 | payload: {
|
269 | id: 'node1 OUT -> IN node2',
|
270 | src: {
|
271 | node: 'node1',
|
272 | port: 'out'
|
273 | },
|
274 | tgt: {
|
275 | node: 'node2',
|
276 | port: 'in'
|
277 | },
|
278 | graph: 'mygraph'
|
279 | }
|
280 | };
|
281 | res = tv4.validate(event, schema);
|
282 | return chai.expect(res).to.be["false"];
|
283 | });
|
284 | return it('should invalidate event with extra fields', function() {
|
285 | var event, res;
|
286 | event = {
|
287 | protocol: 'network',
|
288 | command: 'begingroup',
|
289 | payload: {
|
290 | id: 'node1 OUT -> IN node2',
|
291 | src: {
|
292 | node: 'node1',
|
293 | port: 'out'
|
294 | },
|
295 | tgt: {
|
296 | node: 'node2',
|
297 | port: 'in'
|
298 | },
|
299 | group: 'group1',
|
300 | graph: 'mygraph',
|
301 | extra: 'test'
|
302 | }
|
303 | };
|
304 | res = tv4.validate(event, schema);
|
305 | return chai.expect(res).to.be["false"];
|
306 | });
|
307 | });
|
308 | describe('data', function() {
|
309 | var schema;
|
310 | schema = '/network/output/data';
|
311 | it('should have schema', function() {
|
312 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
313 | });
|
314 | return it('should validate event with required fields', function() {
|
315 | var event, res;
|
316 | event = {
|
317 | protocol: 'network',
|
318 | command: 'data',
|
319 | payload: {
|
320 | id: 'node1 OUT -> IN node2',
|
321 | src: {
|
322 | node: 'node1',
|
323 | port: 'out'
|
324 | },
|
325 | tgt: {
|
326 | node: 'node2',
|
327 | port: 'in'
|
328 | },
|
329 | data: 5,
|
330 | graph: 'mygraph'
|
331 | }
|
332 | };
|
333 | res = tv4.validate(event, schema);
|
334 | return chai.expect(res).to.be["true"];
|
335 | });
|
336 | });
|
337 | describe('endgroup', function() {
|
338 | var schema;
|
339 | schema = '/network/output/endgroup';
|
340 | it('should have schema', function() {
|
341 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
342 | });
|
343 | return it('should validate event with required fields', function() {
|
344 | var event, res;
|
345 | event = {
|
346 | protocol: 'network',
|
347 | command: 'endgroup',
|
348 | payload: {
|
349 | id: 'node1 OUT -> IN node2',
|
350 | src: {
|
351 | node: 'node1',
|
352 | port: 'out'
|
353 | },
|
354 | tgt: {
|
355 | node: 'node2',
|
356 | port: 'in'
|
357 | },
|
358 | group: 'group1',
|
359 | graph: 'mygraph'
|
360 | }
|
361 | };
|
362 | res = tv4.validate(event, schema);
|
363 | return chai.expect(res).to.be["true"];
|
364 | });
|
365 | });
|
366 | return describe('disconnect', function() {
|
367 | var schema;
|
368 | schema = '/network/output/disconnect';
|
369 | it('should have schema', function() {
|
370 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
371 | });
|
372 | return it('should validate event with required fields', function() {
|
373 | var event, res;
|
374 | event = {
|
375 | protocol: 'network',
|
376 | command: 'disconnect',
|
377 | payload: {
|
378 | id: 'node1 OUT -> IN node2',
|
379 | src: {
|
380 | node: 'node1',
|
381 | port: 'out'
|
382 | },
|
383 | tgt: {
|
384 | node: 'node2',
|
385 | port: 'in'
|
386 | },
|
387 | graph: 'mygraph'
|
388 | }
|
389 | };
|
390 | res = tv4.validate(event, schema);
|
391 | return chai.expect(res).to.be["true"];
|
392 | });
|
393 | });
|
394 | });
|
395 | return describe('input', function() {
|
396 | describe('error', function() {
|
397 | var schema;
|
398 | schema = '/network/input/error';
|
399 | it('should have schema', function() {
|
400 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
401 | });
|
402 | return it('should validate event with required fields', function() {
|
403 | var event, res;
|
404 | event = {
|
405 | protocol: 'network',
|
406 | command: 'error',
|
407 | payload: {}
|
408 | };
|
409 | res = tv4.validate(event, schema);
|
410 | return chai.expect(res).to.be["true"];
|
411 | });
|
412 | });
|
413 | describe('start', function() {
|
414 | var schema;
|
415 | schema = '/network/input/start';
|
416 | it('should have schema', function() {
|
417 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
418 | });
|
419 | return it('should validate event with required fields', function() {
|
420 | var event, res;
|
421 | event = {
|
422 | protocol: 'network',
|
423 | command: 'start',
|
424 | payload: {
|
425 | graph: 'start'
|
426 | }
|
427 | };
|
428 | res = tv4.validate(event, schema);
|
429 | return chai.expect(res).to.be["true"];
|
430 | });
|
431 | });
|
432 | describe('getstatus', function() {
|
433 | var schema;
|
434 | schema = '/network/input/getstatus';
|
435 | it('should have schema', function() {
|
436 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
437 | });
|
438 | return it('should validate event with required fields', function() {
|
439 | var event, res;
|
440 | event = {
|
441 | protocol: 'network',
|
442 | command: 'getstatus',
|
443 | payload: {
|
444 | graph: 'mygraph'
|
445 | }
|
446 | };
|
447 | res = tv4.validate(event, schema);
|
448 | return chai.expect(res).to.be["true"];
|
449 | });
|
450 | });
|
451 | describe('getstatus', function() {
|
452 | var schema;
|
453 | schema = '/network/input/getstatus';
|
454 | it('should have schema', function() {
|
455 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
456 | });
|
457 | return it('should validate event with required fields', function() {
|
458 | var event, res;
|
459 | event = {
|
460 | protocol: 'network',
|
461 | command: 'getstatus',
|
462 | payload: {
|
463 | graph: 'mygraph'
|
464 | }
|
465 | };
|
466 | res = tv4.validate(event, schema);
|
467 | return chai.expect(res).to.be["true"];
|
468 | });
|
469 | });
|
470 | describe('stop', function() {
|
471 | var schema;
|
472 | schema = '/network/input/stop';
|
473 | it('should have schema', function() {
|
474 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
475 | });
|
476 | return it('should validate event with required fields', function() {
|
477 | var event, res;
|
478 | event = {
|
479 | protocol: 'network',
|
480 | command: 'stop',
|
481 | payload: {
|
482 | graph: 'mygraph'
|
483 | }
|
484 | };
|
485 | res = tv4.validate(event, schema);
|
486 | return chai.expect(res).to.be["true"];
|
487 | });
|
488 | });
|
489 | describe('persist', function() {
|
490 | var schema;
|
491 | schema = '/network/input/persist';
|
492 | it('should have schema', function() {
|
493 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
494 | });
|
495 | return it('should validate event with required fields', function() {
|
496 | var event, res;
|
497 | event = {
|
498 | protocol: 'network',
|
499 | command: 'persist',
|
500 | payload: {}
|
501 | };
|
502 | res = tv4.validate(event, schema);
|
503 | return chai.expect(res).to.be["true"];
|
504 | });
|
505 | });
|
506 | describe('debug', function() {
|
507 | var schema;
|
508 | schema = '/network/input/debug';
|
509 | it('should have schema', function() {
|
510 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
511 | });
|
512 | return it('should validate event with required fields', function() {
|
513 | var event, res;
|
514 | event = {
|
515 | protocol: 'network',
|
516 | command: 'debug',
|
517 | payload: {
|
518 | enable: true,
|
519 | graph: 'mygraph'
|
520 | }
|
521 | };
|
522 | res = tv4.validate(event, schema);
|
523 | return chai.expect(res).to.be["true"];
|
524 | });
|
525 | });
|
526 | return describe('edges', function() {
|
527 | var schema;
|
528 | schema = '/network/input/edges';
|
529 | it('should have schema', function() {
|
530 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
531 | });
|
532 | return it('should validate event with required fields', function() {
|
533 | var event, res;
|
534 | event = {
|
535 | protocol: 'network',
|
536 | command: 'edges',
|
537 | payload: {
|
538 | edges: [
|
539 | {
|
540 | src: {
|
541 | node: 'node1',
|
542 | port: 'OUT'
|
543 | },
|
544 | tgt: {
|
545 | node: 'node2',
|
546 | port: 'IN',
|
547 | index: 0
|
548 | }
|
549 | }
|
550 | ]
|
551 | }
|
552 | };
|
553 | res = tv4.validate(event, schema);
|
554 | return chai.expect(res).to.be["true"];
|
555 | });
|
556 | });
|
557 | });
|
558 | });
|
559 |
|
560 | }).call(this);
|