Skip to content

Commit 3317484

Browse files
committed
add tests for all field kinds
1 parent 1f779e3 commit 3317484

File tree

3 files changed

+256
-10
lines changed

3 files changed

+256
-10
lines changed

x-pack/platform/plugins/shared/stack_connectors/server/connector_types/resilient/mocks.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ export const resilientFields: ResilientFieldMeta[] = [
125125
internal: false,
126126
prefix: 'properties',
127127
},
128+
{
129+
name: 'resolution_summary',
130+
input_type: 'textarea',
131+
read_only: false,
132+
required: null,
133+
text: '',
134+
internal: true,
135+
prefix: null,
136+
},
128137
];
129138

130139
export const incidentTypes = {

x-pack/platform/plugins/shared/stack_connectors/server/connector_types/resilient/utils.test.ts

Lines changed: 245 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,20 @@ describe('utils', () => {
2222
description: 'desc_updated',
2323
severityCode: 6,
2424
incidentTypes: [12, 16, 1001],
25-
additionalFields: { customField1: 'customValue1' },
25+
additionalFields: {
26+
// custom fields
27+
customField1: 'customValue1',
28+
test_text: 'some text',
29+
test_text_area: 'some textarea',
30+
test_boolean: true,
31+
test_number: 123,
32+
test_select: 'option1',
33+
test_multi_select: ['option1', 'option2'],
34+
test_date_picker: 943983345345,
35+
test_date_time_picker: 943983345345,
36+
// non custom field
37+
resolution_summary: 'some resolution summary',
38+
},
2639
};
2740
expect(
2841
formatUpdateRequest({
@@ -31,7 +44,98 @@ describe('utils', () => {
3144
fields: resilientFields,
3245
})
3346
).toEqual({
34-
changes: [
47+
changes: expect.arrayContaining([
48+
{
49+
field: {
50+
name: 'test_text',
51+
},
52+
new_value: {
53+
text: 'some text',
54+
},
55+
old_value: {},
56+
},
57+
{
58+
field: {
59+
name: 'test_text_area',
60+
},
61+
new_value: {
62+
textarea: {
63+
content: 'some textarea',
64+
format: 'text',
65+
},
66+
},
67+
old_value: {
68+
textarea: null,
69+
},
70+
},
71+
{
72+
field: {
73+
name: 'test_boolean',
74+
},
75+
new_value: {
76+
boolean: true,
77+
},
78+
old_value: {},
79+
},
80+
{
81+
field: {
82+
name: 'test_number',
83+
},
84+
new_value: {
85+
object: 123,
86+
},
87+
old_value: {},
88+
},
89+
{
90+
field: {
91+
name: 'test_select',
92+
},
93+
new_value: {
94+
id: 'option1',
95+
},
96+
old_value: {},
97+
},
98+
{
99+
field: {
100+
name: 'test_multi_select',
101+
},
102+
new_value: {
103+
ids: ['option1', 'option2'],
104+
},
105+
old_value: {},
106+
},
107+
{
108+
field: {
109+
name: 'test_date_picker',
110+
},
111+
new_value: {
112+
date: 943983345345,
113+
},
114+
old_value: {},
115+
},
116+
{
117+
field: {
118+
name: 'test_date_time_picker',
119+
},
120+
new_value: {
121+
date: 943983345345,
122+
},
123+
old_value: {},
124+
},
125+
{
126+
field: {
127+
name: 'resolution_summary',
128+
},
129+
new_value: {
130+
textarea: {
131+
content: 'some resolution summary',
132+
format: 'text',
133+
},
134+
},
135+
old_value: {
136+
textarea: null,
137+
},
138+
},
35139
{
36140
field: { name: 'customField1' },
37141
old_value: {},
@@ -71,7 +175,7 @@ describe('utils', () => {
71175
ids: [12, 16, 1001],
72176
},
73177
},
74-
],
178+
]),
75179
});
76180
});
77181

@@ -81,14 +185,37 @@ describe('utils', () => {
81185
description: { format: 'html', content: 'desc' },
82186
severity_code: 5,
83187
incident_type_ids: [12, 16],
84-
properties: { customField1: 'oldCustomValue' },
188+
// resolution_summary is not a custom field, so not part of `properties`
189+
resolution_summary: 'some resolution summary',
190+
properties: {
191+
customField1: 'oldCustomValue',
192+
test_text: 'some text',
193+
test_text_area: 'some textarea',
194+
test_boolean: true,
195+
test_number: 123,
196+
test_select: 'option1',
197+
test_multi_select: ['option1', 'option2'],
198+
test_date_picker: 943983345345,
199+
test_date_time_picker: 943983345345,
200+
},
85201
};
86202
const newIncident = {
87203
name: 'title_updated',
88204
description: 'desc_updated',
89205
severityCode: 6,
90206
incidentTypes: [12, 16, 1001],
91-
additionalFields: { customField1: 'customValue1' },
207+
additionalFields: {
208+
customField1: 'customValue1',
209+
test_text: 'some new text',
210+
test_text_area: 'some new textarea',
211+
test_boolean: false,
212+
test_number: 1234,
213+
test_select: 'option2',
214+
test_multi_select: ['option3', 'option4'],
215+
test_date_picker: 1234567890123,
216+
test_date_time_picker: 1234567890123,
217+
resolution_summary: 'some new resolution summary',
218+
},
92219
};
93220
expect(
94221
formatUpdateRequest({
@@ -97,7 +224,118 @@ describe('utils', () => {
97224
fields: resilientFields,
98225
})
99226
).toEqual({
100-
changes: [
227+
changes: expect.arrayContaining([
228+
{
229+
field: {
230+
name: 'test_text',
231+
},
232+
new_value: {
233+
text: 'some new text',
234+
},
235+
old_value: {
236+
text: 'some text',
237+
},
238+
},
239+
{
240+
field: {
241+
name: 'test_text_area',
242+
},
243+
new_value: {
244+
textarea: {
245+
content: 'some new textarea',
246+
format: 'text',
247+
},
248+
},
249+
old_value: {
250+
textarea: {
251+
content: 'some textarea',
252+
format: 'text',
253+
},
254+
},
255+
},
256+
{
257+
field: {
258+
name: 'test_boolean',
259+
},
260+
new_value: {
261+
boolean: false,
262+
},
263+
old_value: {
264+
boolean: true,
265+
},
266+
},
267+
{
268+
field: {
269+
name: 'test_number',
270+
},
271+
new_value: {
272+
object: 1234,
273+
},
274+
old_value: {
275+
object: 123,
276+
},
277+
},
278+
{
279+
field: {
280+
name: 'test_select',
281+
},
282+
new_value: {
283+
id: 'option2',
284+
},
285+
old_value: {
286+
id: 'option1',
287+
},
288+
},
289+
{
290+
field: {
291+
name: 'test_multi_select',
292+
},
293+
new_value: {
294+
ids: ['option3', 'option4'],
295+
},
296+
old_value: {
297+
ids: ['option1', 'option2'],
298+
},
299+
},
300+
{
301+
field: {
302+
name: 'test_date_picker',
303+
},
304+
new_value: {
305+
date: 1234567890123,
306+
},
307+
old_value: {
308+
date: 943983345345,
309+
},
310+
},
311+
{
312+
field: {
313+
name: 'test_date_time_picker',
314+
},
315+
new_value: {
316+
date: 1234567890123,
317+
},
318+
old_value: {
319+
date: 943983345345,
320+
},
321+
},
322+
{
323+
field: {
324+
name: 'resolution_summary',
325+
},
326+
new_value: {
327+
textarea: {
328+
content: 'some new resolution summary',
329+
format: 'text',
330+
},
331+
},
332+
old_value: {
333+
textarea: {
334+
content: 'some resolution summary',
335+
format: 'text',
336+
},
337+
},
338+
},
101339
{
102340
field: { name: 'customField1' },
103341
old_value: { text: 'oldCustomValue' },
@@ -137,7 +375,7 @@ describe('utils', () => {
137375
ids: [12, 16, 1001],
138376
},
139377
},
140-
],
378+
]),
141379
});
142380
});
143381
});

x-pack/platform/plugins/shared/stack_connectors/server/connector_types/resilient/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import type {
1515
import type { ResilientFieldMeta } from './schema';
1616

1717
// todo:
18-
// 1. add tests for non-text fields
1918
// 1.1 - add support for `values` check in select/multiselect
2019

21-
export const getValueFromOldField = (
20+
const getValueFromOldField = (
2221
fieldMeta: ResilientFieldMeta,
2322
value: unknown
2423
): ResilientFieldPrimitives => {
@@ -40,7 +39,7 @@ export const getValueFromOldField = (
4039
}
4140
};
4241

43-
export function getValueFieldShape(
42+
function getValueFieldShape(
4443
fieldMeta: ResilientFieldMeta,
4544
value: ResilientFieldPrimitives,
4645
oldValue?: ResilientFieldPrimitives

0 commit comments

Comments
 (0)