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 @@ -527,21 +527,21 @@ public void DoesCourseExistAtCentre_returns_false_if_course_does_not_exist_with_
}

[Test]
public void GetCourseValidationDetails_returns_centreId_and_categoryId_correctly()
public void GetCourseCentreAndCategory_returns_centreId_and_categoryId_correctly()
{
// When
var (centreId, courseCategoryId) = courseDataService.GetCourseValidationDetails(100);
var (centreId, courseCategoryId) = courseDataService.GetCourseCentreAndCategory(100);

// Then
centreId.Should().Be(101);
courseCategoryId.Should().Be(2);
}

[Test]
public void GetCourseValidationDetails_returns_null_when_course_does_not_exist()
public void GetCourseCentreAndCategory_returns_null_when_course_does_not_exist()
{
// When
var (centreId, courseCategoryId) = courseDataService.GetCourseValidationDetails(265);
var (centreId, courseCategoryId) = courseDataService.GetCourseCentreAndCategory(265);

// Then
centreId.Should().BeNull();
Expand Down
20 changes: 10 additions & 10 deletions DigitalLearningSolutions.Data.Tests/Services/CourseServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ public void GetDelegateAttemptsAndCourseCustomPrompts_should_not_fetch_attempt_s
public void VerifyAdminUserCanAccessCourse_should_return_true_when_centreId_and_categoryId_match()
{
// Given
A.CallTo(() => courseDataService.GetCourseValidationDetails(A<int>._))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(A<int>._))
.Returns((2, 2));

// When
var result = courseService.VerifyAdminUserCanAccessCourse(1, 2, 2);

// Then
A.CallTo(() => courseDataService.GetCourseValidationDetails(1))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(1))
.MustHaveHappenedOnceExactly();
result.Should().BeTrue();
}
Expand All @@ -162,14 +162,14 @@ public void
VerifyAdminUserCanAccessCourse_should_return_true_when_centreId_matches_and_admin_category_id_is_null()
{
// Given
A.CallTo(() => courseDataService.GetCourseValidationDetails(A<int>._))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(A<int>._))
.Returns((2, 2));

// When
var result = courseService.VerifyAdminUserCanAccessCourse(1, 2, null);

// Then
A.CallTo(() => courseDataService.GetCourseValidationDetails(1))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(1))
.MustHaveHappenedOnceExactly();
result.Should().BeTrue();
}
Expand All @@ -178,14 +178,14 @@ public void
public void VerifyAdminUserCanAccessCourse_should_return_false_with_incorrect_centre()
{
// Given
A.CallTo(() => courseDataService.GetCourseValidationDetails(A<int>._))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(A<int>._))
.Returns((2, 2));

// When
var result = courseService.VerifyAdminUserCanAccessCourse(1, 1, 2);

// Then
A.CallTo(() => courseDataService.GetCourseValidationDetails(1))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(1))
.MustHaveHappenedOnceExactly();
result.Should().BeFalse();
}
Expand All @@ -194,14 +194,14 @@ public void VerifyAdminUserCanAccessCourse_should_return_false_with_incorrect_ce
public void VerifyAdminUserCanAccessCourse_should_return_false_with_incorrect_categoryID()
{
// Given
A.CallTo(() => courseDataService.GetCourseValidationDetails(A<int>._))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(A<int>._))
.Returns((1, 1));

// When
var result = courseService.VerifyAdminUserCanAccessCourse(1, 1, 2);

// Then
A.CallTo(() => courseDataService.GetCourseValidationDetails(1))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(1))
.MustHaveHappenedOnceExactly();
result.Should().BeFalse();
}
Expand Down Expand Up @@ -246,14 +246,14 @@ public void RemoveDelegateFromCourse_returns_false_if_no_current_progress()
public void VerifyAdminUserCanAccessCourse_should_return_null_when_course_does_not_exist()
{
// Given
A.CallTo(() => courseDataService.GetCourseValidationDetails(A<int>._))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(A<int>._))
.Returns((null, null));

// When
var result = courseService.VerifyAdminUserCanAccessCourse(1, 1, 2);

// Then
A.CallTo(() => courseDataService.GetCourseValidationDetails(1))
A.CallTo(() => courseDataService.GetCourseCentreAndCategory(1))
.MustHaveHappenedOnceExactly();
result.Should().BeNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using DigitalLearningSolutions.Data.Services;
using DigitalLearningSolutions.Data.Tests.TestHelpers;
using FakeItEasy;
using FizzWare.NBuilder;
using FluentAssertions;
using Microsoft.Extensions.Configuration;
using NUnit.Framework;
Expand Down Expand Up @@ -118,6 +119,187 @@ public void AddDelegateGroup_sets_GroupDetails_correctly()
).MustHaveHappenedOnceExactly();
}

