Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 1 | import * as angular from 'angular'; |
| 2 | import 'angular-mocks'; |
| 3 | import 'angular-resource'; |
| 4 | import 'angular-cookies'; |
| 5 | import {xosDataSources} from '../index'; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 6 | import {IModeldefsService} from './modeldefs.rest'; |
| 7 | |
| 8 | let service: IModeldefsService; |
| 9 | let httpBackend: ng.IHttpBackendService; |
| 10 | let $scope; |
| 11 | |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 12 | const MockAppCfg = { |
| 13 | apiEndpoint: 'http://xos-test:3000/api', |
| 14 | websocketClient: 'http://xos-test:3000' |
| 15 | }; |
| 16 | |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 17 | describe('The ModelDefs service', () => { |
| 18 | |
| 19 | beforeEach(angular.mock.module(xosDataSources)); |
| 20 | |
| 21 | beforeEach(() => { |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 22 | |
| 23 | angular.module(xosDataSources) |
| 24 | .constant('AppConfig', MockAppCfg); |
| 25 | |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 26 | angular.mock.module(xosDataSources); |
| 27 | }); |
| 28 | |
| 29 | |
| 30 | beforeEach(angular.mock.inject(( |
| 31 | ModelDefs: IModeldefsService, |
| 32 | $httpBackend: ng.IHttpBackendService, |
| 33 | _$resource_: ng.resource.IResourceService, |
| 34 | _$rootScope_: ng.IRootScopeService |
| 35 | ) => { |
| 36 | service = ModelDefs; |
| 37 | httpBackend = $httpBackend; |
| 38 | $scope = _$rootScope_; |
| 39 | })); |
| 40 | |
| 41 | it('should have a get method', (done) => { |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 42 | httpBackend.expectGET(`${MockAppCfg.apiEndpoint}/utility/modeldefs/`) |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 43 | .respond([ |
| 44 | {name: 'ok'} |
| 45 | ]); |
| 46 | service.get() |
| 47 | .then((res) => { |
| 48 | expect(res[0].name).toEqual('ok'); |
| 49 | done(); |
| 50 | }) |
| 51 | .catch(e => { |
| 52 | done(e); |
| 53 | }); |
| 54 | $scope.$apply(); |
| 55 | httpBackend.flush(); |
| 56 | }); |
| 57 | }); |