diff --git a/src/config.ts b/src/config.ts index c313579e..d00b8405 100644 --- a/src/config.ts +++ b/src/config.ts @@ -48,15 +48,17 @@ class Config * @param data - The data from extension workspace settings to update the global configuration with. */ updateConfig( data: any ) { - this.exhortSnykToken = data.redHatDependencyAnalytics.exhortSnykToken; - this.matchManifestVersions = data.redHatDependencyAnalytics.matchManifestVersions ? 'true' : 'false'; - this.exhortMvnPath = data.mvn.executable.path || 'mvn'; - this.exhortNpmPath = data.npm.executable.path || 'npm'; - this.exhortGoPath = data.go.executable.path || 'go'; - this.exhortPython3Path = data.python3.executable.path || 'python3'; - this.exhortPip3Path = data.pip3.executable.path || 'pip3'; - this.exhortPythonPath = data.python.executable.path || 'python'; - this.exhortPipPath = data.pip.executable.path || 'pip'; + const rhdaData = data.redHatDependencyAnalytics; + + this.exhortSnykToken = rhdaData.exhortSnykToken; + this.matchManifestVersions = rhdaData.matchManifestVersions ? 'true' : 'false'; + this.exhortMvnPath = rhdaData.mvn.executable.path || 'mvn'; + this.exhortNpmPath = rhdaData.npm.executable.path || 'npm'; + this.exhortGoPath = rhdaData.go.executable.path || 'go'; + this.exhortPython3Path = rhdaData.python3.executable.path || 'python3'; + this.exhortPip3Path = rhdaData.pip3.executable.path || 'pip3'; + this.exhortPythonPath = rhdaData.python.executable.path || 'python'; + this.exhortPipPath = rhdaData.pip.executable.path || 'pip'; } } diff --git a/test/config.test.ts b/test/config.test.ts index bb95cd9c..beb56d78 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -10,59 +10,59 @@ describe('Config tests', () => { const data = { redHatDependencyAnalytics: { - exhortSnykToken: 'mockToken', - matchManifestVersions: false - }, - mvn: { - executable: { path: 'mockPath' } - }, - npm: { - executable: { path: 'mockPath' } - }, - go: { - executable: { path: 'mockPath' } - }, - python3: { - executable: { path: 'mockPath' } - }, - pip3: { - executable: { path: 'mockPath' } - }, - python: { - executable: { path: 'mockPath' } - }, - pip: { - executable: { path: 'mockPath' } + exhortSnykToken: 'mockToken', + matchManifestVersions: false, + mvn: { + executable: { path: 'mockPath' } + }, + npm: { + executable: { path: 'mockPath' } + }, + go: { + executable: { path: 'mockPath' } + }, + python3: { + executable: { path: 'mockPath' } + }, + pip3: { + executable: { path: 'mockPath' } + }, + python: { + executable: { path: 'mockPath' } + }, + pip: { + executable: { path: 'mockPath' } + }, }, }; const partialData = { - redHatDependencyAnalytics: { - exhortSnykToken: 'mockToken', - matchManifestVersions: true - }, - mvn: { - executable: { path: '' } - }, - npm: { - executable: { path: '' } - }, - go: { - executable: { path: '' } - }, - python3: { - executable: { path: '' } - }, - pip3: { - executable: { path: '' } - }, - python: { - executable: { path: '' } - }, - pip: { - executable: { path: '' } - }, - }; + redHatDependencyAnalytics: { + exhortSnykToken: 'mockToken', + matchManifestVersions: true, + mvn: { + executable: { path: '' } + }, + npm: { + executable: { path: '' } + }, + go: { + executable: { path: '' } + }, + python3: { + executable: { path: '' } + }, + pip3: { + executable: { path: '' } + }, + python: { + executable: { path: '' } + }, + pip: { + executable: { path: '' } + }, + }, + }; it('should initialize with default values when environment variables are not set', () => { expect(mockConfig.triggerFullStackAnalysis).to.eq(''); @@ -79,7 +79,7 @@ describe('Config tests', () => { expect(mockConfig.exhortPythonPath).to.eq('python'); expect(mockConfig.exhortPipPath).to.eq('pip'); }); - + it('should update configuration based on provided data', () => { mockConfig.updateConfig(data); @@ -97,16 +97,16 @@ describe('Config tests', () => { it('should update configuration based on provided partial data', () => { - mockConfig.updateConfig(partialData); + mockConfig.updateConfig(partialData); - expect(mockConfig.exhortSnykToken).to.eq('mockToken'); - expect(mockConfig.matchManifestVersions).to.eq('true'); - expect(mockConfig.exhortMvnPath).to.eq('mvn'); - expect(mockConfig.exhortNpmPath).to.eq('npm'); - expect(mockConfig.exhortGoPath).to.eq('go'); - expect(mockConfig.exhortPython3Path).to.eq('python3'); - expect(mockConfig.exhortPip3Path).to.eq('pip3'); - expect(mockConfig.exhortPythonPath).to.eq('python'); - expect(mockConfig.exhortPipPath).to.eq('pip'); - }); + expect(mockConfig.exhortSnykToken).to.eq('mockToken'); + expect(mockConfig.matchManifestVersions).to.eq('true'); + expect(mockConfig.exhortMvnPath).to.eq('mvn'); + expect(mockConfig.exhortNpmPath).to.eq('npm'); + expect(mockConfig.exhortGoPath).to.eq('go'); + expect(mockConfig.exhortPython3Path).to.eq('python3'); + expect(mockConfig.exhortPip3Path).to.eq('pip3'); + expect(mockConfig.exhortPythonPath).to.eq('python'); + expect(mockConfig.exhortPipPath).to.eq('pip'); + }); }); \ No newline at end of file