Skip to content

Commit

Permalink
Fix started notebooks disappear issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ppadti committed Jul 11, 2024
1 parent 8a4261f commit e9cd53f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/src/routes/api/status/adminAllowedUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const getUserActivityFromNotebook = async (
.map<[string | undefined, string | undefined]>((notebook) => [
notebook.metadata.annotations?.['opendatahub.io/username'],
notebook.metadata.annotations?.['notebooks.kubeflow.org/last-activity'] ||
notebook.metadata.annotations?.['kubeflow-resource-stopped'],
notebook.metadata.annotations?.['kubeflow-resource-stopped'] ||
'Now',
])
.filter(
(arr): arr is [string, string] =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { testHook } from '~/__tests__/unit/testUtils/hooks';
import { getAllowedUsers } from '~/redux/actions/actions';
import { mockAllowedUsers } from '~/__mocks__/mockAllowedUsers';
import useCheckForAllowedUsers from '~/pages/notebookController/screens/admin/useCheckForAllowedUsers';
import { AllowedUser } from '~/pages/notebookController/screens/admin/types';

jest.mock('~/redux/actions/actions', () => ({
getAllowedUsers: jest.fn(),
}));

jest.mock('~/pages/notebookController/useNamespaces', () => () => ({
notebookNamespace: 'test-project',
dashboardNamespace: 'opendatahub',
}));

const getAllowedUsersMock = jest.mocked(getAllowedUsers);

describe('useCheckForAllowedUsers', () => {
it('should return list of users', async () => {
const mockAllowedUser: AllowedUser = mockAllowedUsers({});
getAllowedUsersMock.mockResolvedValue([mockAllowedUser]);
const renderResult = testHook(useCheckForAllowedUsers)();

expect(getAllowedUsersMock).toHaveBeenCalledTimes(1);
expect(renderResult).hookToStrictEqual([[], false, undefined]);
expect(renderResult).hookToHaveUpdateCount(1);

await renderResult.waitForNextUpdate();
expect(getAllowedUsersMock).toHaveBeenCalledTimes(1);
expect(renderResult).hookToStrictEqual([[mockAllowedUser], true, undefined]);
expect(renderResult).hookToHaveUpdateCount(2);
});

it('should handle error', async () => {
const error = (message: string) => ({
response: {
data: {
message,
},
},
});
getAllowedUsersMock.mockRejectedValue(error('error1'));
const renderResult = testHook(useCheckForAllowedUsers)();

expect(getAllowedUsersMock).toHaveBeenCalledTimes(1);
expect(renderResult).hookToStrictEqual([[], false, undefined]);
expect(renderResult).hookToHaveUpdateCount(1);

await renderResult.waitForNextUpdate();
expect(getAllowedUsersMock).toHaveBeenCalledTimes(1);
expect(renderResult).hookToStrictEqual([[], false, new Error('error1')]);
expect(renderResult).hookToHaveUpdateCount(2);
});
});

0 comments on commit e9cd53f

Please sign in to comment.