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 @@ -301,5 +301,24 @@ public void SetCentreAutoRegistered_should_set_AutoRegistered_true()
transaction.Dispose();
}
}

[Test]
public void GetAllCentreSummariesForSuperAdmin_returns_active_and_inactive_summary_details_and_reference_data()
{
// When
var summaries = centresDataService.GetAllCentreSummariesForSuperAdmin().ToList();

// Then
var activeCentre = summaries.Single(c => c.CentreId == 2);
var inActiveCentre = summaries.Single(c => c.CentreId == 6);

activeCentre.Active.Should().BeTrue();
activeCentre.CentreType.Should().Be("NHS Organisation");
activeCentre.RegionName.Should().Be("North West");

inActiveCentre.Active.Should().BeFalse();
inActiveCentre.CentreType.Should().Be("NHS Organisation");
inActiveCentre.RegionName.Should().Be("East Of England");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
using System;
using System.Linq;
using DigitalLearningSolutions.Data.DataServices;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Data.Services;
using DigitalLearningSolutions.Data.Tests.TestHelpers;
using FakeItEasy;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;

public class CentresServiceTests
{
private ICentresDataService centresDataService = null!;
private IClockService clockService = null!;
private ICentresService centresService = null!;
private IClockService clockService = null!;

[SetUp]
public void Setup()
Expand All @@ -35,7 +37,7 @@ public void Setup()
CentreTestHelper.GetCentreRank(7),
CentreTestHelper.GetCentreRank(8),
CentreTestHelper.GetCentreRank(9),
CentreTestHelper.GetCentreRank(10)
CentreTestHelper.GetCentreRank(10),
}
);
}
Expand Down Expand Up @@ -69,5 +71,21 @@ public void GetCentreRankForCentre_returns_null_with_no_data_for_centre()
// Then
result.Should().BeNull();
}

