Skip to content

Commit

Permalink
Add API module with the current bff calls
Browse files Browse the repository at this point in the history
Signed-off-by: lucferbux <[email protected]>
  • Loading branch information
lucferbux committed Sep 5, 2024
1 parent 556fa16 commit 52535c5
Show file tree
Hide file tree
Showing 18 changed files with 1,556 additions and 7 deletions.
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

0 comments on commit 52535c5

Please sign in to comment.