Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
b3153a0
HEEDLS-554 Create ViewDelegate controller; configure manage button on…
ibrahimmunir14 Jul 13, 2021
a26fa01
HEEDLS-554 Create ViewDelegate blank page with navbar and breadcrumbs
ibrahimmunir14 Jul 13, 2021
baab933
HEEDLS-554 Implement GetDelegateUserCardById method
ibrahimmunir14 Jul 15, 2021
e7714bd
HEEDLS-554 Extract delegate info into DelegateInfoViewModel
ibrahimmunir14 Jul 15, 2021
3925df6
HEEDLS-554 Display delegate info and tags on View Delegate page
ibrahimmunir14 Jul 15, 2021
bfd10f5
HEEDLS-554 Display buttons on ViewDelegate page based on active status
ibrahimmunir14 Jul 15, 2021
e47b871
HEEDLS-554 Display hyphen to indicate no value for optional DelegateU…
ibrahimmunir14 Jul 15, 2021
ba628e3
HEEDLS-554 Fix SearchableDelegateVM tests; add ViewDelegateVM and Del…
ibrahimmunir14 Jul 15, 2021
5696200
HEEDLS-554 Remove unneeded row/col divs from ViewDelegates page
ibrahimmunir14 Jul 15, 2021
a5d564a
HEEDLS-554 Do not match admin when getting DelegateUserCard if admin …
ibrahimmunir14 Jul 15, 2021
0870398
HEEDLS-554 Add visually hidden text to indicate fields with no value;…
ibrahimmunir14 Jul 19, 2021
6db5dcf
HEEDLS-554 Move Deactivate account button to new line
ibrahimmunir14 Jul 19, 2021
101d324
HEEDLS-554 Update delegate-admin linking condition in GetDelegateUser…
ibrahimmunir14 Jul 19, 2021
35446da
HEEDLS-554 Use dash and visually hidden text to indicate no value for…
ibrahimmunir14 Jul 19, 2021
fe4a1f8
HEEDLS-554 Create SummaryFieldValue component and use in summary tabl…
ibrahimmunir14 Jul 19, 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 @@ -6,7 +6,6 @@
using System.Transactions;
using DigitalLearningSolutions.Data.DataServices;
using DigitalLearningSolutions.Data.Mappers;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Data.Tests.TestHelpers;
using FluentAssertions;
using FluentAssertions.Execution;
Expand Down Expand Up @@ -446,19 +445,121 @@ public void GetDelegateUserCardsByCentreId_populates_DelegateUser_fields_correct
}

[Test]
public void GetDelegateUserCardsByCentreId_populates_DelegateUserCard_admin_fields_correctly()
public void GetDelegateUserCardsByCentreId_populates_DelegateUserCard_fields_correctly()
{
// When
var userCards = userDataService.GetDelegateUserCardsByCentreId(101);

// Then
var userCard = userCards.Single(user => user.Id == 3);
userCard.Active.Should().BeTrue();
userCard.SelfReg.Should().BeFalse();
userCard.ExternalReg.Should().BeFalse();
userCard.AdminId.Should().Be(1);
userCard.AliasId.Should().Be("");
userCard.JobGroupId.Should().Be(10);
}

[Test]
public void GetDelegateUserCardsByCentreId_does_not_match_admin_if_not_admin_in_this_centre()
{
// When
var userCards = userDataService.GetDelegateUserCardsByCentreId(409);

// Then
var userCard = userCards.Single(user => user.Id == 268530);
userCard.AdminId.Should().BeNull();
}

[Test]
public void GetDelegateUserCardsByCentreId_does_not_match_admin_if_admin_email_address_is_blank()
{
// When
var userCards = userDataService.GetDelegateUserCardsByCentreId(279);

// Then
var userCard = userCards.Single(user => user.Id == 97055);
var userCard = userCards.First(user => user.EmailAddress == "");
userCard.AdminId.Should().BeNull();
}

