-
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(webapi): Only allow transmissionId on TransmissionOpened activiti…
…es (#1631) <!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> The validator activity validator allows setting TransmissionId on every activity type except DialogOpened. It should only allow on TransmissionOpened. ## Related Issue(s) - #1630 ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] 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
3 changed files
with
68 additions
and
6 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
62 changes: 62 additions & 0 deletions
62
...rten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.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,62 @@ | ||
using AutoMapper; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Common.Actors; | ||
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.Domain.Dialogs.Entities.Activities; | ||
using Digdir.Library.Entity.Abstractions.Features.Identifiable; | ||
using Digdir.Tool.Dialogporten.GenerateFakeData; | ||
using FluentAssertions; | ||
|
||
using UpdateActivityDto = | ||
Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Update.ActivityDto; | ||
using CreateActivityDto = | ||
Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create.ActivityDto; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Unit.Tests.Features.V1.ServiceOwner.Activities; | ||
|
||
public class ActivityValidatorTests | ||
{ | ||
public static IEnumerable<object[]> ActivityTypes() => | ||
from DialogActivityType.Values activityType in Enum.GetValues(typeof(DialogActivityType.Values)) | ||
select new object[] { activityType, }; | ||
|
||
[Theory, MemberData(nameof(ActivityTypes))] | ||
public void Only_TransmissionOpened_Is_Allowed_To_Set_TransmissionId( | ||
DialogActivityType.Values activityType) | ||
{ | ||
// Arrange | ||
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<CreateActivityDto, UpdateActivityDto>()).CreateMapper(); | ||
|
||
var activity = DialogGenerator.GenerateFakeDialogActivity(type: activityType); | ||
activity.TransmissionId = IdentifiableExtensions.CreateVersion7(); | ||
|
||
var localizationValidator = new LocalizationDtosValidator(); | ||
var actorValidator = new ActorValidator(); | ||
|
||
var createValidator = new CreateDialogDialogActivityDtoValidator(localizationValidator, actorValidator); | ||
var updateValidator = new UpdateDialogDialogActivityDtoValidator(localizationValidator, actorValidator); | ||
|
||
// Act | ||
var createValidation = createValidator.Validate(activity); | ||
var updateValidation = updateValidator.Validate(mapper.Map<UpdateActivityDto>(activity)); | ||
|
||
// Assert | ||
if (activityType == DialogActivityType.Values.TransmissionOpened) | ||
{ | ||
createValidation.IsValid.Should().BeTrue(); | ||
updateValidation.IsValid.Should().BeTrue(); | ||
} | ||
else | ||
{ | ||
createValidation.IsValid.Should().BeFalse(); | ||
updateValidation.IsValid.Should().BeFalse(); | ||
|
||
createValidation.Errors.Should().ContainSingle(); | ||
updateValidation.Errors.Should().ContainSingle(); | ||
|
||
createValidation.Errors.First().ErrorMessage.Should().Contain("TransmissionOpened"); | ||
updateValidation.Errors.First().ErrorMessage.Should().Contain("TransmissionOpened"); | ||
} | ||
} | ||
} |