[Test]
public void GetAllCentreSummariesForSuperAdmin_calls_dataService_and_returns_all_summary_details()
{
// Given
var centres = Builder<CentreSummaryForSuperAdmin>.CreateListOfSize(10).Build();
A.CallTo(() => centresDataService.GetAllCentreSummariesForSuperAdmin()).Returns(centres);

// When
var result = centresService.GetAllCentreSummariesForSuperAdmin();

// Then
result
.Should()
.HaveCount(10);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace DigitalLearningSolutions.Data.Tests.TestHelpers
{
using DigitalLearningSolutions.Data.Models;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Data.Models.DbModels;

public static class CentreTestHelper
Expand Down
23 changes: 22 additions & 1 deletion DigitalLearningSolutions.Data/DataServices/CentresDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Data;
using Dapper;
using DigitalLearningSolutions.Data.Models;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Data.Models.DbModels;
using Microsoft.Extensions.Logging;

Expand All @@ -14,6 +14,7 @@ public interface ICentresDataService
string? GetCentreName(int centreId);
IEnumerable<(int, string)> GetCentresForDelegateSelfRegistrationAlphabetical();
Centre? GetCentreDetailsById(int centreId);
IEnumerable<CentreSummaryForSuperAdmin> GetAllCentreSummariesForSuperAdmin();

void UpdateCentreManagerDetails(
int centreId,
Expand Down Expand Up @@ -161,6 +162,26 @@ FROM Centres AS c
return centre;
}

public IEnumerable<CentreSummaryForSuperAdmin> GetAllCentreSummariesForSuperAdmin()
{
return connection.Query<CentreSummaryForSuperAdmin>(
@"SELECT c.CentreID,
c.CentreName,
c.RegionID,
r.RegionName,
c.ContactForename,
c.ContactSurname,
c.ContactEmail,
c.ContactTelephone,
c.CentreTypeId,
ct.CentreType,
c.Active
FROM Centres AS c
INNER JOIN Regions AS r ON r.RegionID = c.RegionID
INNER JOIN CentreTypes AS ct ON ct.CentreTypeId = c.CentreTypeId"
);
}

public void UpdateCentreManagerDetails(
int centreId,
string firstName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System.Collections.Generic;
using System.Linq;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Data.Models.User;

public class CentreContractAdminUsage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DigitalLearningSolutions.Data.Models
namespace DigitalLearningSolutions.Data.Models.Centres
{
public class Centre
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace DigitalLearningSolutions.Data.Models.Centres
{
public class CentreSummaryForSuperAdmin
{
public int CentreId { get; set; }
public string CentreName { get; set; }
public int RegionId { get; set; }
public string RegionName { get; set; }
public string? ContactForename { get; set; }
public string? ContactSurname { get; set; }
public string? ContactEmail { get; set; }
public string? ContactTelephone { get; set; }
public int CentreTypeId { get; set; }
public string CentreType { get; set; }
public bool Active { get; set; }
}
}
8 changes: 8 additions & 0 deletions DigitalLearningSolutions.Data/Services/CentresService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
using System.Collections.Generic;
using System.Linq;
using DigitalLearningSolutions.Data.DataServices;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Data.Models.DbModels;

public interface ICentresService
{
IEnumerable<CentreRanking> GetCentresForCentreRankingPage(int centreId, int numberOfDays, int? regionId);

int? GetCentreRankForCentre(int centreId);

IEnumerable<CentreSummaryForSuperAdmin> GetAllCentreSummariesForSuperAdmin();
}

public class CentresService : ICentresService
Expand Down Expand Up @@ -39,5 +42,10 @@ public IEnumerable<CentreRanking> GetCentresForCentreRankingPage(int centreId, i
var centreRanking = centreRankings.SingleOrDefault(cr => cr.CentreId == centreId);
return centreRanking?.Ranking;
}

public IEnumerable<CentreSummaryForSuperAdmin> GetAllCentreSummariesForSuperAdmin()
{
return centresDataService.GetAllCentreSummariesForSuperAdmin();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public BasicAuthenticatedAccessibilityTests(AuthenticatedAccessibilityTestsFixtu
[InlineData("/NotificationPreferences/Edit/DelegateUser", "Update notification preferences")]
[InlineData("/ChangePassword", "Change password")]
[InlineData("/TrackingSystem/Support", "Support")]
[InlineData("/SuperAdmin/Centres", "Centres")]
[InlineData("/TrackingSystem/Resources", "Resources")]
public void Authenticated_page_has_no_accessibility_errors(string url, string pageTitle)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace DigitalLearningSolutions.Web.Tests.ViewModels.SuperAdmin.Centres
{
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Centres;
using FluentAssertions;
using FluentAssertions.Execution;
using NUnit.Framework;

public class CentreSummaryViewModelTests
{
[Test]
public void CentreSummaryViewModel_constructor_should_populate_expected_properties()
{
// Given
var centre = new CentreSummaryForSuperAdmin()
{
CentreId = 2,
CentreName = "North West Boroughs Healthcare NHS Foundation Trust",
RegionId = 5,
RegionName = "North West",
ContactForename = "TestForename",
ContactSurname = "TestSurname",
ContactEmail = "email@nhs.net",
ContactTelephone = "0123654789",
CentreTypeId = 4,
CentreType = "Social Care",
Active = true,
};

// When
var model = new CentreSummaryViewModel(centre);

// Then
using (new AssertionScope())
{
model.CentreId.Should().Be(2);
model.CentreName.Should().Be("North West Boroughs Healthcare NHS Foundation Trust");
model.RegionName.Should().Be("North West");
model.ContactForename.Should().Be("TestForename");
model.ContactSurname.Should().Be("TestSurname");
model.ContactEmail.Should().Be("email@nhs.net");
model.ContactTelephone.Should().Be("0123654789");
model.CentreType.Should().Be("Social Care");
model.Active.Should().BeTrue();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace DigitalLearningSolutions.Web.Tests.ViewModels.SuperAdmin.Centres
{
using System.Collections.Generic;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Centres;
using FluentAssertions;
using FluentAssertions.Execution;
using NUnit.Framework;

public class CentresViewModelTests
{
[Test]
public void CentresViewModel_default_should_return_first_page_of_centres_in_ascending_order()
{
// Given
var centres = new List<CentreSummaryForSuperAdmin>
{
new CentreSummaryForSuperAdmin { CentreName = "A" },
new CentreSummaryForSuperAdmin { CentreName = "b" },
new CentreSummaryForSuperAdmin { CentreName = "C" },
new CentreSummaryForSuperAdmin { CentreName = "F" },
new CentreSummaryForSuperAdmin { CentreName = "J" },
new CentreSummaryForSuperAdmin { CentreName = "e" },
new CentreSummaryForSuperAdmin { CentreName = "w" },
new CentreSummaryForSuperAdmin { CentreName = "S" },
new CentreSummaryForSuperAdmin { CentreName = "r" },
new CentreSummaryForSuperAdmin { CentreName = "H" },
new CentreSummaryForSuperAdmin { CentreName = "m" },
};

// When
var model = new CentresViewModel(centres);

// Then
using (new AssertionScope())
{
model.Centres
.Should().HaveCount(10)
.And.BeInAscendingOrder(o => o.CentreName);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace DigitalLearningSolutions.Web.Controllers.SuperAdmin.Centres
{
using DigitalLearningSolutions.Data.Enums;
using DigitalLearningSolutions.Data.Services;
using DigitalLearningSolutions.Web.Attributes;
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.Models.Enums;
using DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Centres;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.FeatureManagement.Mvc;

[FeatureGate(FeatureFlags.RefactoredSuperAdminInterface)]
[Authorize(Policy = CustomPolicies.UserSuperAdmin)]
[Route("SuperAdmin/Centres")]
[SetDlsSubApplication(nameof(DlsSubApplication.SuperAdmin))]
[SetSelectedTab(nameof(NavMenuTab.Centres))]
public class CentresController : Controller
{
private readonly ICentresService centresService;

public CentresController(ICentresService centresService)
{
this.centresService = centresService;
}

public IActionResult Index()
{
var centres = centresService.GetAllCentreSummariesForSuperAdmin();
var viewModel = new CentresViewModel(centres);

return View(viewModel);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Centres
{
using DigitalLearningSolutions.Data.Models.Centres;

public class CentreSummaryViewModel
{
public CentreSummaryViewModel(CentreSummaryForSuperAdmin model)
{
CentreId = model.CentreId;
CentreName = model.CentreName;
RegionName = model.RegionName;
ContactForename = model.ContactForename;
ContactSurname = model.ContactSurname;
ContactEmail = model.ContactEmail;
ContactTelephone = model.ContactTelephone;
CentreType = model.CentreType;
Active = model.Active;
}

public int CentreId { get; set; }
public string CentreName { get; set; }
public string RegionName { get; set; }
public string? ContactForename { get; set; }
public string? ContactSurname { get; set; }
public string? ContactEmail { get; set; }
public string? ContactTelephone { get; set; }
public string CentreType { get; set; }
public bool Active { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Centres
{
using System.Collections.Generic;
using System.Linq;
using DigitalLearningSolutions.Data.Models.Centres;

public class CentresViewModel
{
public CentresViewModel(IEnumerable<CentreSummaryForSuperAdmin> centreSummaries)
{
// TODO: HEEDLS-641: add filters/sort/pagination
// .Take(10) should be removed in HEEDLS-641 in favour of the standard pagination functionality.
Centres = centreSummaries.OrderBy(c => c.CentreName).Take(10).Select(c => new CentreSummaryViewModel(c));
}

public IEnumerable<CentreSummaryViewModel> Centres { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Centre.Configuration
{
using DigitalLearningSolutions.Data.Models;
using DigitalLearningSolutions.Data.Models.Centres;

public class CentreConfigurationViewModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Centre.Configuration
{
using System.ComponentModel.DataAnnotations;
using DigitalLearningSolutions.Data.Models;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Web.Attributes;
using Microsoft.AspNetCore.Http;

Expand Down
Loading