Skip to content

Commit

Permalink
test: update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ilona Shishov <[email protected]>
  • Loading branch information
IlonaShishov committed Nov 22, 2023
1 parent 63e1a58 commit 4e6229a
Show file tree
Hide file tree
Showing 21 changed files with 1,360 additions and 1,357 deletions.
170 changes: 165 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dist"
],
"dependencies": {
"@RHEcosystemAppEng/exhort-javascript-api": "^0.0.2-ea.49",
"@RHEcosystemAppEng/exhort-javascript-api": "^0.1.0",
"@xml-tools/ast": "^5.0.5",
"@xml-tools/parser": "^1.0.11",
"json-to-ast": "^2.1.0",
Expand All @@ -43,6 +43,7 @@
"fake-exec": "^1.1.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"sinon": "^17.0.1",
"ts-node": "^10.9.1",
"typedoc": "^0.25.3",
"typescript": "^5.2.2"
Expand Down
26 changes: 3 additions & 23 deletions src/codeActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,22 @@
'use strict';

import { CodeAction, CodeActionKind, Diagnostic } from 'vscode-languageserver/node';
import { codeActionsMap } from './diagnosticsHandler';
import { globalConfig } from './config';
import { RHDA_DIAGNOSTIC_SOURCE } from './constants';

/**
* Retrieves code actions based on diagnostics and file type.
* @param diagnostics - An array of available diagnostics.
* @param fileType - The type of the file based on ecosystem (e.g., 'pom.xml').
* @returns An array of CodeAction objects to be made available to the user.
*/
function getDiagnosticsCodeActions( diagnostics: Diagnostic[], fileType: string ): CodeAction[] {
function getDiagnosticsCodeActions(diagnostics: Diagnostic[]): CodeAction[] {
const hasRhdaDiagonostic = diagnostics.some(diagnostic => diagnostic.source === RHDA_DIAGNOSTIC_SOURCE);
const codeActions: CodeAction[] = [];
let hasRhdaDiagonostic: boolean = false;

for (const diagnostic of diagnostics) {
const codeAction = codeActionsMap[diagnostic.range.start.line + '|' + diagnostic.range.start.character];
if (codeAction) {

if (fileType === 'pom.xml') {
// add Red Hat repository recommendation command to action
codeAction.command = {
title: 'RedHat repository recommendation',
command: globalConfig.triggerRHRepositoryRecommendationNotification,
};
}

codeActions.push(codeAction);

}
if (!hasRhdaDiagonostic) {
hasRhdaDiagonostic = diagnostic.source === RHDA_DIAGNOSTIC_SOURCE;
}
}
if (globalConfig.triggerFullStackAnalysis && hasRhdaDiagonostic) {
codeActions.push(generateFullStackAnalysisAction());
}

return codeActions;
}

Expand Down
15 changes: 9 additions & 6 deletions src/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'use strict';

import { Range } from 'vscode-languageserver';
import { isDefined } from './utils';

/**
* Represents a position inside the manifest file with line and column information.
Expand Down Expand Up @@ -43,10 +44,11 @@ export interface IDependency {
* Represents a dependency and implements the IDependency interface.
*/
export class Dependency implements IDependency {
public version: IPositionedString
public context: IPositionedContext

constructor(
public name: IPositionedString,
public version: IPositionedString = {} as IPositionedString,
public context: IPositionedContext = {} as IPositionedContext,
public name: IPositionedString
) {}
}

Expand All @@ -56,8 +58,9 @@ export class Dependency implements IDependency {
* @returns The range within the text document that represents the dependency.
*/
export function getRange (dep: IDependency): Range {
const pos: IPosition = dep.version.position;
if (pos.line !== 0) {

if (isDefined(dep, 'version', 'position')) {
const pos: IPosition = dep.version.position;
const length = dep.version.value.length;
return {
start: {
Expand Down Expand Up @@ -123,7 +126,7 @@ export class EcosystemDependencyResolver {
}

/**
* RResolves a dependency reference to its actual name in the specified ecosystem.
* Resolves a dependency reference in a specified ecosystem to its name and version string.
* @param ref - The reference string to resolve.
* @returns The resolved name of the dependency.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/componentAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AnalysisResponse implements IAnalysisResponse {
sources.forEach(source => {
source.dependencies.forEach(d => {
if (isDefined(d, 'ref') && isDefined(d, 'issues')) {
const dd = new DependencyData(source.id, d.issues.length, isDefined(d, 'highestVulnerability', 'severity') ? d.highestVulnerability.severity : 'UNKNOWN');
const dd = new DependencyData(source.id, d.issues.length, isDefined(d, 'highestVulnerability', 'severity') ? d.highestVulnerability.severity : 'NONE');
if (this.dependencies[d.ref] === undefined) {
this.dependencies[d.ref] = [];
}
Expand Down
2 changes: 0 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
export class Config
{
triggerFullStackAnalysis: string;
triggerRHRepositoryRecommendationNotification: string;
telemetryId: string;
utmSource: string;
exhortDevMode: string;
Expand All @@ -30,7 +29,6 @@ export class Config
*/
constructor() {
this.triggerFullStackAnalysis = process.env.VSCEXT_TRIGGER_FULL_STACK_ANALYSIS || '';
this.triggerRHRepositoryRecommendationNotification = process.env.VSCEXT_TRIGGER_REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION || '';
this.telemetryId = process.env.VSCEXT_TELEMETRY_ID || '';
this.utmSource = process.env.VSCEXT_UTM_SOURCE || '';
this.exhortDevMode = process.env.VSCEXT_EXHORT_DEV_MODE || 'false';
Expand Down
7 changes: 1 addition & 6 deletions src/diagnosticsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,4 @@ async function performDiagnostics(diagnosticFilePath: string, contents: string,
diagnosticsPipeline.reportDiagnostics();
}

/**
* Map of code actions.
*/
const codeActionsMap = new Map<string, CodeAction>();

export { performDiagnostics, codeActionsMap };
export { performDiagnostics };
Loading

0 comments on commit 4e6229a

Please sign in to comment.