Skip to content

Commit

Permalink
feat(kms): add kms list test
Browse files Browse the repository at this point in the history
ref: MANAGER-15107

Signed-off-by: Romain Jamet <[email protected]>
  • Loading branch information
Romain Jamet committed Oct 10, 2024
1 parent 6edb862 commit 5746641
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 101 deletions.
9 changes: 6 additions & 3 deletions packages/manager/apps/key-management-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@ovh-ux/manager-core-api": "*",
"@ovh-ux/manager-core-utils": "*",
"@ovh-ux/manager-module-order": "^0.5.3",
"@ovh-ux/manager-react-components": "^1.36.0",
"@ovh-ux/manager-react-components": "*",
"@ovh-ux/manager-react-core-application": "*",
"@ovh-ux/manager-react-shell-client": "*",
"@ovh-ux/manager-tailwind-config": "*",
Expand All @@ -53,9 +53,12 @@
"@playwright/test": "^1.34.3",
"@tanstack/react-query-devtools": "^5.51.21",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^14.1.2",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^4.3.2",
"element-internals-polyfill": "^1.3.11",
"msw": "2.1.7",
"typescript": "^5.1.6",
"vite": "^5.2.13",
"vitest": "^1.2.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {
ActionMenu,
DataGridClipboardCell,
Clipboard,
DataGridTextCell,
Links,
} from '@ovh-ux/manager-react-components';
Expand All @@ -26,7 +26,7 @@ import { useKMSServiceInfos } from '@/data/hooks/useKMSServiceInfos';
import { OkmsServiceState } from '../layout-helpers/Dashboard/okmsServiceState/OkmsServiceState.component';

export const DatagridCellId = (props: OKMS | OkmsAllServiceKeys) => {
return <DataGridClipboardCell text={props.id} />;
return <Clipboard value={props.id} />;
};

export const DatagridCellName = (props: OKMS) => {
Expand Down Expand Up @@ -97,7 +97,7 @@ export const DatagridServiceKeyCellName = (props: OkmsAllServiceKeys) => {
};

export const DatagridServiceKeyCellId = (props: OkmsAllServiceKeys) => {
return <DataGridClipboardCell text={props.id} />;
return <Clipboard value={props.id} />;
};

export const DatagridCellType = (props: OkmsAllServiceKeys) => {
Expand Down
14 changes: 0 additions & 14 deletions packages/manager/apps/key-management-service/src/data/api/okms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,6 @@ export const getListingIcebergV2 = async ({
}
};

/**
* Get okms listing with iceberg V2
*/
export const getListingIceberg = async () => {
try {
const List = await fetchIcebergV2({
route: '/okms/resource',
});
return List.data as OKMS[];
} catch (error) {
return null;
}
};

export const getOkmsResourceQueryKey = (okmsId: string) => [
`get/okms/resource/${okmsId}`,
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useQuery } from '@tanstack/react-query';
import apiClient from '@ovh-ux/manager-core-api';
import { useResourcesIcebergV2 } from '@ovh-ux/manager-react-components';

import { OKMS, OKMSOptions } from '@/types/okms.type';
import { OKMS } from '@/types/okms.type';
import { ErrorResponse } from '@/types/api.type';
import {
getListingIceberg,
getOkmsResourceQueryKey,
getOkmsServicesResourceListQueryKey,
sortOKMS,
} from '../api/okms';

export const getOKMSResource = async (
Expand All @@ -16,18 +15,6 @@ export const getOKMSResource = async (
return apiClient.v2.get(`okms/resource/${okmsId}`);
};

export const useAllOKMS = () => {
return useQuery({
queryKey: getOkmsServicesResourceListQueryKey,
queryFn: () => getListingIceberg(),
retry: false,
...{
keepPreviousData: true,
},
refetchInterval: 5000,
});
};

export const useOKMSById = (okmsId: string) => {
return useQuery<{ data: OKMS }, ErrorResponse>({
queryKey: getOkmsResourceQueryKey(okmsId),
Expand All @@ -40,17 +27,9 @@ export const useOKMSById = (okmsId: string) => {
});
};

export const useOKMS = ({ sorting }: OKMSOptions) => {
// retrieve All OKMS from API
const {
data: okms,
error: allOKMSError,
isLoading: allOKMSLoading,
} = useAllOKMS();

return {
isLoading: allOKMSLoading,
error: allOKMSError,
data: sortOKMS(okms || [], sorting),
};
};
export const useOKMSList = ({ pageSize }: { pageSize?: number }) =>
useResourcesIcebergV2<OKMS>({
route: '/okms/resource',
queryKey: getOkmsServicesResourceListQueryKey,
pageSize,
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { describe, expect, it, test } from 'vitest';
import { describe, expect, it, test, vi } from 'vitest';
import { OkmsServiceKeyOperations } from '@/types/okmsServiceKey.type';
import { useServiceKeyOperationsTranslations } from './useServiceKeyOperationsTranslations';

vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (translationKey: string) => translationKey,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}),
}));

describe('get service key operations translation ', () => {
const useCases: {
operation: OkmsServiceKeyOperations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { describe, expect, it, test } from 'vitest';
import { describe, expect, it, test, vi } from 'vitest';
import { OkmsKeyTypes } from '@/types/okmsServiceKey.type';
import { useServiceKeyTypeTranslations } from './useServiceKeyTypeTranslations';

vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (translationKey: string) => translationKey,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}),
}));