[Test]
public void GetDelegateUserCardsByCentreId_does_not_match_admin_if_password_does_not_match()
{
// When
var userCards = userDataService.GetDelegateUserCardsByCentreId(101);

// Then
var adminUser = userDataService.GetAdminUserById(1)!;
var userCard = userCards.Single(user => user.Id == 254480);
userCard.EmailAddress.Should().Be(adminUser.EmailAddress);
userCard.CentreId.Should().Be(adminUser.CentreId);
userCard.Password.Should().NotBe(adminUser.Password);
userCard.AdminId.Should().BeNull();
}

[Test]
public void GetDelegateUserCardById_populates_DelegateUser_fields_correctly()
{
// Given
var expected = UserTestHelper.GetDefaultDelegateUser(
dateRegistered: DateTime.Parse("2010-09-22 06:52:09.080"),
jobGroupName: "Nursing / midwifery"
);

// When
var userCard = userDataService.GetDelegateUserCardById(2);

// Then
userCard.Should().BeEquivalentTo(expected);
}

[Test]
public void GetDelegateUserCardById_populates_DelegateUserCard_fields_correctly()
{
// When
var userCard = userDataService.GetDelegateUserCardById(3)!;

// Then
userCard.Active.Should().BeTrue();
userCard.SelfReg.Should().BeTrue();
userCard.SelfReg.Should().BeFalse();
userCard.ExternalReg.Should().BeFalse();
userCard.AdminId.Should().Be(74);
userCard.AdminId.Should().Be(1);
userCard.AliasId.Should().Be("");
userCard.JobGroupId.Should().Be(6);
userCard.JobGroupId.Should().Be(10);
}

[Test]
public void GetDelegateUserCardById_does_not_match_admin_if_not_admin_in_this_centre()
{
// When
var userCard = userDataService.GetDelegateUserCardById(268530)!;

// Then
userCard.AdminId.Should().BeNull();
}

[Test]
public void GetDelegateUserCardById_does_not_match_admin_if_admin_email_address_is_blank()
{
// When
var userCard = userDataService.GetDelegateUserCardById(41300)!;

// Then
userCard.AdminId.Should().BeNull();
}

[Test]
public void GetDelegateUserCardById_does_not_match_admin_if_password_does_not_match()
{
// When
var userCard = userDataService.GetDelegateUserCardById(254480)!;

// Then
var adminUser = userDataService.GetAdminUserById(1)!;
userCard.EmailAddress.Should().Be(adminUser.EmailAddress);
userCard.CentreId.Should().Be(adminUser.CentreId);
userCard.Password.Should().NotBe(adminUser.Password);
userCard.AdminId.Should().BeNull();
}
}
}
52 changes: 51 additions & 1 deletion DigitalLearningSolutions.Data/DataServices/UserDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IUserDataService
{
public AdminUser? GetAdminUserById(int id);
public DelegateUser? GetDelegateUserById(int id);
public DelegateUserCard? GetDelegateUserCardById(int id);
public List<AdminUser> GetAdminUsersByCentreId(int centreId);
public List<DelegateUserCard> GetDelegateUserCardsByCentreId(int centreId);
public AdminUser? GetAdminUserByUsername(string username);
Expand Down Expand Up @@ -136,6 +137,51 @@ FROM Candidates AS cd
return user;
}

public DelegateUserCard? GetDelegateUserCardById(int id)
{
var user = connection.Query<DelegateUserCard>(
@"SELECT
cd.CandidateID AS Id,
cd.CandidateNumber,
ct.CentreName,
cd.CentreID,
cd.DateRegistered,
ct.Active AS CentreActive,
cd.EmailAddress,
cd.FirstName,
cd.LastName,
cd.Password,
cd.Approved,
cd.Answer1,
cd.Answer2,
cd.Answer3,
cd.Answer4,
cd.Answer5,
cd.Answer6,
cd.JobGroupId,
jg.JobGroupName,
cd.SelfReg,
cd.ExternalReg,
cd.Active,
(SELECT AdminID
FROM AdminUsers au
WHERE (au.Email = cd.EmailAddress
OR au.Email = cd.AliasID)
AND au.Password = cd.Password
AND au.CentreID = cd.CentreID
AND au.Email != ''
) AS AdminID,
cd.AliasID
FROM Candidates AS cd
INNER JOIN Centres AS ct ON ct.CentreID = cd.CentreID
INNER JOIN JobGroups AS jg ON jg.JobGroupID = cd.JobGroupID
WHERE cd.CandidateId = @id",
new { id }
).SingleOrDefault();

return user;
}

