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 | { |
Matteo Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 41 | provider_service: 1, |
| 42 | service_specific_attribute: '{"instance_id": "instance1"}', |
| 43 | subscriber_tenant: 2 |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 44 | }, |
| 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 Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 67 | |
| 68 | it('should retrieve all service specific information', () => { |
| 69 | let info = Service.findSpecificInformation(levelRelations, 1); |
| 70 | expect(info.instance_id).toBe('instance1'); |
| 71 | }); |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 72 | }); |
| 73 | |
Matteo Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 74 | |
| 75 | |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 76 | 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 | |
| 97 | const relations = [ |
| 98 | { |
| 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 | |
| 116 | it('should return a tree ordered by relations', () => { |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 117 | let tree = Service.buildSubscriberServiceTree(services, relations); |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 118 | |
| 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(); |
| 125 | expect(tree.children[0].children.length).toBe(2); |
| 126 | |
| 127 | expect(tree.children[0].children[0].name).toBe('service-2'); |
| 128 | expect(tree.children[0].children[0].children[0].name).toBe('service-3'); |
Matteo Scandolo | 9fe01af | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 129 | expect(tree.children[0].children[0].children[0].children[0].name).toBe('Router'); |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 130 | |
| 131 | expect(tree.children[0].children[1].name).toBe('service-4'); |
Matteo Scandolo | 9fe01af | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 132 | expect(tree.children[0].children[1].children[0].name).toBe('Router'); |
Matteo Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 133 | }); |
| 134 | }); |
| 135 | |
| 136 | describe('given an object', () => { |
| 137 | |
| 138 | const sample = { |
| 139 | name: '1', |
| 140 | children: [ |
| 141 | { |
| 142 | name: '2', |
| 143 | children: [ |
| 144 | { |
| 145 | name: '3' |
| 146 | } |
| 147 | ] |
| 148 | } |
| 149 | ] |
| 150 | }; |
| 151 | |
| 152 | it('should return the depth', () => { |
| 153 | expect(Service.depthOf(sample)).toBe(3); |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 154 | }); |
| 155 | }); |
| 156 | |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 157 | describe('Given a list of services and COARSE tenant', () => { |
| 158 | |
| 159 | const coarseTenants = [ |
| 160 | { |
| 161 | humanReadableName: 'coarse-1', |
| 162 | provider_service: 1, |
| 163 | subscriber_service: 2 |
| 164 | }, |
| 165 | { |
| 166 | humanReadableName: 'coarse-2', |
| 167 | provider_service: 2, |
| 168 | subscriber_service: 3 |
| 169 | } |
| 170 | ]; |
| 171 | |
| 172 | const services = [ |
| 173 | { |
| 174 | id: 1, |
| 175 | humanReadableName: 'vbng' |
| 176 | }, |
| 177 | { |
| 178 | id: 2, |
| 179 | humanReadableName: 'vsg' |
| 180 | }, |
| 181 | { |
| 182 | id: 3, |
| 183 | humanReadableName: 'volt' |
| 184 | } |
| 185 | ]; |
| 186 | |
| 187 | it('should build the tenancy graph', () => { |
| 188 | let tree = Service.buildServiceTree(services, coarseTenants); |
| 189 | |
| 190 | expect(tree.type).toBe('subscriber'); |
| 191 | expect(tree.children[0].humanReadableName).toBe('volt'); |
| 192 | expect(tree.children[0].children[0].humanReadableName).toBe('vsg'); |
| 193 | expect(tree.children[0].children[0].children[0].humanReadableName).toBe('vbng'); |
| 194 | }); |
| 195 | }); |
| 196 | |
Matteo Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 197 | }); |