This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
/
result.js
330 lines (244 loc) · 12.2 KB
/
result.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/* jshint maxstatements: false, maxlen: false */
/* global beforeEach, describe, it */
'use strict';
var assert = require('proclaim');
var sinon = require('sinon');
describe('result', function () {
var createResult;
beforeEach(function () {
createResult = require('../../lib/result');
});
it('should be a function', function () {
assert.isFunction(createResult);
});
describe('.call()', function () {
var result;
beforeEach(function () {
result = createResult();
});
it('should return an object', function () {
assert.isObject(result);
});
describe('[returned object]', function () {
it('should have an errors property (array)', function () {
assert.isArray(result.errors);
});
it('should have a warnings property (array)', function () {
assert.isArray(result.warnings);
});
it('should have a notices property (array)', function () {
assert.isArray(result.notices);
});
it('should have a failPoints property (object)', function () {
assert.isObject(result.failPoints);
assert.strictEqual(result.failPoints.culture, 0);
assert.strictEqual(result.failPoints.realism, 0);
assert.strictEqual(result.failPoints.recruiter, 0);
assert.strictEqual(result.failPoints.tech, 0);
});
it('should have a setCurrentRule method', function () {
assert.isFunction(result.setCurrentRule);
});
it('should have a clearCurrentRule method', function () {
assert.isFunction(result.clearCurrentRule);
});
it('should have an addError method', function () {
assert.isFunction(result.addError);
});
it('should have an addWarning method', function () {
assert.isFunction(result.addWarning);
});
it('should have an addNotice method', function () {
assert.isFunction(result.addNotice);
});
it('should have an addCultureFailPoints method', function () {
assert.isFunction(result.addCultureFailPoints);
});
it('should have an addRealismFailPoints method', function () {
assert.isFunction(result.addRealismFailPoints);
});
it('should have an addRecruiterFailPoints method', function () {
assert.isFunction(result.addRecruiterFailPoints);
});
it('should have an addTechFailPoints method', function () {
assert.isFunction(result.addTechFailPoints);
});
it('should have a hasMessages method', function () {
assert.isFunction(result.hasMessages);
});
it('should have a hasFailPoints method', function () {
assert.isFunction(result.hasFailPoints);
});
it('should have an isClean method', function () {
assert.isFunction(result.isClean);
});
describe('.setCurrentRule()', function () {
var rule;
beforeEach(function () {
rule = {};
result.setCurrentRule(rule);
});
it('should set the currentRule property', function () {
assert.strictEqual(result.currentRule, rule);
});
});
describe('.clearCurrentRule()', function () {
beforeEach(function () {
result.setCurrentRule({});
result.clearCurrentRule();
});
it('should delete the currentRule property', function () {
assert.isUndefined(result.currentRule);
});
});
describe('.addError()', function () {
beforeEach(function () {
result.setCurrentRule({desc: 'hello'});
result.addError('foo');
result.addError('bar');
result.addError('baz', [1, 2, 3]);
result.clearCurrentRule();
});
it('should add the passed in messages to the errors property', function () {
assert.lengthEquals(result.errors, 3);
assert.deepEqual(result.errors[0], {message: 'foo', detail: 'hello', evidence: []});
assert.deepEqual(result.errors[1], {message: 'bar', detail: 'hello', evidence: []});
});
it('should store evidence if given', function () {
assert.deepEqual(result.errors[2], {message: 'baz', detail: 'hello', evidence: [1, 2, 3]});
});
});
describe('.addWarning()', function () {
beforeEach(function () {
result.setCurrentRule({desc: 'hello'});
result.addWarning('foo');
result.addWarning('bar');
result.addWarning('baz', [1, 2, 3]);
result.clearCurrentRule();
});
it('should add the passed in messages to the warnings property', function () {
assert.lengthEquals(result.warnings, 3);
assert.deepEqual(result.warnings[0], {message: 'foo', detail: 'hello', evidence: []});
assert.deepEqual(result.warnings[1], {message: 'bar', detail: 'hello', evidence: []});
});
it('should store evidence if given', function () {
assert.deepEqual(result.warnings[2], {message: 'baz', detail: 'hello', evidence: [1, 2, 3]});
});
});
describe('.addNotice()', function () {
beforeEach(function () {
result.setCurrentRule({desc: 'hello'});
result.addNotice('foo');
result.addNotice('bar');
result.addNotice('baz', [1, 2, 3]);
result.clearCurrentRule();
});
it('should add the passed in messages to the notices property', function () {
assert.lengthEquals(result.notices, 3);
assert.deepEqual(result.notices[0], {message: 'foo', detail: 'hello', evidence: []});
assert.deepEqual(result.notices[1], {message: 'bar', detail: 'hello', evidence: []});
});
it('should store evidence if given', function () {
assert.deepEqual(result.notices[2], {message: 'baz', detail: 'hello', evidence: [1, 2, 3]});
});
});
describe('.addCultureFailPoints()', function () {
it('should increment the failPoints.culture property by the specified amount', function () {
result.addCultureFailPoints(2);
result.addCultureFailPoints(2.5);
assert.strictEqual(result.failPoints.culture, 5);
});
it('should increment the failPoints.culture property by one when called with no arguments', function () {
result.addCultureFailPoints();
assert.strictEqual(result.failPoints.culture, 1);
});
});
describe('.addRealismFailPoints()', function () {
it('should increment the failPoints.realism property by the specified amount', function () {
result.addRealismFailPoints(2);
result.addRealismFailPoints(2.5);
assert.strictEqual(result.failPoints.realism, 5);
});
it('should increment the failPoints.realism property by one when called with no arguments', function () {
result.addRealismFailPoints();
assert.strictEqual(result.failPoints.realism, 1);
});
});
describe('.addRecruiterFailPoints()', function () {
it('should increment the failPoints.recruiter property by the specified amount', function () {
result.addRecruiterFailPoints(2);
result.addRecruiterFailPoints(2.5);
assert.strictEqual(result.failPoints.recruiter, 5);
});
it('should increment the failPoints.recruiter property by one when called with no arguments', function () {
result.addRecruiterFailPoints();
assert.strictEqual(result.failPoints.recruiter, 1);
});
});
describe('.addTechFailPoints()', function () {
it('should increment the failPoints.tech property by the specified amount', function () {
result.addTechFailPoints(2);
result.addTechFailPoints(2.5);
assert.strictEqual(result.failPoints.tech, 5);
});
it('should increment the failPoints.tech property by one when called with no arguments', function () {
result.addTechFailPoints();
assert.strictEqual(result.failPoints.tech, 1);
});
});
describe('.hasMessages()', function () {
it('should return true if any errors, warnings or notices are present', function () {
result.errors = ['foo'];
result.warnings = [];
result.notices = [];
assert.isTrue(result.hasMessages());
result.errors = [];
result.warnings = ['foo'];
result.notices = [];
assert.isTrue(result.hasMessages());
result.errors = [];
result.warnings = [];
result.notices = ['foo'];
assert.isTrue(result.hasMessages());
result.errors = ['foo'];
result.warnings = ['bar'];
result.notices = ['baz'];
assert.isTrue(result.hasMessages());
});
it('should return false if there are no errors, warnings or notices present', function () {
assert.isFalse(result.hasMessages());
});
});
describe('.hasFailPoints()', function () {
it('should return true if any fail points are present', function () {
result.failPoints = {culture: 1, realism: 0, recruiter: 0, tech: 0};
assert.isTrue(result.hasFailPoints());
result.failPoints = {culture: 0, realism: 1, recruiter: 0, tech: 0};
assert.isTrue(result.hasFailPoints());
result.failPoints = {culture: 0, realism: 0, recruiter: 1, tech: 0};
assert.isTrue(result.hasFailPoints());
result.failPoints = {culture: 0, realism: 0, recruiter: 0, tech: 1};
assert.isTrue(result.hasFailPoints());
});
it('should return false if there are no fail points present', function () {
assert.isFalse(result.hasFailPoints());
});
});
describe('.isClean()', function () {
it('should return true if there are no errors or fail points present', function () {
assert.isTrue(result.isClean());
});
it('should return false if there are no fail points present', function () {
result.hasMessages = sinon.stub();
result.hasFailPoints = sinon.stub();
result.hasMessages.returns(true);
result.hasFailPoints.returns(false);
assert.isFalse(result.isClean());
result.hasMessages.returns(false);
result.hasFailPoints.returns(true);
assert.isFalse(result.isClean());
});
});
});
});
});