UNPKG

3.51 kBtext/coffeescriptView Raw
1chai = require 'chai'
2schemas = require '../../schema/schemas.js'
3tv4 = require 'tv4'
4
5describe 'Test component protocol schema on event', ->
6 before ->
7 sharedSchema = schemas.shared
8 componentSchema = schemas.component
9 tv4.addSchema '/shared/', sharedSchema
10 tv4.addSchema '/component/', componentSchema
11
12 describe 'output', ->
13 describe 'error', ->
14 schema = '/component/output/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: 'component'
22 command: 'error'
23 payload: {}
24
25 res = tv4.validate event, schema
26 chai.expect(res).to.be.true
27
28 describe 'component', ->
29 schema = '/component/output/component'
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: 'component'
37 command: 'component'
38 payload:
39 name: 'mycomponent'
40 subgraph: false
41 inPorts: []
42 outPorts: []
43
44 res = tv4.validate event, schema
45 chai.expect(res).to.be.true
46
47 describe 'source', ->
48 schema = '/component/output/source'
49
50 it 'should have schema', ->
51 chai.expect(tv4.getSchema schema).to.exist
52
53 it 'should validate event with required fields', ->
54 event =
55 protocol: 'component'
56 command: 'source'
57 payload:
58 name: 'component1'
59 language: 'coffeescript'
60 code: '-> console.log Array.prototype.slice.call arguments'
61
62 res = tv4.validate event, schema
63 chai.expect(res).to.be.true
64
65 describe 'input', ->
66 describe 'error', ->
67 schema = '/component/input/error'
68
69 it 'should have schema', ->
70 chai.expect(tv4.getSchema schema).to.exist
71
72 it 'should validate event with required fields', ->
73 event =
74 protocol: 'component'
75 command: 'error'
76 payload: {}
77
78 res = tv4.validate event, schema
79 chai.expect(res).to.be.true
80
81 describe 'list', ->
82 schema = '/component/input/list'
83
84 it 'should have schema', ->
85 chai.expect(tv4.getSchema schema).to.exist
86
87 it 'should validate event with required fields', ->
88 event =
89 protocol: 'component'
90 command: 'list'
91 payload: {}
92
93 res = tv4.validate event, schema
94 chai.expect(res).to.be.true
95
96 describe 'getsource', ->
97 schema = '/component/input/getsource'
98
99 it 'should have schema', ->
100 chai.expect(tv4.getSchema schema).to.exist
101
102 it 'should validate event with required fields', ->
103 event =
104 protocol: 'component'
105 command: 'getsource'
106 payload:
107 name: 'component1'
108
109 res = tv4.validate event, schema
110 chai.expect(res).to.be.true
111
112 describe 'source', ->
113 schema = '/component/input/source'
114
115 it 'should have schema', ->
116 chai.expect(tv4.getSchema schema).to.exist
117
118 it 'should validate event with required fields', ->
119 event =
120 protocol: 'component'
121 command: 'source'
122 payload:
123 name: 'component1'
124 language: 'coffeescript'
125 code: '-> console.log Array.prototype.slice.call arguments'
126
127 res = tv4.validate event, schema
128 chai.expect(res).to.be.true
129