|
1
|
|
|
import { mapServiceDtoToService, mapServicesToTreeNodes } from '../../../src/utils/helpers/MappingHelpers'; |
|
2
|
|
|
import { ExpectationsDto, ServiceCommunicationDto, ServiceDto } from '../../../src/api/api.types'; |
|
3
|
|
|
import { Service, TreeNode } from '../../../src/components/types'; |
|
4
|
|
|
import { emptyService } from './MappingHelpers.fixture'; |
|
5
|
|
|
|
|
6
|
|
|
describe('mapServiceDtoToService', () => { |
|
7
|
|
|
it('should correctly map empty serviceDto to service', () => { |
|
8
|
|
|
const serviceDto = { |
|
9
|
|
|
name: 'ui', |
|
10
|
|
|
version: '1.0.0', |
|
11
|
|
|
capabilities: {}, |
|
12
|
|
|
expectations: {}, |
|
13
|
|
|
}; |
|
14
|
|
|
|
|
15
|
|
|
expect(mapServiceDtoToService(serviceDto).name).toBe(serviceDto.name); |
|
16
|
|
|
expect(mapServiceDtoToService(serviceDto).version).toBe(serviceDto.version); |
|
17
|
|
|
expect(mapServiceDtoToService(serviceDto)).toMatchObject({ capabilities: {}, expectations: {} }); |
|
18
|
|
|
}); |
|
19
|
|
|
|
|
20
|
|
|
it('should correctly map serviceDto to service', () => { |
|
21
|
|
|
const capabilities = generateConnections(['rest']); |
|
22
|
|
|
const expectations = { provider: generateConnections(['jms']) }; |
|
23
|
|
|
const serviceDto = { |
|
24
|
|
|
name: 'ui', |
|
25
|
|
|
version: '1.0.0', |
|
26
|
|
|
capabilities, |
|
27
|
|
|
expectations, |
|
28
|
|
|
}; |
|
29
|
|
|
|
|
30
|
|
|
expect(mapServiceDtoToService(serviceDto).name).toBe(serviceDto.name); |
|
31
|
|
|
expect(mapServiceDtoToService(serviceDto).version).toBe(serviceDto.version); |
|
32
|
|
|
expect(mapServiceDtoToService(serviceDto).capabilities.rest).toEqual({ |
|
33
|
|
|
value: JSON.parse(capabilities.rest.value), |
|
34
|
|
|
mimeType: capabilities.rest.mimeType, |
|
35
|
|
|
}); |
|
36
|
|
|
expect(mapServiceDtoToService(serviceDto).expectations.provider).toBeDefined(); |
|
37
|
|
|
expect(mapServiceDtoToService(serviceDto).expectations.provider.jms).toEqual({ |
|
38
|
|
|
value: JSON.parse(expectations.provider.jms.value), |
|
39
|
|
|
mimeType: expectations.provider.jms.mimeType, |
|
40
|
|
|
}); |
|
41
|
|
|
}); |
|
42
|
|
|
|
|
43
|
|
|
it('should correctly map serviceDto with multiple connection types', () => { |
|
44
|
|
|
const capabilities = generateConnections(['rest', 'jms', 'custom']); |
|
45
|
|
|
const expectations = { provider: generateConnections(['rest', 'jms', 'custom']) }; |
|
46
|
|
|
|
|
47
|
|
|
const serviceDto: ServiceDto = { |
|
48
|
|
|
name: 'ui', |
|
49
|
|
|
version: '1.0.0', |
|
50
|
|
|
capabilities, |
|
51
|
|
|
expectations, |
|
52
|
|
|
}; |
|
53
|
|
|
|
|
54
|
|
|
['jms', 'rest', 'custom'].forEach((type: string) => { |
|
55
|
|
|
expect(mapServiceDtoToService(serviceDto).capabilities[type]).toBeDefined(); |
|
56
|
|
|
expect(mapServiceDtoToService(serviceDto).expectations.provider[type]).toBeDefined(); |
|
57
|
|
|
expect(mapServiceDtoToService(serviceDto)).toMatchObject({ |
|
58
|
|
|
capabilities: { |
|
59
|
|
|
[type]: { |
|
60
|
|
|
value: JSON.parse(capabilities[type].value), |
|
61
|
|
|
mimeType: capabilities[type].mimeType, |
|
62
|
|
|
}, |
|
63
|
|
|
}, |
|
64
|
|
|
expectations: { |
|
65
|
|
|
provider: { |
|
66
|
|
|
[type]: { |
|
67
|
|
|
value: JSON.parse(expectations.provider[type].value), |
|
68
|
|
|
mimeType: expectations.provider.jms.mimeType, |
|
69
|
|
|
}, |
|
70
|
|
|
}, |
|
71
|
|
|
}, |
|
72
|
|
|
}); |
|
73
|
|
|
}); |
|
74
|
|
|
}); |
|
75
|
|
|
|
|
76
|
|
|
it('should correctly map serviceDto with multiple providers', () => { |
|
77
|
|
|
const expectations: ExpectationsDto = { |
|
78
|
|
|
firstService: generateConnections(['rest']), |
|
79
|
|
|
secondService: generateConnections(['rest']), |
|
80
|
|
|
thirdService: generateConnections(['rest']), |
|
81
|
|
|
}; |
|
82
|
|
|
|
|
83
|
|
|
const serviceDto = { |
|
84
|
|
|
name: 'ui', |
|
85
|
|
|
version: '1.0.0', |
|
86
|
|
|
capabilities: {}, |
|
87
|
|
|
expectations, |
|
88
|
|
|
}; |
|
89
|
|
|
|
|
90
|
|
|
['firstService', 'secondService', 'thirdService'].forEach((provider: string) => { |
|
91
|
|
|
expect(mapServiceDtoToService(serviceDto).expectations[provider]).toBeDefined(); |
|
92
|
|
|
expect(mapServiceDtoToService(serviceDto).expectations[provider].rest).toEqual({ |
|
93
|
|
|
value: JSON.parse(expectations[provider].rest.value), |
|
94
|
|
|
mimeType: expectations[provider].rest.mimeType, |
|
95
|
|
|
}); |
|
96
|
|
|
}); |
|
97
|
|
|
}); |
|
98
|
|
|
}); |
|
99
|
|
|
|
|
100
|
|
|
describe('mapServicesToTreeNodes', () => { |
|
101
|
|
|
it('should return empty table for given empty table', () => { |
|
102
|
|
|
expect(mapServicesToTreeNodes([])).toEqual([]); |
|
103
|
|
|
}); |
|
104
|
|
|
|
|
105
|
|
|
it('should properly map services to tree nodes', () => { |
|
106
|
|
|
const services: Service[] = [ |
|
107
|
|
|
{ |
|
108
|
|
|
...emptyService, |
|
109
|
|
|
name: 'service-1', |
|
110
|
|
|
expectations: { |
|
111
|
|
|
'service-2': { |
|
112
|
|
|
rest: { |
|
113
|
|
|
value: {}, |
|
114
|
|
|
mimeType: '', |
|
115
|
|
|
}, |
|
116
|
|
|
}, |
|
117
|
|
|
}, |
|
118
|
|
|
}, |
|
119
|
|
|
{ |
|
120
|
|
|
...emptyService, |
|
121
|
|
|
name: 'service-2', |
|
122
|
|
|
}, |
|
123
|
|
|
]; |
|
124
|
|
|
const firstTreeNode: TreeNode = { |
|
125
|
|
|
consumers: [], |
|
126
|
|
|
name: 'service-1', |
|
127
|
|
|
providers: [], |
|
128
|
|
|
}; |
|
129
|
|
|
const secondTreeNode: TreeNode = { |
|
130
|
|
|
consumers: [firstTreeNode], |
|
131
|
|
|
name: 'service-2', |
|
132
|
|
|
providers: [], |
|
133
|
|
|
}; |
|
134
|
|
|
firstTreeNode.providers = [secondTreeNode]; |
|
135
|
|
|
expect(mapServicesToTreeNodes(services)).toEqual([firstTreeNode, secondTreeNode]); |
|
136
|
|
|
}); |
|
137
|
|
|
}); |
|
138
|
|
|
|
|
139
|
|
|
function generateConnections(connection: string[]): ServiceCommunicationDto { |
|
140
|
|
|
return connection.reduce( |
|
141
|
|
|
(connections: ServiceCommunicationDto, type: string) => ({ |
|
142
|
|
|
...connections, |
|
143
|
|
|
[type]: { |
|
144
|
|
|
value: JSON.stringify(type), |
|
145
|
|
|
mimeType: 'application/json', |
|
146
|
|
|
}, |
|
147
|
|
|
}), |
|
148
|
|
|
{} |
|
149
|
|
|
); |
|
150
|
|
|
} |
|
151
|
|
|
|