describe('get service key type translation ', () => {
const useCases: {
type: OkmsKeyTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { PathParams } from 'msw';
import { Handler } from '../../../../../../playwright-helpers';
import { OKMS } from '@/types/okms.type';

export const okmsList: OKMS[] = [
{
iam: {
displayName: 'kms-1',
id: '1b4e7c8e-d1b8-4b46-a584-52c8b4b0225c',
urn: `urn:v1:eu:resource:okms:1b4e7c8e-d1b8-4b46-a584-52c8b4b0225c`,
},
id: '7f3a82ac-a8d8-4c2a-ab0c-f6e86ddf6a7c',
kmipEndpoint: 'eu-west-rbx.okms.ovh.net:1234',
region: 'EU_WEST_RBX',
restEndpoint: 'https://eu-west-rbx.okms.ovh.net',
swaggerEndpoint: '"https://swagger-eu-west-rbx.okms.ovh.net',
},
];

export type GetOkmsMocksParams = {
nbOkms?: number;
};

const findOkmsById = (params: PathParams) =>
okmsList.find(({ id }) => id === params.id);

export const getOkmsMocks = ({
nbOkms = okmsList.length,
}: GetOkmsMocksParams): Handler[] => [
{
url: '/okms/resource/:id',
response: (_: unknown, params: PathParams) => findOkmsById(params),
status: 200,
api: 'v2',
},
{
url: '/okms/resource',
response: okmsList.slice(0, nbOkms),
status: 200,
api: 'v2',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { KMSServiceInfos, OkmsState } from '@/types/okmsService.type';
import { Handler } from '../../../../../../playwright-helpers';

const serviceList: KMSServiceInfos[] = [
{
billing: {
lifecycle: { current: { creationDate: '2024-04-12T18:00:00.000Z' } },
nextBillingDate: '2024-05-12T18:00:00.000Z',
},
customer: { contacts: [{ customerCode: 'code', type: 'type' }] },
resource: {
displayName: 'name',
name: 'name',
product: { name: 'name', description: 'descripton' },
resellingProvider: 'test',
state: OkmsState.Active,
},
},
];

export const getServicesMocks = (): Handler[] => [
{
url: '/services/:id',
response: serviceList[0],
status: 200,
method: 'get',
api: 'v6',
},
{
url: '/services',
response: () => [1234567890],
status: 200,
method: 'get',
api: 'v6',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { act, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderTestApp } from '@/utils/tests/renderTestApp';
import '@testing-library/jest-dom';
import { labels } from '@/utils/tests/init.i18n';
import { okmsList } from '@/mocks/okms.mock';

describe('KMS listing test suite', () => {
it('should redirect to the onboarding page when the kms list is empty', async () => {
await renderTestApp({ nbOkms: 0 });

expect(screen.getByText(labels.onboarding.title)).toBeVisible();

expect(
screen.queryByText(labels.listing.key_management_service_listing_title),
).not.toBeInTheDocument();
});

it('should display the kms listing page', async () => {
await renderTestApp();

expect(
screen.getByText(labels.listing.key_management_service_listing_title),
).toBeVisible();

expect(
screen.queryByText(labels.onboarding.description),
).not.toBeInTheDocument();
});

it(`should navigate to the kms creation form on click on "${labels.listing.key_management_service_listing_add_kms_button}" button`, async () => {
await renderTestApp();

await waitFor(
() =>
expect(
screen.getByText(
labels.listing.key_management_service_listing_add_kms_button,
),
).toBeEnabled(),
{
timeout: 30_000,
},
);

await act(() =>
userEvent.click(
screen.getByText(
labels.listing.key_management_service_listing_add_kms_button,
),
),
);

await waitFor(
() =>
expect(
screen.getByText(
labels.create.key_management_service_create_subtitle,
),
).toBeVisible(),
{ timeout: 30_000 },
);
});

it('should navigate to a kms dashboard on click on kms name', async () => {
await renderTestApp();

await act(() =>
userEvent.click(screen.getByText(okmsList[0].iam.displayName)),
);

await waitFor(
() =>
expect(
screen.getByText(labels.dashboard.general_informations),
).toBeVisible(),
{ timeout: 30_000 },
);
});

it(`should navigate to the kms delete modal on click on "${labels.listing.key_management_service_listing_terminate}" list action button`, async () => {
await renderTestApp();

await act(() =>
userEvent.click(
screen.getByText(
labels.listing.key_management_service_listing_terminate,
),
),
);

await waitFor(
() =>
expect(
screen.getByText(
labels.terminate.key_management_service_terminate_cancel,
),
).toBeVisible(),
{ timeout: 30_000 },
);
});
});
Loading

0 comments on commit 5746641

Please sign in to comment.