blob: fdc6d5049b0bd40787523607742ed1350b29addf [file] [log] [blame]
Matteo Scandoloba678a92016-06-20 17:16:15 -07001/**
2 * © OpenCORD
3 *
4 * Visit http://guide.xosproject.org/devguide/addview/ for more information
5 *
6 * Created by teone on 6/22/16.
7 */
8
9(function () {
10 'use strict';
11 describe('The Site Encoder service', () => {
12 let service, toscaBase, siteGetPromise, SiteSpy, rootScope;
13
14 const toscaBaseDefault = {
15 topology_template: {
16 node_templates: {}
17 }
18 };
19
20 const siteResponse = {
21 name: 'MySite'
22 };
23
24 const expected = [{
25 topology_template: {
26 node_templates: {
27 'MySite': {
28 type: 'tosca.nodes.Site',
29 }
30 }
31 }
32 }, siteResponse];
33
34 beforeEach(module('xos.serviceGrid'));
35 beforeEach(module('templates'));
36
37 beforeEach(inject((SiteEncoder, Sites, $q, $rootScope) => {
38 toscaBase = angular.copy(toscaBaseDefault);
39 service = SiteEncoder;
40 rootScope = $rootScope;
41
42 siteGetPromise= $q.defer();
43 SiteSpy = Sites;
44 spyOn(SiteSpy, 'get').and.callFake(function(){
45 return {$promise: siteGetPromise.promise};
46 });
47 }));
48
49 describe('given a Site Id', () => {
50 it('should return the correct JSON structure', (done) => {
51 service.buildTosca({id: 1}, toscaBase)
52 .then(res => {
53 expect(res).toEqual(expected);
54 done();
55 });
56 siteGetPromise.resolve(siteResponse);
57 rootScope.$apply();
58 });
59 });
60 });
61})();
62