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 @@ -145,11 +145,11 @@ public void AddResourceToActionPlan_calls_expected_insert_data_service_methods()
}

[Test]
public async Task GetIncompleteActionPlanResources_returns_empty_list_if_no_incomplete_learning_log_items_found()
public async Task
GetIncompleteActionPlanResources_returns_empty_list_if_no_incomplete_learning_log_items_found()
{
// Given
const int delegateId = 1;
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("true");
var invalidLearningLogItems = Builder<LearningLogItem>.CreateListOfSize(3)
.All().With(i => i.CompletedDate = null).And(i => i.ArchivedDate = null)
.And(i => i.LearningHubResourceReferenceId = 1)
Expand All @@ -174,7 +174,6 @@ public async Task GetIncompleteActionPlanResources_returns_correctly_matched_act
{
// Given
const int delegateId = 1;
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("true");
var learningLogIds = new List<int> { 4, 5, 6, 7, 8 };
var learningResourceIds = new List<int> { 15, 21, 33, 48, 51 };
var learningLogItems = Builder<LearningLogItem>.CreateListOfSize(5).All()
Expand Down Expand Up @@ -396,7 +395,8 @@ public void VerifyDelegateCanAccessActionPlanResource_returns_null_if_LearningLo
}

[Test]
public void VerifyDelegateCanAccessActionPlanResource_returns_false_if_LearningLogItem_is_for_different_delegate()
public void
VerifyDelegateCanAccessActionPlanResource_returns_false_if_LearningLogItem_is_for_different_delegate()
{
// Given
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("true");
Expand Down
3 changes: 2 additions & 1 deletion DigitalLearningSolutions.Data/Services/ActionPlanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public void RemoveActionPlanResource(int learningLogItemId, int delegateId)

var actionPlanResource = learningLogItemsDataService.GetLearningLogItem(learningLogItemId);

if (!(actionPlanResource is { ArchivedDate: null }) || actionPlanResource.LearningHubResourceReferenceId == null)
if (!(actionPlanResource is { ArchivedDate: null }) ||
actionPlanResource.LearningHubResourceReferenceId == null)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
namespace DigitalLearningSolutions.Web.Tests.Controllers.LearningPortal
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DigitalLearningSolutions.Data.Enums;
using DigitalLearningSolutions.Data.Helpers;
using DigitalLearningSolutions.Data.Models.Courses;
using DigitalLearningSolutions.Data.Models.LearningResources;
using DigitalLearningSolutions.Data.Models.SelfAssessments;
using DigitalLearningSolutions.Web.Tests.TestHelpers;
using DigitalLearningSolutions.Web.ViewModels.LearningPortal.Current;
using FakeItEasy;
Expand Down Expand Up @@ -38,6 +42,7 @@ public async Task Current_action_should_return_view_result()
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(CandidateId))
.Returns(actionPlanResources);
A.CallTo(() => centresDataService.GetBannerText(CentreId)).Returns(bannerText);
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("true");

// When
var result = await controller.Current();
Expand All @@ -57,6 +62,62 @@ public async Task Current_action_should_return_view_result()
.Model.Should().BeEquivalentTo(expectedModel);
}

[Test]
public async Task Current_action_should_not_fetch_ActionPlanResources_if_signposting_disabled()
{
// Given
GivenCurrentActivitesAreEmptyLists();
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("false");

// When
await controller.Current();

// Then
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(CandidateId)).MustNotHaveHappened();
}

[Test]
public async Task Current_action_should_fetch_ActionPlanResources_if_signposting_enabled()
{
// Given
GivenCurrentActivitesAreEmptyLists();
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("false");

// When
await controller.Current();

// Then
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(CandidateId)).MustNotHaveHappened();
}

[Test]
public async Task AllCurrentItems_action_should_not_fetch_ActionPlanResources_if_signposting_disabled()
{
// Given
GivenCurrentActivitesAreEmptyLists();
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("false");

// When
await controller.AllCurrentItems();

// Then
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(CandidateId)).MustNotHaveHappened();
}

[Test]
public async Task AllCurrentItems_action_should_fetch_ActionPlanResources_if_signposting_enabled()
{
// Given
GivenCurrentActivitesAreEmptyLists();
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("false");

// When
await controller.AllCurrentItems();

// Then
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(CandidateId)).MustNotHaveHappened();
}

[Test]
public void Trying_to_edit_complete_by_date_when_not_self_enrolled_should_return_403()
{
Expand Down Expand Up @@ -293,6 +354,7 @@ public async Task Current_action_should_have_banner_text()
// Given
const string bannerText = "Banner text";
A.CallTo(() => centresDataService.GetBannerText(CentreId)).Returns(bannerText);
A.CallTo(() => config[ConfigHelper.UseSignposting]).Returns("true");

// When
var currentViewModel = await CurrentCourseHelper.CurrentPageViewModelFromController(controller);
Expand Down Expand Up @@ -377,5 +439,15 @@ public void MarkActionPlanResourceAsComplete_does_not_call_service_with_invalid_
A.CallTo(() => actionPlanService.SetCompletionDate(learningLogItemId, completedDate))
.MustNotHaveHappened();
}

private void GivenCurrentActivitesAreEmptyLists()
{
A.CallTo(() => courseDataService.GetCurrentCourses(A<int>._)).Returns(new List<CurrentCourse>());
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(A<int>._))
.Returns(new List<CurrentSelfAssessment>());
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(A<int>._))
.Returns(new List<ActionPlanResource>());
A.CallTo(() => centresDataService.GetBannerText(A<int>._)).Returns("bannerText");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace DigitalLearningSolutions.Web.Controllers.LearningPortalController
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DigitalLearningSolutions.Data.Enums;
using DigitalLearningSolutions.Data.Helpers;
using DigitalLearningSolutions.Data.Models.LearningResources;
using DigitalLearningSolutions.Web.Attributes;
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.Models.Enums;
Expand All @@ -29,7 +32,7 @@ public async Task<IActionResult> Current(
var bannerText = GetBannerText();
var selfAssessments =
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateId);
var learningResources = await actionPlanService.GetIncompleteActionPlanResources(delegateId);
var learningResources = await GetIncompleteActionPlanResourcesIfSignpostingEnabled(delegateId);
var model = new CurrentPageViewModel(
currentCourses,
searchString,
Expand All @@ -49,7 +52,7 @@ public async Task<IActionResult> AllCurrentItems()
var currentCourses = courseDataService.GetCurrentCourses(delegateId);
var selfAssessment =
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateId);
var learningResources = await actionPlanService.GetIncompleteActionPlanResources(delegateId);
var learningResources = await GetIncompleteActionPlanResourcesIfSignpostingEnabled(delegateId);
var model = new AllCurrentItemsPageViewModel(currentCourses, selfAssessment, learningResources);
return View("Current/AllCurrentItems", model);
}
Expand Down Expand Up @@ -221,5 +224,14 @@ public IActionResult RemoveResourceFromActionPlanPost(int learningLogItemId)
actionPlanService.RemoveActionPlanResource(learningLogItemId, User.GetCandidateIdKnownNotNull());
return RedirectToAction("Current");
}

private async Task<IEnumerable<ActionPlanResource>> GetIncompleteActionPlanResourcesIfSignpostingEnabled(
int delegateId
)
{
return config.IsSignpostingUsed()
? await actionPlanService.GetIncompleteActionPlanResources(delegateId)
: new List<ActionPlanResource>();
}
}
}