mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 10:15:17 -04:00
fix(config-mocks): adapt all mock config to use create and register functions
This way it's much easier to change the config provided in tests. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
4aadf0bc0d
commit
932075a08f
6 changed files with 113 additions and 37 deletions
|
@ -3,18 +3,26 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { registerAs } from '@nestjs/config';
|
import { ConfigFactoryKeyHost, registerAs } from '@nestjs/config';
|
||||||
|
import { ConfigFactory } from '@nestjs/config/dist/interfaces';
|
||||||
|
|
||||||
import { AppConfig } from '../app.config';
|
import { AppConfig } from '../app.config';
|
||||||
import { Loglevel } from '../loglevel.enum';
|
import { Loglevel } from '../loglevel.enum';
|
||||||
|
|
||||||
export default registerAs(
|
export function createDefaultMockAppConfig(): AppConfig {
|
||||||
'appConfig',
|
return {
|
||||||
(): AppConfig => ({
|
|
||||||
domain: 'md.example.com',
|
domain: 'md.example.com',
|
||||||
rendererBaseUrl: 'md-renderer.example.com',
|
rendererBaseUrl: 'md-renderer.example.com',
|
||||||
port: 3000,
|
port: 3000,
|
||||||
loglevel: Loglevel.ERROR,
|
loglevel: Loglevel.ERROR,
|
||||||
persistInterval: 10,
|
persistInterval: 10,
|
||||||
}),
|
};
|
||||||
);
|
}
|
||||||
|
|
||||||
|
export function registerAppConfig(
|
||||||
|
appConfig: AppConfig,
|
||||||
|
): ConfigFactory<AppConfig> & ConfigFactoryKeyHost<AppConfig> {
|
||||||
|
return registerAs('appConfig', (): AppConfig => appConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default registerAppConfig(createDefaultMockAppConfig());
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { registerAs } from '@nestjs/config';
|
import { ConfigFactoryKeyHost, registerAs } from '@nestjs/config';
|
||||||
|
import { ConfigFactory } from '@nestjs/config/dist/interfaces';
|
||||||
|
|
||||||
import { AuthConfig } from '../auth.config';
|
import { AuthConfig } from '../auth.config';
|
||||||
|
|
||||||
export default registerAs(
|
export function createDefaultMockAuthConfig(): AuthConfig {
|
||||||
'authConfig',
|
return {
|
||||||
(): AuthConfig => ({
|
|
||||||
session: {
|
session: {
|
||||||
secret: 'my_secret',
|
secret: 'my_secret',
|
||||||
lifetime: 1209600000,
|
lifetime: 1209600000,
|
||||||
|
@ -45,5 +45,13 @@ export default registerAs(
|
||||||
ldap: [],
|
ldap: [],
|
||||||
saml: [],
|
saml: [],
|
||||||
oauth2: [],
|
oauth2: [],
|
||||||
}),
|
};
|
||||||
);
|
}
|
||||||
|
|
||||||
|
export function registerAuthConfig(
|
||||||
|
authConfig: AuthConfig,
|
||||||
|
): ConfigFactory<AuthConfig> & ConfigFactoryKeyHost<AuthConfig> {
|
||||||
|
return registerAs('authConfig', (): AuthConfig => authConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default registerAuthConfig(createDefaultMockAuthConfig());
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { registerAs } from '@nestjs/config';
|
import { ConfigFactoryKeyHost, registerAs } from '@nestjs/config';
|
||||||
|
import { ConfigFactory } from '@nestjs/config/dist/interfaces';
|
||||||
|
|
||||||
import { CustomizationConfig } from '../customization.config';
|
import { CustomizationConfig } from '../customization.config';
|
||||||
|
|
||||||
export default registerAs(
|
export function createDefaultMockCustomizationConfig(): CustomizationConfig {
|
||||||
'customizationConfig',
|
return {
|
||||||
(): CustomizationConfig => ({
|
|
||||||
branding: {
|
branding: {
|
||||||
customName: 'ACME Corp',
|
customName: 'ACME Corp',
|
||||||
customLogo: '',
|
customLogo: '',
|
||||||
|
@ -19,5 +19,19 @@ export default registerAs(
|
||||||
termsOfUse: '/test/termsOfUse',
|
termsOfUse: '/test/termsOfUse',
|
||||||
imprint: '/test/imprint',
|
imprint: '/test/imprint',
|
||||||
},
|
},
|
||||||
}),
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerCustomizationConfig(
|
||||||
|
customizationConfig: CustomizationConfig,
|
||||||
|
): ConfigFactory<CustomizationConfig> &
|
||||||
|
ConfigFactoryKeyHost<CustomizationConfig> {
|
||||||
|
return registerAs(
|
||||||
|
'customizationConfig',
|
||||||
|
(): CustomizationConfig => customizationConfig,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default registerCustomizationConfig(
|
||||||
|
createDefaultMockCustomizationConfig(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { registerAs } from '@nestjs/config';
|
import { ConfigFactoryKeyHost, registerAs } from '@nestjs/config';
|
||||||
|
import { ConfigFactory } from '@nestjs/config/dist/interfaces';
|
||||||
|
|
||||||
import { DatabaseType } from '../database-type.enum';
|
import { DatabaseType } from '../database-type.enum';
|
||||||
import { DatabaseConfig } from '../database.config';
|
import { DatabaseConfig } from '../database.config';
|
||||||
|
|
||||||
export default registerAs(
|
export function createDefaultMockDatabaseConfig(): DatabaseConfig {
|
||||||
'databaseConfig',
|
return {
|
||||||
(): DatabaseConfig => ({
|
|
||||||
type: (process.env.HEDGEDOC_TEST_DB_TYPE ||
|
type: (process.env.HEDGEDOC_TEST_DB_TYPE ||
|
||||||
DatabaseType.SQLITE) as DatabaseType,
|
DatabaseType.SQLITE) as DatabaseType,
|
||||||
database: 'hedgedoc',
|
database: 'hedgedoc',
|
||||||
|
@ -18,5 +18,13 @@ export default registerAs(
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 0,
|
port: 0,
|
||||||
username: 'hedgedoc',
|
username: 'hedgedoc',
|
||||||
}),
|
};
|
||||||
);
|
}
|
||||||
|
|
||||||
|
export function registerDatabaseConfig(
|
||||||
|
databaseConfig: DatabaseConfig,
|
||||||
|
): ConfigFactory<DatabaseConfig> & ConfigFactoryKeyHost<DatabaseConfig> {
|
||||||
|
return registerAs('databaseConfig', (): DatabaseConfig => databaseConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default registerDatabaseConfig(createDefaultMockDatabaseConfig());
|
||||||
|
|
|
@ -3,14 +3,28 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { registerAs } from '@nestjs/config';
|
import { ConfigFactoryKeyHost, registerAs } from '@nestjs/config';
|
||||||
|
import { ConfigFactory } from '@nestjs/config/dist/interfaces';
|
||||||
|
|
||||||
import { ExternalServicesConfig } from '../external-services.config';
|
import { ExternalServicesConfig } from '../external-services.config';
|
||||||
|
|
||||||
export default registerAs(
|
export function createDefaultMockExternalServicesConfig(): ExternalServicesConfig {
|
||||||
'externalServicesConfig',
|
return {
|
||||||
(): ExternalServicesConfig => ({
|
|
||||||
plantUmlServer: 'plantuml.example.com',
|
plantUmlServer: 'plantuml.example.com',
|
||||||
imageProxy: 'imageProxy.example.com',
|
imageProxy: 'imageProxy.example.com',
|
||||||
}),
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerExternalServiceConfig(
|
||||||
|
externalServicesConfig: ExternalServicesConfig,
|
||||||
|
): ConfigFactory<ExternalServicesConfig> &
|
||||||
|
ConfigFactoryKeyHost<ExternalServicesConfig> {
|
||||||
|
return registerAs(
|
||||||
|
'externalServicesConfig',
|
||||||
|
(): ExternalServicesConfig => externalServicesConfig,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default registerExternalServiceConfig(
|
||||||
|
createDefaultMockExternalServicesConfig(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,22 +3,46 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { registerAs } from '@nestjs/config';
|
import { ConfigFactoryKeyHost, registerAs } from '@nestjs/config';
|
||||||
|
import { ConfigFactory } from '@nestjs/config/dist/interfaces';
|
||||||
|
|
||||||
import { BackendType } from '../../media/backends/backend-type.enum';
|
import { BackendType } from '../../media/backends/backend-type.enum';
|
||||||
import { MediaBackendConfig, MediaConfig } from '../media.config';
|
import { MediaConfig } from '../media.config';
|
||||||
|
|
||||||
export default registerAs(
|
export function createDefaultMockMediaConfig(): MediaConfig {
|
||||||
'mediaConfig',
|
return {
|
||||||
(): Omit<MediaConfig, 'backend'> & {
|
|
||||||
backend: Pick<MediaBackendConfig, 'use' | 'filesystem'>;
|
|
||||||
} => ({
|
|
||||||
backend: {
|
backend: {
|
||||||
use: BackendType.FILESYSTEM,
|
use: BackendType.FILESYSTEM,
|
||||||
filesystem: {
|
filesystem: {
|
||||||
uploadPath:
|
uploadPath:
|
||||||
'test_uploads' + Math.floor(Math.random() * 100000).toString(),
|
'test_uploads' + Math.floor(Math.random() * 100000).toString(),
|
||||||
},
|
},
|
||||||
|
s3: {
|
||||||
|
accessKeyId: '',
|
||||||
|
secretAccessKey: '',
|
||||||
|
bucket: '',
|
||||||
|
endPoint: '',
|
||||||
|
},
|
||||||
|
azure: {
|
||||||
|
connectionString: '',
|
||||||
|
container: '',
|
||||||
|
},
|
||||||
|
imgur: {
|
||||||
|
clientID: '',
|
||||||
|
},
|
||||||
|
webdav: {
|
||||||
|
connectionString: '',
|
||||||
|
uploadDir: '',
|
||||||
|
publicUrl: '',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
};
|
||||||
);
|
}
|
||||||
|
|
||||||
|
export function registerMediaConfig(
|
||||||
|
appConfig: MediaConfig,
|
||||||
|
): ConfigFactory<MediaConfig> & ConfigFactoryKeyHost<MediaConfig> {
|
||||||
|
return registerAs('mediaConfig', (): MediaConfig => appConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default registerMediaConfig(createDefaultMockMediaConfig());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue