11namespace 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