Skip to content

Commit

Permalink
Fix sonar issues and improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarne committed Nov 15, 2024
1 parent b0d27c8 commit 44219c7
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ IAppMetadata appMetadata
public bool ShouldRunForTask(string taskId) =>
_appMetadata
.GetApplicationMetadata()
.Result.DataTypes.Where(dt =>
.Result.DataTypes.Any(dt =>
dt.TaskId == taskId
&& dt.AppLogic?.ClassRef is not null
&& _appResourceService.GetValidationConfiguration(dt.Id) is not null
)
.Any();
);

/// <summary>
/// This validator has the code "Expression" and this is known by the frontend, who may request this validator to not run for incremental validation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ internal class DataElementValidatorWrapper : IValidator
{
private readonly IDataElementValidator _dataElementValidator;
private readonly string _taskId;
private readonly List<DataType> _dataTypes;

public DataElementValidatorWrapper(
IDataElementValidator dataElementValidator,
string taskId,
List<DataType> dataTypes
)
public DataElementValidatorWrapper(IDataElementValidator dataElementValidator, string taskId)
{
_dataElementValidator = dataElementValidator;
_taskId = taskId;
_dataTypes = dataTypes;
}

/// <inheritdoc />
Expand Down
4 changes: 2 additions & 2 deletions src/Altinn.App.Core/Implementation/AppResourcesSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ private static byte[] ReadFileContentsFromLegalPath(string legalPath, string fil
public string? GetValidationConfiguration(string dataTypeId)
{
using var activity = _telemetry?.StartGetValidationConfigurationActivity();
string legalPath = $"{_settings.AppBasePath}{_settings.ModelsFolder}";
string filename = $"{legalPath}{dataTypeId}.{_settings.ValidationConfigurationFileName}";
string legalPath = Path.Join(_settings.AppBasePath, _settings.ModelsFolder);
string filename = Path.Join(legalPath, $"{dataTypeId}.{_settings.ValidationConfigurationFileName}");
PathHelper.EnsureLegalPath(legalPath, filename);

string? filedata = null;
Expand Down
3 changes: 1 addition & 2 deletions src/Altinn.App.Core/Internal/Validation/IValidatorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ public IEnumerable<IValidator> GetValidators(string taskId)
var dataTypes = _appMetadata.GetApplicationMetadata().Result.DataTypes;

validators.AddRange(
GetDataElementValidators(taskId, dataTypes)
.Select(dev => new DataElementValidatorWrapper(dev, taskId, dataTypes))
GetDataElementValidators(taskId, dataTypes).Select(dev => new DataElementValidatorWrapper(dev, taskId))
);
validators.AddRange(
GetFormDataValidators(taskId, dataTypes).Select(fdv => new FormDataValidatorWrapper(fdv, taskId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ public async Task<UserActionResult> HandleAction(UserActionContext context)
);
break;
case "update":
var originalDataElement = context.DataMutator.GetDataElementsForType("Scheme").First();
var dataType =
context.DataMutator.GetDataType("Scheme") ?? throw new Exception("DataType \"Scheme\" not found");
var originalDataElement = context.DataMutator.GetDataElementsForType(dataType).First();
var data = await context.DataMutator.GetFormData<Scheme>(originalDataElement);

data.TestCustomButtonReadOnlyInput = "Her kommer det data fra backend";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
ActivityName: ApplicationMetadata.Service.GetLayoutModel,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutModel,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSet,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSet,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSet,
IdFormat: W3C
Expand All @@ -28,20 +40,28 @@
ActivityName: ApplicationMetadata.Service.GetLayoutSets,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSets,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSets,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSetsForTask,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet,
ActivityName: ApplicationMetadata.Service.GetLayoutSetsForTask,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetValidationConfiguration,
ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetValidationConfiguration,
ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet,
IdFormat: W3C
},
{
Expand Down Expand Up @@ -153,6 +173,21 @@
],
IdFormat: W3C
},
{
ActivityName: Validation.RunValidator,
Tags: [
{
validation.issue_count: 0
},
{
validator.source: Expression
},
{
validator.type: ExpressionValidator
}
],
IdFormat: W3C
},
{
ActivityName: Validation.RunValidator,
Tags: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
ActivityName: ApplicationMetadata.Service.GetLayoutModel,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutModel,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSet,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSet,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSet,
IdFormat: W3C
Expand All @@ -28,28 +40,36 @@
ActivityName: ApplicationMetadata.Service.GetLayoutSets,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSets,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSets,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSetsForTask,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet,
ActivityName: ApplicationMetadata.Service.GetLayoutSetsForTask,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetTexts,
ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetTexts,
ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetValidationConfiguration,
ActivityName: ApplicationMetadata.Service.GetTexts,
IdFormat: W3C
},
{
ActivityName: ApplicationMetadata.Service.GetValidationConfiguration,
ActivityName: ApplicationMetadata.Service.GetTexts,
IdFormat: W3C
},
{
Expand Down Expand Up @@ -283,6 +303,21 @@
],
IdFormat: W3C
},
{
ActivityName: Validation.RunValidator,
Tags: [
{
validation.issue_count: 0
},
{
validator.source: Expression
},
{
validator.type: ExpressionValidator
}
],
IdFormat: W3C
},
{
ActivityName: Validation.RunValidator,
Tags: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/validation/validation.schema.v1.json",
"validations": {
"melding.name": [
{
"condition": [
"equals",
[
"dataModel",
"melding.name"
],
"Model"
],
"message": "The file must be of type Model"
}
]
}
}

0 comments on commit 44219c7

Please sign in to comment.