Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
48f88cd
HEEDLS-546 Delegate registration by centre: WelcomeEmail page GET
ibrahimmunir14 Jul 6, 2021
2d171a7
HEEDLS-546 Add date validation to WelcomeEmail POST; display date fie…
ibrahimmunir14 Jul 7, 2021
d6e698e
HEEDLS-546 Read/write between ViewModel and Data on WelcomeEmail GET/…
ibrahimmunir14 Jul 7, 2021
2239a71
HEEDLS-546 Add empty constructor to WelcomeEmail viewmodel
ibrahimmunir14 Jul 7, 2021
0b236c8
HEEDLS-546 Delegate registration by centre: Password page
ibrahimmunir14 Jul 7, 2021
15555ec
HEEDLS-546 Delegate registration by centre: Summary page
ibrahimmunir14 Jul 7, 2021
1f71475
HEEDLS-546 Fix and tidy up welcome email date and password set
ibrahimmunir14 Jul 7, 2021
55da6b5
HEEDLS-546 Change back link on Summary to return to correct previous …
ibrahimmunir14 Jul 7, 2021
51297cc
HEEDLS-546 Make password non-required; clear password hash if welcome…
ibrahimmunir14 Jul 7, 2021
daf6cea
Merge branch 'master' into HEEDLS-546-all-delegates-register-3-4-5
ibrahimmunir14 Jul 8, 2021
20c36c0
HEEDLS-546 Create and use DateInput view component
ibrahimmunir14 Jul 8, 2021
052b2bd
HEEDLS-546 Add appropriate css classes to display error border
ibrahimmunir14 Jul 8, 2021
1873ffb
HEEDLS-546 Fix spacing on PersonalInformation page
ibrahimmunir14 Jul 8, 2021
8b4250c
HEEDLS-546 Fix bug where Alias was not set correctly; write DelegateR…
ibrahimmunir14 Jul 13, 2021
544fc2a
Merge remote-tracking branch 'origin/master' into HEEDLS-546-all-dele…
ibrahimmunir14 Jul 13, 2021
884a8ef
HEEDLS-546 Move RDbyC viewmodels into Register/RDbyC folder
ibrahimmunir14 Jul 14, 2021
8a8450b
HEEDLS-546 Tidy up WelcomeEmailDate string formatting; use derived fi…
ibrahimmunir14 Jul 14, 2021
f1c87ec
HEEDLS-546 Rename PasswordVM to ConfirmPasswordVM; move PasswordVM fr…
ibrahimmunir14 Jul 14, 2021
2591d05
HEEDLS-546 Review markups: minor formatting/refactoring
ibrahimmunir14 Jul 14, 2021
917092f
HEEDLS-546 Move ids into variables/consts; use Id param instead of Name
ibrahimmunir14 Jul 14, 2021
48b7f07
HEEDLS-546 Rename a WelcomeEmailVM function
ibrahimmunir14 Jul 15, 2021
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 @@ -22,6 +22,7 @@ public class RegisterDelegateByCentreControllerTests
private IJobGroupsDataService jobGroupsDataService = null!;
private IUserDataService userDataService = null!;
private IUserService userService = null!;
private ICryptoService cryptoService = null!;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add any tests about temp data being updated appropriately?

Copy link
Contributor Author

@ibrahimmunir14 ibrahimmunir14 Jul 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already written tests for populating DelegtateRegistrationbyCentreData from viewmodels. Is that enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone refactors this file and forgets to update TempData? I guess we could catch that in the AutomatedUI tests, when we do accessibility scans of the pages (which I'm happy for you to add as part of whichever subtask)


[SetUp]
public void Setup()
Expand All @@ -30,10 +31,12 @@ public void Setup()
userService = A.Fake<IUserService>();
userDataService = A.Fake<IUserDataService>();
customPromptHelper = A.Fake<CustomPromptHelper>();
cryptoService = A.Fake<ICryptoService>();
controller = new RegisterDelegateByCentreController(
jobGroupsDataService,
userService,
customPromptHelper,
cryptoService,
userDataService
)
.WithDefaultContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public async Task Post_to_index_should_invalidate_reset_hash_if_model_and_hash_v

// When
await unauthenticatedController.Index(
new PasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });
new ConfirmPasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });

