-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add ProcessTasks to AppProcessState * wip: add test for process controller * feat: add ProcessTasks to AppProcessState * wip: add test for process controller * Adding first test for processcontroller * Fix bad case for roles folder in testsetup * User ArgumentNullException.ThrowIfNull instead of custom method * Fix codesmells --------- Co-authored-by: Vemund Gaukstad <tjololo@users.noreply.github.com>
- Loading branch information
Showing
11 changed files
with
213 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Altinn.App.Core/Internal/Process/Elements/AppProcessTaskTypeInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#nullable enable | ||
using System.Xml.Serialization; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Altinn.App.Core.Internal.Process.Elements; | ||
|
||
/// <summary> | ||
/// Representation of a task's id and type. Used by the frontend to determine which tasks | ||
/// exist, and their type. | ||
/// </summary> | ||
public class AppProcessTaskTypeInfo | ||
{ | ||
/// <summary> | ||
/// Gets or sets the task type | ||
/// </summary> | ||
[XmlElement("altinnTaskType", Namespace = "http://altinn.no/process")] | ||
public string? AltinnTaskType { get; set; } | ||
|
||
|
||
/// <summary> | ||
/// Gets or sets a reference to the current task/event element id as given in the process definition. | ||
/// </summary> | ||
[JsonPropertyName(name: "elementId")] | ||
public string? ElementId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Net; | ||
using System.Net.Http.Headers; | ||
using System.Text.Json; | ||
using Altinn.App.Api.Models; | ||
using Altinn.App.Api.Tests.Data; | ||
using Altinn.App.Api.Tests.Utils; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Xunit; | ||
|
||
namespace Altinn.App.Api.Tests.Controllers; | ||
|
||
public class ProcessControllerTests : ApiTestBase, IClassFixture<WebApplicationFactory<Program>> | ||
{ | ||
public ProcessControllerTests(WebApplicationFactory<Program> factory) : base(factory) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task Get_ShouldReturnProcessTasks() | ||
{ | ||
string org = "tdd"; | ||
string app = "contributer-restriction"; | ||
int partyId = 500000; | ||
Guid instanceId = new Guid("5d9e906b-83ed-44df-85a7-2f104c640bff"); | ||
HttpClient client = GetRootedClient(org, app); | ||
|
||
TestData.DeleteInstance(org, app, partyId, instanceId); | ||
TestData.PrepareInstance(org, app, partyId, instanceId); | ||
|
||
string token = PrincipalUtil.GetToken(1337, 500000, 3); | ||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||
|
||
string url = $"/{org}/{app}/instances/{partyId}/{instanceId}/process"; | ||
HttpResponseMessage response = await client.GetAsync(url); | ||
TestData.DeleteInstance(org, app, partyId, instanceId); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
var content = await response.Content.ReadAsStringAsync(); | ||
var expectedString = """ | ||
{ | ||
"currentTask": { | ||
"actions": { | ||
"read": true, | ||
"write": true | ||
}, | ||
"userActions": [ | ||
{ | ||
"id": "read", | ||
"authorized": true, | ||
"type": "ProcessAction" | ||
}, | ||
{ | ||
"id": "write", | ||
"authorized": true, | ||
"type": "ProcessAction" | ||
} | ||
], | ||
"read": true, | ||
"write": true, | ||
"flow": 2, | ||
"started": "2019-12-05T13:24:34.9196661Z", | ||
"elementId": "Task_1", | ||
"name": "Utfylling", | ||
"altinnTaskType": "data", | ||
"ended": null, | ||
"validated": { | ||
"timestamp": "2020-02-07T10:46:36.985894+01:00", | ||
"canCompleteTask": false | ||
}, | ||
"flowType": null | ||
}, | ||
"processTasks": [ | ||
{ | ||
"altinnTaskType": "data", | ||
"elementId": "Task_1" | ||
} | ||
], | ||
"started": "2019-12-05T13:24:34.8412179Z", | ||
"startEvent": "StartEvent_1", | ||
"ended": null, | ||
"endEvent": null | ||
} | ||
"""; | ||
CompareResult<AppProcessState>(expectedString, content); | ||
} | ||
|
||
|
||
//TODO: replace this assertion with a proper one once fluentassertions has a json compare feature scheduled for v7 https://github.com/fluentassertions/fluentassertions/issues/2205 | ||
private static void CompareResult<T>(string expectedString, string actualString) | ||
{ | ||
T? expected = JsonSerializer.Deserialize<T>(expectedString); | ||
T? actual = JsonSerializer.Deserialize<T>(actualString); | ||
actual.Should().BeEquivalentTo(expected); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...nces/tdd/contributer-restriction/500000/5d9e906b-83ed-44df-85a7-2f104c640bff.pretest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"id": "500000/5d9e906b-83ed-44df-85a7-2f104c640bff", | ||
"instanceOwner": { | ||
"partyId": "500000", | ||
"personNumber": "01039012345" | ||
}, | ||
"appId": "tdd/contributer-restriction", | ||
"org": "tdd", | ||
"process": { | ||
"started": "2019-12-05T13:24:34.8412179Z", | ||
"startEvent": "StartEvent_1", | ||
"currentTask": { | ||
"flow": 2, | ||
"started": "2019-12-05T13:24:34.9196661Z", | ||
"elementId": "Task_1", | ||
"name": "Utfylling", | ||
"altinnTaskType": "data", | ||
"validated": { | ||
"timestamp": "2020-02-07T10:46:36.985894+01:00", | ||
"canCompleteTask": false | ||
} | ||
} | ||
}, | ||
"status": { | ||
"isArchived": false, | ||
"isSoftDeleted": false, | ||
"isHardDeleted": false, | ||
"readStatus": "Read" | ||
}, | ||
"data": [ | ||
{ | ||
"id": "de288942-a8af-4f77-a1f1-6e1ede1cd502", | ||
"dataType": "default", | ||
"contentType": "application/xml", | ||
"size": 0, | ||
"locked": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters