Skip to content

Commit

Permalink
Mark onEntry as nullable and add check for null
Browse files Browse the repository at this point in the history
  • Loading branch information
tjololo committed Jul 20, 2023
1 parent 4aaba48 commit 286dd81
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Altinn.App.Core/Implementation/AppResourcesSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ public Application GetApplication()
{
ApplicationMetadata applicationMetadata = _appMetadata.GetApplicationMetadata().Result;
Application application = applicationMetadata;
application.OnEntry = new OnEntryConfig()
if (applicationMetadata.OnEntry != null)
{
Show = applicationMetadata.OnEntry.Show
};
application.OnEntry = new OnEntryConfig()
{
Show = applicationMetadata.OnEntry.Show
};
}

return application;
}
catch (AggregateException ex)
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Core/Models/ApplicationMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ApplicationMetadata(string id)
/// Configure options for handling what happens when entering the application
/// </summary>
[JsonProperty(PropertyName = "onEntry")]
public new OnEntry OnEntry { get; set; }
public new OnEntry? OnEntry { get; set; }

/// <summary>
/// Get AppIdentifier based on ApplicationMetadata.Id
Expand Down
47 changes: 47 additions & 0 deletions test/Altinn.App.Core.Tests/Implementation/AppResourcesSITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,53 @@ public void GetApplication_desrializes_file_from_disk()
actual.Should().NotBeNull();
actual.Should().BeEquivalentTo(expected);
}

[Fact]
public void GetApplication_handles_onEntry_null()
{
AppSettings appSettings = GetAppSettings("AppMetadata", "no-on-entry.applicationmetadata.json");
var settings = Options.Create<AppSettings>(appSettings);
IAppMetadata appMetadata = SetupAppMedata(Options.Create(appSettings));
IAppResources appResources = new AppResourcesSI(settings, appMetadata, null, new NullLogger<AppResourcesSI>());
Application expected = new Application()
{
Id = "tdd/bestilling",
Org = "tdd",
Created = DateTime.Parse("2019-09-16T22:22:22"),
CreatedBy = "username",
Title = new Dictionary<string, string>()
{
{ "nb", "Bestillingseksempelapp" }
},
DataTypes = new List<DataType>()
{
new()
{
Id = "vedlegg",
AllowedContentTypes = new List<string>() { "application/pdf", "image/png", "image/jpeg" },
MinCount = 0,
TaskId = "Task_1"
},
new()
{
Id = "ref-data-as-pdf",
AllowedContentTypes = new List<string>() { "application/pdf" },
MinCount = 1,
TaskId = "Task_1"
}
},
PartyTypesAllowed = new PartyTypesAllowed()
{
BankruptcyEstate = true,
Organisation = true,
Person = true,
SubUnit = true
}
};
var actual = appResources.GetApplication();

Check warning

Code scanning / CodeQL

Call to obsolete method Warning test

Call to obsolete method
GetApplication
.
actual.Should().NotBeNull();
actual.Should().BeEquivalentTo(expected);
}

[Fact]
public void GetApplication_second_read_from_cache()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"id": "tdd/bestilling",
"org": "tdd",
"created": "2019-09-16T22:22:22",
"createdBy": "username",
"title": { "nb": "Bestillingseksempelapp" },
"dataTypes": [
{
"id": "vedlegg",
"allowedContentTypes": [ "application/pdf", "image/png", "image/jpeg" ],
"minCount": 0,
"taskId": "Task_1",
},
{
"id": "ref-data-as-pdf",
"allowedContentTypes": [ "application/pdf" ],
"minCount": 1,
"taskId": "Task_1",
}
],
"partyTypesAllowed": {
"bankruptcyEstate": true,
"organisation": true,
"person": true,
"subUnit": true
}
}

0 comments on commit 286dd81

Please sign in to comment.