[Test]
public void DeleteDelegateGroup_calls_expected_data_services()
{
// Given
const int groupId = 1;
const bool deleteStartedEnrolment = true;
var dateTime = DateTime.UtcNow;
A.CallTo(() => clockService.UtcNow).Returns(dateTime);

// When
groupsService.DeleteDelegateGroup(groupId, deleteStartedEnrolment);

// Then
A.CallTo(
() => groupsDataService.RemoveRelatedProgressRecordsForGroup(
groupId,
deleteStartedEnrolment,
dateTime
)
).MustHaveHappenedOnceExactly();
A.CallTo(() => groupsDataService.DeleteGroupDelegates(groupId)).MustHaveHappenedOnceExactly();
A.CallTo(() => groupsDataService.DeleteGroupCustomisations(groupId)).MustHaveHappenedOnceExactly();
A.CallTo(() => groupsDataService.DeleteGroup(groupId)).MustHaveHappenedOnceExactly();
}

[Test]
public void GetGroupsForCentre_returns_expected_groups()
{
// Given
const int centreId = 1;
var groups = Builder<Group>.CreateListOfSize(10).Build();
A.CallTo(() => groupsDataService.GetGroupsForCentre(centreId)).Returns(groups);

// When
var result = groupsService.GetGroupsForCentre(centreId).ToList();

// Then
result.Should().HaveCount(10);
result.Should().BeEquivalentTo(groups);
}

[Test]
public void GetGroupDelegates_returns_expected_group_delegates()
{
// Given
const int groupId = 1;
var groupDelegates = Builder<GroupDelegate>.CreateListOfSize(10).Build();
A.CallTo(() => groupsDataService.GetGroupDelegates(groupId)).Returns(groupDelegates);

// When
var result = groupsService.GetGroupDelegates(groupId).ToList();

// Then
result.Should().HaveCount(10);
result.Should().BeEquivalentTo(groupDelegates);
}

[Test]
public void GetGroupCourses_returns_expected_group_courses()
{
// Given
const int groupId = 1;
const int centreId = 1;
var groupCourses = Builder<GroupCourse>.CreateListOfSize(10).Build();
A.CallTo(() => groupsDataService.GetGroupCourses(groupId, centreId)).Returns(groupCourses);

// When
var result = groupsService.GetGroupCourses(groupId, centreId).ToList();

// Then
result.Should().HaveCount(10);
result.Should().BeEquivalentTo(groupCourses);
}

[Test]
public void GetGroupName_returns_expected_group_name()
{
// Given
const int groupId = 1;
const int centreId = 1;
var groupName = "Group name";
A.CallTo(() => groupsDataService.GetGroupName(groupId, centreId)).Returns(groupName);

// When
var result = groupsService.GetGroupName(groupId, centreId);

// Then
result.Should().BeEquivalentTo(groupName);
}

[Test]
public void GetRelatedProgressIdForGroupDelegate_returns_expected_progress_id()
{
// Given
const int groupId = 1;
const int delegateId = 1;
const int progressId = 12;
A.CallTo(() => groupsDataService.GetRelatedProgressIdForGroupDelegate(groupId, delegateId))
.Returns(progressId);

// When
var result = groupsService.GetRelatedProgressIdForGroupDelegate(groupId, delegateId);

// Then
result.Should().Be(progressId);
}

[Test]
public void GetGroupAtCentreById_returns_expected_group()
{
// Given
const int groupId = 1;
const int centreId = 1;
var group = GroupTestHelper.GetDefaultGroup();
A.CallTo(() => groupsDataService.GetGroupAtCentreById(groupId, centreId)).Returns(group);

// When
var result = groupsService.GetGroupAtCentreById(groupId, centreId);

// Then
result.Should().BeEquivalentTo(group);
}

[Test]
public void UpdateGroupDescription_calls_expected_data_services()
{
// Given
const int groupId = 1;
const int centreId = 1;
const string groupDescription = "Description";

// When
groupsService.UpdateGroupDescription(groupId, centreId, groupDescription);

// Then
A.CallTo(() => groupsDataService.UpdateGroupDescription(groupId, centreId, groupDescription))
.MustHaveHappenedOnceExactly();
}

