Skip to content

Commit be16198

Browse files
committed
Merge branch 'release-v1.0.0' into DLS-Release-v1.1.0
2 parents 9c78d1b + 84ed4ae commit be16198

File tree

17 files changed

+411
-17
lines changed

17 files changed

+411
-17
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace DigitalLearningSolutions.Data.Migrations
2+
{
3+
using FluentMigrator;
4+
5+
[Migration(202411051212)]
6+
public class UpdateCourseCategories : ForwardOnlyMigration
7+
{
8+
public override void Up()
9+
{
10+
Execute.Sql(@$"UPDATE CourseCategories SET CategoryName = LTRIM(RTRIM(CategoryName))");
11+
}
12+
13+
}
14+
}

DigitalLearningSolutions.Data/DataServices/CentresDataService.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public interface ICentresDataService
2222
string centreStatus);
2323
IEnumerable<CentreSummaryForFindYourCentre> GetAllCentreSummariesForFindCentre();
2424

25-
CentreSummaryForContactDisplay GetCentreSummaryForContactDisplay(int centreId);
25+
CentreSummaryForContactDisplay? GetCentreSummaryForContactDisplay(int centreId);
2626

27-
CentreSummaryForRoleLimits GetRoleLimitsForCentre(int centreId);
27+
CentreSummaryForRoleLimits? GetRoleLimitsForCentre(int centreId);
2828

2929
void UpdateCentreRoleLimits(
3030
int centreId,
@@ -114,6 +114,7 @@ public int ResultCount(string search, int region, int centreType, int contractTy
114114

115115
public IEnumerable<CentresExport> GetAllCentresForSuperAdminExport(string search, int region,
116116
int centreType, int contractType, string centreStatus, int exportQueryRowLimit, int currentRun);
117+
Centre? CountRegisterUserByCentreId(int centreId);
117118
}
118119

119120
public class CentresDataService : ICentresDataService
@@ -325,6 +326,27 @@ FROM Centres AS c
325326
return (centreEntity, resultCount);
326327
}
327328

329+
public Centre? CountRegisterUserByCentreId(int centreId)
330+
{
331+
return connection.QueryFirstOrDefault<Centre>(
332+
$@"SELECT c.CentreID,
333+
c.CentreName,
334+
c.ContactForename,
335+
c.ContactSurname,
336+
c.ContactEmail,
337+
c.ContactTelephone,
338+
c.Active,
339+
c.CentreTypeId,
340+
c.RegionID,
341+
c.AutoRegisterManagerEmail,
342+
(SELECT COUNT(da.ID) AS RegisterUser
343+
FROM DelegateAccounts da WHERE (da.CentreID = c.CentreID) AND (da.Active = 1)) AS RegisterUser
344+
FROM Centres AS c
345+
WHERE c.CentreID = @centreId",
346+
new { centreId }
347+
);
348+
}
349+
328350
public IEnumerable<CentreSummaryForFindYourCentre> GetAllCentreSummariesForFindCentre()
329351
{
330352
return connection.Query<CentreSummaryForFindYourCentre>(
@@ -346,7 +368,7 @@ FROM Centres AS c
346368
);
347369
}
348370

349-
public CentreSummaryForContactDisplay GetCentreSummaryForContactDisplay(int centreId)
371+
public CentreSummaryForContactDisplay? GetCentreSummaryForContactDisplay(int centreId)
350372
{
351373
return connection.QueryFirstOrDefault<CentreSummaryForContactDisplay>(
352374
@"SELECT CentreID,CentreName,pwTelephone AS Telephone,pwEmail AS Email,pwWebURL AS WebUrl,pwHours AS Hours
@@ -717,7 +739,7 @@ public void ReactivateCentre(int centreId)
717739
);
718740
}
719741

720-
public CentreSummaryForRoleLimits GetRoleLimitsForCentre(int centreId)
742+
public CentreSummaryForRoleLimits? GetRoleLimitsForCentre(int centreId)
721743
{
722744
return connection.QueryFirstOrDefault<CentreSummaryForRoleLimits>(
723745
@"SELECT CentreId,

DigitalLearningSolutions.Data/Extensions/ConfigurationExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,5 @@ public static string GetTableauViewName(this IConfiguration config)
268268
{
269269
return config[$"{TableauSectionKey}:{TableauViewName}"]!;
270270
}
271-
272271
}
273272
}

