Skip to content
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 @@ -346,5 +346,35 @@ public void Error_in_RegisterCentreManager_fails_fast()
A.CallTo(() => centresDataService.SetCentreAutoRegistered(testRegistrationModel.Centre))
.MustNotHaveHappened();
}

[Test]
public void RegisterDelegateByCentre_sets_password_if_passwordHash_not_null()
{
// Given
var model = new DelegateRegistrationModel("firstName", "lastName", "email", 0, 0, PasswordHash);
A.CallTo(() => registrationDataService.RegisterDelegateByCentre(model)).Returns(NewCandidateNumber);

// When
registrationService.RegisterDelegateByCentre(model);

// Then
A.CallTo(() => registrationDataService.RegisterDelegateByCentre(model)).MustHaveHappened(1, Times.Exactly);
A.CallTo(() => passwordDataService.SetPasswordByCandidateNumber(NewCandidateNumber, PasswordHash)).MustHaveHappened(1, Times.Exactly);
}

[Test]
public void RegisterDelegateByCentre_does_not_set_password_if_passwordHash_is_null()
{
// Given
var model = new DelegateRegistrationModel("firstName", "lastName", "email", 0, 0, null);
A.CallTo(() => registrationDataService.RegisterDelegateByCentre(model)).Returns(NewCandidateNumber);

// When
registrationService.RegisterDelegateByCentre(model);

// Then
A.CallTo(() => registrationDataService.RegisterDelegateByCentre(model)).MustHaveHappened(1, Times.Exactly);
A.CallTo(() => passwordDataService.SetPasswordByCandidateNumber(A<string>._, A<string>._)).MustNotHaveHappened();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public interface IRegistrationDataService
{
string RegisterDelegate(DelegateRegistrationModel delegateRegistrationModel);
string RegisterDelegateByCentre(DelegateRegistrationModel delegateRegistrationModel);
int RegisterCentreManagerAdmin(RegistrationModel registrationModel);
}

Expand Down Expand Up @@ -53,6 +54,38 @@ public string RegisterDelegate(DelegateRegistrationModel delegateRegistrationMod
return candidateNumber;
}

public string RegisterDelegateByCentre(DelegateRegistrationModel delegateRegistrationModel)
{
var values = new
{
delegateRegistrationModel.FirstName,
delegateRegistrationModel.LastName,
delegateRegistrationModel.Email,
CentreID = delegateRegistrationModel.Centre,
JobGroupID = delegateRegistrationModel.JobGroup,
Active = 1,
Approved = 1,
delegateRegistrationModel.Answer1,
delegateRegistrationModel.Answer2,
delegateRegistrationModel.Answer3,
delegateRegistrationModel.Answer4,
delegateRegistrationModel.Answer5,
delegateRegistrationModel.Answer6,
AliasID = delegateRegistrationModel.AliasId,
ExternalReg = 0,
SelfReg = 0,
delegateRegistrationModel.NotifyDate,
Bulk = 0
};

var candidateNumber = connection.QueryFirstOrDefault<string>(
"uspSaveNewCandidate_V10",
values,
commandType: CommandType.StoredProcedure);

return candidateNumber;
}

public int RegisterCentreManagerAdmin(RegistrationModel registrationModel)
{
var values = new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace DigitalLearningSolutions.Data.Models.Register
{
using System;

public class DelegateRegistrationModel : RegistrationModel
{
public DelegateRegistrationModel(
Expand All @@ -8,20 +10,25 @@ public DelegateRegistrationModel(
string email,
int centre,
int jobGroup,
string passwordHash,
string? passwordHash,
string? answer1,
string? answer2,
string? answer3,
string? answer4,
string? answer5,
string? answer6) : base(firstName, lastName, email, centre, jobGroup, passwordHash)
string? answer6,
string? aliasId = null,
DateTime? notifyDate = null
) : base(firstName, lastName, email, centre, jobGroup, passwordHash)
{
Answer1 = answer1;
Answer2 = answer2;
Answer3 = answer3;
Answer4 = answer4;
Answer5 = answer5;
Answer6 = answer6;
AliasId = aliasId;
NotifyDate = notifyDate;
}

public DelegateRegistrationModel(
Expand All @@ -30,7 +37,7 @@ public DelegateRegistrationModel(
string email,
int centre,
int jobGroup,
string passwordHash
string? passwordHash
) : base(firstName, lastName, email, centre, jobGroup, passwordHash) { }

public string? Answer1 { get; set; }
Expand All @@ -44,5 +51,9 @@ string passwordHash
public string? Answer5 { get; set; }

public string? Answer6 { get; set; }

public string? AliasId { get; set; }

public DateTime? NotifyDate { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public RegistrationModel(
string email,
int centre,
int jobGroup,
string passwordHash
string? passwordHash
)
{
FirstName = firstName;
Expand All @@ -30,7 +30,7 @@ string passwordHash

public int JobGroup { get; set; }

public string PasswordHash { get; set; }
public string? PasswordHash { get; set; }

public bool Approved { get; set; }
}
Expand Down
27 changes: 24 additions & 3 deletions DigitalLearningSolutions.Data/Services/RegistrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface IRegistrationService
bool refactoredTrackingSystemEnabled
);

string RegisterDelegateByCentre(DelegateRegistrationModel delegateRegistrationModel);

void RegisterCentreManager(RegistrationModel registrationModel);
}

Expand Down Expand Up @@ -63,7 +65,7 @@ bool refactoredTrackingSystemEnabled

passwordDataService.SetPasswordByCandidateNumber(
candidateNumber,
delegateRegistrationModel.PasswordHash
delegateRegistrationModel.PasswordHash!
);
if (!delegateRegistrationModel.Approved)
{
Expand All @@ -81,6 +83,25 @@ bool refactoredTrackingSystemEnabled
return (candidateNumber, delegateRegistrationModel.Approved);
}

public string RegisterDelegateByCentre(DelegateRegistrationModel delegateRegistrationModel)
{
var candidateNumber = registrationDataService.RegisterDelegateByCentre(delegateRegistrationModel);
if (candidateNumber == "-1" || candidateNumber == "-4")
{
return candidateNumber;
}

if (delegateRegistrationModel.PasswordHash != null)
{
passwordDataService.SetPasswordByCandidateNumber(
candidateNumber,
delegateRegistrationModel.PasswordHash
);
}

return candidateNumber;
}

public void RegisterCentreManager(RegistrationModel registrationModel)
{
using var transaction = new TransactionScope();
Expand All @@ -102,7 +123,7 @@ private void CreateDelegateAccountForAdmin(RegistrationModel registrationModel)
registrationModel.Email,
registrationModel.Centre,
registrationModel.JobGroup,
registrationModel.PasswordHash
registrationModel.PasswordHash!
) { Approved = true };
var candidateNumber =
registrationDataService.RegisterDelegate(delegateRegistrationModel);
Expand All @@ -115,7 +136,7 @@ private void CreateDelegateAccountForAdmin(RegistrationModel registrationModel)

passwordDataService.SetPasswordByCandidateNumber(
candidateNumber,
delegateRegistrationModel.PasswordHash
delegateRegistrationModel.PasswordHash!
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
{
using DigitalLearningSolutions.Web.AutomatedUiTests.TestHelpers;
using FluentAssertions;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using Selenium.Axe;
using Xunit;

Expand Down Expand Up @@ -45,5 +43,83 @@ public void Registration_journey_has_no_accessibility_errors()
passwordResult.Violations.Should().BeEmpty();
summaryResult.Violations.Should().BeEmpty();
}

[Fact]
public void Registration_by_centre_journey_with_send_email_has_no_accessibility_errors()
{
// given
Driver.LogUserInAsAdminAndDelegate(BaseUrl);
const string registerUrl = "/TrackingSystem/Delegates/Register";

// when
Driver.Navigate().GoToUrl(BaseUrl + registerUrl);
var registerResult = new AxeBuilder(Driver).Analyze();
Driver.FillTextInput("FirstName", "Test");
Driver.FillTextInput("LastName", "User");
Driver.FillTextInput("Email", "candidate@test.com");
Driver.FillTextInput("Alias", "candid8");
Driver.SubmitForm();

var learnerInformationResult = new AxeBuilder(Driver).Analyze();
Driver.SelectDropdownItemValue("Answer1", "Principal Relationship Manager");
Driver.FillTextInput("Answer2", "A Person");
Driver.SelectDropdownItemValue("JobGroup", "1");
Driver.SubmitForm();

var welcomeEmailResult = new AxeBuilder(Driver).Analyze();
Driver.SetCheckboxState("ShouldSendEmail", true);
Driver.FillTextInput("Day", "14");
Driver.FillTextInput("Month", "7");
Driver.FillTextInput("Year", "2222");
Driver.SubmitForm();

var summaryResult = new AxeBuilder(Driver).Analyze();

// then
registerResult.Violations.Should().BeEmpty();
learnerInformationResult.Violations.Should().BeEmpty();
welcomeEmailResult.Violations.Should().BeEmpty();
summaryResult.Violations.Should().BeEmpty();
}

[Fact]
public void Registration_by_centre_journey_with_set_password_has_no_accessibility_errors()
{
// given
Driver.LogUserInAsAdminAndDelegate(BaseUrl);
const string registerUrl = "/TrackingSystem/Delegates/Register";

// when
Driver.Navigate().GoToUrl(BaseUrl + registerUrl);
var registerResult = new AxeBuilder(Driver).Analyze();
Driver.FillTextInput("FirstName", "Test");
Driver.FillTextInput("LastName", "User");
Driver.FillTextInput("Email", "candidate@test.com");
Driver.FillTextInput("Alias", "candid8");
Driver.SubmitForm();

var learnerInformationResult = new AxeBuilder(Driver).Analyze();
Driver.SelectDropdownItemValue("Answer1", "Principal Relationship Manager");
Driver.FillTextInput("Answer2", "A Person");
Driver.SelectDropdownItemValue("JobGroup", "1");
Driver.SubmitForm();

var welcomeEmailResult = new AxeBuilder(Driver).Analyze();
Driver.SetCheckboxState("ShouldSendEmail", false);
Driver.SubmitForm();

var passwordResult = new AxeBuilder(Driver).Analyze();
Driver.FillTextInput("Password", "password!1");
Driver.SubmitForm();

var summaryResult = new AxeBuilder(Driver).Analyze();

// then
registerResult.Violations.Should().BeEmpty();
learnerInformationResult.Violations.Should().BeEmpty();
welcomeEmailResult.Violations.Should().BeEmpty();
passwordResult.Violations.Should().BeEmpty();
summaryResult.Violations.Should().BeEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public static void SelectDropdownItemValue(this IWebDriver driver, string dropdo
dropdown.SelectByValue(selectedValue);
}

public static void SetCheckboxState(this IWebDriver driver, string inputId, bool checkState)
{
var answer = driver.FindElement(By.Id(inputId));
if (answer.Selected != checkState)
{
answer.Click();
}
}

public static void SubmitForm(this IWebDriver driver)
{
var selectPromptForm = driver.FindElement(By.TagName("form"));
Expand Down
Loading