Skip to content

Commit

Permalink
updated some of the missing test config
Browse files Browse the repository at this point in the history
  • Loading branch information
ARADDCC002 committed Nov 18, 2024
1 parent 8773602 commit 8bf2e75
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 50 deletions.
6 changes: 6 additions & 0 deletions backend/src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export type PartialDeep<T> = T extends object
? {
[P in keyof T]?: PartialDeep<T[P]>
}
: T

export const RoleKind = {
ENTRY: 'entry',
SCHEMA: 'schema',
Expand Down
51 changes: 50 additions & 1 deletion backend/src/utils/__mocks__/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
const config = {
import { PartialDeep } from '../../types/types.js'
import { Config } from '../config.js'

const config: PartialDeep<Config> = {
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',
Expand Down Expand Up @@ -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,
Expand Down
44 changes: 1 addition & 43 deletions backend/src/utils/test/testUtils.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
5 changes: 0 additions & 5 deletions backend/test/connectors/authorisation/authorisation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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.`,
)
Expand Down
3 changes: 3 additions & 0 deletions backend/test/testUtils/setupTestConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { vi } from 'vitest'

vi.mock('../../src/utils/config.js')
2 changes: 1 addition & 1 deletion backend/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8bf2e75

Please sign in to comment.