Skip to content

Commit

Permalink
Separate upgrade service in two services
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianogorza committed Mar 19, 2024
1 parent 8c307d3 commit fd6584e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { removeAgentsFromGroupService } from './remove-agents-from-group';
export { addAgentToGroupService } from './add-agent-to-group';
export { addAgentsToGroupService } from './add-agents-to-group';
export { getGroupsService } from './get-groups';
export { upgradeAgentService } from './upgrade-agent';
export { upgradeAgentsService } from './upgrade-agents';
export { getOutdatedAgents } from './get-outdated-agents';
export { getTasks } from './get-tasks';
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const paginatedAgentsRequestService = async ({
agentIds: string[];
groupId?: string;
pageSize?: number;
}): Promise<IApiResponse<string>> => {
}): Promise<IApiResponse<any>> => {
let offset = 0;
let requestAgentIds: string[] = [];
let allAffectedItems: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import IApiResponse from '../../../react-services/interfaces/api-response.interface';
import { WzRequest } from '../../../react-services/wz-request';
import { ResponseUpgradeAgents } from '../types';

export const upgradeAgentService = async (agentId: string) =>
(await WzRequest.apiReq('PUT', '/agents/upgrade', {
params: {
agents_list: agentId,
wait_for_complete: true,
},
})) as IApiResponse<ResponseUpgradeAgents>;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import IApiResponse from '../../../react-services/interfaces/api-response.interface';
import { WzRequest } from '../../../react-services/wz-request';
import { ResponseUpgradeAgents } from '../types';
import { paginatedAgentsRequestService } from './paginated-agents-request';

Expand All @@ -8,15 +7,8 @@ export const upgradeAgentsService = async ({
}: {
agentIds: string[];
}) =>
(agentIds.length === 1
? await WzRequest.apiReq('PUT', '/agents/upgrade', {
params: {
agents_list: agentIds.join(','),
wait_for_complete: true,
},
})
: await paginatedAgentsRequestService({
method: 'PUT',
url: '/agents/upgrade',
agentIds,
})) as IApiResponse<ResponseUpgradeAgents>;
(await paginatedAgentsRequestService({
method: 'PUT',
url: '/agents/upgrade',
agentIds,
})) as IApiResponse<ResponseUpgradeAgents>;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { render, fireEvent, waitFor, act } from '@testing-library/react';
import { render, fireEvent, act } from '@testing-library/react';
import '@testing-library/jest-dom';
import { UpgradeAgentModal } from './upgrade-agent-modal';

jest.mock('../../services', () => ({
upgradeAgentsService: jest.fn(),
upgradeAgentService: jest.fn(),
}));

jest.mock('../../../../react-services/common-services', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { withErrorBoundary, withReduxProvider } from '../../../common/hocs';
import { UI_LOGGER_LEVELS } from '../../../../../common/constants';
import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrator/types';
import { getErrorOrchestrator } from '../../../../react-services/common-services';
import { upgradeAgentsService } from '../../services';
import { upgradeAgentService } from '../../services';
import { Agent } from '../../types';
import { getToasts } from '../../../../kibana-services';

Expand Down Expand Up @@ -45,7 +45,7 @@ export const UpgradeAgentModal = compose(
setIsLoading(true);

try {
await upgradeAgentsService({ agentIds: [agent.id] });
await upgradeAgentService(agent.id);
showToast('success', 'Upgrade agent', 'Upgrade task in progress');
reloadAgents();
setIsUpgradePanelClosed(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { UI_ERROR_SEVERITIES } from '../../../../../react-services/error-orchest
import { getErrorOrchestrator } from '../../../../../react-services/common-services';
import { getAgentsService, upgradeAgentsService } from '../../../services';
import { Agent, ResponseUpgradeAgents } from '../../../types';
import { ErrorAgent } from '../../../services/paginated-agents-group';
import { UpgradeAgentsModalResult } from './result';
import { ErrorAgent } from '../../../services/paginated-agents-request';

export type Result = {
successAgents?: ResponseUpgradeAgents[];
Expand Down

0 comments on commit fd6584e

Please sign in to comment.