public List<AdminUser> GetAdminUsersByCentreId(int centreId)
{
var users = connection.Query<AdminUser>(
Expand Down Expand Up @@ -205,7 +251,11 @@ public List<DelegateUserCard> GetDelegateUserCardsByCentreId(int centreId)
cd.Active,
(SELECT AdminID
FROM AdminUsers au
WHERE au.Email = cd.EmailAddress AND au.CentreID = cd.CentreID
WHERE (au.Email = cd.EmailAddress
OR au.Email = cd.AliasID)
AND au.Password = cd.Password
AND au.CentreID = cd.CentreID
AND au.Email != ''
) AS AdminID,
cd.AliasID
FROM Candidates AS cd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void Page_has_no_accessibility_errors(string url, string pageTitle)
[InlineData("/TrackingSystem/Centre/TopCourses", "Top courses")]
[InlineData("/TrackingSystem/CourseSetup", "Centre course setup")]
[InlineData("/TrackingSystem/Delegates/All", "Delegates")]
[InlineData("/TrackingSystem/Delegates/View/1", "xxxxx xxxxxxxxx")]
[InlineData("/TrackingSystem/Delegates/Approve", "Approve delegate registrations")]
[InlineData("/TrackingSystem/Delegates/BulkUpload", "Bulk upload/update delegates")]
[InlineData("/NotificationPreferences", "Notification preferences")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace DigitalLearningSolutions.Web.Tests.ViewModels.TrackingSystem.Delegates.AllDelegates
{
using System;
using System.Collections.Generic;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Web.ViewModels.Common;
using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates;
using FluentAssertions;
using NUnit.Framework;

public class DelegateInfoViewModelTests
{
private readonly List<CustomFieldViewModel> customFields = new List<CustomFieldViewModel>();

[Test]
public void DelegateInfoViewModel_sets_reg_date_string_correctly()
{
// Given
var date = new DateTime(2021, 05, 13);
var user = new DelegateUserCard { DateRegistered = date };

// When
var model = new DelegateInfoViewModel(user, customFields);

// Then
model.RegistrationDate.Should().Be("13/05/2021");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace DigitalLearningSolutions.Web.Tests.ViewModels.TrackingSystem.Delegates.AllDelegates
{
using System;
using System.Collections.Generic;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Web.ViewModels.Common;
Expand All @@ -20,8 +19,8 @@ public void SearchableDelegateViewModel_sets_active_tag_name_correctly()
var inactiveUser = new DelegateUserCard { Active = false };

// When
var activeModel = new SearchableDelegateViewModel(activeUser, customFields);
var inactiveModel = new SearchableDelegateViewModel(inactiveUser, customFields);
var activeModel = new SearchableDelegateViewModel(new DelegateInfoViewModel(activeUser, customFields));
var inactiveModel = new SearchableDelegateViewModel(new DelegateInfoViewModel(inactiveUser, customFields));

// Then
activeModel.ActiveTagName.Should().Be("Active");
Expand All @@ -36,8 +35,8 @@ public void SearchableDelegateViewModel_sets_password_tag_name_correctly()
var pwNotSetUser = new DelegateUserCard { Password = null };

// When
var pwSetModel = new SearchableDelegateViewModel(pwSetUser, customFields);
var pwNotSetModel = new SearchableDelegateViewModel(pwNotSetUser, customFields);
var pwSetModel = new SearchableDelegateViewModel(new DelegateInfoViewModel(pwSetUser, customFields));
var pwNotSetModel = new SearchableDelegateViewModel(new DelegateInfoViewModel(pwNotSetUser, customFields));

// Then
pwSetModel.PasswordTagName.Should().Be("Password set");
Expand All @@ -53,28 +52,16 @@ public void SearchableDelegateViewModel_sets_regstatus_tag_name_correctly()
var centreRegUser = new DelegateUserCard { SelfReg = false };

// When
var selfRegModel = new SearchableDelegateViewModel(selfRegUser, customFields);
var selfRegExternalModel = new SearchableDelegateViewModel(selfRegExternalUser, customFields);
var centreRegModel = new SearchableDelegateViewModel(centreRegUser, customFields);
var selfRegModel = new SearchableDelegateViewModel(new DelegateInfoViewModel(selfRegUser, customFields));
var selfRegExternalModel =
new SearchableDelegateViewModel(new DelegateInfoViewModel(selfRegExternalUser, customFields));
var centreRegModel =
new SearchableDelegateViewModel(new DelegateInfoViewModel(centreRegUser, customFields));

// Then
selfRegModel.RegStatusTagName.Should().Be("Self registered");
selfRegExternalModel.RegStatusTagName.Should().Be("Self registered (External)");
centreRegModel.RegStatusTagName.Should().Be("Registered by centre");
}

[Test]
public void SearchableDelegateViewModel_sets_reg_date_string_correctly()
{
// Given
var date = new DateTime(2021, 05, 13);
var user = new DelegateUserCard { DateRegistered = date };

// When
var model = new SearchableDelegateViewModel(user, customFields);

// Then
model.RegistrationDate.Should().Be("13/05/2021");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace DigitalLearningSolutions.Web.Tests.ViewModels.TrackingSystem.Delegates.AllDelegates
{
using System.Collections.Generic;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Web.ViewModels.Common;
using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates;
using FluentAssertions;
using NUnit.Framework;

public class ViewDelegateViewModelTests
{
private readonly List<CustomFieldViewModel> customFields = new List<CustomFieldViewModel>();

[Test]
public void ViewDelegateViewModel_sets_active_tag_name_correctly()
{
// Given
var activeUser = new DelegateUserCard { Active = true };
var inactiveUser = new DelegateUserCard { Active = false };

// When
var activeModel = new ViewDelegateViewModel(new DelegateInfoViewModel(activeUser, customFields));
var inactiveModel = new ViewDelegateViewModel(new DelegateInfoViewModel(inactiveUser, customFields));

// Then
activeModel.ActiveTagName.Should().Be("Active");
inactiveModel.ActiveTagName.Should().Be("Inactive");
}

[Test]
public void ViewDelegateViewModel_sets_password_tag_name_correctly()
{
// Given
var pwSetUser = new DelegateUserCard { Password = "pw" };
var pwNotSetUser = new DelegateUserCard { Password = null };

// When
var pwSetModel = new ViewDelegateViewModel(new DelegateInfoViewModel(pwSetUser, customFields));
var pwNotSetModel = new ViewDelegateViewModel(new DelegateInfoViewModel(pwNotSetUser, customFields));

// Then
pwSetModel.PasswordTagName.Should().Be("Password set");
pwNotSetModel.PasswordTagName.Should().Be("Password not set");
}

[Test]
public void ViewDelegateViewModel_sets_regstatus_tag_name_correctly()
{
// Given
var selfRegUser = new DelegateUserCard { SelfReg = true, ExternalReg = false };
var selfRegExternalUser = new DelegateUserCard { SelfReg = true, ExternalReg = true };
var centreRegUser = new DelegateUserCard { SelfReg = false };

// When
var selfRegModel = new ViewDelegateViewModel(new DelegateInfoViewModel(selfRegUser, customFields));
var selfRegExternalModel =
new ViewDelegateViewModel(new DelegateInfoViewModel(selfRegExternalUser, customFields));
var centreRegModel =
new ViewDelegateViewModel(new DelegateInfoViewModel(centreRegUser, customFields));

// Then
selfRegModel.RegStatusTagName.Should().Be("Self registered");
selfRegExternalModel.RegStatusTagName.Should().Be("Self registered (External)");
centreRegModel.RegStatusTagName.Should().Be("Registered by centre");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public IActionResult Index()
delegateUser =>
{
var customFields = customPromptHelper.GetCustomFieldViewModelsForCentre(centreId, delegateUser);
return new SearchableDelegateViewModel(delegateUser, customFields);
var delegateInfoViewModel = new DelegateInfoViewModel(delegateUser, customFields);
return new SearchableDelegateViewModel(delegateInfoViewModel);
}
);
var model = new AllDelegatesViewModel(centreId, searchableDelegateViewModels);
Expand Down
Loading