mock es client search and update

This commit is contained in:
2016-04-28 16:14:39 -07:00
parent c32d806886
commit 1954141345

View File

@@ -1,4 +1,4 @@
import { uniqueId } from 'lodash'; import { uniqueId, times, random } from 'lodash';
import elasticsearch from 'elasticsearch'; import elasticsearch from 'elasticsearch';
function Client() { function Client() {
@@ -52,8 +52,46 @@ Client.prototype.get = function (params, source) {
}; };
}; };
Client.prototype.search = function (params) { Client.prototype.search = function (params, count = 5, source = {}) {
return Promise.resolve(); const hits = times(count, () => {
return {
_index: params.index || 'index',
_type: params.type || 'type',
_id: uniqueId('documentId'),
_version: random(1, 5),
_score: null,
_source: Object.assign({
created_at: new Date().toString(),
number: random(0, count, true)
}, source)
};
});
return Promise.resolve({
took: random(0, 10),
timed_out: false,
_shards: {
total: 5,
successful: 5,
failed: 0
},
hits: {
total: count,
max_score: null,
hits: hits
}
});
};
Client.prototype.update = function (params) {
var shardCount = 2;
return Promise.resolve({
_index: params.index || 'index',
_type: params.type || 'type',
_id: params.id || uniqueId('testDoc'),
_version: params.version + 1 || 2,
_shards: { total: shardCount, successful: shardCount, failed: 0 },
created: true
});
}; };
export default { export default {