-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-tests.js
215 lines (167 loc) · 4.17 KB
/
main-tests.js
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
214
215
const { throws, deepEqual } = require('assert');
const mod = require('./main.js');
describe('validateConfig', function test_validateConfig() {
it('throws if not object', function () {
throws(function () {
mod.validateConfig(null);
}, /OLSKErrorInputNotValid/);
});
it('returns false if parent not object', function () {
deepEqual(mod.validateConfig(uConfig({
parent: null,
})), false);
});
it('returns false if name not string', function () {
deepEqual(mod.validateConfig(uConfig({
name: null,
})), false);
});
it('returns true', function () {
deepEqual(mod.validateConfig(uConfig()), true);
});
context('icon', function () {
it('throws if not string', function () {
deepEqual(mod.validateConfig(uConfig({
icon: null,
})), false);
});
});
context('tiers', function () {
it('throws if not array', function () {
throws(function () {
mod.validateConfig(uConfig({
tiers: null,
}));
}, /ErrorInputNotValid/);
});
it('throws if member not valid', function () {
throws(function () {
mod.validateConfig(uConfig({
tiers: [{}],
}));
}, /ErrorInputNotValid/);
});
});
});
describe('validTier', function test_validTier() {
it('throws if not object', function () {
throws(function () {
mod.validTier(null);
}, /OLSKErrorInputNotValid/);
});
it('returns false if name not string', function () {
deepEqual(mod.validTier(uTier({
name: null,
})), false);
});
it('throws if monthly not valid', function () {
throws(function () {
mod.validTier(uTier({
monthly: {},
}));
}, /ErrorInputNotValid/);
});
it('throws if yearly not valid', function () {
throws(function () {
mod.validTier(uTier({
yearly: {},
}));
}, /ErrorInputNotValid/);
});
it('returns true', function () {
deepEqual(mod.validTier(uTier()), true);
});
context('description', function () {
it('returns false if not string', function () {
deepEqual(mod.validTier(uTier({
description: null,
})), false);
});
it('returns true', function () {
deepEqual(mod.validTier(uTier({
description: Math.random().toString(),
})), true);
});
});
});
describe('validPlan', function test_validPlan() {
it('throws if not object', function () {
throws(function () {
mod.validPlan(null);
}, /OLSKErrorInputNotValid/);
});
it('returns false if price not string', function () {
deepEqual(mod.validPlan(uPlan({
price: null,
})), false);
});
it('throws if links not array', function () {
throws(function () {
mod.validPlan(uPlan({
links: {},
}));
}, /OLSKErrorInputNotValid/);
});
it('throws if links member not valid', function () {
throws(function () {
mod.validPlan(uPlan({
links: [' '],
}));
}, /OLSKErrorInputNotValid/);
});
it('returns true', function () {
deepEqual(mod.validPlan(uPlan()), true);
});
});
describe('linkObjects', function test_linkObjects() {
it('throws if not array', function () {
throws(function () {
mod.linkObjects({});
}, /OLSKErrorInputNotValid/);
});
it('returns array if string', function () {
const url = uLink();
deepEqual(mod.linkObjects([url]), [{
name: (new URL(url)).hostname,
url,
}]);
});
});
describe('validLink', function test_validLink() {
it('throws if not object', function () {
throws(function () {
mod.validLink(null);
}, /OLSKErrorInputNotValid/);
});
it('returns false if name not string', function () {
deepEqual(mod.validLink(uLinkObject({
name: null,
})), false);
});
it('returns false if name empty', function () {
deepEqual(mod.validLink(uLinkObject({
name: ' ',
})), false);
});
it('returns false if url not string', function () {
deepEqual(mod.validLink(uLinkObject({
url: null,
})), false);
});
it('returns false if url empty', function () {
deepEqual(mod.validLink(uLinkObject({
url: ' ',
})), false);
});
it('returns true', function () {
deepEqual(mod.validLink(uLinkObject()), true);
});
context('string', function () {
it('returns false if empty', function () {
deepEqual(mod.validLink(' '), false);
});
it('returns true', function () {
deepEqual(mod.validLink(Math.random().toString()), true);
});
});
});