Skip to content

Commit

Permalink
chore: Updated validator messages (#1133)
Browse files Browse the repository at this point in the history
## Description

Improved validator messages to give error messages with null + when
checks.

## Related Issue(s)

[#1126](#1126)

## Verification

- [x] **Your** code builds clean without any errors or warnings
- [x] 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)


Co-authored-by: Amund Myrbostad <amund.myrbostad@digdir.no>
  • Loading branch information
Fargekritt and Fargekritt authored Sep 16, 2024
1 parent ca39923 commit 760da9e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Digdir.Domain.Dialogporten.Application.Common.Extensions.FluentValidation;
using Digdir.Domain.Dialogporten.Application.Common.Pagination;
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
using Digdir.Domain.Dialogporten.Domain.Common;
using Digdir.Domain.Dialogporten.Domain.Localizations;
using FluentValidation;

Expand Down Expand Up @@ -45,8 +46,8 @@ public SearchDialogQueryValidator()
.When(x => x.ExtendedStatus is not null);

RuleFor(x => x.Process)
.Must(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))
.WithMessage("{PropertyName} must be a valid URI")
.IsValidUri()
.MaximumLength(Constants.DefaultMaxUriLength)
.When(x => x.Process is not null);

RuleForEach(x => x.Status).IsInEnum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public NotificationConditionQueryValidator()
RuleFor(x => x.TransmissionId)
.NotNull()
.NotEqual(default(Guid))
.When(x => x.ActivityType == DialogActivityType.Values.TransmissionOpened);
.When(x => x.ActivityType == DialogActivityType.Values.TransmissionOpened)
.WithMessage($"{{PropertyName}} must not be empty when ${nameof(NotificationConditionQuery.ActivityType)} is ${nameof(DialogActivityType.Values.TransmissionOpened)}");

RuleFor(x => x.TransmissionId)
.Null()
.When(x => x.ActivityType == DialogActivityType.Values.DialogOpened)
.WithMessage($"{{PropertyName}} must be empty when {nameof(NotificationConditionQuery.ActivityType)} is {DialogActivityType.Values.DialogOpened}.");
.WithMessage($"{{PropertyName}} must be empty when {nameof(NotificationConditionQuery.ActivityType)} is {nameof(DialogActivityType.Values.DialogOpened)}.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public CreateDialogCommandValidator(
.SetValidator(activityValidator);

RuleFor(x => x.Process)
.Must(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))
.WithMessage("{PropertyName} must be a valid absolute URI.")
.IsValidUri()
.MaximumLength(Constants.DefaultMaxUriLength)
.When(x => x.Process is not null);

RuleFor(x => x.Process)
Expand All @@ -144,8 +144,8 @@ public CreateDialogCommandValidator(
.When(x => x.PrecedingProcess is not null);

RuleFor(x => x.PrecedingProcess)
.Must(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))
.WithMessage("{PropertyName} must be a valid absolute URI.")
.IsValidUri()
.MaximumLength(Constants.DefaultMaxUriLength)
.When(x => x.PrecedingProcess is not null);
}
}
Expand Down

0 comments on commit 760da9e

Please sign in to comment.