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 @@ -288,6 +288,7 @@ public void GetCandidateAssessments_returns_expected_results()
const int delegateId = 254480;
var expectedCandidateAssessment = new CandidateAssessment
{
Id = 1,
DelegateId = delegateId,
SelfAssessmentId = SelfAssessmentId,
CompletedDate = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DigitalLearningSolutions.Data.DataServices.SelfAssessmentDataService;
using DigitalLearningSolutions.Data.Models.External.LearningHubApiClient;
using DigitalLearningSolutions.Data.Models.LearningResources;
using DigitalLearningSolutions.Data.Models.SelfAssessments;
using DigitalLearningSolutions.Data.Services;
using FakeItEasy;
using FizzWare.NBuilder;
Expand Down Expand Up @@ -64,6 +65,7 @@ public void AddResourceToActionPlan_calls_expected_insert_data_service_methods()
const int learningResourceReferenceId = 1;
const int delegateId = 2;
const int selfAssessmentId = 3;
const int candidateAssessmentId = 4;
const string resourceName = "Activity";
const string resourceLink = "www.test.com";
const int learningLogId = 4;
Expand Down Expand Up @@ -93,6 +95,11 @@ public void AddResourceToActionPlan_calls_expected_insert_data_service_methods()
A.CallTo(() => selfAssessmentDataService.GetCompetencyIdsForSelfAssessment(selfAssessmentId))
.Returns(assessmentCompetencies);

A.CallTo(() => selfAssessmentDataService.GetCandidateAssessments(delegateId, selfAssessmentId))
.Returns(
new[] { Builder<CandidateAssessment>.CreateNew().With(ca => ca.Id = candidateAssessmentId).Build() }
);

A.CallTo(
() => learningLogItemsDataService.InsertLearningLogItem(
A<int>._,
Expand Down Expand Up @@ -120,7 +127,7 @@ public void AddResourceToActionPlan_calls_expected_insert_data_service_methods()
).MustHaveHappenedOnceExactly();
A.CallTo(
() => learningLogItemsDataService.InsertCandidateAssessmentLearningLogItem(
selfAssessmentId,
candidateAssessmentId,
learningLogId
)
).MustHaveHappenedOnceExactly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int InsertLearningLogItem(
int learningResourceReferenceId
);

void InsertCandidateAssessmentLearningLogItem(int assessmentId, int learningLogId);
void InsertCandidateAssessmentLearningLogItem(int candidateAssessmentId, int learningLogId);

void InsertLearningLogItemCompetencies(int learningLogId, int competencyId, DateTime associatedDate);

Expand Down Expand Up @@ -156,13 +156,13 @@ OUTPUT Inserted.LearningLogItemID
return learningLogItemId;
}

public void InsertCandidateAssessmentLearningLogItem(int assessmentId, int learningLogId)
public void InsertCandidateAssessmentLearningLogItem(int candidateAssessmentId, int learningLogId)
{
connection.Execute(
@"INSERT INTO CandidateAssessmentLearningLogItems
(CandidateAssessmentID, LearningLogItemID)
VALUES (@assessmentId, @learningLogId)",
new { assessmentId, learningLogId }
VALUES (@candidateAssessmentId, @learningLogId)",
new { candidateAssessmentId, learningLogId }
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public IEnumerable<CandidateAssessment> GetCandidateAssessments(int delegateId,
{
return connection.Query<CandidateAssessment>(
@"SELECT
ID,
CandidateId AS DelegateId,
SelfAssessmentID,
CompletedDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public class CandidateAssessment
{
public int Id { get; set; }

public int DelegateId { get; set; }

public int SelfAssessmentId { get; set; }
Expand Down
18 changes: 17 additions & 1 deletion DigitalLearningSolutions.Data/Services/ActionPlanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,23 @@ await learningHubResourceService.GetResourceByReferenceId(
learningResourceReferenceId
);

learningLogItemsDataService.InsertCandidateAssessmentLearningLogItem(selfAssessmentId, learningLogItemId);
// We can assume a single Candidate Assessment because we'll be adding a uniqueness constraint
// on CandidateAssessments (candidateId, selfAssessmentId) before releasing (see HEEDLS-932)
var candidateAssessmentIdIfAny = selfAssessmentDataService
.GetCandidateAssessments(delegateId, selfAssessmentId)
.SingleOrDefault()?.Id;

if (candidateAssessmentIdIfAny == null)
{
throw new InvalidOperationException(
$"Cannot add resource to action plan as user {delegateId} is not enrolled on self assessment {selfAssessmentId}"
);
}

learningLogItemsDataService.InsertCandidateAssessmentLearningLogItem(
candidateAssessmentIdIfAny!.Value,
learningLogItemId
);

foreach (var competencyId in learningLogCompetenciesToAdd)
{
Expand Down