blob: 9dc4025ed010d9169cd4e05b4cf244eacbb5daeb [file] [log] [blame]
Matteo Scandoloa4a47112016-12-16 10:06:13 -08001import * as angular from 'angular';
2import 'angular-mocks';
3import 'angular-resource';
4import 'angular-cookies';
5import {xosDataSources} from '../index';
Matteo Scandoloa4a47112016-12-16 10:06:13 -08006import {IModeldefsService} from './modeldefs.rest';
7
8let service: IModeldefsService;
9let httpBackend: ng.IHttpBackendService;
10let $scope;
11
Matteo Scandolo828d1e82017-01-17 14:49:38 -080012const MockAppCfg = {
13 apiEndpoint: 'http://xos-test:3000/api',
14 websocketClient: 'http://xos-test:3000'
15};
16
Matteo Scandoloa4a47112016-12-16 10:06:13 -080017describe('The ModelDefs service', () => {
18
19 beforeEach(angular.mock.module(xosDataSources));
20
21 beforeEach(() => {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080022
23 angular.module(xosDataSources)
24 .constant('AppConfig', MockAppCfg);
25
Matteo Scandoloa4a47112016-12-16 10:06:13 -080026 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 Scandolo828d1e82017-01-17 14:49:38 -080042 httpBackend.expectGET(`${MockAppCfg.apiEndpoint}/utility/modeldefs/`)
Matteo Scandoloa4a47112016-12-16 10:06:13 -080043 .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});