Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS-1416: Change to EndOfTenureDate validation so it can be on the StartOfTenureDate #31

Merged
merged 6 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Hackney.Shared.Tenure.Tests.Boundary.Validation
public class CreateTenureRequestValidatorTests
{
public CreateTenureRequestValidation _classUnderTest;
DateTime _aSetDate = new DateTime(2024, 5, 7);

public CreateTenureRequestValidatorTests()
{
Expand All @@ -17,24 +18,36 @@ public CreateTenureRequestValidatorTests()
private const string StringWithTags = "Some string with <tag> in it.";

[Fact]
public void WhenEndDateisCorrectNoError()
public void WhenEndDateisAfterStartDateNoError()
{
var request = new CreateTenureRequestObject()
{
EndOfTenureDate = DateTime.UtcNow.AddDays(1),
StartOfTenureDate = DateTime.UtcNow
EndOfTenureDate = _aSetDate.AddDays(1),
StartOfTenureDate = _aSetDate
};
var result = _classUnderTest.TestValidate(request);
result.ShouldNotHaveValidationErrorFor(x => x.EndOfTenureDate);
}

[Fact]
public void WhenEndDateIsInCorrectHasError()
public void WhenEndDateisOnStartDateNoError()
{
var request = new CreateTenureRequestObject()
{
EndOfTenureDate = DateTime.UtcNow,
StartOfTenureDate = DateTime.UtcNow.AddDays(1)
EndOfTenureDate = _aSetDate,
StartOfTenureDate = _aSetDate
};
var result = _classUnderTest.TestValidate(request);
result.ShouldNotHaveValidationErrorFor(x => x.EndOfTenureDate);
}

[Fact]
public void WhenEndDateIsIncorrectHasError()
{
var request = new CreateTenureRequestObject()
{
EndOfTenureDate = _aSetDate,
StartOfTenureDate = _aSetDate.AddDays(1)
};
var result = _classUnderTest.TestValidate(request);
result.ShouldHaveValidationErrorFor(x => x.EndOfTenureDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Hackney.Shared.Tenure.Tests.Boundary.Validation
public class EditTenureDetailsRequestValidatorTests
{
public EditTenureDetailsRequestValidation _classUnderTest;
DateTime _aSetDate = new DateTime(2024, 5, 7);

private const string StringWithTags = "Some string with <tag> in it.";

public EditTenureDetailsRequestValidatorTests()
Expand All @@ -21,7 +23,7 @@ public void WhenEndDateIsNullNoError()
{
var request = new EditTenureDetailsRequestObject()
{
StartOfTenureDate = DateTime.UtcNow,
StartOfTenureDate = _aSetDate,
EndOfTenureDate = null
};

Expand All @@ -36,7 +38,7 @@ public void WhenStartDateIsNullNoError()
var request = new EditTenureDetailsRequestObject()
{
StartOfTenureDate = null,
EndOfTenureDate = DateTime.UtcNow
EndOfTenureDate = _aSetDate
};

var result = _classUnderTest.TestValidate(request);
Expand All @@ -49,8 +51,21 @@ public void WhenEndDateIsGreaterThanStartDateNoError()
{
var request = new EditTenureDetailsRequestObject()
{
StartOfTenureDate = DateTime.UtcNow,
EndOfTenureDate = DateTime.UtcNow.AddDays(1)
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate.AddDays(1)
};

var result = _classUnderTest.TestValidate(request);

result.ShouldNotHaveAnyValidationErrors();
}
[Fact]
public void WhenEndDateIsEqualToStartDateNoError()
{
var request = new EditTenureDetailsRequestObject()
{
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate
};

var result = _classUnderTest.TestValidate(request);
Expand All @@ -63,8 +78,8 @@ public void WhenEndDateIsLessThanStartDateHasError()
{
var request = new EditTenureDetailsRequestObject()
{
StartOfTenureDate = DateTime.UtcNow,
EndOfTenureDate = DateTime.UtcNow.AddDays(-1)
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate.AddDays(-1)
};

var result = _classUnderTest.TestValidate(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class TenureInformationValidatorWhenOnlyEndDateTests
{
public TenureInformationValidatorWhenOnlyEndDate _classUnderTest;

DateTime _aSetDate = new DateTime(2024, 5, 7);

public TenureInformationValidatorWhenOnlyEndDateTests()
{
_classUnderTest = new TenureInformationValidatorWhenOnlyEndDate();
Expand All @@ -22,7 +24,7 @@ public void WhenStartDateIsNullhasError()
var request = new TenureInformation()
{
StartOfTenureDate = null,
EndOfTenureDate = DateTime.UtcNow.AddDays(1)
EndOfTenureDate = _aSetDate.AddDays(1)
};

var result = _classUnderTest.TestValidate(request);
Expand All @@ -35,8 +37,23 @@ public void WhenEndDateIsGreaterThanStartDateNoError()
{
var request = new TenureInformation()
{
StartOfTenureDate = DateTime.UtcNow,
EndOfTenureDate = DateTime.UtcNow.AddDays(1)
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate.AddDays(1)
};

var result = _classUnderTest.TestValidate(request);

result.ShouldNotHaveValidationErrorFor(x => x.EndOfTenureDate);
}

[Fact]
public void WhenEndDateIsEqualToStartDateNoError()
{

var request = new TenureInformation()
{
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate
};

var result = _classUnderTest.TestValidate(request);
Expand All @@ -49,8 +66,8 @@ public void WhenEndDateIsLessThanStartDateHasError()
{
var request = new TenureInformation()
{
StartOfTenureDate = DateTime.UtcNow,
EndOfTenureDate = DateTime.UtcNow.AddDays(-1)
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate.AddDays(-1)
};

var result = _classUnderTest.TestValidate(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Hackney.Shared.Tenure.Tests.Boundary.Validation
public class TenureInformationValidatorWhenOnlyStartDateTests
{
public TenureInformationValidatorWhenOnlyStartDate _classUnderTest;
DateTime _aSetDate = new DateTime(2024, 5, 7);

public TenureInformationValidatorWhenOnlyStartDateTests()
{
Expand All @@ -20,7 +21,7 @@ public void WhenEndDateIsNullNoError()
{
var request = new TenureInformation()
{
StartOfTenureDate = DateTime.UtcNow,
StartOfTenureDate = _aSetDate,
EndOfTenureDate = null
};

Expand All @@ -34,8 +35,22 @@ public void WhenEndDateIsGreaterThanStartDateNoError()
{
var request = new TenureInformation()
{
StartOfTenureDate = DateTime.UtcNow,
EndOfTenureDate = DateTime.UtcNow.AddDays(1)
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate.AddDays(1)
};

var result = _classUnderTest.TestValidate(request);

result.ShouldNotHaveValidationErrorFor(x => x.EndOfTenureDate);
}

[Fact]
public void WhenEndDateIsEqualToStartDateNoError()
{
var request = new TenureInformation()
{
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate
};

var result = _classUnderTest.TestValidate(request);
Expand All @@ -48,8 +63,8 @@ public void WhenEndDateIsLessThanStartDateHasError()
{
var request = new TenureInformation()
{
StartOfTenureDate = DateTime.UtcNow,
EndOfTenureDate = DateTime.UtcNow.AddDays(-1)
StartOfTenureDate = _aSetDate,
EndOfTenureDate = _aSetDate.AddDays(-1)
};

var result = _classUnderTest.TestValidate(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CreateTenureRequestValidation : AbstractValidator<CreateTenureReque
public CreateTenureRequestValidation()
{
RuleFor(x => x.EndOfTenureDate)
.GreaterThan(x => x.StartOfTenureDate)
.GreaterThanOrEqualTo(x => x.StartOfTenureDate)
.WithErrorCode(ErrorCodes.TenureEndDate);

RuleFor(x => x.PaymentReference).NotXssString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public EditTenureDetailsRequestValidation()
When(tenure => tenure.EndOfTenureDate != null && tenure.StartOfTenureDate != null, () =>
{
RuleFor(x => x.EndOfTenureDate)
.GreaterThan(x => x.StartOfTenureDate)
.GreaterThanOrEqualTo(x => x.StartOfTenureDate)
.WithErrorCode(ErrorCodes.TenureEndDate);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ namespace Hackney.Shared.Tenure.Boundary.Requests.Validation
public static class ErrorCodes
{
public const string XssCheckFailure = "W42";
public const string TenureEndDate = "W29";
public const string TenureEndDate = "W59";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public TenureInformationValidatorWhenOnlyEndDate()
RuleFor(x => x.StartOfTenureDate)
.NotNull();

// the end date must be greater than start date
// the end date must be greater than or the same as the start date
RuleFor(x => x.EndOfTenureDate)
.GreaterThan(x => x.StartOfTenureDate)
.GreaterThanOrEqualTo(x => x.StartOfTenureDate)
martapederiva marked this conversation as resolved.
Show resolved Hide resolved
.WithErrorCode(ErrorCodes.TenureEndDate);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public TenureInformationValidatorWhenOnlyStartDate()
When(tenure => tenure.EndOfTenureDate != null, () =>
{
RuleFor(x => x.StartOfTenureDate)
.LessThan(x => x.EndOfTenureDate)
.LessThanOrEqualTo(x => x.EndOfTenureDate)
.WithErrorCode(ErrorCodes.TenureEndDate);
});
}
Expand Down
Loading