-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patherrors.js
112 lines (94 loc) · 4.43 KB
/
errors.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
const should = require('should');
const ValidationError = require('../lib/errors').ValidationError;
const DatabaseError = require('../lib/errors').DatabaseError;
const DuplicateRecordError = require('../lib/errors').DuplicateRecordError;
describe("Custom Error Classes", function() {
describe("ValidationError", function() {
const errorMessage = "oops, validation failed";
const errorData = { foo : "bar", baz : { bat : "bif" } };
const error1 = new ValidationError(errorData);
const error2 = new ValidationError(errorData, errorMessage);
it("Should be an instance of Error", function() {
(error1 instanceof Error).should.be.true();
(error2 instanceof Error).should.be.true();
});
it("Should be an instance of ValidationError", function() {
(error1 instanceof ValidationError).should.be.true();
(error2 instanceof ValidationError).should.be.true();
});
it("Should have the data property set", function() {
// do a deep equal
should(error1.data).eql(errorData);
should(error2.data).eql(errorData);
});
it("Should have the message property set", function() {
error1.should.have.property("message");
error2.should.have.property("message", errorMessage);
});
});
describe("DatabaseError", function() {
const errorMessage = "oops, a database error";
const errorData = { foo : "boo", baz : { bat : "blah" } };
const error1 = new DatabaseError(errorData);
const error2 = new DatabaseError(errorData, errorMessage);
const nestedError = new Error("This is the nested error with a code");
nestedError.code = "This is the code";
const error3 = new DatabaseError(nestedError, errorMessage);
it("Should be an instance of Error", function() {
(error1 instanceof Error).should.be.true();
(error2 instanceof Error).should.be.true();
(error3 instanceof Error).should.be.true();
});
it("Should be an instance of DatabaseError", function() {
(error1 instanceof DatabaseError).should.be.true();
(error2 instanceof DatabaseError).should.be.true();
(error3 instanceof DatabaseError).should.be.true();
});
it("Should have the data property set", function() {
// do a deep equal
should(error1.data).eql(errorData);
should(error2.data).eql(errorData);
should(error3.data).eql(nestedError);
});
it("Should have the message property set", function() {
error1.should.have.property("message");
error2.should.have.property("message", errorMessage);
error3.should.have.property("message", errorMessage);
});
});
describe("DuplicateRecordError", function() {
const errorMessage = "oops, a duplicate record error";
const errorData = { foo : "duplicate", baz : { bat : "record" } };
const error1 = new DuplicateRecordError(errorData);
const error2 = new DuplicateRecordError(errorData, errorMessage);
const nestedError = new Error("This is the nested error with a code");
nestedError.code = "This is the code";
const error3 = new DuplicateRecordError(nestedError, errorMessage);
it("Should be an instance of Error", function() {
(error1 instanceof Error).should.be.true();
(error2 instanceof Error).should.be.true();
(error3 instanceof Error).should.be.true();
});
it("Should be an instance of DatabaseError", function() {
(error1 instanceof DatabaseError).should.be.true();
(error2 instanceof DatabaseError).should.be.true();
(error3 instanceof DatabaseError).should.be.true();
});
it("Should be an instance of DuplicateRecordError", function() {
(error1 instanceof DuplicateRecordError).should.be.true();
(error2 instanceof DuplicateRecordError).should.be.true();
(error3 instanceof DuplicateRecordError).should.be.true();
});
it("Should have the data property set", function() {
// do a deep equal
should(error1.data).eql(errorData);
should(error2.data).eql(errorData);
should(error3.data).eql(nestedError);
});
it("Should have the message property set", function() {
error1.should.have.property("message");
error2.should.have.property("message", errorMessage);
error3.should.have.property("message", errorMessage);
});
});
});