From 5079f05e63da562359cc84dc333cd8dc93fa46bc Mon Sep 17 00:00:00 2001 From: lucferbux Date: Fri, 13 Dec 2024 01:09:22 +0100 Subject: [PATCH] Fix tests Signed-off-by: lucferbux --- .../ui/frontend/src/__mocks__/mockUserSettings.ts | 14 ++++++++++++++ .../cypress/cypress/support/commands/api.ts | 6 ++++++ .../src/__tests__/cypress/cypress/support/e2e.ts | 12 ++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 clients/ui/frontend/src/__mocks__/mockUserSettings.ts diff --git a/clients/ui/frontend/src/__mocks__/mockUserSettings.ts b/clients/ui/frontend/src/__mocks__/mockUserSettings.ts new file mode 100644 index 00000000..926b0c0f --- /dev/null +++ b/clients/ui/frontend/src/__mocks__/mockUserSettings.ts @@ -0,0 +1,14 @@ +import { UserSettings } from '~/shared/types'; + +type MockUserSettingsType = { + userId?: string; + clusterAdmin?: boolean; +}; + +export const mockUserSettings = ({ + userId = 'user@example.com', + clusterAdmin = true, +}: MockUserSettingsType): UserSettings => ({ + userId, + clusterAdmin, +}); diff --git a/clients/ui/frontend/src/__tests__/cypress/cypress/support/commands/api.ts b/clients/ui/frontend/src/__tests__/cypress/cypress/support/commands/api.ts index 08423f51..54cbb27e 100644 --- a/clients/ui/frontend/src/__tests__/cypress/cypress/support/commands/api.ts +++ b/clients/ui/frontend/src/__tests__/cypress/cypress/support/commands/api.ts @@ -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 }; @@ -102,6 +103,11 @@ declare global { type: 'GET /api/:apiVersion/model_registry', options: { path: { apiVersion: string } }, response: ApiResponse, + ) => Cypress.Chainable) & + (( + type: 'GET /api/:apiVersion/user', + options: { path: { apiVersion: string } }, + response: ApiResponse, ) => Cypress.Chainable); } } diff --git a/clients/ui/frontend/src/__tests__/cypress/cypress/support/e2e.ts b/clients/ui/frontend/src/__tests__/cypress/cypress/support/e2e.ts index 4a6016e9..5b196a70 100644 --- a/clients/ui/frontend/src/__tests__/cypress/cypress/support/e2e.ts +++ b/clients/ui/frontend/src/__tests__/cypress/cypress/support/e2e.ts @@ -15,8 +15,10 @@ import chaiSubset from 'chai-subset'; import '@cypress/code-coverage/support'; +import { mockUserSettings } from '~/__mocks__/mockUserSettings'; import 'cypress-mochawesome-reporter/register'; import './commands'; +import { MODEL_REGISTRY_API_VERSION } from './commands/api'; chai.use(chaiSubset); @@ -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({}), + ); } });