openstack-health/test/unit/services/config_spec.js
Glauco Oliveira 41dd7818f7 Add unit tests around ConfigService
As part of building a reliable UI, we need to include tests around our
components.

Change-Id: Ibaef121b8727363e3ee16e4188f6cef9c6930f1f
2015-10-21 18:44:43 +00:00

50 lines
1.3 KiB
JavaScript

describe('ConfigService', function() {
beforeEach(function() {
module('app');
module('app.services');
});
var config, $httpBackend;
beforeEach(inject(function(_$httpBackend_, _config_) {
$httpBackend = _$httpBackend_;
config = _config_;
}));
it('should get app configuration and pass it to your method', function() {
var apiRoot = 'http://8.8.4.4:8080';
var expectedResponse = [{ apiRoot: apiRoot }];
$httpBackend.expectGET('config.json').respond(200, expectedResponse);
var onSuccess = function(configResponse) {
expect(configResponse[0].apiRoot).toEqual(apiRoot);
};
var onFailure = function() {
throw new Error('should not execute this!');
};
config.get().then(onSuccess, onFailure);
$httpBackend.flush();
});
it('should execute your fallback in case of an error', function() {
var expectedResponse = [{}, {}, {}];
$httpBackend.expectGET('config.json').respond(500, expectedResponse);
var onSuccess = function(configResponse) {
throw new Error('should not execute this!');
};
var onFailure = function(reason) {
expect(reason.status).toEqual(500);
expect(reason.data).toEqual(expectedResponse);
};
config.get().then(onSuccess, onFailure);
$httpBackend.flush();
});
});