diff --git a/frontend/src/concepts/modelRegistry/apiHooks/__tests__/usePrefillDeployModalFromModelRegistry.spec.ts b/frontend/src/concepts/modelRegistry/apiHooks/__tests__/usePrefillDeployModalFromModelRegistry.spec.ts new file mode 100644 index 0000000000..aaf344654b --- /dev/null +++ b/frontend/src/concepts/modelRegistry/apiHooks/__tests__/usePrefillDeployModalFromModelRegistry.spec.ts @@ -0,0 +1,48 @@ +import { renderHook } from '@testing-library/react'; +import usePrefillDeployModalFromModelRegistry from '~/pages/modelRegistry/screens/RegisteredModels/usePrefillDeployModalFromModelRegistry'; +import { ProjectKind } from '~/k8sTypes'; +import { RegisteredModelDeployInfo } from '~/pages/modelRegistry/screens/RegisteredModels/useRegisteredModelDeployInfo'; +import { mockInferenceServiceModalData } from '~/__mocks__/mockInferenceServiceModalData'; +import { DataConnection } from '~/pages/projects/types'; + +describe('usePrefillDeployModalFromModelRegistry', () => { + const mockProjectContext = { + currentProject: { + apiVersion: 'v1', + kind: 'Project', + metadata: { + name: 'test-project', + namespace: 'test-namespace', + }, + } as ProjectKind, + dataConnections: [] as DataConnection[], + }; + + const data = mockInferenceServiceModalData({}); + + const mockSetCreateData = jest.fn(); + + const mockRegisteredModelDeployInfo: RegisteredModelDeployInfo = { + modelName: 'test-model', + modelArtifactUri: 's3://bucket/path', + modelArtifactStorageKey: 'test-key', + }; + + it('should ensure awsData array never has more than one element per key', () => { + renderHook(() => + usePrefillDeployModalFromModelRegistry( + mockProjectContext, + data, + mockSetCreateData, + mockRegisteredModelDeployInfo, + ), + ); + + const { awsData } = mockSetCreateData.mock.calls.find(([key]) => key === 'storage')[1]; + + const keys = awsData.map((item: { key: string }) => item.key); + const uniqueKeys = new Set(keys); + + expect(keys.length).toBe(uniqueKeys.size); + }); +}); diff --git a/frontend/src/pages/modelRegistry/screens/RegisteredModels/usePrefillDeployModalFromModelRegistry.ts b/frontend/src/pages/modelRegistry/screens/RegisteredModels/usePrefillDeployModalFromModelRegistry.ts index 22b6e757ea..5adcac3cc9 100644 --- a/frontend/src/pages/modelRegistry/screens/RegisteredModels/usePrefillDeployModalFromModelRegistry.ts +++ b/frontend/src/pages/modelRegistry/screens/RegisteredModels/usePrefillDeployModalFromModelRegistry.ts @@ -41,12 +41,18 @@ const usePrefillDeployModalFromModelRegistry = ( type: InferenceServiceStorageType.EXISTING_STORAGE, }); } else { + const prefilledKeys: (typeof EMPTY_AWS_SECRET_DATA)[number]['key'][] = [ + AwsKeys.NAME, + AwsKeys.AWS_S3_BUCKET, + AwsKeys.S3_ENDPOINT, + AwsKeys.DEFAULT_REGION, + ]; const prefilledAWSData = [ { key: AwsKeys.NAME, value: registeredModelDeployInfo.modelArtifactStorageKey || '' }, { key: AwsKeys.AWS_S3_BUCKET, value: storageFields.bucket }, { key: AwsKeys.S3_ENDPOINT, value: storageFields.endpoint }, { key: AwsKeys.DEFAULT_REGION, value: storageFields.region || '' }, - ...EMPTY_AWS_SECRET_DATA, + ...EMPTY_AWS_SECRET_DATA.filter((item) => !prefilledKeys.includes(item.key)), ]; if (recommendedDataConnections.length === 0) { setCreateData('storage', {