@@ -27,87 +27,103 @@ function jobsPopulate(type, count) {
27
27
28
28
29
29
describe ( 'JSON API' , function ( ) {
30
+ var jobs = null ;
30
31
31
32
32
- describe ( 'Create jobs' , function ( ) {
33
- var jobs = null ;
33
+ before ( function ( done ) {
34
+ jobs = kue . createQueue ( ) ;
35
+ done ( ) ;
36
+ } ) ;
34
37
35
- beforeEach ( function ( done ) {
36
- jobs = kue . createQueue ( ) ;
37
- jobs . promote ( 1 ) ;
38
- done ( ) ;
39
- } ) ;
40
38
39
+ after ( function ( done ) {
40
+ jobs . shutdown ( function ( err ) {
41
+ jobs = null ;
42
+ done ( err ) ;
43
+ } , 500 ) ;
44
+ } ) ;
41
45
42
- afterEach ( function ( done ) {
43
- jobs . shutdown ( function ( err ) {
44
- jobs = null ;
45
- done ( err ) ;
46
- } , 500 ) ;
47
- } ) ;
48
46
47
+ it ( 'should insert a job and respond with an id' , function ( done ) {
48
+ request ( app )
49
+ . post ( '/job' )
50
+ . send ( jobsPopulate ( 'insert a job' , 1 ) )
51
+ . expect ( 200 )
52
+ . expect ( function ( res ) {
53
+ res . body . message . should . equal ( 'job created' ) ;
54
+ res . body . id . should . be . a . Number ;
55
+ Object . keys ( res . body ) . should . have . lengthOf ( 2 ) ;
56
+ } )
57
+ . end ( done ) ;
58
+ } ) ;
49
59
50
- it ( 'should insert a job and respond with an id' , function ( done ) {
51
- request ( app )
52
- . post ( '/job' )
53
- . send ( jobsPopulate ( 'insert a job' , 1 ) )
54
- . expect ( 200 )
55
- . expect ( function ( res ) {
56
- res . body . message . should . equal ( 'job created' ) ;
57
- res . body . id . should . be . a . Number ;
58
- Object . keys ( res . body ) . should . have . lengthOf ( 2 ) ;
59
- } )
60
- . end ( done ) ;
61
- } ) ;
60
+
61
+ it ( 'should insert multiple jobs and respond with ids' , function ( done ) {
62
+ var jobCount = Math . floor ( Math . random ( ) ) * 10 + 2 ;
63
+
64
+ request ( app )
65
+ . post ( '/job' )
66
+ . send ( jobsPopulate ( 'insert jobs' , jobCount ) )
67
+ . expect ( 200 )
68
+ . expect ( function ( res ) {
69
+ var created = res . body ;
70
+ created . should . be . ok ;
71
+ created . length . should . equal ( jobCount ) ;
72
+
73
+ for ( var i = 0 ; i < jobCount ; i ++ ) {
74
+ var job = created [ i ] ;
75
+ job . message . should . be . equal ( 'job created' ) ;
76
+ job . id . should . be . a . Number ;
77
+ Object . keys ( job ) . should . have . lengthOf ( 2 ) ;
78
+ }
79
+ } )
80
+ . end ( done ) ;
81
+ } ) ;
62
82
63
83
64
- it ( 'should insert multiple jobs and respond with ids' , function ( done ) {
65
- var jobCount = Math . floor ( Math . random ( ) ) * 10 + 2 ;
66
-
67
- request ( app )
68
- . post ( '/job' )
69
- . send ( jobsPopulate ( 'insert jobs' , jobCount ) )
70
- . expect ( 200 )
71
- . expect ( function ( res ) {
72
- var created = res . body ;
73
- created . should . be . ok ;
74
- created . length . should . equal ( jobCount ) ;
75
-
76
- for ( var i = 0 ; i < jobCount ; i ++ ) {
77
- var job = created [ i ] ;
78
- job . message . should . be . equal ( 'job created' )
79
- job . id . should . be . a . Number
80
- Object . keys ( job ) . should . have . lengthOf ( 2 ) ;
81
- }
82
- } )
83
- . end ( done ) ;
84
- } ) ;
84
+ it ( 'should insert jobs including an invalid job, respond with ids and error' , function ( done ) {
85
+ var jobs = jobsPopulate ( 'insert jobs including error' , 3 ) ;
86
+ delete jobs [ 1 ] . type ;
85
87
88
+ request ( app )
89
+ . post ( '/job' )
90
+ . send ( jobs )
91
+ . expect ( 400 ) // Expect a bad request
92
+ . expect ( function ( res ) {
93
+ var created = res . body ;
86
94
87
- it ( 'should insert jobs including an invaild job, respond with ids and error' , function ( done ) {
88
- var jobs = jobsPopulate ( 'insert jobs including error' , 3 ) ;
89
- delete jobs [ 1 ] . type ;
95
+ created . should . be . ok ;
96
+ created . length . should . equal ( 2 ) ; // the second one failed
90
97
91
- request ( app )
92
- . post ( '/job' )
93
- . send ( jobs )
94
- . expect ( 400 ) // Expect a bad request
95
- . expect ( function ( res ) {
96
- var created = res . body ;
98
+ // The first one succeeded
99
+ created [ 0 ] . message . should . be . equal ( 'job created' ) ;
100
+ created [ 0 ] . id . should . be . a . Number ;
101
+ Object . keys ( created [ 0 ] ) . should . have . lengthOf ( 2 ) ;
97
102
98
- created . should . be . ok ;
99
- created . length . should . equal ( 2 ) ; // the second one failed
103
+ // The second one failed
104
+ created [ 1 ] . error . should . equal ( 'Must provide job type' ) ;
105
+ Object . keys ( created [ 1 ] ) . should . have . lengthOf ( 1 ) ;
106
+ } )
107
+ . end ( done ) ;
108
+ } ) ;
100
109
101
- // The first one succeeded
102
- created [ 0 ] . message . should . be . equal ( 'job created' ) ;
103
- created [ 0 ] . id . should . be . a . Number ;
104
- Object . keys ( created [ 0 ] ) . should . have . lengthOf ( 2 ) ;
105
110
106
- // The second one failed
107
- created [ 1 ] . error . should . equal ( 'Must provide job type' ) ;
108
- Object . keys ( created [ 1 ] ) . should . have . lengthOf ( 1 ) ;
109
- } )
110
- . end ( done ) ;
111
- } ) ;
111
+ it ( 'get stats' , function ( done ) {
112
+ request ( app )
113
+ . get ( '/stats' )
114
+ . expect ( function ( res ) {
115
+ ( res . body . inactiveCount ) . should . exist ;
116
+ ( res . body . completeCount ) . should . exist ;
117
+ ( res . body . activeCount ) . should . exist ;
118
+ ( res . body . delayedCount ) . should . exist ;
119
+ ( res . body . workTime ) . should . exist ;
120
+ } )
121
+ . end ( done ) ;
122
+ } ) ;
123
+
124
+
125
+ it ( 'get job by id' , function ( done ) {
126
+ console . log ( jobs )
127
+ done ( )
112
128
} ) ;
113
129
} ) ;
0 commit comments