1
+ const Code = require ( 'code' ) ;
2
+ const Lab = require ( 'lab' ) ;
3
+
4
+ const JSONErrors = require ( '..' ) ;
5
+
6
+ const lab = exports . lab = Lab . script ( ) ;
7
+
8
+ const describe = lab . describe ;
9
+ const it = lab . it ;
10
+ const expect = Code . expect ;
11
+ const beforeEach = lab . beforeEach ;
12
+
13
+ var Client , err , errObject ;
14
+
15
+ describe ( 'JSONErrors.create' , ( ) => {
16
+ err = { id : 'CUSTOM_ERROR' , message : 'This is a custom error' } ;
17
+ errObject = { errors : [ { id : err . id , message : err . message } ] } ;
18
+
19
+ beforeEach ( ( done ) => {
20
+ Client = new JSONErrors ( ) ;
21
+ done ( ) ;
22
+ } ) ;
23
+
24
+ describe ( 'validation' , ( ) => {
25
+ it ( 'fails if no id is provided' , ( done ) => {
26
+ expect ( ( ) => {
27
+ ClientClient . create ( null , err . message ) ;
28
+ } ) . to . throw ( ) ;
29
+
30
+ done ( ) ;
31
+ } ) ;
32
+
33
+ it ( 'fails if no message is provided' , ( done ) => {
34
+ expect ( ( ) => {
35
+ ClientClient . create ( err . id , null ) ;
36
+ } ) . to . throw ( ) ;
37
+
38
+ done ( ) ;
39
+ } ) ;
40
+ } ) ;
41
+
42
+ it ( 'creates an error object' , ( done ) => {
43
+ var error = Client . create ( err . id , err . message ) ;
44
+
45
+ expect ( error ) . to . equal ( err ) ;
46
+ done ( ) ;
47
+ } ) ;
48
+
49
+ it ( 'adds meta to the error when specified' , ( done ) => {
50
+ var error = Client . create ( err . id , err . message , 'meta' ) ;
51
+
52
+ expect ( error . meta ) . to . equal ( 'meta' ) ;
53
+ done ( ) ;
54
+ } ) ;
55
+ } ) ;
0 commit comments