Matteo Scandolo | be9b13d | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 3 | describe('The Service Relation Service', () => { |
Matteo Scandolo | be9b13d | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 4 | |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 5 | var Service; |
Matteo Scandolo | be9b13d | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 6 | |
Matteo Scandolo | 0b8b7ab | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 7 | beforeEach(module('xos.diagnostic')); |
Matteo Scandolo | be9b13d | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 8 | beforeEach(module('templates')); |
| 9 | |
Matteo Scandolo | 8927639 | 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 | be9b13d | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 14 | })); |
| 15 | |
Matteo Scandolo | 8927639 | 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 | be9b13d | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 35 | }); |
| 36 | |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 37 | describe('given a set of relation', () => { |
| 38 | |
| 39 | const levelRelations = [ |
| 40 | { |
Matteo Scandolo | 998e465 | 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 | 8927639 | 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 | 998e465 | 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 | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 72 | }); |
| 73 | |
Matteo Scandolo | 998e465 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 74 | |
| 75 | |
Matteo Scandolo | 8927639 | 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 | |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 97 | const tenants = [ |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 98 | { |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 99 | id: 1, |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 100 | provider_service: 2, |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 101 | subscriber_tenant: 4, |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 102 | subscriber_service: 1, |
| 103 | }, |
| 104 | { |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 105 | id: 2, |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 106 | provider_service: 3, |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 107 | subscriber_tenant: 1, |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 108 | subscriber_service: 2 |
| 109 | }, |
| 110 | { |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 111 | id: 3, |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 112 | provider_service: 4, |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 113 | subscriber_tenant: 4, |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 114 | subscriber_service: 1 |
| 115 | }, |
| 116 | { |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 117 | id: 4, |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 118 | subscriber_root: 1, |
| 119 | provider_service: 1 |
| 120 | } |
| 121 | ]; |
| 122 | |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 123 | it('should return a tree ordered by tenants', () => { |
| 124 | let tree = Service.buildSubscriberServiceTree(services, tenants); |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 125 | |
| 126 | expect(tree.name).toBe('fakeSubs'); |
| 127 | expect(tree.parent).toBeNull(); |
| 128 | expect(tree.children.length).toBe(1); |
| 129 | |
| 130 | expect(tree.children[0].name).toBe('service-1'); |
| 131 | expect(tree.children[0].parent).toBeNull(); |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 132 | expect(tree.children[0].tenant).toEqual({id: 4, subscriber_root: 1, provider_service: 1}); |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 133 | expect(tree.children[0].children.length).toBe(2); |
| 134 | |
| 135 | expect(tree.children[0].children[0].name).toBe('service-2'); |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 136 | expect(tree.children[0].children[0].tenant).toEqual({ id: 1, provider_service: 2, subscriber_tenant: 4, subscriber_service: 1 });; |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 137 | expect(tree.children[0].children[0].children[0].name).toBe('service-3'); |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 138 | |
Matteo Scandolo | 0b8b7ab | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 139 | // expect(tree.children[0].children[0].children[0].children[0].name).toBe('Router'); |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 140 | |
| 141 | expect(tree.children[0].children[1].name).toBe('service-4'); |
Matteo Scandolo | 0b8b7ab | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 142 | // expect(tree.children[0].children[1].children[0].name).toBe('Router'); |
Matteo Scandolo | fb46f5b | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 143 | }); |
| 144 | }); |
| 145 | |
| 146 | describe('given an object', () => { |
| 147 | |
| 148 | const sample = { |
| 149 | name: '1', |
| 150 | children: [ |
| 151 | { |
| 152 | name: '2', |
| 153 | children: [ |
| 154 | { |
| 155 | name: '3' |
| 156 | } |
| 157 | ] |
| 158 | } |
| 159 | ] |
| 160 | }; |
| 161 | |
| 162 | it('should return the depth', () => { |
| 163 | expect(Service.depthOf(sample)).toBe(3); |
Matteo Scandolo | 8927639 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 164 | }); |
| 165 | }); |
| 166 | |
Matteo Scandolo | 657d132 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 167 | describe('Given a list of services and COARSE tenant', () => { |
| 168 | |
| 169 | const coarseTenants = [ |
| 170 | { |
| 171 | humanReadableName: 'coarse-1', |
| 172 | provider_service: 1, |
| 173 | subscriber_service: 2 |
| 174 | }, |
| 175 | { |
| 176 | humanReadableName: 'coarse-2', |
| 177 | provider_service: 2, |
| 178 | subscriber_service: 3 |
| 179 | } |
| 180 | ]; |
| 181 | |
| 182 | const services = [ |
| 183 | { |
| 184 | id: 1, |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 185 | name: 'vbng', |
Matteo Scandolo | 657d132 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 186 | humanReadableName: 'vbng' |
| 187 | }, |
| 188 | { |
| 189 | id: 2, |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 190 | name: 'vsg', |
Matteo Scandolo | 657d132 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 191 | humanReadableName: 'vsg' |
| 192 | }, |
| 193 | { |
| 194 | id: 3, |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 195 | name: 'volt', |
Matteo Scandolo | 657d132 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 196 | humanReadableName: 'volt' |
| 197 | } |
| 198 | ]; |
| 199 | |
| 200 | it('should build the tenancy graph', () => { |
| 201 | let tree = Service.buildServiceTree(services, coarseTenants); |
| 202 | |
| 203 | expect(tree.type).toBe('subscriber'); |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 204 | expect(tree.children[0].name).toBe('volt'); |
| 205 | expect(tree.children[0].service).toBeDefined(); |
| 206 | expect(tree.children[0].children[0].name).toBe('vsg'); |
| 207 | expect(tree.children[0].children[0].children[0].name).toBe('vbng'); |
Matteo Scandolo | 657d132 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 208 | }); |
| 209 | }); |
| 210 | |
Matteo Scandolo | be9b13d | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 211 | }); |