|
| 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 | +}) |
0 commit comments