Skip to content

Commit

Permalink
[Cloud Security] Fix auto increment issue on the integrations page (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
opauloh committed Jul 6, 2023
1 parent 8a17024 commit 2c01f7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Expand Up @@ -42,13 +42,22 @@ jest.mock('../../common/api/use_package_policy_list');

const onChange = jest.fn();

const createReactQueryResponseWithRefetch = (
data: Parameters<typeof createReactQueryResponse>[0]
) => {
return {
...createReactQueryResponse(data),
refetch: jest.fn(),
};
};

describe('<CspPolicyTemplateForm />', () => {
beforeEach(() => {
(useParams as jest.Mock).mockReturnValue({
integration: undefined,
});
(usePackagePolicyList as jest.Mock).mockImplementation((packageName) =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
items: [],
Expand All @@ -57,7 +66,7 @@ describe('<CspPolicyTemplateForm />', () => {
);
onChange.mockClear();
(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: { status: 'indexed', installedPackageVersion: '1.2.13' },
})
Expand Down Expand Up @@ -240,7 +249,7 @@ describe('<CspPolicyTemplateForm />', () => {
});

(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
kspm: { status: 'not-deployed', healthyAgents: 0, installedPackagePolicies: 1 },
Expand All @@ -249,7 +258,7 @@ describe('<CspPolicyTemplateForm />', () => {
);

(usePackagePolicyList as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
items: [
Expand Down Expand Up @@ -329,15 +338,15 @@ describe('<CspPolicyTemplateForm />', () => {
integration: 'vuln_mgmt',
});
(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
vuln_mgmt: { status: 'not-deployed', healthyAgents: 0, installedPackagePolicies: 1 },
},
})
);
(usePackagePolicyList as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
items: [
Expand Down Expand Up @@ -419,15 +428,15 @@ describe('<CspPolicyTemplateForm />', () => {
});

(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
cspm: { status: 'not-deployed', healthyAgents: 0, installedPackagePolicies: 1 },
},
})
);
(usePackagePolicyList as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
items: [
Expand Down
Expand Up @@ -136,7 +136,7 @@ export const CspPolicyTemplateForm = memo<PackagePolicyReplaceDefineStepExtensio
setTimeout(() => setIsLoading(false), 200);
}, [validationResultsNonNullFields]);

const { data: packagePolicyList } = usePackagePolicyList(packageInfo.name, {
const { data: packagePolicyList, refetch } = usePackagePolicyList(packageInfo.name, {
enabled: canFetchIntegration,
});

Expand All @@ -148,6 +148,7 @@ export const CspPolicyTemplateForm = memo<PackagePolicyReplaceDefineStepExtensio
// Required for mount only to ensure a single input type is selected
// This will remove errors in validationResults.vars
setEnabledPolicyInput(DEFAULT_INPUT_TYPE[input.policy_template]);
refetch();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoading, input.policy_template, isEditPage]);

Expand Down

0 comments on commit 2c01f7e

Please sign in to comment.