blob: 6688e527a3a7ae233583010a1c9e6c38e6a02be6 [file] [log] [blame]
Matteo Scandolofb46ae62017-08-08 09:10:50 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandoloa4a47112016-12-16 10:06:13 -080019import * as angular from 'angular';
20import 'angular-mocks';
21import 'angular-resource';
22import 'angular-cookies';
23import {xosDataSources} from '../index';
Matteo Scandolo1aee1982017-02-17 08:33:23 -080024import {IXosModeldefsService} from './modeldefs.rest';
Matteo Scandoloa4a47112016-12-16 10:06:13 -080025
Matteo Scandolo1aee1982017-02-17 08:33:23 -080026let service: IXosModeldefsService;
Matteo Scandoloa4a47112016-12-16 10:06:13 -080027let httpBackend: ng.IHttpBackendService;
28let $scope;
29
Matteo Scandolo828d1e82017-01-17 14:49:38 -080030const MockAppCfg = {
31 apiEndpoint: 'http://xos-test:3000/api',
32 websocketClient: 'http://xos-test:3000'
33};
34
Matteo Scandolo1aee1982017-02-17 08:33:23 -080035describe('The XosModelDefs service', () => {
Matteo Scandoloa4a47112016-12-16 10:06:13 -080036
37 beforeEach(angular.mock.module(xosDataSources));
38
39 beforeEach(() => {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080040
41 angular.module(xosDataSources)
42 .constant('AppConfig', MockAppCfg);
43
Matteo Scandoloa4a47112016-12-16 10:06:13 -080044 angular.mock.module(xosDataSources);
45 });
46
Matteo Scandoloa4a47112016-12-16 10:06:13 -080047 beforeEach(angular.mock.inject((
Matteo Scandolo1aee1982017-02-17 08:33:23 -080048 XosModelDefs: IXosModeldefsService,
Matteo Scandoloa4a47112016-12-16 10:06:13 -080049 $httpBackend: ng.IHttpBackendService,
50 _$resource_: ng.resource.IResourceService,
51 _$rootScope_: ng.IRootScopeService
52 ) => {
Matteo Scandolo1aee1982017-02-17 08:33:23 -080053 service = XosModelDefs;
Matteo Scandoloa4a47112016-12-16 10:06:13 -080054 httpBackend = $httpBackend;
55 $scope = _$rootScope_;
56 }));
57
58 it('should have a get method', (done) => {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080059 httpBackend.expectGET(`${MockAppCfg.apiEndpoint}/utility/modeldefs/`)
Matteo Scandoloa4a47112016-12-16 10:06:13 -080060 .respond([
61 {name: 'ok'}
62 ]);
63 service.get()
64 .then((res) => {
65 expect(res[0].name).toEqual('ok');
66 done();
67 })
68 .catch(e => {
69 done(e);
70 });
71 $scope.$apply();
Matteo Scandolo710dc152017-04-11 13:54:23 -070072 // httpBackend.flush();
Matteo Scandoloa4a47112016-12-16 10:06:13 -080073 });
74});