@@ -15,12 +15,17 @@ describe('Kuzzle methods', function () {
15
15
should ( collection ) . be . null ( ) ;
16
16
should ( controller ) . be . exactly ( expectedQuery . controller ) ;
17
17
should ( action ) . be . exactly ( expectedQuery . action ) ;
18
- should ( Object . keys ( query ) . length ) . be . exactly ( 0 ) ;
19
18
20
19
if ( passedOptions ) {
21
20
should ( options ) . match ( passedOptions ) ;
22
21
}
23
22
23
+ if ( expectedQuery . body ) {
24
+ should ( query . body ) . match ( expectedQuery . body ) ;
25
+ } else {
26
+ should ( Object . keys ( query ) . length ) . be . exactly ( 0 ) ;
27
+ }
28
+
24
29
cb ( error , result ) ;
25
30
} ,
26
31
emitted ,
@@ -98,6 +103,85 @@ describe('Kuzzle methods', function () {
98
103
} ) ;
99
104
} ) ;
100
105
106
+ describe ( '#getStatistics' , function ( ) {
107
+ beforeEach ( function ( ) {
108
+ kuzzle = new Kuzzle ( 'foo' ) ;
109
+ kuzzle . query = queryStub ;
110
+ emitted = false ;
111
+ passedOptions = null ;
112
+ error = null ;
113
+ result = { statistics : { } } ;
114
+ expectedQuery = {
115
+ controller : 'admin' ,
116
+ action : 'getLastStats'
117
+ } ;
118
+ } ) ;
119
+
120
+ it ( 'should throw an error if no callback is provided' , function ( ) {
121
+ should ( function ( ) { kuzzle . getStatistics ( ) ; } ) . throw ( Error ) ;
122
+ should ( function ( ) { kuzzle . getStatistics ( 123456 ) ; } ) . throw ( Error ) ;
123
+ should ( function ( ) { kuzzle . getStatistics ( { } ) ; } ) . throw ( Error ) ;
124
+ should ( function ( ) { kuzzle . getStatistics ( 123456 , { } ) ; } ) . throw ( Error ) ;
125
+ } ) ;
126
+
127
+ it ( 'should return the last statistics frame if no timestamp is provided' , function ( ) {
128
+ should ( kuzzle . getStatistics ( function ( ) { } ) ) . be . exactly ( kuzzle ) ;
129
+ should ( emitted ) . be . true ( ) ;
130
+ } ) ;
131
+
132
+ it ( 'should return statistics frames starting from the given timestamp' , function ( ) {
133
+ expectedQuery = {
134
+ controller : 'admin' ,
135
+ action : 'getStats' ,
136
+ body : { startTime : 123 }
137
+ } ;
138
+
139
+ result = {
140
+ statistics : {
141
+ 123 : { } ,
142
+ 456 : { } ,
143
+ 789 : { }
144
+ }
145
+ } ;
146
+
147
+ kuzzle . getStatistics ( 123 , function ( ) { } ) ;
148
+ should ( emitted ) . be . true ( ) ;
149
+ } ) ;
150
+
151
+ it ( 'should execute the provided callback with an error argument if one occurs' , function ( done ) {
152
+ error = 'foobar' ;
153
+ kuzzle . getStatistics ( function ( err , res ) {
154
+ should ( emitted ) . be . true ( ) ;
155
+ should ( err ) . be . exactly ( 'foobar' ) ;
156
+ should ( res ) . be . undefined ( ) ;
157
+ done ( ) ;
158
+ } ) ;
159
+ } ) ;
160
+
161
+ it ( 'should handle arguments properly' , function ( ) {
162
+ /*
163
+ already tested by previous tests:
164
+ getStatistics(callback)
165
+ getStatistics(timestamp, callback)
166
+ */
167
+
168
+ // testing: getStatistics(options, callback)
169
+ passedOptions = { foo : 'bar' } ;
170
+ kuzzle . getStatistics ( passedOptions , function ( ) { } ) ;
171
+ should ( emitted ) . be . true ( ) ;
172
+
173
+ // testing: getStatistics(timestamp, options callback);
174
+ emitted = false ;
175
+ expectedQuery = {
176
+ controller : 'admin' ,
177
+ action : 'getStats' ,
178
+ body : { startTime : 123 }
179
+ } ;
180
+ kuzzle . getStatistics ( 123 , passedOptions , function ( ) { } ) ;
181
+ should ( emitted ) . be . true ( ) ;
182
+ } ) ;
183
+ } ) ;
184
+
101
185
describe ( '#dataCollectionFactory' , function ( ) {
102
186
beforeEach ( function ( ) {
103
187
kuzzle = new Kuzzle ( 'foo' ) ;
0 commit comments