blob: 8b490e7f32464cd9a6b3ab688d33866e112a5f83 [file] [log] [blame]
Matteo Scandolobe9b13d2016-01-21 11:21:03 -08001'use strict';
2
Matteo Scandolo89276392016-01-22 16:36:34 -08003describe('The Service Relation Service', () => {
Matteo Scandolobe9b13d2016-01-21 11:21:03 -08004
Matteo Scandolo89276392016-01-22 16:36:34 -08005 var Service;
Matteo Scandolobe9b13d2016-01-21 11:21:03 -08006
7 beforeEach(module('xos.serviceTopology'));
8 beforeEach(module('templates'));
9
Matteo Scandolo89276392016-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 Scandolobe9b13d2016-01-21 11:21:03 -080014 }));
15
Matteo Scandolo89276392016-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 Scandolobe9b13d2016-01-21 11:21:03 -080035 });
36
Matteo Scandolo89276392016-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');
120
121 expect(tree.children[0].children[1].name).toBe('service-4');
122 });
123 });
124
125
Matteo Scandolobe9b13d2016-01-21 11:21:03 -0800126});