-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-integration-collection2.coffee
213 lines (185 loc) · 3.96 KB
/
test-integration-collection2.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
a = new Mongo.Collection 'TestA2'
c = new Mongo.Collection 'TestC2'
class D extends soop.InLine
@schema:
d:
type: Number
class C extends soop.Base
@collection: c
@schema:
c:
type: String
c2:
type: [Number]
optional: true
c3:
type: [D]
optional: true
c4:
type: [[D]]
optional: true
class B extends soop.InLine
@schema:
b:
type: String
b2:
type: C
optional: true
class A extends soop.Base
@collection: a
@schema:
a:
type: String
a2:
type: B
optional: true
a3:
type: Number
optional: true
min: 8
max: 18
soop.attachSchema(A)
describe 'basic suite integration with aldeed:collection2', ->
beforeEach (test)->
a.remove({})
c.remove({})
afterEach (test) ->
a.remove({})
c.remove({})
it 'test basic save that fails', (test) ->
elem = new A
try
elem.save()
test.equal 0,1
catch error
if error.sanitizedError
test.equal 1, 1
else
console.log error
test.equal 0, 1
it 'test basic save ok', (test) ->
elem = new A
a: 'hello world'
elem.save()
test.equal 1,1
it 'test fails at B level', (test) ->
elem = new A
a: 'hello world'
a2: new B
try
elem.save()
test.equal 0,1
catch error
if error.sanitizedError
test.equal 1, 1
else
console.log error
test.equal 0, 1
it 'test fails at last level', (test) ->
elem = new A
a: 'hello world'
a2: new B
b: 'insert coin'
b2: new C
try
elem.save()
test.equal 0,1
catch error
if error.sanitizedError
test.equal 1, 1
else
console.log error
test.equal 0, 1
it 'test basic C ok', (test)->
elem = new C
c: 'credits'
try
elem.save()
test.equal 0,0
elem2 = C.findOne(elem._id)
test.equal elem, elem2
catch error
console.log error
test.equal 1, 0
it 'test C ok', (test)->
elem = new C
c: 'credits'
c2: [1,2,3]
try
elem.save()
test.equal 0,0
elem2 = C.findOne(elem._id)
test.equal elem, elem2
catch error
console.log error
test.equal 1, 0
it 'test A->B->C', (test) ->
elem = new A
a: 'hello world'
a2: new B
b: 'insert coin'
b2: new C
c: 'game over!'
c2: [5,6,7]
try
elem.save()
test.equal 0,0
elem2 = A.findOne(elem._id)
test.equal elem, elem2
catch error
test.equal 1, 0
it 'test validate', (test) ->
elem = new A
a: 'hello world'
a2: new B
b: 'insert coin'
b2: new C
c: 'game over!'
c2: [5,6,7]
test.isTrue elem.isValid()
it 'test validate [D]', (test) ->
elem = new A
a: 'hello world'
a2: new B
b: 'insert coin'
b2: new C
c: 'game over!'
c2: [5,6,7]
c3: [new D(d:1), 2]
test.isFalse elem.isValid()
x = (x for x in soop.validate(elem) when x.valid is false)[0]
test.equal x.path, '.a2.b2.c3.1.d'
test.equal x.message, 'D is required'
it 'test validate [[D]]', (test) ->
elem = new A
a: 'hello world'
a2: new B
b: 'insert coin'
b2: new C
c: 'game over!'
c2: [5,6,7]
c3: [new D(d:1)]
c4: [[1]]
test.isFalse elem.isValid()
x = (x for x in soop.validate(elem) when x.valid is false)[0]
test.equal x.path, '.a2.b2.c4.0.0.d'
test.equal x.message, 'D is required'
it 'test min-max ok', (test) ->
elem = new A
a: 'hello world'
a3: 10
elem.save()
test.equal 1,1
it 'test fails min', (test) ->
elem = new A
a: 'hello world'
a3: 0
try
elem.save()
test.equal 0,1
catch error
if error.sanitizedError
test.equal 1, 1
else
console.log error
test.equal 0, 1