refactor(config): type config mocks

To minimize type errors, when the config objects are changed, this commit introduces types to the mock config object accordingly.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2022-01-30 15:51:18 +01:00
parent 6c82b95ea2
commit 2d8d29cf20
4 changed files with 86 additions and 63 deletions

View file

@ -1,11 +1,15 @@
/* /*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { registerAs } from '@nestjs/config'; import { registerAs } from '@nestjs/config';
export default registerAs('authConfig', () => ({ import { AuthConfig } from '../auth.config';
export default registerAs(
'authConfig',
(): AuthConfig => ({
session: { session: {
secret: 'my_secret', secret: 'my_secret',
lifetime: 1209600000, lifetime: 1209600000,
@ -15,29 +19,30 @@ export default registerAs('authConfig', () => ({
enableRegister: true, enableRegister: true,
}, },
facebook: { facebook: {
clientID: undefined, clientID: '',
clientSecret: undefined, clientSecret: '',
}, },
twitter: { twitter: {
consumerKey: undefined, consumerKey: '',
consumerSecret: undefined, consumerSecret: '',
}, },
github: { github: {
clientID: undefined, clientID: '',
clientSecret: undefined, clientSecret: '',
}, },
dropbox: { dropbox: {
clientID: undefined, clientID: '',
clientSecret: undefined, clientSecret: '',
appKey: undefined, appKey: '',
}, },
google: { google: {
clientID: undefined, clientID: '',
clientSecret: undefined, clientSecret: '',
apiKey: undefined, apiKey: '',
}, },
gitlab: [], gitlab: [],
ldap: [], ldap: [],
saml: [], saml: [],
oauth2: [], oauth2: [],
})); }),
);

View file

@ -1,11 +1,15 @@
/* /*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { registerAs } from '@nestjs/config'; import { registerAs } from '@nestjs/config';
export default registerAs('customizationConfig', () => ({ import { CustomizationConfig } from '../customization.config';
export default registerAs(
'customizationConfig',
(): CustomizationConfig => ({
branding: { branding: {
customName: 'ACME Corp', customName: 'ACME Corp',
customLogo: '', customLogo: '',
@ -15,4 +19,5 @@ export default registerAs('customizationConfig', () => ({
termsOfUse: '/test/termsOfUse', termsOfUse: '/test/termsOfUse',
imprint: '/test/imprint', imprint: '/test/imprint',
}, },
})); }),
);

View file

@ -1,11 +1,16 @@
/* /*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { registerAs } from '@nestjs/config'; import { registerAs } from '@nestjs/config';
export default registerAs('externalServicesConfig', () => ({ import { ExternalServicesConfig } from '../external-services.config';
export default registerAs(
'externalServicesConfig',
(): ExternalServicesConfig => ({
plantUmlServer: 'plantuml.example.com', plantUmlServer: 'plantuml.example.com',
imageProxy: 'imageProxy.example.com', imageProxy: 'imageProxy.example.com',
})); }),
);

View file

@ -1,16 +1,24 @@
/* /*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { registerAs } from '@nestjs/config'; import { registerAs } from '@nestjs/config';
export default registerAs('mediaConfig', () => ({ import { BackendType } from '../../media/backends/backend-type.enum';
import { MediaBackendConfig, MediaConfig } from '../media.config';
export default registerAs(
'mediaConfig',
(): Omit<MediaConfig, 'backend'> & {
backend: Pick<MediaBackendConfig, 'use' | 'filesystem'>;
} => ({
backend: { backend: {
use: 'filesystem', use: BackendType.FILESYSTEM,
filesystem: { filesystem: {
uploadPath: uploadPath:
'test_uploads' + Math.floor(Math.random() * 100000).toString(), 'test_uploads' + Math.floor(Math.random() * 100000).toString(),
}, },
}, },
})); }),
);