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 | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 6 | import {IXosModeldefsService} from './modeldefs.rest'; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 7 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 8 | let service: IXosModeldefsService; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 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 | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 17 | describe('The XosModelDefs service', () => { |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 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 | |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 29 | beforeEach(angular.mock.inject(( |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 30 | XosModelDefs: IXosModeldefsService, |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 31 | $httpBackend: ng.IHttpBackendService, |
| 32 | _$resource_: ng.resource.IResourceService, |
| 33 | _$rootScope_: ng.IRootScopeService |
| 34 | ) => { |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 35 | service = XosModelDefs; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 36 | httpBackend = $httpBackend; |
| 37 | $scope = _$rootScope_; |
| 38 | })); |
| 39 | |
| 40 | it('should have a get method', (done) => { |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 41 | httpBackend.expectGET(`${MockAppCfg.apiEndpoint}/utility/modeldefs/`) |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 42 | .respond([ |
| 43 | {name: 'ok'} |
| 44 | ]); |
| 45 | service.get() |
| 46 | .then((res) => { |
| 47 | expect(res[0].name).toEqual('ok'); |
| 48 | done(); |
| 49 | }) |
| 50 | .catch(e => { |
| 51 | done(e); |
| 52 | }); |
| 53 | $scope.$apply(); |
Matteo Scandolo | 710dc15 | 2017-04-11 13:54:23 -0700 | [diff] [blame] | 54 | // httpBackend.flush(); |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 55 | }); |
| 56 | }); |