DigitalLearningSolutions.Data/Helpers/NewlineSeparatedStringListHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public static string RemoveStringFromNewlineSeparatedList(string list, int index
1717
public static string AddStringToNewlineSeparatedList(string? list, string newItem)
1818
{
1919
var options = list != null ? SplitNewlineSeparatedList(list) : new List<string>();
20-
options.Add(newItem?.Trim());
20+
if (!string.IsNullOrWhiteSpace(newItem))
21+
{
22+
options.Add(newItem.Trim());
23+
}
2124
return JoinNewlineSeparatedList(options);
2225
}
2326

DigitalLearningSolutions.Data/Models/Centres/Centre.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ public class Centre
4343
public DateTime? ContractReviewDate { get; set; }
4444
public string? RegistrationEmail { get; set; }
4545
public bool AddITSPcourses { get; set; }
46+
public int RegisterUser { get; set; }
47+
public string? AutoRegisterManagerEmail { get; set; }
48+
public string? EmailInvite { get; set; }
49+
4650
}
4751
}

DigitalLearningSolutions.Web.Tests/Controllers/SuperAdmin/CentresControllerTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using NUnit.Framework;
1515
using System;
1616
using System.Collections.Generic;
17+
using Microsoft.Extensions.Configuration;
1718

1819
namespace DigitalLearningSolutions.Web.Tests.Controllers.SuperAdmin
1920
{
@@ -29,6 +30,9 @@ public class CentresControllerTests
2930
private readonly ICentresDownloadFileService centresDownloadFileService = A.Fake<ICentresDownloadFileService>();
3031
private readonly ICentreSelfAssessmentsService centreSelfAssessmentsService = A.Fake<ICentreSelfAssessmentsService>();
3132
private CentresController controller = null!;
33+
private readonly IPasswordResetService passwordResetService = A.Fake<IPasswordResetService>();
34+
private IConfiguration config = A.Fake<IConfiguration>();
35+
private readonly IConfigService configService = A.Fake<IConfigService>();
3236

3337
[SetUp]
3438
public void Setup()
@@ -41,7 +45,10 @@ public void Setup()
4145
contractTypesService,
4246
courseService,
4347
centresDownloadFileService,
44-
centreSelfAssessmentsService
48+
centreSelfAssessmentsService,
49+
passwordResetService,
50+
config,
51+
configService
4552
)
4653
.WithDefaultContext()
4754
.WithMockUser(true);

