Skip to content

Commit 419faa7

Browse files
TD-4790 Write unit tests for tags added on optional competencies in the supervisor view
1 parent 7eef360 commit 419faa7

File tree

2 files changed

+302
-1
lines changed

2 files changed

+302
-1
lines changed

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

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
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 CandidateId = 11;
27+
private const int DelegateUserId = 11;
28+
private const int SelfAssessmentId = 1;
29+
private const int CentreId = 2;
30+
public const int AdminId = 7;
31+
public const int DelegateId = 2;
32+
public const int UserId = 2;
33+
public const string EmailAddress = "email";
1634
private ISupervisorService supervisorService = null!;
1735
private ICommonService commonService = null!;
1836
private IFrameworkNotificationService frameworkNotificationService = null!;
@@ -32,6 +50,7 @@ public class SupervisorControllerTests
3250
private IClockUtility clockUtility = null!;
3351
private ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService = null!;
3452
private IPdfService pdfService = null!;
53+
private SupervisorController controller = null!;
3554

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

62118
[TestCase(1, "test", "Digital Capability Self Assessment Deprecated", 1)]
@@ -97,5 +153,109 @@ public void ExportCandidateAssessment_should_return_file_object_with_file_name_i
97153
Assert.AreEqual(expectedFileName, result!.FileDownloadName);
98154
});
99155
}
156+
157+
158+
[Test]
159+
public void ReviewDelegateSelfAssessment_Should_Return_View_With_Optional_Competency_Is_True()
160+
{
161+
// Given
162+
int candidateAssessmentId = 1;
163+
int supervisorDelegateId = 2;
164+
var superviseDelegate = SupervisorTestHelper.CreateDefaultSupervisorDelegateDetail();
165+
var delegateSelfAssessment = SupervisorTestHelper.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?.FirstOrDefault()?.FirstOrDefault()?.Optional.Should().Be(true);
208+
}
209+
[Test]
210+
public void ReviewDelegateSelfAssessment_Should_Return_View_With_Optional_Competency_Is_False()
211+
{
212+
// Given
213+
int candidateAssessmentId = 1;
214+
int supervisorDelegateId = 2;
215+
var superviseDelegate = SupervisorTestHelper.CreateDefaultSupervisorDelegateDetail();
216+
var delegateSelfAssessment = SupervisorTestHelper.CreateDefaultDelegateSelfAssessment();
217+
var appliedFilterViewModel = new List<AppliedFilterViewModel>();
218+
var competencySummaries = new CompetencySummary();
219+
var search = new SearchSupervisorCompetencyViewModel();
220+
var competencies = new List<Competency>
221+
{
222+
new Competency { CompetencyGroup = "A", Id = 1, CompetencyGroupID = 1,SelfAssessmentStructureId=1, Optional = true },
223+
new Competency { CompetencyGroup = "A", Id = 2, CompetencyGroupID = 1,SelfAssessmentStructureId=1, Optional = false },
224+
};
225+
var expectedCompetencyGroups = competencies.GroupBy(c => c.CompetencyGroup).ToList();
226+
var supervisorSignOffs = new List<SupervisorSignOff>();
227+
var expectedModel = new ReviewSelfAssessmentViewModel()
228+
{
229+
SupervisorDelegateDetail = superviseDelegate,
230+
DelegateSelfAssessment = delegateSelfAssessment,
231+
CompetencyGroups = expectedCompetencyGroups,
232+
IsSupervisorResultsReviewed = delegateSelfAssessment.IsSupervisorResultsReviewed,
233+
SearchViewModel = search,
234+
CandidateAssessmentId = candidateAssessmentId,
235+
ExportToExcelHide = delegateSelfAssessment.SupervisorRoleTitle?.Contains("Assessor") ?? false,
236+
SupervisorSignOffs = supervisorSignOffs,
237+
CompetencySummaries = competencySummaries
238+
};
239+
var loggedInAdmin = UserTestHelper.GetDefaultAdminEntity();
240+
A.CallTo(() => userService.GetAdminById(loggedInAdmin.AdminAccount.Id)).Returns(loggedInAdmin);
241+
242+
A.CallTo(() => supervisorService.GetSupervisorDelegateDetailsById(supervisorDelegateId, AdminId, 0))
243+
.Returns(superviseDelegate);
244+
A.CallTo(() => supervisorService.GetSelfAssessmentByCandidateAssessmentId(candidateAssessmentId, AdminId))
245+
.Returns(delegateSelfAssessment);
246+
A.CallTo(() => selfAssessmentService.GetMostRecentResults(SelfAssessmentId, DelegateUserId))
247+
.Returns(competencies);
248+
249+
// When
250+
var result = controller.ReviewDelegateSelfAssessment(supervisorDelegateId, candidateAssessmentId, SelfAssessmentId);
251+
252+
// Then
253+
result.Should().BeViewResult().ModelAs<ReviewSelfAssessmentViewModel>();
254+
255+
result.Should().BeViewResult()
256+
.WithViewName("ReviewSelfAssessment")
257+
.ModelAs<ReviewSelfAssessmentViewModel>()
258+
.CompetencyGroups?.FirstOrDefault()?.FirstOrDefault()?.Optional.Should().Be(false);
259+
}
100260
}
101261
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using DigitalLearningSolutions.Data.Models.Supervisor;
2+
using DigitalLearningSolutions.Data.Utilities;
3+
using System;
4+
5+
namespace DigitalLearningSolutions.Web.Tests.TestHelpers
6+
{
7+
public static class SupervisorTestHelper
8+
{
9+
private static readonly IClockUtility ClockUtility = new ClockUtility();
10+
11+
public static SupervisorDelegateDetail CreateDefaultSupervisorDelegateDetail(
12+
int id =1,
13+
string supervisorEmail = "[email protected]",
14+
string SupervisorName = "Supervisor",
15+
int? supervisorAdminID = 1,
16+
int centreId = 101,
17+
string delegateEmail = "[email protected]",
18+
int? delegateUserID = 1,
19+
bool addedByDelegate = false,
20+
DateTime? removed = null,
21+
string? firstName = null,
22+
string? lastName = null,
23+
string candidateNumber = "DELEGATE",
24+
string candidateEmail = "[email protected]",
25+
string? jobGroupName =null,
26+
string? customPrompt1 =null,
27+
string? answer1 = null,
28+
string? customPrompt2 = null,
29+
string? answer2 = null,
30+
string? customPrompt3 = null,
31+
string? answer3 = null,
32+
string? customPrompt4 = null,
33+
string? answer4 = null,
34+
string? customPrompt5 = null,
35+
string? answer5 = null,
36+
string? customPrompt6 = null,
37+
string? answer6 = null,
38+
string? supervisorName = null,
39+
int candidateAssessmentCount =0,
40+
Guid? InviteHash =null,
41+
bool delegateIsNominatedSupervisor = false,
42+
bool delegateIsSupervisor = false,
43+
string professionalRegistrationNumber = "string.Empty",
44+
int? delegateID = 0,
45+
bool? active =false
46+
)
47+
{
48+
return new SupervisorDelegateDetail
49+
{
50+
ID = id,
51+
Active = active,
52+
FirstName = firstName,
53+
LastName = lastName,
54+
CentreId = centreId,
55+
CandidateAssessmentCount = candidateAssessmentCount,
56+
CandidateNumber = candidateNumber,
57+
CandidateEmail = candidateEmail,
58+
Answer1 = answer1,
59+
Answer2 = answer2,
60+
Answer3 = answer3,
61+
Answer4 = answer4,
62+
Answer5 = answer5,
63+
Answer6 = answer6,
64+
JobGroupName = jobGroupName,
65+
DelegateEmail = delegateEmail,
66+
DelegateID = delegateID,
67+
DelegateIsNominatedSupervisor= delegateIsNominatedSupervisor,
68+
DelegateIsSupervisor= delegateIsSupervisor,
69+
DelegateUserID = delegateUserID,
70+
SupervisorAdminID = supervisorAdminID,
71+
SupervisorEmail= supervisorEmail,
72+
SupervisorName = supervisorName,
73+
CustomPrompt1 = customPrompt1,
74+
CustomPrompt2 = customPrompt2,
75+
CustomPrompt3 = customPrompt3,
76+
CustomPrompt4 = customPrompt4,
77+
CustomPrompt5 = customPrompt5,
78+
CustomPrompt6 = customPrompt6,
79+
Removed = removed,
80+
InviteHash = InviteHash,
81+
ProfessionalRegistrationNumber = professionalRegistrationNumber,
82+
83+
};
84+
}
85+
86+
public static DelegateSelfAssessment CreateDefaultDelegateSelfAssessment(
87+
int id = 1,
88+
int selfAssessmentID =6,
89+
int delegateUserID =1,
90+
string? roleName =null,
91+
bool supervisorSelfAssessmentReview =false,
92+
bool supervisorResultsReview = false,
93+
string? supervisorRoleTitle = "Assessor",
94+
DateTime? signedOffDate =null,
95+
bool signedOff = false,
96+
DateTime? completeByDate=null,
97+
int launchCount = 0,
98+
DateTime? completedDate =null,
99+
string? professionalGroup = null,
100+
string? questionLabel = null,
101+
string? descriptionLabel = null,
102+
string? reviewerCommentsLabel = null,
103+
string? subGroup = null,
104+
string? roleProfile = null,
105+
int signOffRequested =1,
106+
int resultsVerificationRequests =1,
107+
bool isSupervisorResultsReviewed =false,
108+
bool isAssignedToSupervisor = false,
109+
bool nonReportable = false
110+
)
111+
{
112+
return new DelegateSelfAssessment {
113+
ID = id,
114+
SelfAssessmentID = selfAssessmentID,
115+
DelegateUserID = delegateUserID,
116+
ResultsVerificationRequests = resultsVerificationRequests,
117+
ReviewerCommentsLabel = reviewerCommentsLabel,
118+
SubGroup = subGroup,
119+
RoleProfile = roleProfile,
120+
SignOffRequested = signOffRequested,
121+
SupervisorResultsReview = supervisorResultsReview,
122+
SupervisorSelfAssessmentReview= supervisorSelfAssessmentReview,
123+
SignedOff = signedOff,
124+
CompleteByDate = completeByDate,
125+
LaunchCount = launchCount,
126+
CompletedDate = completedDate,
127+
SignedOffDate = signedOffDate,
128+
ProfessionalGroup = professionalGroup,
129+
QuestionLabel = questionLabel,
130+
DescriptionLabel = descriptionLabel,
131+
IsAssignedToSupervisor = isAssignedToSupervisor,
132+
NonReportable = nonReportable,
133+
IsSupervisorResultsReviewed= isSupervisorResultsReviewed,
134+
RoleName = roleName,
135+
SupervisorRoleTitle = supervisorRoleTitle,
136+
137+
};
138+
}
139+
140+
}
141+
}

0 commit comments

Comments
 (0)