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