Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: lucferbux <[email protected]>
  • Loading branch information
lucferbux committed Dec 13, 2024
1 parent 8c54dde commit e820f42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions clients/ui/frontend/src/__mocks__/mockUserSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { UserSettings } from '~/shared/types';

type MockUserSettingsType = {
userId?: string;
clusterAdmin?: boolean;
};

export const mockUserSettings = ({
userId = '[email protected]',
clusterAdmin = true,
}: MockUserSettingsType): UserSettings => ({
userId,
clusterAdmin,
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
RegisteredModel,
RegisteredModelList,
} from '~/app/types';
import type { UserSettings } from '~/shared/types';

const MODEL_REGISTRY_API_VERSION = 'v1';
export { MODEL_REGISTRY_API_VERSION };
Expand Down Expand Up @@ -102,6 +103,11 @@ declare global {
type: 'GET /api/:apiVersion/model_registry',
options: { path: { apiVersion: string } },
response: ApiResponse<ModelRegistry[]>,
) => Cypress.Chainable<null>) &
((
type: 'GET /api/:apiVersion/user',
options: { path: { apiVersion: string } },
response: ApiResponse<UserSettings>,
) => Cypress.Chainable<null>);
}
}
Expand Down
12 changes: 12 additions & 0 deletions clients/ui/frontend/src/__tests__/cypress/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import chaiSubset from 'chai-subset';
import '@cypress/code-coverage/support';
import 'cypress-mochawesome-reporter/register';
import './commands';
import { MODEL_REGISTRY_API_VERSION } from './commands/api';
import { mockUserSettings } from '~/__mocks__/mockUserSettings';

Check failure on line 21 in clients/ui/frontend/src/__tests__/cypress/cypress/support/e2e.ts

View workflow job for this annotation

GitHub Actions / test-and-build

`~/__mocks__/mockUserSettings` import should occur before import of `./commands/api`

chai.use(chaiSubset);

Expand All @@ -28,5 +30,15 @@ beforeEach(() => {
if (Cypress.env('MOCK')) {
// fallback: return 404 for all api requests
cy.intercept({ pathname: '/api/**' }, { statusCode: 404 });

cy.interceptApi(
'GET /api/:apiVersion/user',
{
path: {
apiVersion: MODEL_REGISTRY_API_VERSION,
},
},
mockUserSettings({}),
);
}
});

0 comments on commit e820f42

Please sign in to comment.