Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -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 | ba678a9 | 2016-06-20 17:16:15 -0700 | [diff] [blame] | 19 | /** |
| 20 | * © OpenCORD |
| 21 | * |
| 22 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 23 | * |
| 24 | * Created by teone on 6/22/16. |
| 25 | */ |
| 26 | |
| 27 | (function () { |
| 28 | 'use strict'; |
| 29 | describe('The Site Encoder service', () => { |
| 30 | let service, toscaBase, siteGetPromise, SiteSpy, rootScope; |
| 31 | |
| 32 | const toscaBaseDefault = { |
| 33 | topology_template: { |
| 34 | node_templates: {} |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | const siteResponse = { |
| 39 | name: 'MySite' |
| 40 | }; |
| 41 | |
| 42 | const expected = [{ |
| 43 | topology_template: { |
| 44 | node_templates: { |
| 45 | 'MySite': { |
| 46 | type: 'tosca.nodes.Site', |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | }, siteResponse]; |
| 51 | |
| 52 | beforeEach(module('xos.serviceGrid')); |
| 53 | beforeEach(module('templates')); |
| 54 | |
| 55 | beforeEach(inject((SiteEncoder, Sites, $q, $rootScope) => { |
| 56 | toscaBase = angular.copy(toscaBaseDefault); |
| 57 | service = SiteEncoder; |
| 58 | rootScope = $rootScope; |
| 59 | |
| 60 | siteGetPromise= $q.defer(); |
| 61 | SiteSpy = Sites; |
| 62 | spyOn(SiteSpy, 'get').and.callFake(function(){ |
| 63 | return {$promise: siteGetPromise.promise}; |
| 64 | }); |
| 65 | })); |
| 66 | |
| 67 | describe('given a Site Id', () => { |
| 68 | it('should return the correct JSON structure', (done) => { |
| 69 | service.buildTosca({id: 1}, toscaBase) |
| 70 | .then(res => { |
| 71 | expect(res).toEqual(expected); |
| 72 | done(); |
| 73 | }); |
| 74 | siteGetPromise.resolve(siteResponse); |
| 75 | rootScope.$apply(); |
| 76 | }); |
| 77 | }); |
| 78 | }); |
| 79 | })(); |
| 80 | |