Skip to content

Commit

Permalink
ER-1494 Limit QA and Provider report time-spans to three months (#809)…
Browse files Browse the repository at this point in the history
… +semver: minor
  • Loading branch information
mrpmorris authored and shomavg committed Nov 5, 2019
1 parent b8fe001 commit 07c95e5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class ProviderApplicationsReportCreateEditModelValidator : AbstractValida
{
public ProviderApplicationsReportCreateEditModelValidator(ITimeProvider timeProvider)
{

RuleFor(x => x.DateRange)
.NotNull()
.WithMessage("You must select the time period for the report");
Expand All @@ -31,11 +30,13 @@ public ProviderApplicationsReportCreateEditModelValidator(ITimeProvider timeProv
RuleFor(x => x.ToDate)
.Cascade(CascadeMode.StopOnFirstFailure)
.Must(date => date.AsDateTimeUk() < timeProvider.NextDay)
.WithMessage("Date to cannot be in the future");
.WithMessage("Date to cannot be in the future")
.Must((model, x) => model.ToDate.AsDateTimeUk() < model.FromDate.AsDateTimeUk().Value.AddMonths(3))
.WithMessage("Enter a date within three months from the start date");

RuleFor(x => x.FromDate)
.Must((model, _) => model.FromDate.AsDateTimeUk() < model.ToDate.AsDateTimeUk())
.WithMessage("Date from must be less than Date to");
.WithMessage("Date from must be earlier than Date to");
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
type="radio"
data-aria-controls="custom-range-panel">
<label for="daterange-custom" class="govuk-label govuk-radios__label">
a custom date range
choose a date range
<span class="govuk-hint">Maximum of 3 months</span>
</label>
</div>
<div id="custom-range-panel" class="govuk-radios__conditional govuk-radios__conditional--hidden">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void ShouldValidateToDateIsGreaterThanFromDate()
var result = validator.Validate(m);

result.Errors.Count.Should().Be(1);
result.Errors[0].ErrorMessage.Should().Be("Date from must be less than Date to");
result.Errors[0].ErrorMessage.Should().Be("Date from must be earlier than Date to");
}

private ProviderApplicationsReportCreateEditModelValidator GetValidator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class ApplicationsReportCreateEditModelValidator : AbstractValidator<Appl
{
public ApplicationsReportCreateEditModelValidator(ITimeProvider timeProvider)
{

RuleFor(x => x.DateRange)
.NotNull()
.WithMessage("You must select the time period for the report");
Expand All @@ -27,16 +26,18 @@ public ApplicationsReportCreateEditModelValidator(ITimeProvider timeProvider)
When(x => x.DateRange == DateRangeType.Custom &&
x.FromDate.AsDateTimeUk() != null &&
x.ToDate.AsDateTimeUk() != null, () =>
{
RuleFor(x => x.ToDate)
.Cascade(CascadeMode.StopOnFirstFailure)
.Must(date => date.AsDateTimeUk() < timeProvider.NextDay)
.WithMessage("Date to cannot be in the future");
{
RuleFor(x => x.ToDate)
.Cascade(CascadeMode.StopOnFirstFailure)
.Must(date => date.AsDateTimeUk() < timeProvider.NextDay)
.WithMessage("Date to cannot be in the future")
.Must((model, x) => model.ToDate.AsDateTimeUk() < model.FromDate.AsDateTimeUk().Value.AddMonths(3))
.WithMessage("Enter a date within three months from the start date");

RuleFor(x => x.FromDate)
.Must((model, _) => model.FromDate.AsDateTimeUk() < model.ToDate.AsDateTimeUk())
.WithMessage("Date from must be less than Date to");
});
RuleFor(x => x.FromDate)
.Must((model, _) => model.FromDate.AsDateTimeUk() < model.ToDate.AsDateTimeUk())
.WithMessage("Date from must be ealier than Date to");
});
}
}
}
3 changes: 2 additions & 1 deletion src/QA/QA.Web/Views/Reports/ApplicationsReport/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
type="radio"
data-aria-controls="custom-range-panel">
<label for="daterange-custom" class="govuk-label govuk-radios__label">
a custom date range
choose a date range
<span class="govuk-hint">Maximum of 3 months</span>
</label>
</div>
<div id="custom-range-panel" class="govuk-radios__conditional govuk-radios__conditional--hidden">
Expand Down

0 comments on commit 07c95e5

Please sign in to comment.