Skip to content

Commit e029db7

Browse files
authored
Add server:capabilities method (#693)
## What does this PR do ? add the following action `server:capabilities`
1 parent d4cf21e commit e029db7

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ export * from './src/controllers/Collection';
3131
export * from './src/controllers/Document';
3232
export * from './src/controllers/Index';
3333
export * from './src/controllers/Realtime';
34+
export * from './src/controllers/Server';

src/Kuzzle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class Kuzzle extends KuzzleEventEmitter {
9696
public ms: any;
9797
public realtime: RealtimeController;
9898
public security: SecurityController;
99-
public server: any;
99+
public server: ServerController;
100100

101101
private _protectedEvents: any;
102102
private _offlineQueue: any;

src/controllers/Server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ export class ServerController extends BaseController {
2727
.then(response => response.result.exists);
2828
}
2929

30+
/**
31+
* Returns the Kuzzle capabilities
32+
* @param {Object} options - {queuable: Boolean(true)}
33+
* @example https://docs.kuzzle.io/core/2/api/controllers/server/capabilities/#response
34+
* @returns {Promise<Object>}
35+
*/
36+
capabilities (options: ArgsServerControllerGetAllStats) {
37+
return this.query({
38+
action: 'capabilities'
39+
}, options)
40+
.then(response => response.result);
41+
}
3042

3143
/**
3244
* Returns all stored statistics frames

test/controllers/server.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,59 @@ describe('Server Controller', () => {
113113
});
114114
});
115115

116+
describe('#capabilities', () => {
117+
const
118+
expectQuery = {
119+
controller: 'server',
120+
action: 'capabilities'
121+
},
122+
result = {
123+
limits: {
124+
concurrentRequests: 100,
125+
documentsFetchCount: 10000,
126+
documentsWriteCount: 200,
127+
loginsPerSecond: 50,
128+
requestsBufferSize: 50000,
129+
requestsBufferWarningThreshold: 5000,
130+
subscriptionConditionsCount: 100,
131+
subscriptionRooms: 1000000,
132+
subscriptionDocumentTTL: 259200000
133+
},
134+
plugins: {},
135+
version: '<current kuzzle version>',
136+
};
137+
138+
it('should call query with the right arguments and return Promise which resolves the capabilities', async () => {
139+
kuzzle.query.resolves({ result });
140+
141+
let res = await kuzzle.server.capabilities();
142+
143+
should(kuzzle.query).be.calledOnce();
144+
should(kuzzle.query).be.calledWith(expectQuery, {});
145+
should(res).match(result);
146+
147+
kuzzle.query.resetHistory();
148+
res = await kuzzle.server.capabilities({queuable: false});
149+
150+
should(kuzzle.query).be.calledOnce();
151+
should(kuzzle.query).be.calledWith(expectQuery, {queuable: false});
152+
should(res).match(result);
153+
});
154+
155+
it('should reject the promise if an error occurs', async () => {
156+
const error = new Error('foobar error');
157+
error.status = 412;
158+
kuzzle.query.rejects(error);
159+
160+
try {
161+
await kuzzle.server.capabilities();
162+
}
163+
catch (err) {
164+
should(err).be.match({status: 412, message: 'foobar error'});
165+
}
166+
});
167+
});
168+
116169
describe('#getConfig', () => {
117170
const
118171
expectedQuery = {

0 commit comments

Comments
 (0)