-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set test environment. Write tests. Fix bugs.
An example of server test Rename reports scope var. Now controllers do not reload to get new data as result of timefilter change. Add test file for alarms controller. Fix description in the controllers. Add first test for Watcher factory. Add tests for watcher factory. Better handle errors in watcher factory. Refactor watcher factory to work with tests. Fix bug in Watcher.nestedSource(). Properties with false as value were not nested. Add tests for nestedSource and flatSource methods. Add more tests for factores which use Sentinl API. Add tests for saved objects api. Catch errors in asynch tests. Execute asynch tests in synch modei, one by one. Create mock for saved objects API. Fix saved objects api for Watcher. Use sinon to stub backend. Delete unused code. Use scopes in tests. Catch promise exception. Add saved objects api tests for Script factory. Fix doc type name for user. Fix searching savedObjectsAPI using query string. Fix dashboard spy button watcher creation. Parse catched error objects. Add firs tests for watchersController. Delete obsolete code. Uses standard jasmine done to catch rejections in promisses; Do not stringify entire error message object. Dosplay only message property. Dsiplay notify message when user is saved. Display original exception error. Remove console log. Do not timeout notifications after index/delete of docs. Indexes are refreshed after this operations to make new data available instantly. Fix doc id in reports and alarms controllers. Delete unneded error message. Add a test for watchers controller. Add tests for editor controller. Add test for watcher edit.
- Loading branch information
1 parent
a1cf2dd
commit f3046b1
Showing
32 changed files
with
1,291 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ var include = [ | |
'index.js', | ||
'init.js', | ||
'server', | ||
'lib', | ||
'public', | ||
'phantomjs' | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('../../server/__tests__/index'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
describe('Sentinl', function () { | ||
require('../controllers/__tests__/watchersController'); | ||
require('../controllers/__tests__/reportsController'); | ||
require('../controllers/__tests__/alarmsController'); | ||
require('../services/__tests__/watcher'); | ||
require('../services/__tests__/alarm'); | ||
require('../services/__tests__/user'); | ||
require('../services/__tests__/script'); | ||
require('../services/__tests__/report'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import moment from 'moment'; | ||
import sinon from 'auto-release-sinon'; | ||
import Promise from 'bluebird'; | ||
import ngMock from 'ng_mock'; | ||
import expect from 'expect.js'; | ||
|
||
import '../alarmsController'; | ||
|
||
describe('Alarms Controller', function () { | ||
|
||
var $scope; | ||
var $httpBackend; | ||
var $route; | ||
|
||
function init({hits = []}) { | ||
ngMock.module('kibana'); | ||
|
||
ngMock.inject(function ($rootScope, $controller, _$route_, $injector, _$httpBackend_) { | ||
$httpBackend = _$httpBackend_; | ||
$httpBackend.whenGET(/\.\.\/api\/sentinl\/set\/interval\/.+/).respond(200, { | ||
status: '200 OK' | ||
}); | ||
$httpBackend.whenGET('../api/sentinl/list/alarms').respond(200, { | ||
hits: { | ||
hits: hits | ||
} | ||
}); | ||
|
||
$route = _$route_; | ||
$route.current = { | ||
locals: { | ||
currentTime: moment('2016-08-08T11:56:42.108Z') | ||
} | ||
}; | ||
$scope = $rootScope; | ||
$controller('AlarmsController', { | ||
$scope, | ||
$route, | ||
$uibModal: {} | ||
}); | ||
$scope.$digest(); | ||
$httpBackend.flush(); | ||
}); | ||
} | ||
|
||
|
||
afterEach(function () { | ||
$httpBackend.verifyNoOutstandingExpectation(); | ||
$httpBackend.verifyNoOutstandingRequest(); | ||
}); | ||
|
||
it('Title and description', function () { | ||
init({}); | ||
expect($scope.title).to.equal('Sentinl: Alarms'); | ||
expect($scope.description).to.be('Kibi/Kibana Report App for Elasticsearch'); | ||
}); | ||
|
||
it('2 http requests should be made when controller is created', function () { | ||
init({hits: [{id: 1}, {id: 2}]}); | ||
expect($scope.alarms.length).to.equal(2); | ||
expect($scope.alarms).to.eql([{id: 1}, {id: 2}]); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import moment from 'moment'; | ||
import sinon from 'auto-release-sinon'; | ||
import Promise from 'bluebird'; | ||
import ngMock from 'ng_mock'; | ||
import expect from 'expect.js'; | ||
import _ from 'lodash'; | ||
|
||
import defaultEmailSource from '../../defaults/email_watcher'; | ||
|
||
import '../editorController'; | ||
|
||
describe('editorController', function () { | ||
let $httpBackend; | ||
let $scope; | ||
let $route; | ||
let $location; | ||
let $routeParams; | ||
let Watcher; | ||
let Script; | ||
let dataTransfer; | ||
let Notifier; | ||
let watcher; | ||
|
||
|
||
describe('new watcher', function () { | ||
|
||
const initNew = function (done) { | ||
ngMock.module('kibana'); | ||
|
||
ngMock.inject(function ($rootScope, $controller, _$location_, _$httpBackend_, _$route_, | ||
_Watcher_, _dataTransfer_, _Notifier_, _$routeParams_, _Script_) { | ||
$scope = $rootScope; | ||
$route = _$route_; | ||
$location = _$location_; | ||
$httpBackend = _$httpBackend_; | ||
$routeParams = _$routeParams_; | ||
Watcher = _Watcher_; | ||
Script = _Script_; | ||
dataTransfer = _dataTransfer_; | ||
Notifier = _Notifier_; | ||
|
||
$route.current = { | ||
locals: { | ||
currentTime: moment('2016-08-08T11:56:42.108Z') | ||
} | ||
}; | ||
|
||
watcher = { | ||
_id: '123', | ||
_type: 'sentinl-watcher', | ||
_source: _.cloneDeep(defaultEmailSource) | ||
}; | ||
|
||
dataTransfer.setWatcher(watcher); | ||
|
||
$routeParams.watcherId = undefined; | ||
$location.$$path = '/editor'; | ||
|
||
$httpBackend.when('GET', '../api/sentinl/config').respond(200, { | ||
es: { | ||
numer_of_results: 50 | ||
}, | ||
authentication: { | ||
enabled: false, | ||
mode: '' | ||
} | ||
}); | ||
|
||
sinon.stub(Script, 'list', () => { | ||
return Promise.resolve([ | ||
{ _id: '123' }, | ||
{ _id: '456' } | ||
]); | ||
}); | ||
|
||
$controller('EditorController', { | ||
$scope, | ||
$route, | ||
$uibModal: {} | ||
}); | ||
|
||
$httpBackend.flush(); | ||
}); | ||
}; | ||
|
||
beforeEach(function () { | ||
initNew(); | ||
}); | ||
|
||
afterEach(function () { | ||
$httpBackend.verifyNoOutstandingExpectation(); | ||
$httpBackend.verifyNoOutstandingRequest(); | ||
Notifier.prototype._notifs.length = 0; | ||
}); | ||
|
||
it('set watcher defaults', function () { | ||
expect($scope.watcher._id).to.equal(watcher._id); | ||
expect(_.isEqual(_.keys($scope.watcher._source).sort(), _.keys(watcher._source).sort())).to.be(true); | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('edit watcher', function () { | ||
|
||
const initEdit = function (done) { | ||
ngMock.module('kibana'); | ||
|
||
ngMock.inject(function ($rootScope, $controller, _$location_, _$httpBackend_, _$route_, | ||
_Watcher_, _dataTransfer_, _Notifier_, _$routeParams_, _Script_) { | ||
$scope = $rootScope; | ||
$route = _$route_; | ||
$location = _$location_; | ||
$httpBackend = _$httpBackend_; | ||
$routeParams = _$routeParams_; | ||
Watcher = _Watcher_; | ||
Script = _Script_; | ||
dataTransfer = _dataTransfer_; | ||
Notifier = _Notifier_; | ||
|
||
$route.current = { | ||
locals: { | ||
currentTime: moment('2016-08-08T11:56:42.108Z') | ||
} | ||
}; | ||
|
||
watcher = { | ||
_id: '123', | ||
_type: 'sentinl-watcher', | ||
_source: _.cloneDeep(defaultEmailSource) | ||
}; | ||
|
||
$routeParams.watcherId = watcher._id; | ||
$location.$$path = '/editor'; | ||
|
||
$httpBackend.when('GET', '../api/sentinl/config').respond(200, { | ||
es: { | ||
numer_of_results: 50 | ||
}, | ||
authentication: { | ||
enabled: false, | ||
mode: '' | ||
} | ||
}); | ||
|
||
sinon.stub(Watcher, 'get', () => { | ||
return Promise.resolve(watcher); | ||
}); | ||
|
||
sinon.stub(Script, 'list', () => { | ||
return Promise.resolve([ | ||
{ _id: '123' }, | ||
{ _id: '456' } | ||
]); | ||
}); | ||
|
||
$controller('EditorController', { | ||
$scope, | ||
$route, | ||
$uibModal: {} | ||
}); | ||
|
||
}); | ||
}; | ||
|
||
beforeEach(function () { | ||
initEdit(); | ||
}); | ||
|
||
afterEach(function () { | ||
$httpBackend.verifyNoOutstandingExpectation(); | ||
$httpBackend.verifyNoOutstandingRequest(); | ||
Notifier.prototype._notifs.length = 0; | ||
}); | ||
|
||
it('get watcher data', function (done) { | ||
setTimeout(function () { | ||
$httpBackend.flush(); | ||
expect($scope.watcher._id).to.equal(watcher._id); | ||
expect(_.isEqual(_.keys($scope.watcher._source).sort(), _.keys(watcher._source).sort())).to.be(true); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.