Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI - Model Registry API spec #350

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions clients/ui/frontend/src/__mocks__/mockRegisteredModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ModelState, RegisteredModel } from '~/app/types';
import { createModelRegistryLabelsObject } from './utils';

type MockRegisteredModelType = {
id?: string;
name?: string;
owner?: string;
state?: ModelState;
description?: string;
labels?: string[];
};

export const mockRegisteredModel = ({
name = 'test',
owner = 'Author 1',
state = ModelState.LIVE,
description = '',
labels = [],
id = '1',
}: MockRegisteredModelType): RegisteredModel => ({
createTimeSinceEpoch: '1710404288975',
description,
externalID: '1234132asdfasdf',
id,
lastUpdateTimeSinceEpoch: '1710404288975',
name,
state,
owner,
customProperties: createModelRegistryLabelsObject(labels),
});
13 changes: 13 additions & 0 deletions clients/ui/frontend/src/__mocks__/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ModelRegistryMetadataType, ModelRegistryStringCustomProperties } from '~/app/types';

export const createModelRegistryLabelsObject = (
labels: string[],
): ModelRegistryStringCustomProperties =>
labels.reduce((acc, label) => {
acc[label] = {
metadataType: ModelRegistryMetadataType.STRING,
// eslint-disable-next-line camelcase
string_value: '',
};
return acc;
}, {} as ModelRegistryStringCustomProperties);
33 changes: 33 additions & 0 deletions clients/ui/frontend/src/app/api/__tests__/errorUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { NotReadyError } from '~/utilities/useFetchState';
import { APIError } from '~/types';
import { handleRestFailures } from '~/app/api/errorUtils';
import { mockRegisteredModel } from '~/__mocks__/mockRegisteredModel';

describe('handleRestFailures', () => {
it('should successfully return registered models', async () => {
const modelRegistryMock = mockRegisteredModel({});
const result = await handleRestFailures(Promise.resolve(modelRegistryMock));
expect(result).toStrictEqual(modelRegistryMock);
});

it('should handle and throw model registry errors', async () => {
const statusMock: APIError = {
code: '',
message: 'error',
};

await expect(handleRestFailures(Promise.resolve(statusMock))).rejects.toThrow('error');
});

it('should handle common state errors ', async () => {
await expect(handleRestFailures(Promise.reject(new NotReadyError('error')))).rejects.toThrow(
'error',
);
});

it('should handle other errors', async () => {
await expect(handleRestFailures(Promise.reject(new Error('error')))).rejects.toThrow(
'Error communicating with server',
);
});
});
Loading
Loading