Skip to content

Commit 1dbd61c

Browse files
committed
tests
1 parent 3e885c1 commit 1dbd61c

File tree

5 files changed

+139
-2
lines changed

5 files changed

+139
-2
lines changed

x-pack/plugins/siem/public/containers/case/use_get_case_user_actions.test.tsx

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ describe('useGetCaseUserActions', () => {
122122
...basicPush,
123123
firstPushIndex: 3,
124124
lastPushIndex: 3,
125+
commentsToUpdate: [],
125126
hasDataToPush: false,
126127
},
127128
},
128129
});
129130
});
130131

131-
it('Correctly marks first/last index - hasDataToPush: true', () => {
132+
it('Correctly marks first/last index and comment id - hasDataToPush: true', () => {
132133
const userActions = [
133134
...caseUserActions,
134135
getUserAction(['pushed'], 'push-to-service'),
@@ -142,6 +143,83 @@ describe('useGetCaseUserActions', () => {
142143
...basicPush,
143144
firstPushIndex: 3,
144145
lastPushIndex: 3,
146+
commentsToUpdate: [userActions[userActions.length - 1].commentId],
147+
hasDataToPush: true,
148+
},
149+
},
150+
});
151+
});
152+
153+
it('Correctly marks first/last index and multiple comment ids, both needs push', () => {
154+
const userActions = [
155+
...caseUserActions,
156+
getUserAction(['pushed'], 'push-to-service'),
157+
getUserAction(['comment'], 'create'),
158+
{ ...getUserAction(['comment'], 'create'), commentId: 'muahaha' },
159+
];
160+
const result = getPushedInfo(userActions, '123');
161+
expect(result).toEqual({
162+
hasDataToPush: true,
163+
caseServices: {
164+
'123': {
165+
...basicPush,
166+
firstPushIndex: 3,
167+
lastPushIndex: 3,
168+
commentsToUpdate: [
169+
userActions[userActions.length - 2].commentId,
170+
userActions[userActions.length - 1].commentId,
171+
],
172+
hasDataToPush: true,
173+
},
174+
},
175+
});
176+
});
177+
178+
it('Correctly marks first/last index and multiple comment ids, one needs push', () => {
179+
const userActions = [
180+
...caseUserActions,
181+
getUserAction(['pushed'], 'push-to-service'),
182+
getUserAction(['comment'], 'create'),
183+
getUserAction(['pushed'], 'push-to-service'),
184+
{ ...getUserAction(['comment'], 'create'), commentId: 'muahaha' },
185+
];
186+
const result = getPushedInfo(userActions, '123');
187+
expect(result).toEqual({
188+
hasDataToPush: true,
189+
caseServices: {
190+
'123': {
191+
...basicPush,
192+
firstPushIndex: 3,
193+
lastPushIndex: 5,
194+
commentsToUpdate: [userActions[userActions.length - 1].commentId],
195+
hasDataToPush: true,
196+
},
197+
},
198+
});
199+
});
200+
201+
it('Correctly marks first/last index and multiple comment ids, one needs push and one needs update', () => {
202+
const userActions = [
203+
...caseUserActions,
204+
getUserAction(['pushed'], 'push-to-service'),
205+
getUserAction(['comment'], 'create'),
206+
getUserAction(['pushed'], 'push-to-service'),
207+
{ ...getUserAction(['comment'], 'create'), commentId: 'muahaha' },
208+
getUserAction(['comment'], 'update'),
209+
getUserAction(['comment'], 'update'),
210+
];
211+
const result = getPushedInfo(userActions, '123');
212+
expect(result).toEqual({
213+
hasDataToPush: true,
214+
caseServices: {
215+
'123': {
216+
...basicPush,
217+
firstPushIndex: 3,
218+
lastPushIndex: 5,
219+
commentsToUpdate: [
220+
userActions[userActions.length - 3].commentId,
221+
userActions[userActions.length - 1].commentId,
222+
],
145223
hasDataToPush: true,
146224
},
147225
},
@@ -162,6 +240,7 @@ describe('useGetCaseUserActions', () => {
162240
...basicPush,
163241
firstPushIndex: 3,
164242
lastPushIndex: 3,
243+
commentsToUpdate: [],
165244
hasDataToPush: false,
166245
},
167246
},
@@ -182,11 +261,34 @@ describe('useGetCaseUserActions', () => {
182261
...basicPush,
183262
firstPushIndex: 3,
184263
lastPushIndex: 5,
264+
commentsToUpdate: [],
185265
hasDataToPush: false,
186266
},
187267
},
188268
});
189269
});
270+
it('Correctly handles comment update with multiple push actions', () => {
271+
const userActions = [
272+
...caseUserActions,
273+
getUserAction(['pushed'], 'push-to-service'),
274+
getUserAction(['comment'], 'create'),
275+
getUserAction(['pushed'], 'push-to-service'),
276+
getUserAction(['comment'], 'update'),
277+
];
278+
const result = getPushedInfo(userActions, '123');
279+
expect(result).toEqual({
280+
hasDataToPush: true,
281+
caseServices: {
282+
'123': {
283+
...basicPush,
284+
firstPushIndex: 3,
285+
lastPushIndex: 5,
286+
commentsToUpdate: [userActions[userActions.length - 1].commentId],
287+
hasDataToPush: true,
288+
},
289+
},
290+
});
291+
});
190292

191293
it('Multiple connector tracking - hasDataToPush: true', () => {
192294
const pushAction123 = getUserAction(['pushed'], 'push-to-service');
@@ -215,6 +317,7 @@ describe('useGetCaseUserActions', () => {
215317
...basicPush,
216318
firstPushIndex: 3,
217319
lastPushIndex: 3,
320+
commentsToUpdate: [userActions[userActions.length - 2].commentId],
218321
hasDataToPush: true,
219322
},
220323
'456': {
@@ -224,6 +327,7 @@ describe('useGetCaseUserActions', () => {
224327
externalId: 'other_external_id',
225328
firstPushIndex: 5,
226329
lastPushIndex: 5,
330+
commentsToUpdate: [],
227331
hasDataToPush: false,
228332
},
229333
},
@@ -257,6 +361,7 @@ describe('useGetCaseUserActions', () => {
257361
...basicPush,
258362
firstPushIndex: 3,
259363
lastPushIndex: 3,
364+
commentsToUpdate: [userActions[userActions.length - 2].commentId],
260365
hasDataToPush: true,
261366
},
262367
'456': {
@@ -266,6 +371,7 @@ describe('useGetCaseUserActions', () => {
266371
externalId: 'other_external_id',
267372
firstPushIndex: 5,
268373
lastPushIndex: 5,
374+
commentsToUpdate: [],
269375
hasDataToPush: false,
270376
},
271377
},

x-pack/plugins/siem/public/containers/case/use_post_push_to_service.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
serviceConnectorUser,
2020
} from './mock';
2121
import * as api from './api';
22+
import { CaseServices } from './use_get_case_user_actions';
2223

2324
jest.mock('./api');
2425

@@ -32,6 +33,7 @@ describe('usePostPushToService', () => {
3233
...basicPush,
3334
firstPushIndex: 1,
3435
lastPushIndex: 1,
36+
commentsToUpdate: [basicComment.id],
3537
hasDataToPush: false,
3638
},
3739
},
@@ -64,13 +66,15 @@ describe('usePostPushToService', () => {
6466
...basicPush,
6567
firstPushIndex: 1,
6668
lastPushIndex: 1,
69+
commentsToUpdate: [basicComment.id],
6770
hasDataToPush: true,
6871
},
6972
'456': {
7073
...basicPush,
7174
connectorId: '456',
7275
externalId: 'other_external_id',
7376
firstPushIndex: 4,
77+
commentsToUpdate: [basicComment.id],
7478
lastPushIndex: 6,
7579
hasDataToPush: false,
7680
},
@@ -127,6 +131,31 @@ describe('usePostPushToService', () => {
127131
await waitForNextUpdate();
128132
expect(spyOnPushToService).toBeCalledWith(
129133
samplePush.connectorId,
134+
formatServiceRequestData(basicCase, '123', sampleCaseServices as CaseServices),
135+
abortCtrl.signal
136+
);
137+
});
138+
});
139+
140+
it('calls pushToService with correct arguments when no push history', async () => {
141+
const samplePush2 = {
142+
caseId: pushedCase.id,
143+
caseServices: {},
144+
connectorName: 'connector name',
145+
connectorId: 'none',
146+
updateCase,
147+
};
148+
const spyOnPushToService = jest.spyOn(api, 'pushToService');
149+
150+
await act(async () => {
151+
const { result, waitForNextUpdate } = renderHook<string, UsePostPushToService>(() =>
152+
usePostPushToService()
153+
);
154+
await waitForNextUpdate();
155+
result.current.postPushToService(samplePush2);
156+
await waitForNextUpdate();
157+
expect(spyOnPushToService).toBeCalledWith(
158+
samplePush2.connectorId,
130159
formatServiceRequestData(basicCase, 'none', {}),
131160
abortCtrl.signal
132161
);

x-pack/plugins/siem/public/containers/case/use_post_push_to_service.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ export const formatServiceRequestData = (
163163
updatedAt,
164164
updatedBy,
165165
} = myCase;
166-
167166
const actualExternalService = caseServices[connectorId] ?? null;
168167

169168
return {

x-pack/plugins/siem/public/pages/case/components/use_push_to_service/index.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('usePushToService', () => {
3333
...basicPush,
3434
firstPushIndex: 0,
3535
lastPushIndex: 0,
36+
commentsToUpdate: [],
3637
hasDataToPush: true,
3738
},
3839
};

x-pack/plugins/siem/public/pages/case/components/user_action_tree/index.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ describe('UserActionTree ', () => {
8686
...basicPush,
8787
firstPushIndex: 0,
8888
lastPushIndex: 0,
89+
commentsToUpdate: [`${ourActions[ourActions.length - 1].commentId}`],
8990
hasDataToPush: true,
9091
},
9192
},
@@ -111,6 +112,7 @@ describe('UserActionTree ', () => {
111112
...basicPush,
112113
firstPushIndex: 0,
113114
lastPushIndex: 0,
115+
commentsToUpdate: [],
114116
hasDataToPush: false,
115117
},
116118
},

0 commit comments

Comments
 (0)