Matteo Scandolo | fb46ae6 | 2017-08-08 09:10:50 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 19 | import * as angular from 'angular'; |
| 20 | import 'angular-mocks'; |
| 21 | import 'angular-resource'; |
| 22 | import 'angular-cookies'; |
| 23 | import {xosDataSources} from '../index'; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 24 | import {IXosModeldefsService} from './modeldefs.rest'; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 25 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 26 | let service: IXosModeldefsService; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 27 | let httpBackend: ng.IHttpBackendService; |
| 28 | let $scope; |
| 29 | |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 30 | const MockAppCfg = { |
| 31 | apiEndpoint: 'http://xos-test:3000/api', |
| 32 | websocketClient: 'http://xos-test:3000' |
| 33 | }; |
| 34 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 35 | describe('The XosModelDefs service', () => { |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 36 | |
| 37 | beforeEach(angular.mock.module(xosDataSources)); |
| 38 | |
| 39 | beforeEach(() => { |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 40 | |
| 41 | angular.module(xosDataSources) |
| 42 | .constant('AppConfig', MockAppCfg); |
| 43 | |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 44 | angular.mock.module(xosDataSources); |
| 45 | }); |
| 46 | |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 47 | beforeEach(angular.mock.inject(( |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 48 | XosModelDefs: IXosModeldefsService, |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 49 | $httpBackend: ng.IHttpBackendService, |
| 50 | _$resource_: ng.resource.IResourceService, |
| 51 | _$rootScope_: ng.IRootScopeService |
| 52 | ) => { |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 53 | service = XosModelDefs; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 54 | httpBackend = $httpBackend; |
| 55 | $scope = _$rootScope_; |
| 56 | })); |
| 57 | |
| 58 | it('should have a get method', (done) => { |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 59 | httpBackend.expectGET(`${MockAppCfg.apiEndpoint}/utility/modeldefs/`) |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 60 | .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 Scandolo | 710dc15 | 2017-04-11 13:54:23 -0700 | [diff] [blame] | 72 | // httpBackend.flush(); |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 73 | }); |
| 74 | }); |