DigitalLearningSolutions.Web.Tests/Controllers/SupervisorController/SupervisorControllerTests.cs

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
namespace DigitalLearningSolutions.Web.Tests.Controllers.Support
22
{
3-
3+
using DigitalLearningSolutions.Data.Models.SelfAssessments;
44
using DigitalLearningSolutions.Data.Utilities;
55
using DigitalLearningSolutions.Web.Controllers.SupervisorController;
66
using DigitalLearningSolutions.Web.Services;
7+
using DigitalLearningSolutions.Web.Tests.ControllerHelpers;
8+
using DigitalLearningSolutions.Web.Tests.TestHelpers;
9+
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;
10+
using DigitalLearningSolutions.Web.ViewModels.Supervisor;
711
using FakeItEasy;
12+
using FluentAssertions;
13+
using FluentAssertions.AspNetCore.Mvc;
814
using GDS.MultiPageFormData;
15+
using Microsoft.AspNetCore.Http;
916
using Microsoft.AspNetCore.Mvc;
1017
using Microsoft.Extensions.Configuration;
1118
using Microsoft.Extensions.Logging;
1219
using NUnit.Framework;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
using System.Security.Claims;
1323

1424
public class SupervisorControllerTests
1525
{
26+
private const int DelegateUserId = 11;
27+
private const int SelfAssessmentId = 1;
28+
private const int CentreId = 2;
29+
public const int AdminId = 7;
30+
public const string EmailAddress = "email";
1631
private ISupervisorService supervisorService = null!;
1732
private ICommonService commonService = null!;
1833
private IFrameworkNotificationService frameworkNotificationService = null!;
@@ -33,6 +48,7 @@ public class SupervisorControllerTests
3348
private ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService = null!;
3449
private IPdfService pdfService = null!;
3550
private ICourseCategoriesService courseCategoriesService = null!;
51+
private SupervisorController controller = null!;
3652

3753
[SetUp]
3854
public void Setup()
@@ -59,6 +75,43 @@ public void Setup()
5975
courseCategoriesService = A.Fake<ICourseCategoriesService>();
6076
A.CallTo(() => candidateAssessmentDownloadFileService.GetCandidateAssessmentDownloadFileForCentre(A<int>._, A<int>._, A<bool>._))
6177
.Returns(new byte[] { });
78+
79+
var user = new ClaimsPrincipal(
80+
new ClaimsIdentity(
81+
new[]
82+
{
83+
new Claim("UserCentreID", CentreId.ToString()),
84+
new Claim("UserId", DelegateUserId.ToString()),
85+
new Claim("UserAdminId", AdminId.ToString())
86+
},
87+
"mock"
88+
)
89+
);
90+
91+
controller = new SupervisorController(
92+
supervisorService,
93+
commonService,
94+
frameworkNotificationService,
95+
selfAssessmentService,
96+
frameworkService,
97+
configService,
98+
centreRegistrationPromptsService,
99+
userService,
100+
logger,
101+
config,
102+
searchSortFilterPaginateService,
103+
multiPageFormService,
104+
registrationService,
105+
centresService,
106+
emailGenerationService,
107+
emailService,
108+
candidateAssessmentDownloadFileService,
109+
clockUtility,
110+
pdfService
111+
);
112+
controller.ControllerContext = new ControllerContext
113+
{ HttpContext = new DefaultHttpContext { User = user } };
114+
controller = controller.WithMockTempData();
62115
}
63116

64117
[TestCase(1, "test", "Digital Capability Self Assessment Deprecated", 1)]
@@ -100,5 +153,63 @@ public void ExportCandidateAssessment_should_return_file_object_with_file_name_i
100153
Assert.AreEqual(expectedFileName, result!.FileDownloadName);
101154
});
102155
}
156+
157+
158+
[Test]
159+
public void ReviewDelegateSelfAssessment_Should_Return_View_With_Optional_Competency()
160+
{
161+
// Given
162+
int candidateAssessmentId = 1;
163+
int supervisorDelegateId = 2;
164+
var superviseDelegate = SupervisorTagTestHelper.CreateDefaultSupervisorDelegateDetail();
165+
var delegateSelfAssessment = SupervisorTagTestHelper.CreateDefaultDelegateSelfAssessment();
166+
var appliedFilterViewModel = new List<AppliedFilterViewModel>();
167+
var competencySummaries = new CompetencySummary();
168+
var search = new SearchSupervisorCompetencyViewModel();
169+
var competencies = new List<Competency>
170+
{
171+
new Competency { CompetencyGroup = "A", Id = 1, CompetencyGroupID = 1,SelfAssessmentStructureId=1, Optional = true },
172+
new Competency { CompetencyGroup = "A", Id = 2, CompetencyGroupID = 1,SelfAssessmentStructureId=1, Optional = false },
173+
};
174+
var expectedCompetencyGroups = competencies.GroupBy(c => c.CompetencyGroup).ToList();
175+
var supervisorSignOffs = new List<SupervisorSignOff>();
176+
var expectedModel = new ReviewSelfAssessmentViewModel()
177+
{
178+
SupervisorDelegateDetail = superviseDelegate,
179+
DelegateSelfAssessment = delegateSelfAssessment,
180+
CompetencyGroups = expectedCompetencyGroups,
181+
IsSupervisorResultsReviewed = delegateSelfAssessment.IsSupervisorResultsReviewed,
182+
SearchViewModel = search,
183+
CandidateAssessmentId = candidateAssessmentId,
184+
ExportToExcelHide = delegateSelfAssessment.SupervisorRoleTitle?.Contains("Assessor") ?? false,
185+
SupervisorSignOffs = supervisorSignOffs,
186+
CompetencySummaries = competencySummaries
187+
};
188+
var loggedInAdmin = UserTestHelper.GetDefaultAdminEntity();
189+
A.CallTo(() => userService.GetAdminById(loggedInAdmin.AdminAccount.Id)).Returns(loggedInAdmin);
190+
191+
A.CallTo(() => supervisorService.GetSupervisorDelegateDetailsById(supervisorDelegateId, AdminId, 0))
192+
.Returns(superviseDelegate);
193+
A.CallTo(() => supervisorService.GetSelfAssessmentByCandidateAssessmentId(candidateAssessmentId, AdminId))
194+
.Returns(delegateSelfAssessment);
195+
A.CallTo(() => selfAssessmentService.GetMostRecentResults(SelfAssessmentId, DelegateUserId))
196+
.Returns(competencies);
197+
198+
// When
199+
var result = controller.ReviewDelegateSelfAssessment(supervisorDelegateId, candidateAssessmentId, SelfAssessmentId);
200+
201+
// Then
202+
result.Should().BeViewResult().ModelAs<ReviewSelfAssessmentViewModel>();
203+
204+
result.Should().BeViewResult()
205+
.WithViewName("ReviewSelfAssessment")
206+
.ModelAs<ReviewSelfAssessmentViewModel>()
207+
.CompetencyGroups ?.SelectMany(group => group).FirstOrDefault(x => x.Id == 1)?.Optional.Should().Be(true);
208+
result.Should().BeViewResult()
209+
.WithViewName("ReviewSelfAssessment")
210+
.ModelAs<ReviewSelfAssessmentViewModel>()
211+
.CompetencyGroups?.SelectMany(group => group).FirstOrDefault(x => x.Id == 2)?.Optional.Should().Be(false);
212+
}
213+
103214
}
104215
}

0 commit comments

Comments
 (0)