Merge pull request #5318 from spalger/fix/5270
[courier/fetch] fix bug when fetching a single source
This commit is contained in:
commit
e42ff7e4a4
4 changed files with 80 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
||||||
var Bluebird = require('bluebird');
|
var Bluebird = require('bluebird');
|
||||||
require('ui/promises');
|
require('ui/promises');
|
||||||
|
|
||||||
|
Bluebird.longStackTraces();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* replace the Promise service with Bluebird so that tests
|
* replace the Promise service with Bluebird so that tests
|
||||||
* can use promises without having to call $rootScope.apply()
|
* can use promises without having to call $rootScope.apply()
|
||||||
|
|
73
src/ui/public/courier/fetch/__tests__/fetch.js
Normal file
73
src/ui/public/courier/fetch/__tests__/fetch.js
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import ngMock from 'ngMock';
|
||||||
|
import expect from 'expect.js';
|
||||||
|
import sinon from 'auto-release-sinon';
|
||||||
|
|
||||||
|
import FetchProvider from 'ui/courier/fetch';
|
||||||
|
import IndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||||
|
import searchResp from 'fixtures/search_response';
|
||||||
|
|
||||||
|
describe('Fetch service', function () {
|
||||||
|
require('testUtils/noDigestPromises').activateForSuite();
|
||||||
|
|
||||||
|
let es;
|
||||||
|
let fetch;
|
||||||
|
let Promise;
|
||||||
|
let DocSource;
|
||||||
|
let SearchSource;
|
||||||
|
let indexPattern;
|
||||||
|
|
||||||
|
beforeEach(ngMock.module('kibana'));
|
||||||
|
beforeEach(ngMock.inject(function ($injector, Private) {
|
||||||
|
es = $injector.get('es');
|
||||||
|
Promise = $injector.get('Promise');
|
||||||
|
fetch = Private(FetchProvider);
|
||||||
|
indexPattern = Private(IndexPatternProvider);
|
||||||
|
DocSource = Private(require('ui/courier/data_source/doc_source'));
|
||||||
|
SearchSource = Private(require('ui/courier/data_source/search_source'));
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('#doc(docSource)', function () {
|
||||||
|
it('fetches a single doc source', function () {
|
||||||
|
const doc = {
|
||||||
|
_index: 'test-index',
|
||||||
|
_type: 'test-type',
|
||||||
|
_id: 'test-id',
|
||||||
|
};
|
||||||
|
|
||||||
|
const source = new DocSource({
|
||||||
|
index: doc._index,
|
||||||
|
type: doc._type,
|
||||||
|
id: doc._id
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.stub(es, 'mget').returns(Promise.resolve({
|
||||||
|
docs: [doc]
|
||||||
|
}));
|
||||||
|
|
||||||
|
return fetch.doc(source).then(function (resp) {
|
||||||
|
expect(resp).to.be(doc);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#search(searchSource)', function () {
|
||||||
|
it('fetches a single search source', function () {
|
||||||
|
const resp = searchResp;
|
||||||
|
const mresp = {
|
||||||
|
responses: [resp]
|
||||||
|
};
|
||||||
|
|
||||||
|
const source = new SearchSource({
|
||||||
|
index: indexPattern
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.stub(es, 'msearch').returns(Promise.resolve(mresp));
|
||||||
|
|
||||||
|
return fetch
|
||||||
|
.search(source)
|
||||||
|
.then(function (courierResp) {
|
||||||
|
expect(courierResp).to.be(resp);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -33,7 +33,10 @@ define(function (require) {
|
||||||
return responses[_.findIndex(executable, req)];
|
return responses[_.findIndex(executable, req)];
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(defer.resolve, defer.reject);
|
.then(
|
||||||
|
(res) => defer.resolve(res),
|
||||||
|
(err) => defer.reject(err)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ define(function (require) {
|
||||||
var defer = Promise.defer();
|
var defer = Promise.defer();
|
||||||
|
|
||||||
fetchThese([
|
fetchThese([
|
||||||
source._createRequest(defer.resolve)
|
source._createRequest(defer)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
|
|
Loading…
Reference in a new issue