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'; |
| 6 | import {AppConfig} from '../../config/app.config'; |
| 7 | import {IModeldefsService} from './modeldefs.rest'; |
| 8 | |
| 9 | let service: IModeldefsService; |
| 10 | let httpBackend: ng.IHttpBackendService; |
| 11 | let $scope; |
| 12 | |
| 13 | describe('The ModelDefs service', () => { |
| 14 | |
| 15 | beforeEach(angular.mock.module(xosDataSources)); |
| 16 | |
| 17 | beforeEach(() => { |
| 18 | angular.mock.module(xosDataSources); |
| 19 | }); |
| 20 | |
| 21 | |
| 22 | beforeEach(angular.mock.inject(( |
| 23 | ModelDefs: IModeldefsService, |
| 24 | $httpBackend: ng.IHttpBackendService, |
| 25 | _$resource_: ng.resource.IResourceService, |
| 26 | _$rootScope_: ng.IRootScopeService |
| 27 | ) => { |
| 28 | service = ModelDefs; |
| 29 | httpBackend = $httpBackend; |
| 30 | $scope = _$rootScope_; |
| 31 | })); |
| 32 | |
| 33 | it('should have a get method', (done) => { |
| 34 | httpBackend.expectGET(`${AppConfig.apiEndpoint}/utility/modeldefs/`) |
| 35 | .respond([ |
| 36 | {name: 'ok'} |
| 37 | ]); |
| 38 | service.get() |
| 39 | .then((res) => { |
| 40 | expect(res[0].name).toEqual('ok'); |
| 41 | done(); |
| 42 | }) |
| 43 | .catch(e => { |
| 44 | done(e); |
| 45 | }); |
| 46 | $scope.$apply(); |
| 47 | httpBackend.flush(); |
| 48 | }); |
| 49 | }); |