UNPKG

5.06 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 component protocol schema on event', function() {
11 before(function() {
12 var componentSchema, sharedSchema;
13 sharedSchema = schemas.shared;
14 componentSchema = schemas.component;
15 tv4.addSchema('/shared/', sharedSchema);
16 return tv4.addSchema('/component/', componentSchema);
17 });
18 describe('output', function() {
19 describe('error', function() {
20 var schema;
21 schema = '/component/output/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: 'component',
29 command: 'error',
30 payload: {}
31 };
32 res = tv4.validate(event, schema);
33 return chai.expect(res).to.be["true"];
34 });
35 });
36 describe('component', function() {
37 var schema;
38 schema = '/component/output/component';
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: 'component',
46 command: 'component',
47 payload: {
48 name: 'mycomponent',
49 subgraph: false,
50 inPorts: [],
51 outPorts: []
52 }
53 };
54 res = tv4.validate(event, schema);
55 return chai.expect(res).to.be["true"];
56 });
57 });
58 return describe('source', function() {
59 var schema;
60 schema = '/component/output/source';
61 it('should have schema', function() {
62 return chai.expect(tv4.getSchema(schema)).to.exist;
63 });
64 return it('should validate event with required fields', function() {
65 var event, res;
66 event = {
67 protocol: 'component',
68 command: 'source',
69 payload: {
70 name: 'component1',
71 language: 'coffeescript',
72 code: '-> console.log Array.prototype.slice.call arguments'
73 }
74 };
75 res = tv4.validate(event, schema);
76 return chai.expect(res).to.be["true"];
77 });
78 });
79 });
80 return describe('input', function() {
81 describe('error', function() {
82 var schema;
83 schema = '/component/input/error';
84 it('should have schema', function() {
85 return chai.expect(tv4.getSchema(schema)).to.exist;
86 });
87 return it('should validate event with required fields', function() {
88 var event, res;
89 event = {
90 protocol: 'component',
91 command: 'error',
92 payload: {}
93 };
94 res = tv4.validate(event, schema);
95 return chai.expect(res).to.be["true"];
96 });
97 });
98 describe('list', function() {
99 var schema;
100 schema = '/component/input/list';
101 it('should have schema', function() {
102 return chai.expect(tv4.getSchema(schema)).to.exist;
103 });
104 return it('should validate event with required fields', function() {
105 var event, res;
106 event = {
107 protocol: 'component',
108 command: 'list',
109 payload: {}
110 };
111 res = tv4.validate(event, schema);
112 return chai.expect(res).to.be["true"];
113 });
114 });
115 describe('getsource', function() {
116 var schema;
117 schema = '/component/input/getsource';
118 it('should have schema', function() {
119 return chai.expect(tv4.getSchema(schema)).to.exist;
120 });
121 return it('should validate event with required fields', function() {
122 var event, res;
123 event = {
124 protocol: 'component',
125 command: 'getsource',
126 payload: {
127 name: 'component1'
128 }
129 };
130 res = tv4.validate(event, schema);
131 return chai.expect(res).to.be["true"];
132 });
133 });
134 return describe('source', function() {
135 var schema;
136 schema = '/component/input/source';
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: 'component',
144 command: 'source',
145 payload: {
146 name: 'component1',
147 language: 'coffeescript',
148 code: '-> console.log Array.prototype.slice.call arguments'
149 }
150 };
151 res = tv4.validate(event, schema);
152 return chai.expect(res).to.be["true"];
153 });
154 });
155 });
156 });
157
158}).call(this);