-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API module with the current bff calls
Signed-off-by: lucferbux <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,556 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
clients/ui/frontend/src/app/api/__tests__/errorUtils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
); | ||
}); | ||
}); |
Oops, something went wrong.