-
Notifications
You must be signed in to change notification settings - Fork 1
Heedls 568 edit supervisor #699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dbfd239
HEEDLS-568 Edit supervisor view and actions
AlexJacksonDS ba559cf
HEEDLS-568 Edit supervisor backend
AlexJacksonDS d4106c7
HEEDLS-568 Add unit tests
AlexJacksonDS 5ca8999
HEEDLS-568 Fix broken back link
AlexJacksonDS c95e6e7
HEEDLS-568 Allow users to set no supervisor
AlexJacksonDS 48791f1
Merge branch 'master' into HEEDLS-568-edit-supervisor
AlexJacksonDS 5a83a8f
HEEDLS-568 Null check progress record in service
AlexJacksonDS 248260e
HEEDLS-568 tech lead review markups
AlexJacksonDS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
DigitalLearningSolutions.Data.Tests/Services/ProgressServiceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| namespace DigitalLearningSolutions.Data.Tests.Services | ||
| { | ||
| using System; | ||
| using DigitalLearningSolutions.Data.DataServices; | ||
| using DigitalLearningSolutions.Data.Exceptions; | ||
| using DigitalLearningSolutions.Data.Models.Courses; | ||
| using DigitalLearningSolutions.Data.Services; | ||
| using FakeItEasy; | ||
| using NUnit.Framework; | ||
|
|
||
| public class ProgressServiceTests | ||
| { | ||
| private ICourseDataService courseDataService = null!; | ||
| private IProgressDataService progressDataService = null!; | ||
| private IProgressService progressService = null!; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| courseDataService = A.Fake<ICourseDataService>(); | ||
| progressDataService = A.Fake<IProgressDataService>(); | ||
|
|
||
| progressService = new ProgressService(courseDataService, progressDataService); | ||
| } | ||
|
|
||
| [Test] | ||
| public void UpdateSupervisor_does_not_update_records_if_new_supervisor_matches_current() | ||
| { | ||
| // Given | ||
| const int supervisorId = 1; | ||
| const int progressId = 1; | ||
| var courseInfo = new DelegateCourseInfo { SupervisorAdminId = supervisorId }; | ||
| A.CallTo(() => courseDataService.GetDelegateCourseInfoByProgressId(progressId)).Returns(courseInfo); | ||
|
|
||
| // When | ||
| progressService.UpdateSupervisor(progressId, supervisorId); | ||
|
|
||
| // Then | ||
| A.CallTo( | ||
| () => progressDataService.UpdateProgressSupervisorAndCompleteByDate(A<int>._, A<int>._, A<DateTime?>._) | ||
| ).MustNotHaveHappened(); | ||
| A.CallTo( | ||
| () => progressDataService.ClearAspProgressVerificationRequest(A<int>._) | ||
| ).MustNotHaveHappened(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void UpdateSupervisor_updates_records_if_new_supervisor_does_not_match_current() | ||
| { | ||
| // Given | ||
| const int oldSupervisorId = 1; | ||
| const int newSupervisorId = 6; | ||
| const int progressId = 1; | ||
| var courseInfo = new DelegateCourseInfo { SupervisorAdminId = oldSupervisorId }; | ||
| A.CallTo(() => courseDataService.GetDelegateCourseInfoByProgressId(progressId)).Returns(courseInfo); | ||
|
|
||
| // When | ||
| progressService.UpdateSupervisor(progressId, newSupervisorId); | ||
|
|
||
| // Then | ||
| A.CallTo( | ||
| () => progressDataService.UpdateProgressSupervisorAndCompleteByDate(progressId, newSupervisorId, A<DateTime?>._) | ||
| ).MustHaveHappened(); | ||
| A.CallTo( | ||
| () => progressDataService.ClearAspProgressVerificationRequest(progressId) | ||
| ).MustHaveHappened(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void UpdateSupervisor_sets_supervisor_id_to_0_if_new_supervisor_is_null() | ||
| { | ||
| // Given | ||
| const int oldSupervisorId = 1; | ||
| const int progressId = 1; | ||
| var courseInfo = new DelegateCourseInfo { SupervisorAdminId = oldSupervisorId }; | ||
| A.CallTo(() => courseDataService.GetDelegateCourseInfoByProgressId(progressId)).Returns(courseInfo); | ||
|
|
||
| // When | ||
| progressService.UpdateSupervisor(progressId, null); | ||
|
|
||
| // Then | ||
| A.CallTo( | ||
| () => progressDataService.UpdateProgressSupervisorAndCompleteByDate(progressId, 0, A<DateTime?>._) | ||
| ).MustHaveHappened(); | ||
| A.CallTo( | ||
| () => progressDataService.ClearAspProgressVerificationRequest(progressId) | ||
| ).MustHaveHappened(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void UpdateSupervisor_throws_exception_if_no_progress_record_found() | ||
| { | ||
| // Given | ||
| const int progressId = 1; | ||
| A.CallTo(() => courseDataService.GetDelegateCourseInfoByProgressId(progressId)).Returns(null); | ||
|
|
||
| // Then | ||
| Assert.Throws<ProgressNotFoundException>(() => progressService.UpdateSupervisor(progressId, null)); | ||
| A.CallTo( | ||
| () => progressDataService.UpdateProgressSupervisorAndCompleteByDate(A<int>._, A<int>._, A<DateTime?>._) | ||
| ).MustNotHaveHappened(); | ||
| A.CallTo( | ||
| () => progressDataService.ClearAspProgressVerificationRequest(A<int>._) | ||
| ).MustNotHaveHappened(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
DigitalLearningSolutions.Data/Exceptions/ProgressNotFoundException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace DigitalLearningSolutions.Data.Exceptions | ||
| { | ||
| using System; | ||
|
|
||
| public class ProgressNotFoundException : Exception | ||
| { | ||
| public ProgressNotFoundException(string message) | ||
| : base(message) { } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| namespace DigitalLearningSolutions.Data.Services | ||
| { | ||
| using System.Transactions; | ||
| using DigitalLearningSolutions.Data.DataServices; | ||
| using DigitalLearningSolutions.Data.Exceptions; | ||
|
|
||
| public interface IProgressService | ||
| { | ||
| void UpdateSupervisor(int progressId, int? newSupervisorId); | ||
| } | ||
|
|
||
| public class ProgressService : IProgressService | ||
| { | ||
| private readonly ICourseDataService courseDataService; | ||
| private readonly IProgressDataService progressDataService; | ||
|
|
||
| public ProgressService(ICourseDataService courseDataService, IProgressDataService progressDataService) | ||
| { | ||
| this.courseDataService = courseDataService; | ||
| this.progressDataService = progressDataService; | ||
| } | ||
|
|
||
| public void UpdateSupervisor(int progressId, int? newSupervisorId) | ||
| { | ||
| var courseInfo = courseDataService.GetDelegateCourseInfoByProgressId(progressId); | ||
|
|
||
| if (courseInfo == null) | ||
| { | ||
| throw new ProgressNotFoundException($"No progress record found for ProgressID {progressId}"); | ||
| } | ||
|
|
||
| if (courseInfo.SupervisorAdminId == newSupervisorId) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var supervisorId = newSupervisorId ?? 0; | ||
|
|
||
| using var transaction = new TransactionScope(); | ||
|
|
||
| progressDataService.UpdateProgressSupervisorAndCompleteByDate( | ||
| progressId, | ||
| supervisorId, | ||
| courseInfo.CompleteBy | ||
| ); | ||
|
|
||
| progressDataService.ClearAspProgressVerificationRequest(progressId); | ||
|
|
||
| transaction.Complete(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this must work since the tests pass, but my understanding of the Single() LINQ operator is that it throws if there's not exactly one result, so this can never return null. Can you tell me what I've got wrong here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The column SupervisorVerificationRequested is a nullable datetime, so if the aspProgress record exists but has null it will return null, hence the DateTime? return type.
As you say, this will throw an exception if there is not exactly one result, but since we are looking it up by aspProgressId and using it in a unit test this is the behaviour we would want. i.e. this will only throw an exception if the aspProgress record gets deleted from the database for some reason.