1 | (function() {
|
2 | var chai, schemas, tv4;
|
3 |
|
4 | chai = require('chai');
|
5 |
|
6 | schemas = require('../../schema/schemas.js');
|
7 |
|
8 | tv4 = require('tv4');
|
9 |
|
10 | describe('Test graph protocol schema on event', function() {
|
11 | before(function() {
|
12 | var graphSchema, sharedSchema;
|
13 | sharedSchema = schemas.shared;
|
14 | graphSchema = schemas.graph;
|
15 | tv4.addSchema('/shared/', sharedSchema);
|
16 | return tv4.addSchema('/graph/', graphSchema);
|
17 | });
|
18 | describe('addnode', function() {
|
19 | var schema;
|
20 | schema = '/graph/input/addnode';
|
21 | it('should have input schema', function() {
|
22 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
23 | });
|
24 | it('should have output shema', function() {
|
25 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/addnode').properties);
|
26 | });
|
27 | it('should validate event with required fields', function() {
|
28 | var event, res;
|
29 | event = {
|
30 | protocol: 'graph',
|
31 | command: 'addnode',
|
32 | payload: {
|
33 | id: 'node1',
|
34 | component: 'core/Kick',
|
35 | graph: 'mygraph'
|
36 | }
|
37 | };
|
38 | res = tv4.validate(event, schema);
|
39 | return chai.expect(res).to.be["true"];
|
40 | });
|
41 | it('should invalidate additional properties', function() {
|
42 | var event, res;
|
43 | event = {
|
44 | protocol: 'graph',
|
45 | command: 'addnode',
|
46 | payload: {
|
47 | id: 'node1',
|
48 | component: 'core/Kick',
|
49 | graph: 'mygraph',
|
50 | whatisthis: 'notallowed'
|
51 | }
|
52 | };
|
53 | res = tv4.validate(event, schema);
|
54 | return chai.expect(res).to.be["false"];
|
55 | });
|
56 | return it('should invalidate event without required fields', function() {
|
57 | var event, res;
|
58 | event = {
|
59 | protocol: 'graph',
|
60 | payload: {
|
61 | id: 'node1',
|
62 | component: 'core/Kick',
|
63 | graph: 'mygraph'
|
64 | }
|
65 | };
|
66 | res = tv4.validate(event, schema);
|
67 | chai.expect(res).to.be["false"];
|
68 | return event = {
|
69 | protocol: 'graph',
|
70 | command: 'removenode',
|
71 | payload: {
|
72 | id: 'node1',
|
73 | component: 'core/Kick',
|
74 | graph: 'mygraph'
|
75 | }
|
76 | };
|
77 | });
|
78 | });
|
79 | describe('removenode', function() {
|
80 | var schema;
|
81 | schema = '/graph/input/removenode';
|
82 | it('should have input schema', function() {
|
83 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
84 | });
|
85 | it('should have output shema', function() {
|
86 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/removenode').properties);
|
87 | });
|
88 | return it('should validate event with required fields', function() {
|
89 | var event;
|
90 | event = {
|
91 | protocol: 'graph',
|
92 | command: 'removenode',
|
93 | payload: {
|
94 | id: 'node1',
|
95 | graph: 'mygraph'
|
96 | }
|
97 | };
|
98 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
99 | });
|
100 | });
|
101 | describe('renamenode', function() {
|
102 | var schema;
|
103 | schema = '/graph/input/renamenode';
|
104 | it('should have input schema', function() {
|
105 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
106 | });
|
107 | it('should have output shema', function() {
|
108 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/renamenode').properties);
|
109 | });
|
110 | return it('should validate event with required fields', function() {
|
111 | var event;
|
112 | event = {
|
113 | protocol: 'graph',
|
114 | command: 'renamenode',
|
115 | payload: {
|
116 | from: 'node1',
|
117 | to: 'node2',
|
118 | graph: 'mygraph'
|
119 | }
|
120 | };
|
121 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
122 | });
|
123 | });
|
124 | describe('changenode', function() {
|
125 | var schema;
|
126 | schema = '/graph/input/changenode';
|
127 | it('should have input schema', function() {
|
128 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
129 | });
|
130 | it('should have output shema', function() {
|
131 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/changenode').properties);
|
132 | });
|
133 | it('should validate event with required fields', function() {
|
134 | var event;
|
135 | event = {
|
136 | protocol: 'graph',
|
137 | command: 'changenode',
|
138 | payload: {
|
139 | id: 'node1',
|
140 | graph: 'mygraph',
|
141 | metadata: {
|
142 | x: 5,
|
143 | y: -1000.1
|
144 | }
|
145 | }
|
146 | };
|
147 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
148 | });
|
149 | return it('should invalidate event without required fields', function() {
|
150 | var event;
|
151 | event = {
|
152 | protocol: 'graph',
|
153 | command: 'changenode',
|
154 | payload: {
|
155 | id: 'node1',
|
156 | graph: 'mygraph'
|
157 | }
|
158 | };
|
159 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
160 | });
|
161 | });
|
162 | describe('addedge', function() {
|
163 | var schema;
|
164 | schema = '/graph/input/addedge';
|
165 | it('should have input schema', function() {
|
166 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
167 | });
|
168 | it('should have output schema', function() {
|
169 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/addedge').properties);
|
170 | });
|
171 | it('should validate event with required fields', function() {
|
172 | var event;
|
173 | event = {
|
174 | protocol: 'graph',
|
175 | command: 'addedge',
|
176 | payload: {
|
177 | graph: 'mygraph',
|
178 | src: {
|
179 | node: 'node1',
|
180 | port: 'OUT'
|
181 | },
|
182 | tgt: {
|
183 | node: 'node2',
|
184 | port: 'IN'
|
185 | }
|
186 | }
|
187 | };
|
188 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
189 | });
|
190 | return it('should invalidate event without required fields', function() {
|
191 | var event;
|
192 | event = {
|
193 | protocol: 'graph',
|
194 | command: 'addedge',
|
195 | payload: {
|
196 | graph: 'mygraph',
|
197 | src: {
|
198 | port: 'OUT'
|
199 | },
|
200 | tgt: {
|
201 | port: 'IN'
|
202 | }
|
203 | }
|
204 | };
|
205 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
206 | });
|
207 | });
|
208 | describe('removeedge', function() {
|
209 | var schema;
|
210 | schema = '/graph/input/removeedge';
|
211 | it('should have input schema', function() {
|
212 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
213 | });
|
214 | it('should have output schema', function() {
|
215 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/removeedge').properties);
|
216 | });
|
217 | return it('should validate event with required fields', function() {
|
218 | var event;
|
219 | event = {
|
220 | protocol: 'graph',
|
221 | command: 'removeedge',
|
222 | payload: {
|
223 | graph: 'mygraph',
|
224 | src: {
|
225 | node: 'node1',
|
226 | port: 'OUT'
|
227 | },
|
228 | tgt: {
|
229 | node: 'node2',
|
230 | port: 'IN'
|
231 | }
|
232 | }
|
233 | };
|
234 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
235 | });
|
236 | });
|
237 | describe('changeedge', function() {
|
238 | var schema;
|
239 | schema = '/graph/input/changeedge';
|
240 | it('should have input schema', function() {
|
241 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
242 | });
|
243 | it('should have output schema', function() {
|
244 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/changeedge').properties);
|
245 | });
|
246 | return it('should validate event with required fields', function() {
|
247 | var event;
|
248 | event = {
|
249 | protocol: 'graph',
|
250 | command: 'changeedge',
|
251 | payload: {
|
252 | graph: 'mygraph',
|
253 | src: {
|
254 | node: 'node1',
|
255 | port: 'OUT'
|
256 | },
|
257 | tgt: {
|
258 | node: 'node2',
|
259 | port: 'IN'
|
260 | },
|
261 | metadata: {
|
262 | route: 1
|
263 | }
|
264 | }
|
265 | };
|
266 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
267 | });
|
268 | });
|
269 | describe('addinitial', function() {
|
270 | var schema;
|
271 | schema = '/graph/input/addinitial';
|
272 | it('should have input schema', function() {
|
273 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
274 | });
|
275 | it('should have output shema', function() {
|
276 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/addinitial').properties);
|
277 | });
|
278 | it('should validate event with required fields', function() {
|
279 | var event;
|
280 | event = {
|
281 | protocol: 'graph',
|
282 | command: 'addinitial',
|
283 | payload: {
|
284 | graph: 'mygraph',
|
285 | src: {
|
286 | data: 5
|
287 | },
|
288 | tgt: {
|
289 | node: 'node2',
|
290 | port: 'IN'
|
291 | }
|
292 | }
|
293 | };
|
294 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
295 | });
|
296 | return it('should invalidate event without required fields', function() {
|
297 | var event;
|
298 | event = {
|
299 | protocol: 'graph',
|
300 | command: 'addinitial',
|
301 | payload: {
|
302 | graph: 'mygraph',
|
303 | src: {},
|
304 | tgt: {
|
305 | port: 'IN',
|
306 | node: 'node2'
|
307 | }
|
308 | }
|
309 | };
|
310 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
311 | });
|
312 | });
|
313 | describe('removeinitial', function() {
|
314 | var schema;
|
315 | schema = '/graph/input/removeinitial';
|
316 | it('should have input shema', function() {
|
317 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
318 | });
|
319 | it('should have output shema', function() {
|
320 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/removeinitial').properties);
|
321 | });
|
322 | it('should validate event with required fields', function() {
|
323 | var event;
|
324 | event = {
|
325 | protocol: 'graph',
|
326 | command: 'removeinitial',
|
327 | payload: {
|
328 | graph: 'mygraph',
|
329 | tgt: {
|
330 | node: 'node2',
|
331 | port: 'IN'
|
332 | }
|
333 | }
|
334 | };
|
335 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
336 | });
|
337 | return it('should invalidate event with extra fields', function() {
|
338 | var event;
|
339 | event = {
|
340 | protocol: 'graph',
|
341 | command: 'removeinitial',
|
342 | payload: {
|
343 | graph: 'mygraph',
|
344 | src: {
|
345 | data: 5
|
346 | },
|
347 | tgt: {
|
348 | node: 'node2',
|
349 | port: 'IN'
|
350 | }
|
351 | }
|
352 | };
|
353 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
354 | });
|
355 | });
|
356 | describe('addinport', function() {
|
357 | var schema;
|
358 | schema = '/graph/input/addinport';
|
359 | it('should have input shema', function() {
|
360 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
361 | });
|
362 | it('should have output schema', function() {
|
363 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/addinport').properties);
|
364 | });
|
365 | it('should validate event with required fields', function() {
|
366 | var event;
|
367 | event = {
|
368 | protocol: 'graph',
|
369 | command: 'addinport',
|
370 | payload: {
|
371 | graph: 'mygraph',
|
372 | "public": 'IN',
|
373 | node: 'core/Kick',
|
374 | port: 'DATA'
|
375 | }
|
376 | };
|
377 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
378 | });
|
379 | return it('should invalidate event with extra fields', function() {
|
380 | var event;
|
381 | event = {
|
382 | protocol: 'graph',
|
383 | command: 'addinport',
|
384 | payload: {
|
385 | graph: 'mygraph',
|
386 | "public": 'IN',
|
387 | node: 'core/Kick',
|
388 | port: 'DATA',
|
389 | extra: 'doesntwork'
|
390 | }
|
391 | };
|
392 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
393 | });
|
394 | });
|
395 | describe('removeinport', function() {
|
396 | var schema;
|
397 | schema = '/graph/input/removeinport';
|
398 | it('should have input shema', function() {
|
399 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
400 | });
|
401 | it('should have output schema', function() {
|
402 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/removeinport').properties);
|
403 | });
|
404 | it('should validate event with required fields', function() {
|
405 | var event;
|
406 | event = {
|
407 | protocol: 'graph',
|
408 | command: 'removeinport',
|
409 | payload: {
|
410 | graph: 'mygraph',
|
411 | "public": 'IN'
|
412 | }
|
413 | };
|
414 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
415 | });
|
416 | return it('should invalidate event with extra fields', function() {
|
417 | var event;
|
418 | event = {
|
419 | protocol: 'graph',
|
420 | command: 'removeinport',
|
421 | payload: {
|
422 | graph: 'mygraph',
|
423 | "public": 'IN',
|
424 | node: 'core/Kick',
|
425 | port: 'DATA'
|
426 | }
|
427 | };
|
428 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
429 | });
|
430 | });
|
431 | describe('renameinport', function() {
|
432 | var schema;
|
433 | schema = '/graph/input/renameinport';
|
434 | it('should have input shema', function() {
|
435 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
436 | });
|
437 | it('should have output schema', function() {
|
438 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/renameinport').properties);
|
439 | });
|
440 | return it('should validate event with required fields', function() {
|
441 | var event;
|
442 | event = {
|
443 | protocol: 'graph',
|
444 | command: 'renameinport',
|
445 | payload: {
|
446 | graph: 'mygraph',
|
447 | from: 'IN',
|
448 | to: 'MORE_IN'
|
449 | }
|
450 | };
|
451 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
452 | });
|
453 | });
|
454 | describe('addoutport', function() {
|
455 | var schema;
|
456 | schema = '/graph/input/addoutport';
|
457 | it('should have input shema', function() {
|
458 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
459 | });
|
460 | it('should have output schema', function() {
|
461 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/addoutport').properties);
|
462 | });
|
463 | it('should validate event with required fields', function() {
|
464 | var event;
|
465 | event = {
|
466 | protocol: 'graph',
|
467 | command: 'addoutport',
|
468 | payload: {
|
469 | graph: 'mygraph',
|
470 | "public": 'OUT',
|
471 | node: 'core/Repeat',
|
472 | port: 'OUT'
|
473 | }
|
474 | };
|
475 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
476 | });
|
477 | return it('should invalidate event with extra fields', function() {
|
478 | var event;
|
479 | event = {
|
480 | protocol: 'graph',
|
481 | command: 'addoutport',
|
482 | payload: {
|
483 | graph: 'mygraph',
|
484 | "public": 'OUT',
|
485 | node: 'core/Repeat',
|
486 | port: 'OUT',
|
487 | extra: 'doesntwork'
|
488 | }
|
489 | };
|
490 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
491 | });
|
492 | });
|
493 | describe('removeoutport', function() {
|
494 | var schema;
|
495 | schema = '/graph/input/removeoutport';
|
496 | it('should have input shema', function() {
|
497 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
498 | });
|
499 | it('should have output schema', function() {
|
500 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/removeoutport').properties);
|
501 | });
|
502 | it('should validate event with required fields', function() {
|
503 | var event;
|
504 | event = {
|
505 | protocol: 'graph',
|
506 | command: 'removeoutport',
|
507 | payload: {
|
508 | graph: 'mygraph',
|
509 | "public": 'OUT'
|
510 | }
|
511 | };
|
512 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
513 | });
|
514 | return it('should invalidate event with extra fields', function() {
|
515 | var event;
|
516 | event = {
|
517 | protocol: 'graph',
|
518 | command: 'removeoutport',
|
519 | payload: {
|
520 | graph: 'mygraph',
|
521 | "public": 'OUT',
|
522 | node: 'core/Kick',
|
523 | port: 'DATA'
|
524 | }
|
525 | };
|
526 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
527 | });
|
528 | });
|
529 | describe('renameoutport', function() {
|
530 | var schema;
|
531 | schema = '/graph/input/renameoutport';
|
532 | it('should have input shema', function() {
|
533 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
534 | });
|
535 | it('should have output schema', function() {
|
536 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/renameoutport').properties);
|
537 | });
|
538 | return it('should validate event with required fields', function() {
|
539 | var event;
|
540 | event = {
|
541 | protocol: 'graph',
|
542 | command: 'renameoutport',
|
543 | payload: {
|
544 | graph: 'mygraph',
|
545 | from: 'OUT',
|
546 | to: 'MORE_OUT'
|
547 | }
|
548 | };
|
549 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
550 | });
|
551 | });
|
552 | describe('addgroup', function() {
|
553 | var schema;
|
554 | schema = '/graph/input/addgroup';
|
555 | it('should have input schema', function() {
|
556 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
557 | });
|
558 | it('should have output shema', function() {
|
559 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/addgroup').properties);
|
560 | });
|
561 | it('should validate event with required fields', function() {
|
562 | var event;
|
563 | event = {
|
564 | protocol: 'graph',
|
565 | command: 'addgroup',
|
566 | payload: {
|
567 | graph: 'mygraph',
|
568 | name: 'mygroup',
|
569 | nodes: ['Kick', 'Drop']
|
570 | }
|
571 | };
|
572 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
573 | });
|
574 | return it('should invalidate event with extra fields', function() {
|
575 | var event;
|
576 | event = {
|
577 | protocol: 'graph',
|
578 | command: 'addgroup',
|
579 | payload: {
|
580 | graph: 'mygraph',
|
581 | name: 'mygroup',
|
582 | nodes: ['Kick', 'Drop'],
|
583 | extra: 'nope'
|
584 | }
|
585 | };
|
586 | return chai.expect(tv4.validate(event, schema)).to.be["false"];
|
587 | });
|
588 | });
|
589 | describe('removegroup', function() {
|
590 | var schema;
|
591 | schema = '/graph/input/removegroup';
|
592 | it('should have input shema', function() {
|
593 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
594 | });
|
595 | it('should have output schema', function() {
|
596 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/removegroup').properties);
|
597 | });
|
598 | return it('should validate event with required fields', function() {
|
599 | var event;
|
600 | event = {
|
601 | protocol: 'graph',
|
602 | command: 'removegroup',
|
603 | payload: {
|
604 | graph: 'mygraph',
|
605 | name: 'mygroup'
|
606 | }
|
607 | };
|
608 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
609 | });
|
610 | });
|
611 | describe('renamegroup', function() {
|
612 | var schema;
|
613 | schema = '/graph/input/renamegroup';
|
614 | it('should have input shema', function() {
|
615 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
616 | });
|
617 | it('should have output schema', function() {
|
618 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/renamegroup').properties);
|
619 | });
|
620 | return it('should validate event with required fields', function() {
|
621 | var event;
|
622 | event = {
|
623 | protocol: 'graph',
|
624 | command: 'renamegroup',
|
625 | payload: {
|
626 | graph: 'mygraph',
|
627 | from: 'mygroup',
|
628 | to: 'yourgroup'
|
629 | }
|
630 | };
|
631 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
632 | });
|
633 | });
|
634 | return describe('changegroup', function() {
|
635 | var schema;
|
636 | schema = '/graph/input/changegroup';
|
637 | it('should have input schema', function() {
|
638 | return chai.expect(tv4.getSchema(schema)).to.exist;
|
639 | });
|
640 | it('should have output shema', function() {
|
641 | return chai.expect(tv4.getSchema(schema).properties).to.eql(tv4.getSchema('/graph/output/changegroup').properties);
|
642 | });
|
643 | return it('should validate event with required fields', function() {
|
644 | var event;
|
645 | event = {
|
646 | protocol: 'graph',
|
647 | command: 'changegroup',
|
648 | payload: {
|
649 | graph: 'mygraph',
|
650 | name: 'mygroup',
|
651 | metadata: {}
|
652 | }
|
653 | };
|
654 | return chai.expect(tv4.validate(event, schema)).to.be["true"];
|
655 | });
|
656 | });
|
657 | });
|
658 |
|
659 | }).call(this);
|