314 lines
11 KiB
C#
314 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
|
using LCU.Library.Internal.IncentiveApiModels.Common;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
|
|
using NUnit.Framework;
|
|
|
|
namespace Application.UnitTests.Models
|
|
{
|
|
public class EmployeeProgressTest
|
|
{
|
|
[Test]
|
|
public void ApplyProgress_Basic()
|
|
{
|
|
var activity = new List<Activity>()
|
|
{
|
|
new Activity()
|
|
{
|
|
Id = 5,
|
|
Product = Product.Mortgage,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
AccountBalance = 5100.25
|
|
}
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 5,
|
|
Product = Product.Vehicle,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
IsDebtProtectionEligible = true,
|
|
DebtProtectionAddDate = DateTime.Today,
|
|
AccountBalance = 5100.25
|
|
}
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 6,
|
|
Product = Product.Mortgage,
|
|
State = ActivityState.Rejected,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
AccountBalance = 7100.75
|
|
}
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 55,
|
|
Product = Product.CheckCard,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 56,
|
|
Product = Product.CheckCard,
|
|
State = ActivityState.Transferred,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 57,
|
|
Product = Product.ATMCard,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale
|
|
}
|
|
};
|
|
var user = new AppUser()
|
|
{
|
|
AdEmail = "[email protected]",
|
|
BaseRole = "Tester",
|
|
EmployeeId = "11771",
|
|
FullName = "Test McTester",
|
|
HomeDepartment = "HOME",
|
|
PersonId = 565,
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
DepartmentId = 55,
|
|
Role = Role.Admin
|
|
}
|
|
}
|
|
};
|
|
var range = new MonthRange(2021, 1, 2021, 2);
|
|
|
|
var employeeProgress = new EmployeeProgress(user, range, new List<IPayoutRule>());
|
|
Assert.NotNull(employeeProgress.Departments);
|
|
Assert.AreEqual(1, employeeProgress.Departments.Count);
|
|
|
|
Assert.AreEqual(0, employeeProgress.Progress[55].ProductActivity[Product.Mortgage]);
|
|
Assert.AreEqual(0, employeeProgress.Progress[55].ProductActivity[Product.CheckCard]);
|
|
employeeProgress.ApplyAll(activity);
|
|
Assert.AreEqual(5100.25, employeeProgress.Progress[55].ProductActivity[Product.Mortgage]);
|
|
Assert.AreEqual(1, employeeProgress.Progress[55].ProductActivity[Product.CheckCard]);
|
|
}
|
|
|
|
[Test]
|
|
public void ApplyProgress_GAP_DP()
|
|
{
|
|
var activity = new List<Activity>()
|
|
{
|
|
new Activity()
|
|
{
|
|
Id = 2,
|
|
Product = Product.Mortgage,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
AccountBalance = 5100.25
|
|
}
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 2,
|
|
Product = Product.Vehicle,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
IsDebtProtectionEligible = true,
|
|
DebtProtectionAddDate = null,
|
|
AccountBalance = 5100.25
|
|
}
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 3,
|
|
Product = Product.DebtProtectionEligibleLoan,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
IsDebtProtectionEligible = true,
|
|
DebtProtectionAddDate = null,
|
|
AccountBalance = 5100.25
|
|
}
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 5,
|
|
Product = Product.Vehicle,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
IsDebtProtectionEligible = true,
|
|
DebtProtectionAddDate = DateTime.Today,
|
|
AccountBalance = 5100.25
|
|
}
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 6,
|
|
Product = Product.Mortgage,
|
|
State = ActivityState.Rejected,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
AccountBalance = 7100.75
|
|
}
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 55,
|
|
Product = Product.CheckCard,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 56,
|
|
Product = Product.CheckCard,
|
|
State = ActivityState.Transferred,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale
|
|
},
|
|
new Activity()
|
|
{
|
|
Id = 57,
|
|
Product = Product.ATMCard,
|
|
State = ActivityState.Accepted,
|
|
EmployeeId = "11771",
|
|
DepartmentId = 55,
|
|
Type = ActivityType.Sale
|
|
}
|
|
};
|
|
var user = new AppUser()
|
|
{
|
|
AdEmail = "[email protected]",
|
|
BaseRole = "Tester",
|
|
EmployeeId = "11771",
|
|
FullName = "Test McTester",
|
|
HomeDepartment = "HOME",
|
|
PersonId = 565,
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
DepartmentId = 55,
|
|
Role = Role.Admin
|
|
}
|
|
}
|
|
};
|
|
var range = new MonthRange(2021, 1, 2021, 2);
|
|
|
|
var employeeProgress = new EmployeeProgress(user, range, new List<IPayoutRule>());
|
|
Assert.NotNull(employeeProgress.Departments);
|
|
Assert.AreEqual(1, employeeProgress.Departments.Count);
|
|
|
|
Assert.AreEqual(0, employeeProgress.Progress[55].ProductActivity[Product.DebtProtectionEligibleLoan]);
|
|
employeeProgress.ApplyAll(activity);
|
|
Assert.AreEqual(1, employeeProgress.Progress[55].ProductActivity[Product.DebtProtectionEligibleLoan]);
|
|
Assert.AreEqual(3, employeeProgress.Progress[55].ProductOther[Product.DebtProtectionEligibleLoan]);
|
|
}
|
|
|
|
[Test]
|
|
public void EmployeeProgress_CreatesProgressForDepartmentsAssignedInRange()
|
|
{
|
|
var departmentBeforeRange = new UserDepartment()
|
|
{
|
|
DepartmentId = 1,
|
|
StartDate = new DateTime(2020, 12, 1),
|
|
EndDate = new DateTime(2020, 12, 31),
|
|
Role = Role.Admin
|
|
};
|
|
|
|
var departmentAfterRange = new UserDepartment()
|
|
{
|
|
DepartmentId = 2,
|
|
StartDate = new DateTime(2021, 3, 1),
|
|
EndDate = new DateTime(2021, 3, 31),
|
|
Role = Role.Admin
|
|
};
|
|
|
|
var departmentInRange = new UserDepartment()
|
|
{
|
|
DepartmentId = 3,
|
|
StartDate = new DateTime(2021, 2, 1),
|
|
EndDate = new DateTime(2021, 2, 28),
|
|
Role = Role.Admin
|
|
};
|
|
|
|
var departmentCurrentlyAssigned = new UserDepartment()
|
|
{
|
|
DepartmentId = 4,
|
|
StartDate = new DateTime(2020, 1, 1),
|
|
EndDate = null,
|
|
Role = Role.Admin
|
|
};
|
|
|
|
var user = new AppUser()
|
|
{
|
|
AdEmail = "[email protected]",
|
|
BaseRole = "Tester",
|
|
EmployeeId = "11771",
|
|
FullName = "Test McTester",
|
|
HomeDepartment = "HOME",
|
|
PersonId = 565,
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
departmentBeforeRange,
|
|
departmentAfterRange,
|
|
departmentCurrentlyAssigned,
|
|
departmentInRange
|
|
}
|
|
};
|
|
var range = new MonthRange(2021, 1, 2021, 2);
|
|
|
|
var employeeProgress = new EmployeeProgress(user, range, new List<IPayoutRule>());
|
|
|
|
Assert.AreEqual(2, employeeProgress.Departments.Count);
|
|
Assert.IsFalse(employeeProgress.Departments.Contains(departmentBeforeRange));
|
|
Assert.IsFalse(employeeProgress.Departments.Contains(departmentAfterRange));
|
|
Assert.IsTrue(employeeProgress.Departments.Contains(departmentInRange));
|
|
Assert.IsTrue(employeeProgress.Departments.Contains(departmentCurrentlyAssigned));
|
|
}
|
|
}
|
|
}
|