blob: 677463b4c13b27a90274095363636161fc64dc51 [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 Scandolo1aee1982017-02-17 08:33:23 -08006import {IXosModeldefsService} from './modeldefs.rest';
Matteo Scandoloa4a47112016-12-16 10:06:13 -08007
Matteo Scandolo1aee1982017-02-17 08:33:23 -08008let service: IXosModeldefsService;
Matteo Scandoloa4a47112016-12-16 10:06:13 -08009let 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 Scandolo1aee1982017-02-17 08:33:23 -080017describe('The XosModelDefs service', () => {
Matteo Scandoloa4a47112016-12-16 10:06:13 -080018
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
Matteo Scandoloa4a47112016-12-16 10:06:13 -080029 beforeEach(angular.mock.inject((
Matteo Scandolo1aee1982017-02-17 08:33:23 -080030 XosModelDefs: IXosModeldefsService,
Matteo Scandoloa4a47112016-12-16 10:06:13 -080031 $httpBackend: ng.IHttpBackendService,
32 _$resource_: ng.resource.IResourceService,
33 _$rootScope_: ng.IRootScopeService
34 ) => {
Matteo Scandolo1aee1982017-02-17 08:33:23 -080035 service = XosModelDefs;
Matteo Scandoloa4a47112016-12-16 10:06:13 -080036 httpBackend = $httpBackend;
37 $scope = _$rootScope_;
38 }));
39
40 it('should have a get method', (done) => {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080041 httpBackend.expectGET(`${MockAppCfg.apiEndpoint}/utility/modeldefs/`)
Matteo Scandoloa4a47112016-12-16 10:06:13 -080042 .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();
54 httpBackend.flush();
55 });
56});