Skip to content

Commit

Permalink
Merge branch 'main' into 146996-flaky-test-edit-field
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta authored Dec 5, 2022
2 parents db66470 + 035ebc4 commit f8a2d6c
Show file tree
Hide file tree
Showing 42 changed files with 801 additions and 312 deletions.
223 changes: 119 additions & 104 deletions x-pack/plugins/actions/server/create_execute_function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,24 +605,27 @@ describe('bulkExecute()', () => {
]
`);
expect(savedObjectsClient.bulkGet).toHaveBeenCalledWith([{ id: '123', type: 'action' }]);
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith([
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
},
references: [
{
id: '123',
name: 'actionRef',
type: 'action',
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith(
[
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
},
],
},
]);
references: [
{
id: '123',
name: 'actionRef',
type: 'action',
},
],
},
],
{ refresh: false }
);
expect(actionTypeRegistry.isActionExecutable).toHaveBeenCalledWith('123', 'mock-action', {
notifyUsage: true,
});
Expand Down Expand Up @@ -691,25 +694,28 @@ describe('bulkExecute()', () => {
]
`);
expect(savedObjectsClient.bulkGet).toHaveBeenCalledWith([{ id: '123', type: 'action' }]);
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith([
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
executionId: '123abc',
consumer: 'test-consumer',
apiKey: Buffer.from('123:abc').toString('base64'),
},
references: [
{
id: '123',
name: 'actionRef',
type: 'action',
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith(
[
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
executionId: '123abc',
consumer: 'test-consumer',
apiKey: Buffer.from('123:abc').toString('base64'),
},
],
},
]);
references: [
{
id: '123',
name: 'actionRef',
type: 'action',
},
],
},
],
{ refresh: false }
);
expect(actionTypeRegistry.isActionExecutable).toHaveBeenCalledWith('123', 'mock-action', {
notifyUsage: true,
});
Expand Down Expand Up @@ -763,37 +769,40 @@ describe('bulkExecute()', () => {
],
},
]);
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith([
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
relatedSavedObjects: [
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith(
[
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
relatedSavedObjects: [
{
id: 'related_some-type_0',
namespace: 'some-namespace',
type: 'some-type',
typeId: 'some-typeId',
},
],
},
references: [
{
id: 'related_some-type_0',
namespace: 'some-namespace',
id: '123',
name: 'actionRef',
type: 'action',
},
{
id: 'some-id',
name: 'related_some-type_0',
type: 'some-type',
typeId: 'some-typeId',
},
],
},
references: [
{
id: '123',
name: 'actionRef',
type: 'action',
},
{
id: 'some-id',
name: 'related_some-type_0',
type: 'some-type',
},
],
},
]);
],
{ refresh: false }
);
});

test('schedules the action with all given parameters with a preconfigured action', async () => {
Expand Down Expand Up @@ -868,24 +877,27 @@ describe('bulkExecute()', () => {
]
`);
expect(savedObjectsClient.get).not.toHaveBeenCalled();
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith([
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
},
references: [
{
id: source.id,
name: 'source',
type: source.type,
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith(
[
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
},
],
},
]);
references: [
{
id: source.id,
name: 'source',
type: source.type,
},
],
},
],
{ refresh: false }
);
});

test('schedules the action with all given parameters with a preconfigured action and relatedSavedObjects', async () => {
Expand Down Expand Up @@ -968,37 +980,40 @@ describe('bulkExecute()', () => {
]
`);
expect(savedObjectsClient.get).not.toHaveBeenCalled();
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith([
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
relatedSavedObjects: [
expect(savedObjectsClient.bulkCreate).toHaveBeenCalledWith(
[
{
type: 'action_task_params',
attributes: {
actionId: '123',
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
relatedSavedObjects: [
{
id: 'related_some-type_0',
namespace: 'some-namespace',
type: 'some-type',
typeId: 'some-typeId',
},
],
},
references: [
{
id: 'related_some-type_0',
namespace: 'some-namespace',
id: source.id,
name: 'source',
type: source.type,
},
{
id: 'some-id',
name: 'related_some-type_0',
type: 'some-type',
typeId: 'some-typeId',
},
],
},
references: [
{
id: source.id,
name: 'source',
type: source.type,
},
{
id: 'some-id',
name: 'related_some-type_0',
type: 'some-type',
},
],
},
]);
],
{ refresh: false }
);
});

test('throws when passing isESOCanEncrypt with false as a value', async () => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/actions/server/create_execute_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export function createBulkExecutionEnqueuerFunction({
};
});
const actionTaskParamsRecords: SavedObjectsBulkResponse<ActionTaskParams> =
await unsecuredSavedObjectsClient.bulkCreate(actions);
await unsecuredSavedObjectsClient.bulkCreate(actions, { refresh: false });
const taskInstances = actionTaskParamsRecords.saved_objects.map((so) => {
const actionId = so.attributes.actionId;
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) {
path: { serviceName },
query,
}),
append: <BetaBadge icon="editorBold" />,
append: <BetaBadge icon="beta" />,
label: i18n.translate('xpack.apm.home.infraTabLabel', {
defaultMessage: 'Infrastructure',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function DependencyDetailTemplate({ children }: Props) {
isSelected:
path === '/dependencies/operations' ||
path === '/dependencies/operation',
append: <BetaBadge />,
append: <BetaBadge icon="beta" />,
},
]
: [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('use cases add to existing case modal hook', () => {
const defaultParams = () => {
return { onRowClick: jest.fn() };
};

beforeEach(() => {
appMockRender = createAppMockRenderer();
dispatch.mockReset();
Expand Down Expand Up @@ -166,7 +167,7 @@ describe('use cases add to existing case modal hook', () => {
expect(mockedToastSuccess).toHaveBeenCalled();
});

it('should not call createAttachments nor show toast success when a case is not selected', async () => {
it('should not call createAttachments nor show toast success when a case is not selected', async () => {
const mockBulkCreateAttachments = jest.fn();
useCreateAttachmentsMock.mockReturnValueOnce({
createAttachments: mockBulkCreateAttachments,
Expand All @@ -178,11 +179,11 @@ describe('use cases add to existing case modal hook', () => {
});

AllCasesSelectorModalMock.mockImplementation(({ onRowClick }) => {
onRowClick();
return null;
});

const result = appMockRender.render(<TestComponent />);

userEvent.click(result.getByTestId('open-modal'));
// give a small delay for the reducer to run

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const useCasesAddToExistingCaseModal = (props: AddToExistingFlyoutProps =
},
[closeModal, dispatch, handleOnRowClick, props]
);

return {
open: openModal,
close: closeModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { useCallback, useRef, useState } from 'react';
import { useCallback, useRef, useState, useEffect } from 'react';
import { useLocation, useHistory } from 'react-router-dom';
import { isEqual } from 'lodash';

Expand Down Expand Up @@ -121,10 +121,12 @@ export function useAllCasesQueryParams(isModalView: boolean = false) {
]
);

if (isFirstRenderRef.current) {
persistAndUpdateQueryParams(isModalView ? DEFAULT_QUERY_PARAMS : {});
isFirstRenderRef.current = false;
}
useEffect(() => {
if (isFirstRenderRef.current) {
persistAndUpdateQueryParams(isModalView ? DEFAULT_QUERY_PARAMS : {});
isFirstRenderRef.current = false;
}
}, [isModalView, persistAndUpdateQueryParams]);

return {
queryParams,
Expand Down
Loading

0 comments on commit f8a2d6c

Please sign in to comment.