215 lines
9.4 KiB
C#
215 lines
9.4 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
|
using System.Collections.Generic;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.Rules;
|
|
using LCU.Library.Internal.IncentiveApiModels.Common;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
|
|
|
namespace Application.UnitTests.Services
|
|
{
|
|
public class DashboardServiceTest
|
|
{
|
|
private DashboardService _dashboardService;
|
|
private IActivityRepository _mockActivityRepository;
|
|
private IGoalRepository _mockGoalRepository;
|
|
private IDepartmentService _mockDepartmentService;
|
|
private IBusinessRuleService _mockBusinessRuleService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockDepartmentService = Mock.Of<IDepartmentService>();
|
|
_mockActivityRepository = Mock.Of<IActivityRepository>();
|
|
_mockGoalRepository = Mock.Of<IGoalRepository>();
|
|
_mockBusinessRuleService = Mock.Of<IBusinessRuleService>();
|
|
_dashboardService = new DashboardService(_mockDepartmentService, _mockActivityRepository,
|
|
_mockGoalRepository, _mockBusinessRuleService);
|
|
}
|
|
|
|
// We need a test, given some activity, returns it differently for personal or department progress.
|
|
// So we'll need some activities:
|
|
// 1. A New Checking Referral
|
|
// 2. A New Checking Sale
|
|
// 3. An LIC Referral
|
|
// 4. An CreditCard Sale
|
|
// 5. A First Mortgage Referral and Sale
|
|
// This should credit 2 to the person and 1 to the department, unless the department is Member Services.
|
|
[TestCase(55, 1,2)]
|
|
[TestCase(56 /* Member Services */, 2,2)]
|
|
public async Task Special_Rules_Sample_NonMemberServices(int testDepartmentId, int expectedDepartmentTotal, int expectedPersonalTotal)
|
|
{
|
|
var range = new MonthRange(2021, 1, 2021, 2);
|
|
var user = new AppUser()
|
|
{
|
|
EmployeeId = "11771",
|
|
FullName = "Test Worker"
|
|
};
|
|
var departments = new List<Department>()
|
|
{
|
|
new Department()
|
|
{
|
|
Id = testDepartmentId,
|
|
State = DepartmentState.Active,
|
|
DepartmentName = "Developers",
|
|
BusinessLineCode = BusinessLine.MemberServices.Code,
|
|
RegionCode = Region.North.Code
|
|
}
|
|
};
|
|
var userDepartments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
Department = departments.First(x => x.Id == testDepartmentId),
|
|
Role = Role.BM,
|
|
Employee = user,
|
|
StartDate = range.StartTime,
|
|
EndDate = range.EndTime
|
|
}
|
|
};
|
|
var goals = new List<Goal>()
|
|
{
|
|
new Goal()
|
|
{
|
|
Product = Product.NewChecking,
|
|
EndDate = range.EndTime,
|
|
StartDate = range.StartTime,
|
|
Value = 2,
|
|
DepartmentId = testDepartmentId
|
|
},
|
|
new Goal()
|
|
{
|
|
Product = Product.NewChecking,
|
|
EndDate = range.EndTime,
|
|
StartDate = range.StartTime,
|
|
Value = 2,
|
|
DepartmentId = testDepartmentId,
|
|
EmployeeId = "11771"
|
|
}
|
|
};
|
|
var activities = new List<Activity>()
|
|
{
|
|
new Activity()
|
|
{
|
|
Id = 100,
|
|
Product = Product.NewChecking,
|
|
Type = ActivityType.Referral,
|
|
State = ActivityState.Accepted,
|
|
Accepted = range.StartTime,
|
|
Created = range.StartTime,
|
|
DepartmentId = testDepartmentId,
|
|
EmployeeId = "11771",
|
|
Detail = new ActivityDetail(),
|
|
MatchingActivityId = 101
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 101,
|
|
Product = Product.NewChecking,
|
|
Type = ActivityType.Sale,
|
|
State = ActivityState.Accepted,
|
|
Accepted = range.StartTime,
|
|
Created = range.StartTime,
|
|
DepartmentId = testDepartmentId,
|
|
EmployeeId = "11771",
|
|
Detail = new ActivityDetail(),
|
|
MatchingActivityId = 100
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 102,
|
|
Product = Product.LIC,
|
|
Type = ActivityType.Referral,
|
|
State = ActivityState.Accepted,
|
|
Accepted = range.StartTime,
|
|
Created = range.StartTime,
|
|
DepartmentId = testDepartmentId,
|
|
EmployeeId = "11771",
|
|
Detail = new ActivityDetail()
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 103,
|
|
Product = Product.CreditCard,
|
|
Type = ActivityType.Sale,
|
|
State = ActivityState.Accepted,
|
|
Accepted = range.StartTime,
|
|
Created = range.StartTime,
|
|
DepartmentId = testDepartmentId,
|
|
EmployeeId = "11771",
|
|
Detail = new ActivityDetail()
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 104,
|
|
Product = Product.FirstMortgageReferral,
|
|
Type = ActivityType.Sale,
|
|
State = ActivityState.Accepted,
|
|
Accepted = range.StartTime,
|
|
Created = range.StartTime,
|
|
DepartmentId = testDepartmentId,
|
|
EmployeeId = "11771",
|
|
Detail = new ActivityDetail()
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 105,
|
|
Product = Product.FirstMortgageReferral,
|
|
Type = ActivityType.Referral,
|
|
State = ActivityState.PendingReferral,
|
|
Accepted = range.StartTime,
|
|
Created = range.StartTime,
|
|
DepartmentId = testDepartmentId,
|
|
EmployeeId = "11771",
|
|
Detail = new ActivityDetail()
|
|
}
|
|
};
|
|
|
|
var departmentRules = new List<IPayoutRule>()
|
|
{
|
|
new NewCheckingReferralRule(56) // this simulates looking up 200.
|
|
};
|
|
var personalRules = new List<IPayoutRule>()
|
|
{
|
|
};
|
|
|
|
Mock.Get(_mockDepartmentService).Setup(s => s.FindDepartmentAssignmentsForRange(testDepartmentId,range))
|
|
.ReturnsAsync(userDepartments);
|
|
Mock.Get(_mockActivityRepository).Setup(s => s.FindDepartmentActivityByMonthRange(testDepartmentId, range))
|
|
.ReturnsAsync(activities);
|
|
Mock.Get(_mockGoalRepository).Setup(s => s.FindDepartmentGoalsByMonthRange(testDepartmentId, range))
|
|
.ReturnsAsync(goals.Where(x => x.EmployeeId == null).ToList());
|
|
Mock.Get(_mockGoalRepository).Setup(s => s.FindPersonnelGoalsByMonthRange(testDepartmentId, It.IsAny<List<string>>(),range))
|
|
.ReturnsAsync(goals.Where(x => x.EmployeeId != null).ToList());
|
|
Mock.Get(_mockBusinessRuleService).Setup(x => x.GetRules(PayoutType.Department)).Returns(departmentRules);
|
|
Mock.Get(_mockBusinessRuleService).Setup(x => x.GetRules(PayoutType.Personal)).Returns(personalRules);
|
|
|
|
var result = await _dashboardService.GetDepartmentProgressForMonthRangeAsync(testDepartmentId, range);
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual(expectedDepartmentTotal, result.Progress.ProductActivity[Product.NewChecking]);
|
|
Assert.AreEqual(1, result.Progress.ProductActivity[Product.CreditCard]);
|
|
Assert.AreEqual(1, result.Progress.ProductActivity[Product.LIC]);
|
|
Assert.AreEqual(1, result.Progress.ProductActivity[Product.FirstMortgageReferral]);
|
|
Assert.AreEqual(expectedPersonalTotal, result.EmployeeProgress["11771"].ProductActivity[Product.NewChecking]);
|
|
Assert.AreEqual(1, result.EmployeeProgress["11771"].ProductActivity[Product.CreditCard]);
|
|
Assert.AreEqual(1, result.EmployeeProgress["11771"].ProductActivity[Product.LIC]);
|
|
|
|
Mock.Get(_mockDepartmentService).Verify(s => s.FindDepartmentAssignmentsForRange(testDepartmentId, range),
|
|
Times.Once);
|
|
Mock.Get(_mockActivityRepository).Verify(s => s.FindDepartmentActivityByMonthRange(testDepartmentId, range),
|
|
Times.Once);
|
|
Mock.Get(_mockGoalRepository).Verify(s => s.FindDepartmentGoalsByMonthRange(testDepartmentId, range),
|
|
Times.Once);
|
|
Mock.Get(_mockGoalRepository).Verify(s => s.FindPersonnelGoalsByMonthRange(testDepartmentId, It.IsAny<List<string>>(),range),
|
|
Times.Once);
|
|
}
|
|
|
|
|
|
}
|
|
}
|