[Test]
public void RemoveDelegateFromGroup_calls_expected_data_services()
{
// Given
const int groupId = 1;
const int delegateId = 1;
const bool deleteStartedEnrolment = true;
var dateTime = DateTime.UtcNow;
A.CallTo(() => clockService.UtcNow).Returns(dateTime);

// When
groupsService.RemoveDelegateFromGroup(groupId, delegateId, deleteStartedEnrolment);

// Then
A.CallTo(
() => groupsDataService.RemoveRelatedProgressRecordsForGroup(
groupId,
delegateId,
deleteStartedEnrolment,
dateTime
)
).MustHaveHappenedOnceExactly();
A.CallTo(() => groupsDataService.DeleteGroupDelegatesRecordForDelegate(groupId, delegateId))
.MustHaveHappenedOnceExactly();
}

[Test]
public void GetGroupCentreId_returns_expected_centre_id()
{
// Given
const int groupId = 1;
const int centreId = 12;
A.CallTo(() => groupsDataService.GetGroupCentreId(groupId))
.Returns(centreId);

// When
var result = groupsService.GetGroupCentreId(groupId);

// Then
result.Should().Be(centreId);
}

[Test]
public void GetGroupCoursesForCategory_filters_courses_by_category()
{
Expand Down
28 changes: 27 additions & 1 deletion DigitalLearningSolutions.Data.Tests/Services/UserServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,36 @@ public void GetSupervisorsAtCentre_returns_expected_admins()
var result = userService.GetSupervisorsAtCentre(1).ToList();

// Then
result.Count().Should().Be(5);
result.Should().HaveCount(5);
result.All(au => au.IsSupervisor).Should().BeTrue();
}

[Test]
public void GetSupervisorsAtCentreForCategory_returns_expected_admins()
{
// Given
var adminUsers = Builder<AdminUser>.CreateListOfSize(10)
.TheFirst(3)
.With(au => au.IsSupervisor = true)
.With(au => au.CategoryId = 1)
.TheNext(2)
.With(au => au.IsSupervisor = true)
.With(au => au.CategoryId = 0)
.TheNext(3)
.With(au => au.IsSupervisor = true)
.With(au => au.CategoryId = 2)
.TheRest().With(au => au.IsSupervisor = false).Build().ToList();
A.CallTo(() => userDataService.GetAdminUsersByCentreId(A<int>._)).Returns(adminUsers);

// When
var result = userService.GetSupervisorsAtCentreForCategory(1, 1).ToList();

// Then
result.Should().HaveCount(5);
result.Should().OnlyContain(au => au.IsSupervisor);
result.Should().OnlyContain(au => au.CategoryId == 0 || au.CategoryId == 1);
}

private void AssertAdminPermissionsCalledCorrectly(
int adminId,
AdminRoles adminRoles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static CourseDetails GetDefaultCourseDetails(
string? refreshToApplicationName = null,
string? refreshToCustomisationName = null,
int autoRefreshMonths = 0,
bool applyLpDefaultsToSelfEnrol = false
bool applyLpDefaultsToSelfEnrol = false,
int courseCategoryId = 2
)
{
return new CourseDetails
Expand Down Expand Up @@ -69,7 +70,8 @@ public static CourseDetails GetDefaultCourseDetails(
RefreshToApplicationName = refreshToApplicationName,
RefreshToCustomisationName = refreshToCustomisationName,
AutoRefreshMonths = autoRefreshMonths,
ApplyLpDefaultsToSelfEnrol = applyLpDefaultsToSelfEnrol
ApplyLpDefaultsToSelfEnrol = applyLpDefaultsToSelfEnrol,
CourseCategoryId = courseCategoryId
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int diagCompletionThreshold

CourseOptions? GetCourseOptionsFilteredByCategory(int customisationId, int centreId, int? categoryId);

public (int? centreId, int? courseCategoryId) GetCourseValidationDetails(int customisationId);
public (int? centreId, int? courseCategoryId) GetCourseCentreAndCategory(int customisationId);
}

public class CourseDataService : ICourseDataService
Expand Down Expand Up @@ -373,7 +373,8 @@ FROM AssessAttempts aa
cu.ApplyLPDefaultsToSelfEnrol,
{LastAccessedQuery},
{DelegateCountQuery},
{CompletedCountQuery}
{CompletedCountQuery},
ap.CourseCategoryID
FROM dbo.Customisations AS cu
INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = cu.ApplicationID
LEFT JOIN dbo.Customisations AS refreshToCu ON refreshToCu.CustomisationID = cu.RefreshToCustomisationId
Expand Down Expand Up @@ -486,7 +487,7 @@ ELSE CAST(0 AS BIT) END",
);
}

public (int? centreId, int? courseCategoryId) GetCourseValidationDetails(int customisationId)
public (int? centreId, int? courseCategoryId) GetCourseCentreAndCategory(int customisationId)
{
return connection.QueryFirstOrDefault<(int?, int?)>(
@"SELECT c.CentreId, a.CourseCategoryId
Expand Down
Loading