|
11 | 11 |
|
12 | 12 | //@ts-ignore
|
13 | 13 | import moment from 'moment';
|
14 |
| -import { getAnomalySummary } from '../anomalyChartUtils'; |
| 14 | +import { |
| 15 | + getAnomalySummary, |
| 16 | + convertAlerts, |
| 17 | + generateAlertAnnotations, |
| 18 | +} from '../anomalyChartUtils'; |
| 19 | +import { httpClientMock, coreServicesMock } from '../../../../../test/mocks'; |
| 20 | +import { MonitorAlert } from '../../../../models/interfaces'; |
15 | 21 |
|
16 | 22 | describe('anomalyChartUtils', () => {
|
17 | 23 | describe('getAnomalySummary', () => {
|
@@ -75,3 +81,80 @@ describe('anomalyChartUtils', () => {
|
75 | 81 | });
|
76 | 82 | });
|
77 | 83 | });
|
| 84 | + |
| 85 | +describe('anomalyChartUtils function tests', () => { |
| 86 | + const alertResponse = { |
| 87 | + response: { |
| 88 | + alerts: [ |
| 89 | + { |
| 90 | + id: 'eQURa3gBKo1jAh6qUo49', |
| 91 | + version: 300, |
| 92 | + monitor_id: 'awUMa3gBKo1jAh6qu47E', |
| 93 | + schema_version: 2, |
| 94 | + monitor_version: 2, |
| 95 | + monitor_name: 'Example_monitor_name', |
| 96 | + monitor_user: { |
| 97 | + name: 'admin', |
| 98 | + backend_roles: ['admin'], |
| 99 | + roles: ['all_access', 'own_index'], |
| 100 | + custom_attribute_names: [], |
| 101 | + user_requested_tenant: null, |
| 102 | + }, |
| 103 | + trigger_id: 'bQUQa3gBKo1jAh6qnY6G', |
| 104 | + trigger_name: 'Example_trigger_name', |
| 105 | + state: 'ACTIVE', |
| 106 | + error_message: null, |
| 107 | + alert_history: [ |
| 108 | + { |
| 109 | + timestamp: 1617314504873, |
| 110 | + message: 'Example error emssage', |
| 111 | + }, |
| 112 | + { |
| 113 | + timestamp: 1617312543925, |
| 114 | + message: 'Example error message', |
| 115 | + }, |
| 116 | + ], |
| 117 | + severity: 1, |
| 118 | + action_execution_results: [ |
| 119 | + { |
| 120 | + action_id: 'bgUQa3gBKo1jAh6qnY6G', |
| 121 | + last_execution_time: 1617317979908, |
| 122 | + throttled_count: 0, |
| 123 | + }, |
| 124 | + ], |
| 125 | + start_time: 1616704000492, |
| 126 | + last_notification_time: 1617317979908, |
| 127 | + end_time: null, |
| 128 | + acknowledged_time: null, |
| 129 | + }, |
| 130 | + ], |
| 131 | + totalAlerts: 1, |
| 132 | + }, |
| 133 | + }; |
| 134 | + const alertConverted = [ |
| 135 | + { |
| 136 | + monitorName: 'Example_monitor_name', |
| 137 | + triggerName: 'Example_trigger_name', |
| 138 | + severity: 1, |
| 139 | + state: 'ACTIVE', |
| 140 | + error: null, |
| 141 | + startTime: 1616704000492, |
| 142 | + endTime: null, |
| 143 | + acknowledgedTime: null, |
| 144 | + }, |
| 145 | + ] as MonitorAlert[]; |
| 146 | + test('convertAlerts', () => { |
| 147 | + expect(convertAlerts(alertResponse)).toStrictEqual(alertConverted); |
| 148 | + }); |
| 149 | + test('generateAlertAnnotations', () => { |
| 150 | + const alertsConverted = generateAlertAnnotations(alertConverted); |
| 151 | + expect(alertsConverted).toStrictEqual([ |
| 152 | + { |
| 153 | + dataValue: 1616704000492, |
| 154 | + details: |
| 155 | + 'There is a severity 1 alert with state ACTIVE from 03/25/21 08:26:40 PM.', |
| 156 | + header: '03/25/21 08:26:40 PM', |
| 157 | + }, |
| 158 | + ]); |
| 159 | + }); |
| 160 | +}); |
0 commit comments