// Then
A.CallTo(() => passwordResetService.InvalidateResetPasswordForEmailAsync("email"))
Expand All @@ -133,7 +133,7 @@ public async Task Post_to_index_should_update_password_if_model_and_hash_valid()

// When
await unauthenticatedController.Index(
new PasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });
new ConfirmPasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });

// Then
A.CallTo(() => passwordService.ChangePasswordAsync("email", "testPass-9"))
Expand All @@ -149,7 +149,7 @@ public async Task Post_to_index_should_return_success_page_if_model_and_hash_val

// When
var result = await unauthenticatedController.Index(
new PasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });
new ConfirmPasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });

// Then
result.Should().BeViewResult().WithViewName("Success");
Expand All @@ -165,7 +165,7 @@ public async Task Post_to_index_should_clear_temp_data_if_model_and_hash_valid()

// When
await unauthenticatedController.Index(
new PasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });
new ConfirmPasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });

// Then
unauthenticatedController.TempData.Peek<ResetPasswordData>().Should().BeNull();
Expand All @@ -182,7 +182,7 @@ public async Task Post_to_index_should_clear_temp_data_if_hash_invalid()

// When
await unauthenticatedController.Index(
new PasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });
new ConfirmPasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });

// Then
unauthenticatedController.TempData.Peek<ResetPasswordData>().Should().BeNull();
Expand All @@ -199,7 +199,7 @@ public async Task Post_to_index_should_preserve_temp_data_if_model_invalid()

// When
await unauthenticatedController.Index(
new PasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });
new ConfirmPasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });

// Then
unauthenticatedController.TempData.Peek<ResetPasswordData>().Should()
Expand All @@ -216,7 +216,7 @@ public async Task Post_to_index_should_return_form_if_model_state_invalid()

// When
var result = await unauthenticatedController.Index(
new PasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });
new ConfirmPasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });

// Then
result.Should().BeViewResult().WithDefaultViewName();
Expand All @@ -231,7 +231,7 @@ public async Task Post_to_index_should_redirect_to_Error_if_reset_password_inval

// When
var result = await unauthenticatedController.Index(
new PasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });
new ConfirmPasswordViewModel { Password = "testPass-9", ConfirmPassword = "testPass-9" });

// Then
result.Should().BeRedirectToActionResult().WithActionName("Error").WithControllerName(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace DigitalLearningSolutions.Web.Tests.Models
{
using System;
using DigitalLearningSolutions.Web.Models;
using DigitalLearningSolutions.Web.ViewModels.Register;
using DigitalLearningSolutions.Web.ViewModels.Register.RegisterDelegateByCentre;
using FluentAssertions;
using NUnit.Framework;

internal class DelegateRegistrationByCentreDataTests
{
private const string FirstName = "Test";
private const string LastName = "User";
private const string Email = "test@email.com";
private const string Alias = "testuser";
private const int CentreId = 5;

[Test]
public void SetPersonalInformation_sets_data_correctly()
{
// Given
var model = new PersonalInformationViewModel
{
FirstName = FirstName,
LastName = LastName,
Centre = CentreId,
Email = Email,
Alias = Alias
};
var data = new DelegateRegistrationByCentreData();

// When
data.SetPersonalInformation(model);

// Then
data.FirstName.Should().Be(FirstName);
data.LastName.Should().Be(LastName);
data.Email.Should().Be(Email);
data.Centre.Should().Be(CentreId);
data.Alias.Should().Be(Alias);
}

[Test]
public void SetWelcomeEmail_with_ShouldSendEmail_false_sets_data_correctly()
{
// Given
var model = new WelcomeEmailViewModel { ShouldSendEmail = false, Day = 7, Month = 7, Year = 2200 };
var data = new DelegateRegistrationByCentreData();

// When
data.SetWelcomeEmail(model);

// Then
data.ShouldSendEmail.Should().BeFalse();
data.WelcomeEmailDate.Should().BeNull();
}

[Test]
public void SetWelcomeEmail_with_ShouldSendEmail_true_sets_data_correctly()
{
// Given
var date = new DateTime(2200, 7, 7);
var model = new WelcomeEmailViewModel
{ ShouldSendEmail = true, Day = date.Day, Month = date.Month, Year = date.Year };
var data = new DelegateRegistrationByCentreData();

// When
data.SetWelcomeEmail(model);

// Then
data.ShouldSendEmail.Should().BeTrue();
data.WelcomeEmailDate.Should().Be(date);
data.IsPasswordSet.Should().BeFalse();
data.PasswordHash.Should().BeNull();
}
}
}
41 changes: 35 additions & 6 deletions DigitalLearningSolutions.Web/ControllerHelpers/DateValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ public ValidationResult(int day, int month, int year)
public int? Year { get; }
}

