UNPKG

4.9 kBJavaScriptView Raw
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 runtime protocol schema on event', function() {
11 before(function() {
12 var runtimeSchema, sharedSchema;
13 sharedSchema = schemas.shared;
14 runtimeSchema = schemas.runtime;
15 tv4.addSchema('/shared/', sharedSchema);
16 return tv4.addSchema('/runtime/', runtimeSchema);
17 });
18 describe('input', function() {
19 describe('error', function() {
20 var schema;
21 schema = '/runtime/input/error';
22 it('should have schema', function() {
23 return chai.expect(tv4.getSchema(schema)).to.exist;
24 });
25 return it('should validate event with required fields', function() {
26 var event, res;
27 event = {
28 protocol: 'runtime',
29 command: 'error',
30 payload: {}
31 };
32 res = tv4.validate(event, schema);
33 return chai.expect(res).to.be["true"];
34 });
35 });
36 describe('getruntime', function() {
37 var schema;
38 schema = '/runtime/input/getruntime';
39 it('should have schema', function() {
40 return chai.expect(tv4.getSchema(schema)).to.exist;
41 });
42 return it('should validate event with required fields', function() {
43 var event, res;
44 event = {
45 protocol: 'runtime',
46 command: 'getruntime',
47 payload: {}
48 };
49 res = tv4.validate(event, schema);
50 return chai.expect(res).to.be["true"];
51 });
52 });
53 return describe('packet', function() {
54 var schema;
55 schema = '/runtime/input/packet';
56 it('should have schema', function() {
57 return chai.expect(tv4.getSchema(schema)).to.exist;
58 });
59 it('should validate event with required fields', function() {
60 var event, res;
61 event = {
62 protocol: 'runtime',
63 command: 'packet',
64 payload: {
65 port: 'IN',
66 graph: 'mygraph',
67 event: 'connect'
68 }
69 };
70 res = tv4.validate(event, schema);
71 return chai.expect(res).to.be["true"];
72 });
73 return it('should invalidate event with invalid enum choice', function() {
74 var event, res;
75 event = {
76 protocol: 'runtime',
77 command: 'packet',
78 payload: {
79 port: 'IN',
80 graph: 'mygraph',
81 event: 'bad event'
82 }
83 };
84 res = tv4.validate(event, schema);
85 return chai.expect(res).to.be["false"];
86 });
87 });
88 });
89 return describe('output', function() {
90 describe('error', function() {
91 var schema;
92 schema = '/runtime/output/error';
93 it('should have schema', function() {
94 return chai.expect(tv4.getSchema(schema)).to.exist;
95 });
96 return it('should validate event with required fields', function() {
97 var event, res;
98 event = {
99 protocol: 'runtime',
100 command: 'error',
101 payload: {}
102 };
103 res = tv4.validate(event, schema);
104 return chai.expect(res).to.be["true"];
105 });
106 });
107 describe('ports', function() {
108 var schema;
109 schema = '/runtime/output/ports';
110 it('should have schema', function() {
111 return chai.expect(tv4.getSchema(schema)).to.exist;
112 });
113 return it('should validate event with required fields', function() {
114 var event, res;
115 event = {
116 protocol: 'runtime',
117 command: 'ports',
118 payload: {
119 graph: 'mygraph',
120 inPorts: [
121 {
122 id: 'IN',
123 addressable: true,
124 type: 'string'
125 }
126 ],
127 outPorts: []
128 }
129 };
130 res = tv4.validate(event, schema);
131 return chai.expect(res).to.be["true"];
132 });
133 });
134 return describe('runtime', function() {
135 var schema;
136 schema = '/runtime/output/runtime';
137 it('should have schema', function() {
138 return chai.expect(tv4.getSchema(schema)).to.exist;
139 });
140 return it('should validate event with required fields', function() {
141 var event, res;
142 event = {
143 protocol: 'runtime',
144 command: 'runtime',
145 payload: {
146 version: '0.2',
147 capabilities: ['protocol:network', 'protocol:runtime', 'network:persist'],
148 type: 'noflo'
149 }
150 };
151 res = tv4.validate(event, schema);
152 return chai.expect(res).to.be["true"];
153 });
154 });
155 });
156 });
157
158}).call(this);