blob: 45630e9acb4dcf0f62cf1695d9877696b2a95162 [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 {
41 provider_service: 1
42 },
43 {
44 provider_service: 2
45 }
46 ];
47
48 const services = [
49 {
50 id: 1
51 },
52 {
53 id: 2
54 },
55 {
56 id: 3
57 }
58 ];
59
60 it('should find all the provider service', () => {
61 expect(typeof Service.findLevelServices).toBe('function');
62 let levelServices = Service.findLevelServices(levelRelations, services);
63 expect(levelServices.length).toBe(2);
64 });
65 });
66
67 describe('given a list of services and a list of relations', () => {
68
69 const services = [
70 {
71 id: 1,
72 humanReadableName: 'service-1'
73 },
74 {
75 id: 2,
76 humanReadableName: 'service-2'
77 },
78 {
79 id: 3,
80 humanReadableName: 'service-3'
81 },
82 {
83 id: 4,
84 humanReadableName: 'service-4'
85 }
86 ];
87
88 const relations = [
89 {
90 provider_service: 2,
91 subscriber_service: 1,
92 },
93 {
94 provider_service: 3,
95 subscriber_service: 2
96 },
97 {
98 provider_service: 4,
99 subscriber_service: 1
100 },
101 {
102 subscriber_root: 1,
103 provider_service: 1
104 }
105 ];
106
107 it('should return a tree ordered by relations', () => {
108 let tree = Service.buildServiceTree(services, relations);
109
110 expect(tree.name).toBe('fakeSubs');
111 expect(tree.parent).toBeNull();
112 expect(tree.children.length).toBe(1);
113
114 expect(tree.children[0].name).toBe('service-1');
115 expect(tree.children[0].parent).toBeNull();
116 expect(tree.children[0].children.length).toBe(2);
117
118 expect(tree.children[0].children[0].name).toBe('service-2');
119 expect(tree.children[0].children[0].children[0].name).toBe('service-3');
Matteo Scandolof2c99012016-01-25 10:10:38 -0800120 expect(tree.children[0].children[0].children[0].children[0].name).toBe('Internet');
Matteo Scandoloff7df762016-01-22 16:36:34 -0800121
122 expect(tree.children[0].children[1].name).toBe('service-4');
Matteo Scandolof2c99012016-01-25 10:10:38 -0800123 expect(tree.children[0].children[1].children[0].name).toBe('Internet');
124 });
125 });
126
127 describe('given an object', () => {
128
129 const sample = {
130 name: '1',
131 children: [
132 {
133 name: '2',
134 children: [
135 {
136 name: '3'
137 }
138 ]
139 }
140 ]
141 };
142
143 it('should return the depth', () => {
144 expect(Service.depthOf(sample)).toBe(3);
Matteo Scandoloff7df762016-01-22 16:36:34 -0800145 });
146 });
147
Matteo Scandolo5bf04572016-01-25 17:36:08 -0800148 describe('given slices and instances', () => {
149 const slices = [
150 {
151 id: 12,
152 name: 'First'
153 },
154 {
155 id: 13,
156 name: 'Second'
157 }
158 ];
159
160 const instances = [
161 [
162 {
163 humanReadableName: 'first-slice-instance-1'
164 },
165 {
166 humanReadableName: 'first-slice-instance-2'
167 }
168 ],
169 [
170 {
171 humanReadableName: 'second-slice-instance'
172 }
173 ]
174 ];
175
176 it('should create a tree grouping instances', () => {
177 const res = Service.buildServiceInterfacesTree(slices, instances);
178
179 expect(res[0].name).toBe('First');
180 expect(res[0].children[0].name).toBe('first-slice-instance-1');
181 expect(res[0].children[1].name).toBe('first-slice-instance-2');
182
183 expect(res[1].name).toBe('Second');
184 expect(res[1].children[0].name).toBe('second-slice-instance');
185 });
186 });
187
Matteo Scandoloff7df762016-01-22 16:36:34 -0800188
Matteo Scandolo8a64fa42016-01-21 11:21:03 -0800189});