Matteo Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 3 | describe('The Service Relation Service', () => { |
Matteo Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 4 | |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 5 | var Service; |
Matteo Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 6 | |
| 7 | beforeEach(module('xos.serviceTopology')); |
| 8 | beforeEach(module('templates')); |
| 9 | |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 10 | // 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 Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 14 | })); |
| 15 | |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 16 | 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 Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 35 | }); |
| 36 | |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 37 | 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 Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 120 | expect(tree.children[0].children[0].children[0].children[0].name).toBe('Internet'); |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 121 | |
| 122 | expect(tree.children[0].children[1].name).toBe('service-4'); |
Matteo Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 123 | 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 Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 145 | }); |
| 146 | }); |
| 147 | |
Matteo Scandolo | 5bf0457 | 2016-01-25 17:36:08 -0800 | [diff] [blame] | 148 | 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 Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 188 | |
Matteo Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 189 | }); |