public static ValidationResult ValidateRequiredDate(int? day, int? month, int? year, string name)
{
day ??= 0;
month ??= 0;
year ??= 0;

try
{
var newDate = new DateTime(year.Value, month.Value, day.Value);
if (newDate <= DateTime.Today)
{
return new ValidationResult(day.Value, month.Value, year.Value)
{
DateValid = false,
DayValid = false,
MonthValid = false,
YearValid = false,
ErrorMessage = "Email delivery date must be in the future"
};
}

return new ValidationResult(day.Value, month.Value, year.Value);
}
catch (ArgumentOutOfRangeException)
{
return GetValidationError(day.Value, month.Value, year.Value, name);
}
}

public static ValidationResult ValidateDate(int day, int month, int year)
{
if (day == 0 && month == 0 && year == 0)
Expand Down Expand Up @@ -70,11 +99,11 @@ public static ValidationResult ValidateDate(int day, int month, int year)
}
catch (ArgumentOutOfRangeException)
{
return GetValidationError(day, month, year);
return GetValidationError(day, month, year, "Complete by date");
}
}

private static ValidationResult GetValidationError(int day, int month, int year)
private static ValidationResult GetValidationError(int day, int month, int year, string name)
{
var error = new ValidationResult(day, month, year) { DateValid = false };

Expand All @@ -93,7 +122,7 @@ private static ValidationResult GetValidationError(int day, int month, int year)
error.YearValid = false;
}

error.ErrorMessage = ConstructErrorMessage(day, month, year);
error.ErrorMessage = ConstructErrorMessage(day, month, year, name);

return error;
}
Expand All @@ -113,7 +142,7 @@ private static bool YearIsValid(int year)
return year > 1752 && year < 10000;
}

private static string ConstructErrorMessage(int day, int month, int year)
private static string ConstructErrorMessage(int day, int month, int year, string name)
{
List<string> emptyElements = new List<string>();

Expand All @@ -134,10 +163,10 @@ private static string ConstructErrorMessage(int day, int month, int year)

if (emptyElements.Any())
{
return "Complete by date must include a " + string.Join(" and ", emptyElements);
return name + " must include a " + string.Join(" and ", emptyElements);
}

return "Complete by date must be a real date";
return name + " must be a real date";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public IActionResult LearnerInformation(LearnerInformationViewModel model)
[HttpGet]
public IActionResult Password()
{
return View(new PasswordViewModel());
return View(new ConfirmPasswordViewModel());
}

[ServiceFilter(typeof(RedirectEmptySessionData<RegistrationData>))]
[HttpPost]
public IActionResult Password(PasswordViewModel model)
public IActionResult Password(ConfirmPasswordViewModel model)
{
if (!ModelState.IsValid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ public IActionResult LearnerInformation(LearnerInformationViewModel model)
[HttpGet]
public IActionResult Password()
{
return View(new PasswordViewModel());
return View(new ConfirmPasswordViewModel());
}

[ServiceFilter(typeof(RedirectEmptySessionData<DelegateRegistrationData>))]
[HttpPost]
public IActionResult Password(PasswordViewModel model)
public IActionResult Password(ConfirmPasswordViewModel model)
{
if (!ModelState.IsValid)
{
Expand Down
Loading