UNPKG

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