-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sorting on models page by Last Modified is reflecting changes in vers…
…ions as well (#3597) * working version * Remove not-needed * working version * fixed lint * fixed side effect for label * removed files * fixed rebase * fixing * addressed comments * filtering and fixes * cleanup * more comments * tests * added Jira issue in comment * added comment
- Loading branch information
1 parent
e91020a
commit d1c56d9
Showing
13 changed files
with
407 additions
and
47 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
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
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
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
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
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
127 changes: 127 additions & 0 deletions
127
frontend/src/concepts/modelRegistry/apiHooks/__tests__/updateTimestamps.test.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,127 @@ | ||
import { | ||
ModelRegistryAPIs, | ||
ModelState, | ||
ModelRegistryMetadataType, | ||
ModelVersion, | ||
RegisteredModel, | ||
} from '~/concepts/modelRegistry/types'; | ||
import { | ||
bumpModelVersionTimestamp, | ||
bumpRegisteredModelTimestamp, | ||
bumpBothTimestamps, | ||
} from '~/concepts/modelRegistry/utils/updateTimestamps'; | ||
|
||
describe('updateTimestamps', () => { | ||
const mockApi = jest.mocked<ModelRegistryAPIs>({ | ||
createRegisteredModel: jest.fn(), | ||
createModelVersion: jest.fn(), | ||
createModelVersionForRegisteredModel: jest.fn(), | ||
createModelArtifact: jest.fn(), | ||
createModelArtifactForModelVersion: jest.fn(), | ||
getRegisteredModel: jest.fn(), | ||
getModelVersion: jest.fn(), | ||
getModelArtifact: jest.fn(), | ||
listModelArtifacts: jest.fn(), | ||
listModelVersions: jest.fn(), | ||
listRegisteredModels: jest.fn(), | ||
getModelVersionsByRegisteredModel: jest.fn(), | ||
getModelArtifactsByModelVersion: jest.fn(), | ||
patchRegisteredModel: jest.fn(), | ||
patchModelVersion: jest.fn(), | ||
patchModelArtifact: jest.fn(), | ||
}); | ||
const fakeModelVersionId = 'test-model-version-id'; | ||
const fakeRegisteredModelId = 'test-registered-model-id'; | ||
|
||
beforeEach(() => { | ||
jest.spyOn(Date.prototype, 'toISOString').mockReturnValue('2024-01-01T00:00:00.000Z'); | ||
}); | ||
|
||
describe('bumpModelVersionTimestamp', () => { | ||
it('should successfully update model version timestamp', async () => { | ||
await bumpModelVersionTimestamp(mockApi, fakeModelVersionId); | ||
|
||
expect(mockApi.patchModelVersion).toHaveBeenCalledWith( | ||
{}, | ||
{ state: ModelState.LIVE }, | ||
fakeModelVersionId, | ||
); | ||
}); | ||
|
||
it('should throw error if modelVersionId is empty', async () => { | ||
await expect(bumpModelVersionTimestamp(mockApi, '')).rejects.toThrow( | ||
'Model version ID is required', | ||
); | ||
}); | ||
|
||
it('should handle API errors appropriately', async () => { | ||
const errorMessage = 'API Error'; | ||
// Use proper type for mock function | ||
const mockFn = mockApi.patchModelVersion; | ||
mockFn.mockRejectedValue(new Error(errorMessage)); | ||
|
||
await expect(bumpModelVersionTimestamp(mockApi, fakeModelVersionId)).rejects.toThrow( | ||
`Failed to update model version timestamp: ${errorMessage}`, | ||
); | ||
}); | ||
}); | ||
|
||
describe('bumpRegisteredModelTimestamp', () => { | ||
it('should successfully update registered model timestamp', async () => { | ||
await bumpRegisteredModelTimestamp(mockApi, fakeRegisteredModelId); | ||
|
||
expect(mockApi.patchRegisteredModel).toHaveBeenCalledWith( | ||
{}, | ||
{ | ||
state: ModelState.LIVE, | ||
customProperties: { | ||
_lastModified: { | ||
metadataType: ModelRegistryMetadataType.STRING, | ||
// eslint-disable-next-line camelcase | ||
string_value: '2024-01-01T00:00:00.000Z', | ||
}, | ||
}, | ||
}, | ||
fakeRegisteredModelId, | ||
); | ||
}); | ||
|
||
it('should throw error if registeredModelId is empty', async () => { | ||
await expect(bumpRegisteredModelTimestamp(mockApi, '')).rejects.toThrow( | ||
'Registered model ID is required', | ||
); | ||
}); | ||
|
||
it('should handle API errors appropriately', async () => { | ||
const errorMessage = 'API Error'; | ||
// Use proper type for mock function | ||
const mockFn = mockApi.patchRegisteredModel; | ||
mockFn.mockRejectedValue(new Error(errorMessage)); | ||
|
||
await expect(bumpRegisteredModelTimestamp(mockApi, fakeRegisteredModelId)).rejects.toThrow( | ||
`Failed to update registered model timestamp: ${errorMessage}`, | ||
); | ||
}); | ||
}); | ||
|
||
describe('bumpBothTimestamps', () => { | ||
it('should update both timestamps successfully', async () => { | ||
mockApi.patchModelVersion.mockResolvedValue({} as ModelVersion); | ||
mockApi.patchRegisteredModel.mockResolvedValue({} as RegisteredModel); | ||
|
||
await bumpBothTimestamps(mockApi, fakeModelVersionId, fakeRegisteredModelId); | ||
|
||
expect(mockApi.patchModelVersion).toHaveBeenCalled(); | ||
expect(mockApi.patchRegisteredModel).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should handle errors from either update', async () => { | ||
const errorMessage = 'API Error'; | ||
mockApi.patchModelVersion.mockRejectedValue(new Error(errorMessage)); | ||
|
||
await expect( | ||
bumpBothTimestamps(mockApi, fakeModelVersionId, fakeRegisteredModelId), | ||
).rejects.toThrow(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.