Skip to content

Commit 7f33671

Browse files
Orvis Evansorvisevans
authored andcommitted
ENG-23170 add histories service
1 parent ad55265 commit 7f33671

File tree

4 files changed

+190
-2
lines changed

4 files changed

+190
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import crud from '../../../crudOperations'
2+
3+
const URL = 'v3/cmp/histories'
4+
5+
export default {
6+
/**
7+
* Retrieve a list of existing histories
8+
* @param options anything parsable by URLSearchParams. See useful options here https://docs.cloudbolt.io/articles/#!cloudbolt-latest-docs/api-conventions/a/h2__904191799
9+
* @returns {Promise} resolves with a list of all Histories
10+
*/
11+
list: (options) => crud.getItems(URL, options),
12+
13+
/**
14+
* Retrieve an existing history
15+
* @param {string} id or global_id
16+
* @param options anything parsable by URLSearchParams. See useful options here https://docs.cloudbolt.io/articles/#!cloudbolt-latest-docs/api-conventions/a/h2__904191799
17+
* @returns {Promise} resolves with a cloudbolt API Response object of the History object
18+
*/
19+
get: (id, options) => crud.getItemById(URL, id, options)
20+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import { baseApi } from '../../../baseApi'
2+
import HistoriesService from './HistoriesService'
3+
4+
const mockListResponse = {
5+
_links: {
6+
self: {
7+
href: '/api/v3/cmp/histories/?page=1&page_size=2',
8+
title: 'List of Histories - Page 1 of 111'
9+
},
10+
next: {
11+
href: '/api/v3/cmp/histories/?page=2&page_size=2',
12+
title: 'Next List Page'
13+
}
14+
},
15+
total: 221,
16+
count: 2,
17+
_embedded: {
18+
histories: [
19+
{
20+
_links: {
21+
self: {
22+
href: '/api/v3/cmp/histories/HIS-255ugi0f/',
23+
title: ''
24+
},
25+
owner: {},
26+
job: {},
27+
server: {},
28+
resourceAction: {},
29+
serverAction: {},
30+
environment: {},
31+
order: {}
32+
},
33+
id: 'HIS-255ugi0f',
34+
eventMessage: 'An alert has been requested to be sent',
35+
eventType: 'SENT',
36+
actionTime: '2022-11-04 23:39:10.866753',
37+
rateChange: null,
38+
historyType: 'alerthistory',
39+
jobId: null,
40+
serverId: null,
41+
resourceId: null,
42+
serverActionId: null,
43+
resourceActionId: null,
44+
environmentId: null,
45+
orderId: null,
46+
serverPowerStatus: null
47+
},
48+
{
49+
_links: {
50+
self: {
51+
href: '/api/v3/cmp/histories/HIS-iy5r0duf/',
52+
title: 'experience_eCIT_10'
53+
},
54+
owner: {},
55+
job: {
56+
href: '/api/v3/cmp/jobs/JOB-f62k4gru/',
57+
title: 'Synchronize VMs from vCenter Job 344'
58+
},
59+
server: {
60+
href: '/api/v3/cmp/servers/SVR-byvtcaee/',
61+
title: 'experience_eCIT_10'
62+
},
63+
resourceAction: {},
64+
serverAction: {},
65+
environment: {},
66+
order: {}
67+
},
68+
id: 'HIS-iy5r0duf',
69+
eventMessage:
70+
" Server record set to historical because its VM can no longer be found on resource handler 'VMware vCenter'",
71+
eventType: 'DECOMMISSION',
72+
actionTime: '2022-11-04 19:32:23.021371',
73+
rateChange: '0E-10',
74+
historyType: 'serverhistory',
75+
jobId: 'JOB-f62k4gru',
76+
serverId: 'SVR-byvtcaee',
77+
resourceId: null,
78+
serverActionId: null,
79+
resourceActionId: null,
80+
environmentId: null,
81+
orderId: null,
82+
serverPowerStatus: 'POWEROFF'
83+
}
84+
]
85+
}
86+
}
87+
88+
const mockGetResponse = {
89+
_links: {
90+
self: {
91+
href: '/api/v3/cmp/histories/HIS-iy5r0duf/',
92+
title: 'experience_eCIT_10'
93+
},
94+
owner: {},
95+
job: {
96+
href: '/api/v3/cmp/jobs/JOB-f62k4gru/',
97+
title: 'Synchronize VMs from vCenter Job 344'
98+
},
99+
server: {
100+
href: '/api/v3/cmp/servers/SVR-byvtcaee/',
101+
title: 'experience_eCIT_10'
102+
},
103+
resourceAction: {},
104+
serverAction: {},
105+
environment: {},
106+
order: {}
107+
},
108+
id: 'HIS-iy5r0duf',
109+
eventMessage:
110+
" Server record set to historical because its VM can no longer be found on resource handler 'VMware vCenter'",
111+
eventType: 'DECOMMISSION',
112+
actionTime: '2022-11-04 19:32:23.021371',
113+
rateChange: '0E-10',
114+
historyType: 'serverhistory',
115+
jobId: 'JOB-f62k4gru',
116+
serverId: 'SVR-byvtcaee',
117+
resourceId: null,
118+
serverActionId: null,
119+
resourceActionId: null,
120+
environmentId: null,
121+
orderId: null,
122+
serverPowerStatus: 'POWEROFF'
123+
}
124+
125+
test('list calls the correct endpoint', async () => {
126+
const mockFn = jest.spyOn(baseApi, 'get').mockResolvedValue({
127+
data: [{ hello: 'world' }]
128+
})
129+
await HistoriesService.list()
130+
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/histories/')
131+
})
132+
133+
test('list parses data without issue', async () => {
134+
jest.spyOn(baseApi, 'get').mockResolvedValue({
135+
data: mockListResponse
136+
})
137+
const result = await HistoriesService.list()
138+
expect(result.items).toEqual(mockListResponse._embedded.histories)
139+
})
140+
141+
test('get calls the correct endpoint', async () => {
142+
const mockFn = jest.spyOn(baseApi, 'get').mockResolvedValue({
143+
data: { hello: 'world' }
144+
})
145+
await HistoriesService.get('history-id')
146+
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/histories/history-id/')
147+
})
148+
149+
test('get parses data without issue', async () => {
150+
jest.spyOn(baseApi, 'get').mockResolvedValue({
151+
data: mockGetResponse
152+
})
153+
const result = await HistoriesService.get('history-id')
154+
expect(result).toEqual(mockGetResponse)
155+
})

src/api/services/v3/cmp/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CitService from './CitService'
88
import EnvironmentsService from './EnvironmentsService'
99
import EulaService from './EulaService'
1010
import GroupsService from './GroupsService'
11+
import HistoriesService from './HistoriesService'
1112
import JobsService from './JobsService'
1213
import LicensingService from './LicensingService'
1314
import LoggingService from './LoggingService'
@@ -47,6 +48,7 @@ export default {
4748
environments: EnvironmentsService,
4849
eula: EulaService,
4950
groups: GroupsService,
51+
histories: HistoriesService,
5052
jobs: JobsService,
5153
licensing: LicensingService,
5254
logging: LoggingService,

src/api/services/v3/cmp/index.test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ it('should export an object', () => {
55
expect(typeof cmp).toBe('object')
66
})
77

8-
test.each([
8+
const services = [
9+
'alerts',
910
'apiToken',
1011
'applicationRates',
1112
'blueprintCategories',
@@ -16,6 +17,7 @@ test.each([
1617
'environments',
1718
'eula',
1819
'groups',
20+
'histories',
1921
'jobs',
2022
'licensing',
2123
'licensing',
@@ -42,7 +44,16 @@ test.each([
4244
'servers',
4345
'uiExtensionComponents',
4446
'users'
45-
])('should export a %s service', (serviceName) => {
47+
]
48+
49+
test.each(services)('should export a %s service', (serviceName) => {
4650
expect(cmp[serviceName]).toBeDefined()
4751
expect(typeof cmp[serviceName]).toBe('object')
4852
})
53+
54+
test('should only have expected services', () => {
55+
const keyToTrueReducer = (obj, key) => ({ ...obj, [key]: true })
56+
const expectedServices = services.reduce(keyToTrueReducer, {})
57+
const actualServices = Object.keys(cmp).reduce(keyToTrueReducer, {})
58+
expect(actualServices).toEqual(expectedServices)
59+
})

0 commit comments

Comments
 (0)