mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-24 20:14:35 -04:00
test(FrontendConfig): Remove loop over irrelevant variables
Some variables are not used in any logic, so looping over them does not make any sense. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
f3cf4f4b1f
commit
d104a98f81
1 changed files with 104 additions and 131 deletions
|
@ -298,143 +298,116 @@ describe('FrontendConfigService', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const maxDocumentLength = 100000;
|
||||||
|
const enableRegister = true;
|
||||||
|
const imageProxy = 'https://imageProxy.example.com';
|
||||||
|
const customName = 'Test Branding Name';
|
||||||
|
|
||||||
let index = 1;
|
let index = 1;
|
||||||
for (const renderOrigin of [undefined, 'http://md-renderer.example.com']) {
|
for (const renderOrigin of [undefined, 'http://md-renderer.example.com']) {
|
||||||
for (const maxDocumentLength of [100000, 900]) {
|
for (const customLogo of [undefined, 'https://example.com/logo.png']) {
|
||||||
for (const enableLogin of [true, false]) {
|
for (const privacyLink of [undefined, 'https://example.com/privacy']) {
|
||||||
for (const enableRegister of [true, false]) {
|
for (const termsOfUseLink of [undefined, 'https://example.com/terms']) {
|
||||||
for (const customName of [undefined, 'Test Branding Name']) {
|
for (const imprintLink of [
|
||||||
for (const customLogo of [
|
undefined,
|
||||||
|
'https://example.com/imprint',
|
||||||
|
]) {
|
||||||
|
for (const plantUmlServer of [
|
||||||
undefined,
|
undefined,
|
||||||
'https://example.com/logo.png',
|
'https://plantuml.example.com',
|
||||||
]) {
|
]) {
|
||||||
for (const privacyLink of [
|
it(`combination #${index} works`, async () => {
|
||||||
undefined,
|
const appConfig: AppConfig = {
|
||||||
'https://example.com/privacy',
|
domain: domain,
|
||||||
]) {
|
rendererOrigin: renderOrigin ?? domain,
|
||||||
for (const termsOfUseLink of [
|
port: 3000,
|
||||||
undefined,
|
loglevel: Loglevel.ERROR,
|
||||||
'https://example.com/terms',
|
};
|
||||||
]) {
|
const authConfig: AuthConfig = {
|
||||||
for (const imprintLink of [
|
...emptyAuthConfig,
|
||||||
undefined,
|
local: {
|
||||||
'https://example.com/imprint',
|
enableLogin: true,
|
||||||
]) {
|
enableRegister,
|
||||||
for (const plantUmlServer of [
|
},
|
||||||
undefined,
|
};
|
||||||
'https://plantuml.example.com',
|
const customizationConfig: CustomizationConfig = {
|
||||||
]) {
|
branding: {
|
||||||
for (const imageProxy of [
|
customName: customName,
|
||||||
undefined,
|
customLogo: customLogo,
|
||||||
'https://imageProxy.example.com',
|
},
|
||||||
]) {
|
specialUrls: {
|
||||||
it(`combination #${index} works`, async () => {
|
privacy: privacyLink,
|
||||||
const appConfig: AppConfig = {
|
termsOfUse: termsOfUseLink,
|
||||||
domain: domain,
|
imprint: imprintLink,
|
||||||
rendererOrigin: renderOrigin ?? domain,
|
},
|
||||||
port: 3000,
|
};
|
||||||
loglevel: Loglevel.ERROR,
|
const externalServicesConfig: ExternalServicesConfig = {
|
||||||
};
|
plantUmlServer: plantUmlServer,
|
||||||
const authConfig: AuthConfig = {
|
imageProxy: imageProxy,
|
||||||
...emptyAuthConfig,
|
};
|
||||||
local: {
|
const noteConfig: NoteConfig = {
|
||||||
enableLogin,
|
forbiddenNoteIds: [],
|
||||||
enableRegister,
|
maxDocumentLength: maxDocumentLength,
|
||||||
},
|
};
|
||||||
};
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
const customizationConfig: CustomizationConfig = {
|
imports: [
|
||||||
branding: {
|
ConfigModule.forRoot({
|
||||||
customName: customName,
|
isGlobal: true,
|
||||||
customLogo: customLogo,
|
load: [
|
||||||
},
|
registerAs('appConfig', () => appConfig),
|
||||||
specialUrls: {
|
registerAs('authConfig', () => authConfig),
|
||||||
privacy: privacyLink,
|
registerAs(
|
||||||
termsOfUse: termsOfUseLink,
|
'customizationConfig',
|
||||||
imprint: imprintLink,
|
() => customizationConfig,
|
||||||
},
|
),
|
||||||
};
|
registerAs(
|
||||||
const externalServicesConfig: ExternalServicesConfig =
|
'externalServicesConfig',
|
||||||
{
|
() => externalServicesConfig,
|
||||||
plantUmlServer: plantUmlServer,
|
),
|
||||||
imageProxy: imageProxy,
|
registerAs('noteConfig', () => noteConfig),
|
||||||
};
|
],
|
||||||
const noteConfig: NoteConfig = {
|
}),
|
||||||
forbiddenNoteIds: [],
|
LoggerModule,
|
||||||
maxDocumentLength: maxDocumentLength,
|
],
|
||||||
};
|
providers: [FrontendConfigService],
|
||||||
const module: TestingModule =
|
}).compile();
|
||||||
await Test.createTestingModule({
|
|
||||||
imports: [
|
|
||||||
ConfigModule.forRoot({
|
|
||||||
isGlobal: true,
|
|
||||||
load: [
|
|
||||||
registerAs('appConfig', () => appConfig),
|
|
||||||
registerAs('authConfig', () => authConfig),
|
|
||||||
registerAs(
|
|
||||||
'customizationConfig',
|
|
||||||
() => customizationConfig,
|
|
||||||
),
|
|
||||||
registerAs(
|
|
||||||
'externalServicesConfig',
|
|
||||||
() => externalServicesConfig,
|
|
||||||
),
|
|
||||||
registerAs('noteConfig', () => noteConfig),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
LoggerModule,
|
|
||||||
],
|
|
||||||
providers: [FrontendConfigService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
const service = module.get(FrontendConfigService);
|
const service = module.get(FrontendConfigService);
|
||||||
const config = await service.getFrontendConfig();
|
const config = await service.getFrontendConfig();
|
||||||
expect(config.allowRegister).toEqual(enableRegister);
|
expect(config.allowRegister).toEqual(enableRegister);
|
||||||
|
|
||||||
expect(config.allowAnonymous).toEqual(false);
|
expect(config.allowAnonymous).toEqual(false);
|
||||||
expect(config.branding.name).toEqual(customName);
|
expect(config.branding.name).toEqual(customName);
|
||||||
expect(config.branding.logo).toEqual(
|
expect(config.branding.logo).toEqual(
|
||||||
customLogo ? new URL(customLogo) : undefined,
|
customLogo ? new URL(customLogo) : undefined,
|
||||||
);
|
);
|
||||||
expect(
|
expect(config.iframeCommunication.editorOrigin).toEqual(
|
||||||
config.iframeCommunication.editorOrigin,
|
new URL(appConfig.domain),
|
||||||
).toEqual(new URL(appConfig.domain));
|
);
|
||||||
expect(
|
expect(config.iframeCommunication.rendererOrigin).toEqual(
|
||||||
config.iframeCommunication.rendererOrigin,
|
appConfig.rendererOrigin
|
||||||
).toEqual(
|
? new URL(appConfig.rendererOrigin)
|
||||||
appConfig.rendererOrigin
|
: new URL(appConfig.domain),
|
||||||
? new URL(appConfig.rendererOrigin)
|
);
|
||||||
: new URL(appConfig.domain),
|
expect(config.maxDocumentLength).toEqual(maxDocumentLength);
|
||||||
);
|
expect(config.plantUmlServer).toEqual(
|
||||||
expect(config.maxDocumentLength).toEqual(
|
plantUmlServer ? new URL(plantUmlServer) : undefined,
|
||||||
maxDocumentLength,
|
);
|
||||||
);
|
expect(config.specialUrls.imprint).toEqual(
|
||||||
expect(config.plantUmlServer).toEqual(
|
imprintLink ? new URL(imprintLink) : undefined,
|
||||||
plantUmlServer
|
);
|
||||||
? new URL(plantUmlServer)
|
expect(config.specialUrls.privacy).toEqual(
|
||||||
: undefined,
|
privacyLink ? new URL(privacyLink) : undefined,
|
||||||
);
|
);
|
||||||
expect(config.specialUrls.imprint).toEqual(
|
expect(config.specialUrls.termsOfUse).toEqual(
|
||||||
imprintLink ? new URL(imprintLink) : undefined,
|
termsOfUseLink ? new URL(termsOfUseLink) : undefined,
|
||||||
);
|
);
|
||||||
expect(config.specialUrls.privacy).toEqual(
|
expect(config.useImageProxy).toEqual(!!imageProxy);
|
||||||
privacyLink ? new URL(privacyLink) : undefined,
|
expect(config.version).toEqual(
|
||||||
);
|
await getServerVersionFromPackageJson(),
|
||||||
expect(config.specialUrls.termsOfUse).toEqual(
|
);
|
||||||
termsOfUseLink
|
});
|
||||||
? new URL(termsOfUseLink)
|
index += 1;
|
||||||
: undefined,
|
|
||||||
);
|
|
||||||
expect(config.useImageProxy).toEqual(!!imageProxy);
|
|
||||||
expect(config.version).toEqual(
|
|
||||||
await getServerVersionFromPackageJson(),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue