diff --git a/backend/src/types/types.ts b/backend/src/types/types.ts index bd7125bd5..7fcb4196a 100644 --- a/backend/src/types/types.ts +++ b/backend/src/types/types.ts @@ -1,3 +1,9 @@ +export type PartialDeep = T extends object + ? { + [P in keyof T]?: PartialDeep + } + : T + export const RoleKind = { ENTRY: 'entry', SCHEMA: 'schema', diff --git a/backend/src/utils/__mocks__/config.ts b/backend/src/utils/__mocks__/config.ts index 1d8daf572..57dfdc45c 100644 --- a/backend/src/utils/__mocks__/config.ts +++ b/backend/src/utils/__mocks__/config.ts @@ -1,10 +1,22 @@ -const config = { +import { PartialDeep } from '../../types/types.js' +import { Config } from '../config.js' + +const config: PartialDeep = { app: { protocol: '', host: '', port: 3000, }, s3: { + credentials: { + accessKeyId: '', + secretAccessKey: '', + }, + endpoint: 'http://minio:9000', + region: 'ignored', + forcePathStyle: true, + rejectUnauthorized: true, + automaticallyCreateBuckets: true, buckets: { uploads: 'uploads', registry: 'registry', @@ -35,6 +47,43 @@ const config = { instrumentation: { enabled: false, }, + session: { + secret: '', + }, + oauth: { + provider: 'cognito', + grant: { + defaults: { + origin: '', + prefix: 'api/connect', + transport: 'session', + }, + cognito: { + key: '', + secret: '', + dynamic: ['scope'], + response: ['tokens', 'raw', 'jwt'], + callback: '/', + subdomain: '', + }, + }, + cognito: { + identityProviderClient: { + region: 'eu-west-1', + credentials: { + accessKeyId: '', + secretAccessKey: '', + }, + }, + userPoolId: '', + userIdAttribute: '', + }, + }, + mongo: { + uri: 'mongodb://localhost:27017/bailo?directConnection=true', + user: undefined, + pass: undefined, + }, ui: { inference: { enabled: true, diff --git a/backend/src/utils/test/testUtils.ts b/backend/src/utils/test/testUtils.ts index dceaf7895..291f8960c 100644 --- a/backend/src/utils/test/testUtils.ts +++ b/backend/src/utils/test/testUtils.ts @@ -1,50 +1,8 @@ import supertest from 'supertest' -import { expect, vi } from 'vitest' +import { expect } from 'vitest' import { server } from '../../routes.js' -vi.mock('../../utils/config.js', () => { - return { - __esModule: true, - default: { - app: { - app: { - protocol: '', - }, - }, - logging: { - stroom: { - enabled: false, - }, - file: { - enabled: false, - }, - }, - minio: { - connection: { - endPoint: 'fake', - }, - buckets: { - uploads: 'uploads', - }, - }, - oauth: { - enabled: false, - }, - ui: { - seldonVersions: [ - { - name: 'seldonio - 1.10.0', - image: 'seldonio/seldon-core-s2i-python37:1.10.0', - }, - ], - banner: '', - registry: '', - }, - }, - } -}) - export function authenticatedGetRequest(path: string) { const request = supertest(server) return request.get(path).set('Content-Type', 'application/json').set('Accept', 'application/json') diff --git a/backend/test/connectors/authorisation/authorisation.spec.ts b/backend/test/connectors/authorisation/authorisation.spec.ts index 3c492ebf3..10bd896f5 100644 --- a/backend/test/connectors/authorisation/authorisation.spec.ts +++ b/backend/test/connectors/authorisation/authorisation.spec.ts @@ -2,9 +2,6 @@ import { describe, expect, test, vi } from 'vitest' import { getAuthorisationConnector } from '../../../src/connectors/authorisation/index.js' import { FileScanResult } from '../../../src/connectors/fileScanning/Base.js' -// import config from '../../../src/utils/__mocks__/config.js' - -// vi.mock('../../../src/utils/config.js') vi.mock('../../../src/connectors/authentication/index.js', () => ({ default: { @@ -61,11 +58,9 @@ describe('connectors > authorisation', () => { const connector = getAuthorisationConnector(false) expect(connector.constructor.name).toBe('BasicAuthorisationConnector') }) - test('invalid', () => { const invalidConnector = 'invalid' configMock.connectors.authorisation.kind = invalidConnector - expect(() => getAuthorisationConnector(false)).toThrowError( `'${invalidConnector}' is not a valid authorisation kind.`, ) diff --git a/backend/test/testUtils/setupTestConfig.ts b/backend/test/testUtils/setupTestConfig.ts new file mode 100644 index 000000000..5d24d21c9 --- /dev/null +++ b/backend/test/testUtils/setupTestConfig.ts @@ -0,0 +1,3 @@ +import { vi } from 'vitest' + +vi.mock('../../src/utils/config.js') diff --git a/backend/vitest.config.ts b/backend/vitest.config.ts index 2795c0d72..34f4373a3 100644 --- a/backend/vitest.config.ts +++ b/backend/vitest.config.ts @@ -5,7 +5,7 @@ export default defineConfig({ plugins: [tsconfigPaths()], test: { restoreMocks: true, - setupFiles: ['./test/testUtils/zod.ts'], + setupFiles: ['./test/testUtils/zod.ts', './test/testUtils/setupTestConfig.ts'], include: ['test/**/*.spec.ts'], coverage: { enabled: true,