|
| 1 | +import { OutputType } from '../../src/run/common/enums/outputType'; |
| 2 | +import { ProcessingType } from '../../src/run/common/enums/processingType'; |
| 3 | +import { checkInputsAreValid, getOutputTypeForFiles, getProcessingTypeForFiles } from '../../src/decompile/index'; |
| 4 | + |
| 5 | +describe('checkInputsAreValid throws correct errors', () => { |
| 6 | + test('if source directory is not defined and process type is multiple', () => { |
| 7 | + expect(() => |
| 8 | + checkInputsAreValid(undefined, undefined, 'multiple', undefined, undefined, undefined), |
| 9 | + ).toThrowError("The variable 'sourceDirectory' is mandatory when process is 'multiple'."); |
| 10 | + }); |
| 11 | + |
| 12 | + test('if source directory is not defined and process type is undefined', () => { |
| 13 | + expect(() => |
| 14 | + checkInputsAreValid(undefined, undefined, undefined, undefined, undefined, undefined), |
| 15 | + ).toThrowError("The variable 'sourceDirectory' is mandatory when process is 'multiple'."); |
| 16 | + }); |
| 17 | + |
| 18 | + test('if source file is not defined and process type is single', () => { |
| 19 | + expect(() => checkInputsAreValid(undefined, undefined, 'single', undefined, undefined, undefined)).toThrowError( |
| 20 | + "The variable 'sourceFile' is mandatory when process is 'single'.", |
| 21 | + ); |
| 22 | + }); |
| 23 | + |
| 24 | + test('if output directory is not defined and output type is outDir', () => { |
| 25 | + expect(() => |
| 26 | + checkInputsAreValid('any path', undefined, 'multiple', 'outDir', undefined, undefined), |
| 27 | + ).toThrowError("The variable 'outDir' is mandatory when outputProcess is 'outDir'."); |
| 28 | + }); |
| 29 | + |
| 30 | + test('if output file is not defined and output type is outFile', () => { |
| 31 | + expect(() => |
| 32 | + checkInputsAreValid('any path', undefined, 'multiple', 'outFile', undefined, undefined), |
| 33 | + ).toThrowError("The variable 'outFile' is mandatory when outputProcess is 'outFile'."); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('getProcessingTypeForFiles returns correct ProcessingType', () => { |
| 38 | + test('if source directory is defined and process type is multiple then processing type is multiple', () => { |
| 39 | + expect(getProcessingTypeForFiles('.', undefined, 'multiple')).toEqual(ProcessingType.Multiple); |
| 40 | + }); |
| 41 | + |
| 42 | + test('if source directory is not defined and process type is multiple then processing type is Invalid', () => { |
| 43 | + expect(getProcessingTypeForFiles(undefined, undefined, 'multiple')).toEqual(ProcessingType.Invalid); |
| 44 | + }); |
| 45 | + |
| 46 | + test('if source directory is defined and process type is undefined then processing type is multiple', () => { |
| 47 | + expect(getProcessingTypeForFiles('.', undefined, undefined)).toEqual(ProcessingType.Multiple); |
| 48 | + }); |
| 49 | + |
| 50 | + test('if source directory is not defined and process type is undefined then processing type is Invalid', () => { |
| 51 | + expect(getProcessingTypeForFiles(undefined, undefined, undefined)).toEqual(ProcessingType.Invalid); |
| 52 | + }); |
| 53 | + |
| 54 | + test('if source file is defined and process type is single then processing type is single', () => { |
| 55 | + expect(getProcessingTypeForFiles(undefined, '.', 'single')).toEqual(ProcessingType.Single); |
| 56 | + }); |
| 57 | + |
| 58 | + test('if source file is not defined and process type is single then processing type is Invalid', () => { |
| 59 | + expect(getProcessingTypeForFiles(undefined, undefined, 'single')).toEqual(ProcessingType.Invalid); |
| 60 | + }); |
| 61 | +}); |
| 62 | + |
| 63 | +describe('getOutputTypeForFiles returns correct OutputType', () => { |
| 64 | + test('if stdout enabled then returns OutputType.Stdout', () => { |
| 65 | + expect(getOutputTypeForFiles(undefined, undefined, true, undefined)).toEqual(OutputType.Stdout); |
| 66 | + }); |
| 67 | + |
| 68 | + test('if output file is set then returns OutputType.OutFile', () => { |
| 69 | + expect(getOutputTypeForFiles(undefined, 'anyFile', undefined, undefined)).toEqual(OutputType.OutFile); |
| 70 | + }); |
| 71 | + |
| 72 | + test('if output directory is set then returns OutputType.OutDir', () => { |
| 73 | + expect(getOutputTypeForFiles('.', undefined, undefined, undefined)).toEqual(OutputType.OutDir); |
| 74 | + }); |
| 75 | + |
| 76 | + test('if no option is set then returns OutputType.Default', () => { |
| 77 | + expect(getOutputTypeForFiles(undefined, undefined, undefined, undefined)).toEqual(OutputType.Default); |
| 78 | + }); |
| 79 | + |
| 80 | + test('if outputProcess is set to stdout then returns OutputType.Stdout', () => { |
| 81 | + expect(getOutputTypeForFiles(undefined, undefined, undefined, 'stdout')).toEqual(OutputType.Stdout); |
| 82 | + }); |
| 83 | + |
| 84 | + test('if outputProcess is set to outFile then returns OutputType.OutFile', () => { |
| 85 | + expect(getOutputTypeForFiles(undefined, undefined, undefined, 'outFile')).toEqual(OutputType.OutFile); |
| 86 | + }); |
| 87 | + |
| 88 | + test('if outputProcess is set to outDir then returns OutputType.OutDir', () => { |
| 89 | + expect(getOutputTypeForFiles(undefined, undefined, undefined, 'outDir')).toEqual(OutputType.OutDir); |
| 90 | + }); |
| 91 | +}); |
0 commit comments