blob: 0c06ea8ad662faeb9cca77d7fd3b659235738627 [file] [log] [blame]
Matteo Scandolo8a64fa42016-01-21 11:21:03 -08001'use strict';
2
Matteo Scandoloff7df762016-01-22 16:36:34 -08003describe('The Service Relation Service', () => {
Matteo Scandolo8a64fa42016-01-21 11:21:03 -08004
Matteo Scandoloff7df762016-01-22 16:36:34 -08005 var Service;
Matteo Scandolo8a64fa42016-01-21 11:21:03 -08006
7 beforeEach(module('xos.serviceTopology'));
8 beforeEach(module('templates'));
9
Matteo Scandoloff7df762016-01-22 16:36:34 -080010 // inject the cartService
11 beforeEach(inject(function (_ServiceRelation_) {
12 // The injector unwraps the underscores (_) from around the parameter names when matching
13 Service = _ServiceRelation_;
Matteo Scandolo8a64fa42016-01-21 11:21:03 -080014 }));
15
Matteo Scandoloff7df762016-01-22 16:36:34 -080016 describe('given a service', () => {
17
18 const levelRelations = [
19 {
20 subscriber_service: 1
21 },
22 {
23 subscriber_service: 1
24 },
25 {
26 subscriber_service: 2
27 }
28 ];
29
30 it('should find all involved relations', () => {
31 expect(typeof Service.findLevelRelation).toBe('function');
32 let levelRelation = Service.findLevelRelation(levelRelations, 1);
33 expect(levelRelation.length).toBe(2);
34 });
Matteo Scandolo8a64fa42016-01-21 11:21:03 -080035 });
36
Matteo Scandoloff7df762016-01-22 16:36:34 -080037 describe('given a set of relation', () => {
38
39 const levelRelations = [
40 {
Matteo Scandoloc9ebd922016-01-28 12:02:57 -080041 provider_service: 1,
42 service_specific_attribute: '{"instance_id": "instance1"}',
43 subscriber_tenant: 2
Matteo Scandoloff7df762016-01-22 16:36:34 -080044 },
45 {
46 provider_service: 2
47 }
48 ];
49
50 const services = [
51 {
52 id: 1
53 },
54 {
55 id: 2
56 },
57 {
58 id: 3
59 }
60 ];
61
62 it('should find all the provider service', () => {
63 expect(typeof Service.findLevelServices).toBe('function');
64 let levelServices = Service.findLevelServices(levelRelations, services);
65 expect(levelServices.length).toBe(2);
66 });
Matteo Scandoloc9ebd922016-01-28 12:02:57 -080067
68 it('should retrieve all service specific information', () => {
69 let info = Service.findSpecificInformation(levelRelations, 1);
70 expect(info.instance_id).toBe('instance1');
71 });
Matteo Scandoloff7df762016-01-22 16:36:34 -080072 });
73
Matteo Scandoloc9ebd922016-01-28 12:02:57 -080074
75
Matteo Scandoloff7df762016-01-22 16:36:34 -080076 describe('given a list of services and a list of relations', () => {
77
78 const services = [
79 {
80 id: 1,
81 humanReadableName: 'service-1'
82 },
83 {
84 id: 2,
85 humanReadableName: 'service-2'
86 },
87 {
88 id: 3,
89 humanReadableName: 'service-3'
90 },
91 {
92 id: 4,
93 humanReadableName: 'service-4'
94 }
95 ];
96
Matteo Scandolo012dddb2016-02-22 16:53:22 -080097 const tenants = [
Matteo Scandoloff7df762016-01-22 16:36:34 -080098 {
99 provider_service: 2,
100 subscriber_service: 1,
101 },
102 {
103 provider_service: 3,
104 subscriber_service: 2
105 },
106 {
107 provider_service: 4,
108 subscriber_service: 1
109 },
110 {
111 subscriber_root: 1,
112 provider_service: 1
113 }
114 ];
115
Matteo Scandolo012dddb2016-02-22 16:53:22 -0800116 it('should return a tree ordered by tenants', () => {
117 let tree = Service.buildSubscriberServiceTree(services, tenants);
Matteo Scandoloff7df762016-01-22 16:36:34 -0800118
119 expect(tree.name).toBe('fakeSubs');
120 expect(tree.parent).toBeNull();
121 expect(tree.children.length).toBe(1);
122
123 expect(tree.children[0].name).toBe('service-1');
124 expect(tree.children[0].parent).toBeNull();
Matteo Scandolo012dddb2016-02-22 16:53:22 -0800125 expect(tree.children[0].tenant).toEqual({subscriber_root: 1, provider_service: 1});
Matteo Scandoloff7df762016-01-22 16:36:34 -0800126 expect(tree.children[0].children.length).toBe(2);
127
128 expect(tree.children[0].children[0].name).toBe('service-2');
Matteo Scandolo012dddb2016-02-22 16:53:22 -0800129 expect(tree.children[0].children[0].tenant).toEqual({subscriber_service: 1, provider_service: 2});;
Matteo Scandoloff7df762016-01-22 16:36:34 -0800130 expect(tree.children[0].children[0].children[0].name).toBe('service-3');
Matteo Scandolo012dddb2016-02-22 16:53:22 -0800131
Matteo Scandolo9fe01af2016-02-09 16:01:49 -0800132 expect(tree.children[0].children[0].children[0].children[0].name).toBe('Router');
Matteo Scandoloff7df762016-01-22 16:36:34 -0800133
134 expect(tree.children[0].children[1].name).toBe('service-4');
Matteo Scandolo9fe01af2016-02-09 16:01:49 -0800135 expect(tree.children[0].children[1].children[0].name).toBe('Router');
Matteo Scandolof2c99012016-01-25 10:10:38 -0800136 });
137 });
138
139 describe('given an object', () => {
140
141 const sample = {
142 name: '1',
143 children: [
144 {
145 name: '2',
146 children: [
147 {
148 name: '3'
149 }
150 ]
151 }
152 ]
153 };
154
155 it('should return the depth', () => {
156 expect(Service.depthOf(sample)).toBe(3);
Matteo Scandoloff7df762016-01-22 16:36:34 -0800157 });
158 });
159
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800160 describe('Given a list of services and COARSE tenant', () => {
161
162 const coarseTenants = [
163 {
164 humanReadableName: 'coarse-1',
165 provider_service: 1,
166 subscriber_service: 2
167 },
168 {
169 humanReadableName: 'coarse-2',
170 provider_service: 2,
171 subscriber_service: 3
172 }
173 ];
174
175 const services = [
176 {
177 id: 1,
Matteo Scandolo45fba732016-02-22 14:53:44 -0800178 name: 'vbng',
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800179 humanReadableName: 'vbng'
180 },
181 {
182 id: 2,
Matteo Scandolo45fba732016-02-22 14:53:44 -0800183 name: 'vsg',
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800184 humanReadableName: 'vsg'
185 },
186 {
187 id: 3,
Matteo Scandolo45fba732016-02-22 14:53:44 -0800188 name: 'volt',
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800189 humanReadableName: 'volt'
190 }
191 ];
192
193 it('should build the tenancy graph', () => {
194 let tree = Service.buildServiceTree(services, coarseTenants);
195
196 expect(tree.type).toBe('subscriber');
Matteo Scandolo45fba732016-02-22 14:53:44 -0800197 expect(tree.children[0].name).toBe('volt');
198 expect(tree.children[0].service).toBeDefined();
199 expect(tree.children[0].children[0].name).toBe('vsg');
200 expect(tree.children[0].children[0].children[0].name).toBe('vbng');
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800201 });
202 });
203
Matteo Scandolo8a64fa42016-01-21 11:21:03 -0800204});