Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Refactor generate vdm test (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Richter authored Dec 20, 2019
1 parent a89ea0f commit b0b13d2
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions test/generate-vdm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,10 @@ describe('generate-vdm', () => {

function getDefault(projectDir: string): GeneratorOptionsSDK {
return {
...(Object.keys(generatorOptionsSDK).reduce((prev, current) => {
...Object.keys(generatorOptionsSDK).reduce((prev, current) => {
const value = generatorOptionsSDK[current as keyof GeneratorOptionsSDK];
if (value) {
prev[current as keyof GeneratorOptionsSDK] = value.default;
}
return prev;
}, {} as any) as GeneratorOptionsSDK),
return value ? { ...prev, [current]: value.default } : prev;
}, {} as any),
inputDir: path.resolve(projectDir, 'input'),
outputDir: path.resolve(projectDir, 'output'),
serviceMapping: path.resolve(projectDir, 'input', 'service-mapping.json')
Expand All @@ -105,18 +102,15 @@ describe('generate-vdm', () => {

function getCliInputWithAllBooleanFlagsFalse(): string[] {
const allFalse = getParsedInputWithAllBooleanFlagsFalse();
const stringArguments = Object.entries(allFalse).reduce((collected: string[], [key, value]) => {
return Object.entries(allFalse).reduce((collected: string[], [key, value]) => {
switch (typeof allFalse[key as keyof generateVdmUtil.FlagsParsed]) {
case 'string':
collected.push(`--${key}`, value!.toString());
break;
return [...collected, `--${key}`, value!.toString()];
case 'boolean':
collected = generatorOptionsSDK[key as keyof GeneratorOptionsSDK]?.default ? [...collected, `--no-${key}`] : collected;
break;
default:
return generatorOptionsSDK[key as keyof GeneratorOptionsSDK]?.default ? [...collected, `--no-${key}`] : collected;
}
return collected;
}, []);
return [...stringArguments];
}

function getParsedInputWithAllBooleanFlagsFalse(): generateVdmUtil.FlagsParsed {
Expand Down

0 comments on commit b0b13d2

Please sign in to comment.