-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow new activities to reference old activities (#935)
<!--- Provide a general summary of your changes in the Title above --> ## Description It is currently not possible to create a new DialogActivity that refers to an old DialogActivity via `relatedActivityId` This check in the validator requires the referred Id to be present in the DTO, which we don't allow. ```cshap RuleForEach(x => x.Activities) .IsIn(x => x.Activities, dependentKeySelector: activity => activity.RelatedActivityId, principalKeySelector: activity => activity.Id) .SetValidator(activityValidator); ``` This suggestion is to move this check from the validator to the handler and load all activities to verify the relation ID. ## Related Issue(s) - #931 ## Verification - [x] **Your** code builds clean without any errors or warnings - [x] Manual testing done (required) - [x] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable)
- Loading branch information
Showing
4 changed files
with
93 additions
and
11 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
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
52 changes: 47 additions & 5 deletions
52
...lication.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/UpdateDialogTests.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 |
---|---|---|
@@ -1,13 +1,55 @@ | ||
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Get; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Update; | ||
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors; | ||
using Digdir.Tool.Dialogporten.GenerateFakeData; | ||
using FluentAssertions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Features.V1.ServiceOwner.Dialogs.Commands; | ||
|
||
[Collection(nameof(DialogCqrsCollectionFixture))] | ||
public class UpdateDialogTests : ApplicationCollectionFixture | ||
public class UpdateDialogTests(DialogApplication application) : ApplicationCollectionFixture(application) | ||
{ | ||
public UpdateDialogTests(DialogApplication application) : base(application) | ||
[Fact] | ||
public async Task New_Activity_Should_Be_Able_To_Refer_To_Old_Activity() | ||
{ | ||
// Arrange | ||
var (_, createCommandResponse) = await GenerateDialogWithActivity(); | ||
var getDialogQuery = new GetDialogQuery { DialogId = createCommandResponse.AsT0.Value }; | ||
var getDialogDto = await Application.Send(getDialogQuery); | ||
|
||
var mapper = Application.GetMapper(); | ||
var updateDialogDto = mapper.Map<UpdateDialogDto>(getDialogDto.AsT0); | ||
|
||
// New activity refering to old activity | ||
updateDialogDto.Activities.Add(new UpdateDialogDialogActivityDto | ||
{ | ||
Type = DialogActivityType.Values.DialogClosed, | ||
RelatedActivityId = getDialogDto.AsT0.Activities.First().Id, | ||
PerformedBy = new UpdateDialogDialogActivityActorDto | ||
{ | ||
ActorType = DialogActorType.Values.ServiceOwner | ||
} | ||
}); | ||
|
||
// Act | ||
var updateResponse = await Application.Send(new UpdateDialogCommand { Id = createCommandResponse.AsT0.Value, Dto = updateDialogDto }); | ||
|
||
// Assert | ||
updateResponse.TryPickT0(out var result, out _).Should().BeTrue(); | ||
result.Should().NotBeNull(); | ||
} | ||
// TODO: Add tests | ||
} | ||
|
||
private async Task<(CreateDialogCommand, CreateDialogResult)> GenerateDialogWithActivity() | ||
{ | ||
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); | ||
var activity = DialogGenerator.GenerateFakeDialogActivity(type: DialogActivityType.Values.Information); | ||
activity.PerformedBy.ActorId = DialogGenerator.GenerateRandomParty(forcePerson: true); | ||
activity.PerformedBy.ActorName = null; | ||
createDialogCommand.Activities.Add(activity); | ||
var createCommandResponse = await Application.Send(createDialogCommand); | ||
return (createDialogCommand, createCommandResponse); | ||
} | ||
} |