UNPKG

3.44 kBtext/coffeescriptView Raw
1chai = require 'chai'
2schemas = require '../../schema/schemas.js'
3tv4 = require 'tv4'
4
5describe 'Test runtime protocol schema on event', ->
6 before ->
7 sharedSchema = schemas.shared
8 runtimeSchema = schemas.runtime
9 tv4.addSchema '/shared/', sharedSchema
10 tv4.addSchema '/runtime/', runtimeSchema
11
12 describe 'input', ->
13 describe 'error', ->
14 schema = '/runtime/input/error'
15
16 it 'should have schema', ->
17 chai.expect(tv4.getSchema schema).to.exist
18
19 it 'should validate event with required fields', ->
20 event =
21 protocol: 'runtime'
22 command: 'error'
23 payload: {}
24
25 res = tv4.validate event, schema
26 chai.expect(res).to.be.true
27
28 describe 'getruntime', ->
29 schema = '/runtime/input/getruntime'
30
31 it 'should have schema', ->
32 chai.expect(tv4.getSchema schema).to.exist
33
34 it 'should validate event with required fields', ->
35 event =
36 protocol: 'runtime'
37 command: 'getruntime'
38 payload: {}
39
40 res = tv4.validate event, schema
41 chai.expect(res).to.be.true
42
43 describe 'packet', ->
44 schema = '/runtime/input/packet'
45
46 it 'should have schema', ->
47 chai.expect(tv4.getSchema schema).to.exist
48
49 it 'should validate event with required fields', ->
50 event =
51 protocol: 'runtime'
52 command: 'packet'
53 payload:
54 port: 'IN'
55 graph: 'mygraph'
56 event: 'connect'
57
58 res = tv4.validate event, schema
59 chai.expect(res).to.be.true
60
61 it 'should invalidate event with invalid enum choice', ->
62 event =
63 protocol: 'runtime'
64 command: 'packet'
65 payload:
66 port: 'IN'
67 graph: 'mygraph'
68 event: 'bad event'
69
70 res = tv4.validate event, schema
71 chai.expect(res).to.be.false
72
73 describe 'output', ->
74 describe 'error', ->
75 schema = '/runtime/output/error'
76
77 it 'should have schema', ->
78 chai.expect(tv4.getSchema schema).to.exist
79
80 it 'should validate event with required fields', ->
81 event =
82 protocol: 'runtime'
83 command: 'error'
84 payload: {}
85
86 res = tv4.validate event, schema
87 chai.expect(res).to.be.true
88
89 describe 'ports', ->
90 schema = '/runtime/output/ports'
91
92 it 'should have schema', ->
93 chai.expect(tv4.getSchema schema).to.exist
94
95 it 'should validate event with required fields', ->
96 event =
97 protocol: 'runtime'
98 command: 'ports'
99 payload:
100 graph: 'mygraph'
101 inPorts: [
102 id: 'IN'
103 addressable: true
104 type: 'string'
105 ]
106 outPorts: []
107
108 res = tv4.validate event, schema
109 chai.expect(res).to.be.true
110
111 describe 'runtime', ->
112 schema = '/runtime/output/runtime'
113
114 it 'should have schema', ->
115 chai.expect(tv4.getSchema schema).to.exist
116
117 it 'should validate event with required fields', ->
118 event =
119 protocol: 'runtime'
120 command: 'runtime'
121 payload:
122 version: '0.2'
123 capabilities: [
124 'protocol:network'
125 'protocol:runtime'
126 'network:persist'
127 ]
128 type: 'noflo'
129
130 res = tv4.validate event, schema
131 chai.expect(res).to.be.true
132