784 lines
36 KiB
C#
784 lines
36 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.Payout;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.Dayforce;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models.Dayforce;
|
|
using LCU.Library.Internal.IncentiveApiModels.Results;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
|
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
|
|
|
namespace Application.UnitTests.Services
|
|
{
|
|
public class DayForceSyncServiceTest
|
|
{
|
|
private IDayForceClientService _dayForceClientService;
|
|
private IDayForceSyncService _dayForceSyncService;
|
|
private INotificationApiService _notificationService;
|
|
private IPayoutService _payoutService;
|
|
private ISettingsService _settingsService;
|
|
private IUnitOfWork _unitOfWork;
|
|
private IUserService _userService;
|
|
private DayForceConfiguration _dayForceConfig;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_dayForceClientService = Mock.Of<IDayForceClientService>();
|
|
_notificationService = Mock.Of<INotificationApiService>();
|
|
_payoutService = Mock.Of<IPayoutService>();
|
|
_settingsService = Mock.Of<ISettingsService>();
|
|
_unitOfWork = Mock.Of<IUnitOfWork>();
|
|
_userService = Mock.Of<IUserService>();
|
|
_dayForceConfig = Mock.Of<DayForceConfiguration>();
|
|
_dayForceConfig.DayForceActiveUserReport = "INCENTIVE_MANAGER_ACTIVE";
|
|
_dayForceConfig.DayForceTerminatedUserReport = "INCENTIVE_MANAGER_TERMINATED";
|
|
_dayForceConfig.DayForceManualReportRecipients = new List<string>() { "[email protected]" };
|
|
|
|
_dayForceSyncService = new DayForceSyncService(
|
|
_unitOfWork,
|
|
_userService,
|
|
_notificationService,
|
|
_payoutService,
|
|
_dayForceClientService,
|
|
_settingsService,
|
|
_dayForceConfig
|
|
);
|
|
}
|
|
|
|
[Test]
|
|
public void Sync_Active_Throws()
|
|
{
|
|
Mock.Get(_dayForceClientService)
|
|
.Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{ });
|
|
|
|
Assert.Throws<Exception>(() => { _dayForceSyncService.SyncActiveDayForceUsers(new List<string>()).GetAwaiter().GetResult(); });
|
|
|
|
Mock.Get(_dayForceClientService)
|
|
.Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.Once);
|
|
Mock.Get(_dayForceClientService)
|
|
.Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public void Sync_Term_Throws()
|
|
{
|
|
Mock.Get(_dayForceClientService)
|
|
.Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{ });
|
|
|
|
Assert.Throws<Exception>(() => { _dayForceSyncService.SyncTerminatedDayForceUsers(new List<string>()).GetAwaiter().GetResult(); });
|
|
|
|
Mock.Get(_dayForceClientService)
|
|
.Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport),
|
|
Times.Never);
|
|
Mock.Get(_dayForceClientService)
|
|
.Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport),
|
|
Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Sync_Active_Empty()
|
|
{
|
|
Mock.Get(_dayForceClientService)
|
|
.Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceActiveUserReport,
|
|
Rows = new List<Dictionary<string, string>>()
|
|
});
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_notificationService)
|
|
.Setup(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>())).Verifiable();
|
|
|
|
Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable();
|
|
|
|
await _dayForceSyncService.SyncActiveDayForceUsers(new List<string>());
|
|
|
|
Mock.Get(_dayForceClientService)
|
|
.Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport),
|
|
Times.Once);
|
|
Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never);
|
|
|
|
Mock.Get(_userService).Verify(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()), Times.Never);
|
|
Mock.Get(_notificationService)
|
|
.Verify(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()),
|
|
Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Sync_Active_Basic()
|
|
{
|
|
var row1 = new Dictionary<string, string>();
|
|
var row2 = new Dictionary<string, string>();
|
|
row1["EmploymentStatus_ShortName"] = "Active";
|
|
row1["Employee_DisplayName"] = "Test One";
|
|
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
|
row1["IdLibrary_LoginName"] = "[email protected]";
|
|
row1["OrgUnit_ShortName"] = "IT";
|
|
row1["Job_ShortName"] = "ELEPHANT";
|
|
row1["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row1["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row1["OrgUnit_LedgerCode"] = "101";
|
|
row2["EmploymentStatus_ShortName"] = "Active";
|
|
row2["Employee_DisplayName"] = "Test Two";
|
|
row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002";
|
|
row2["IdLibrary_LoginName"] = "[email protected]";
|
|
row2["OrgUnit_ShortName"] = "IT";
|
|
row2["Job_ShortName"] = "Developer";
|
|
row2["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row2["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row2["OrgUnit_LedgerCode"] = "103";
|
|
|
|
Mock.Get(_dayForceClientService)
|
|
.Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceActiveUserReport,
|
|
Rows = new List<Dictionary<string, string>>()
|
|
{ row1, row2 }
|
|
});
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_notificationService)
|
|
.Setup(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()))
|
|
.Verifiable();
|
|
|
|
Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable();
|
|
|
|
await _dayForceSyncService.SyncActiveDayForceUsers(new List<string>());
|
|
|
|
Mock.Get(_dayForceClientService)
|
|
.Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport),
|
|
Times.Once);
|
|
Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never);
|
|
|
|
Mock.Get(_userService).Verify(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()), Times.Exactly(2));
|
|
Mock.Get(_notificationService)
|
|
.Verify(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()),
|
|
Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Sync_Term_Empty()
|
|
{
|
|
Mock.Get(_dayForceClientService)
|
|
.Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceTerminatedUserReport,
|
|
Rows = new List<Dictionary<string, string>>()
|
|
});
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.FindManager(It.IsAny<AppUser>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_payoutService)
|
|
.Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()))
|
|
.ReturnsAsync(
|
|
new TerminatedEmployeeReceipt(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}, new PayoutEntry(), new PayoutEntry(), new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
})
|
|
);
|
|
|
|
Mock.Get(_notificationService)
|
|
.Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()))
|
|
.Verifiable();
|
|
|
|
await _dayForceSyncService.SyncTerminatedDayForceUsers(new List<string>());
|
|
|
|
Mock.Get(_dayForceClientService)
|
|
.Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport),
|
|
Times.Once);
|
|
|
|
Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()), Times.Never);
|
|
Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny<AppUser>()), Times.Never);
|
|
Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()), Times.Never);
|
|
Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Sync_Term_Basic()
|
|
{
|
|
var row1 = new Dictionary<string, string>();
|
|
var row2 = new Dictionary<string, string>();
|
|
row1["Employee_DisplayName"] = "Test One";
|
|
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
|
row1["IdLibrary_LoginName"] = "[email protected]";
|
|
row1["OrgUnit_ShortName"] = "IT";
|
|
row1["Job_ShortName"] = "ELEPHANT";
|
|
row1["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row1["Employee_TerminationDate"] = "2021-07-01T00:00:00.000";
|
|
row2["Employee_DisplayName"] = "Test Two";
|
|
row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002";
|
|
row2["IdLibrary_LoginName"] = "[email protected]";
|
|
row2["OrgUnit_ShortName"] = "IT";
|
|
row2["Job_ShortName"] = "Developer";
|
|
row2["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row2["Employee_TerminationDate"] = "2021-07-01T00:00:00.000";
|
|
|
|
Mock.Get(_dayForceClientService)
|
|
.Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceTerminatedUserReport,
|
|
Rows = new List<Dictionary<string, string>>() { row1, row2 }
|
|
});
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.FindManager(It.IsAny<AppUser>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_payoutService)
|
|
.Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()))
|
|
.ReturnsAsync(
|
|
new TerminatedEmployeeReceipt(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}, new PayoutEntry(), new PayoutEntry(), new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
})
|
|
);
|
|
|
|
Mock.Get(_notificationService)
|
|
.Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()))
|
|
.Verifiable();
|
|
|
|
await _dayForceSyncService.SyncTerminatedDayForceUsers(new List<string>());
|
|
|
|
Mock.Get(_dayForceClientService)
|
|
.Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport),
|
|
Times.Once);
|
|
|
|
Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()), Times.Exactly(2));
|
|
Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny<AppUser>()), Times.Exactly(2));
|
|
Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()), Times.Exactly(2));
|
|
Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DayForceSync_ManualReportRecipients_Ok()
|
|
{
|
|
//setup for Active Users Email
|
|
var row3 = new Dictionary<string, string>();
|
|
var row4 = new Dictionary<string, string>();
|
|
|
|
row3["EmploymentStatus_ShortName"] = "Active";
|
|
row3["Employee_DisplayName"] = "Test One";
|
|
row3["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
|
row3["IdLibrary_LoginName"] = "[email protected]";
|
|
row3["OrgUnit_ShortName"] = "IT";
|
|
row3["Job_ShortName"] = "ELEPHANT";
|
|
row3["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row3["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row3["OrgUnit_LedgerCode"] = "101";
|
|
|
|
row4["EmploymentStatus_ShortName"] = "Active";
|
|
row4["Employee_DisplayName"] = "Test Two";
|
|
row4["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002";
|
|
row4["IdLibrary_LoginName"] = "[email protected]";
|
|
row4["OrgUnit_ShortName"] = "IT";
|
|
row4["Job_ShortName"] = "Developer";
|
|
row4["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row4["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row4["OrgUnit_LedgerCode"] = "103";
|
|
|
|
Mock.Get(_dayForceClientService).Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceActiveUserReport,
|
|
Rows = new List<Dictionary<string, string>>() { row3, row4 }
|
|
});
|
|
|
|
Mock.Get(_userService).Setup(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]",
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
Role = Role.MISSING_ROLE
|
|
}
|
|
}
|
|
}
|
|
);
|
|
|
|
Mock.Get(_notificationService).Setup(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>())).Verifiable();
|
|
|
|
//Setup for Terminated Email
|
|
Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable();
|
|
|
|
var row1 = new Dictionary<string, string>();
|
|
var row2 = new Dictionary<string, string>();
|
|
|
|
row1["Employee_DisplayName"] = "Test One";
|
|
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
|
row1["IdLibrary_LoginName"] = "[email protected]";
|
|
row1["OrgUnit_ShortName"] = "IT";
|
|
row1["Job_ShortName"] = "ELEPHANT";
|
|
row1["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row1["Employee_TerminationDate"] = "2021-07-01T00:00:00.000";
|
|
|
|
row2["Employee_DisplayName"] = "Test Two";
|
|
row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002";
|
|
row2["IdLibrary_LoginName"] = "[email protected]";
|
|
row2["OrgUnit_ShortName"] = "IT";
|
|
row2["Job_ShortName"] = "Developer";
|
|
row2["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row2["Employee_TerminationDate"] = "2021-07-01T00:00:00.000";
|
|
|
|
Mock.Get(_dayForceClientService).Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceTerminatedUserReport,
|
|
Rows = new List<Dictionary<string, string>>() { row1, row2 }
|
|
});
|
|
|
|
Mock.Get(_userService).Setup(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_userService).Setup(s => s.FindManager(It.IsAny<AppUser>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_payoutService).Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()))
|
|
.ReturnsAsync(
|
|
new TerminatedEmployeeReceipt(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}, new PayoutEntry(), new PayoutEntry(), new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
})
|
|
);
|
|
|
|
Mock.Get(_notificationService).Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>())).Verifiable();
|
|
|
|
var request = new DayforceProcessRequest();
|
|
await _dayForceSyncService.SyncDayForceUsers(request);
|
|
|
|
//Active Role Checks
|
|
Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.AtLeastOnce);
|
|
Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never);
|
|
Mock.Get(_userService).Verify(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()), Times.Exactly(2));
|
|
Mock.Get(_notificationService).Verify(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()), Times.Once);
|
|
|
|
Mock.Equals(request.MissingRoleNotification, _dayForceConfig.DayForceManualReportRecipients);
|
|
Assert.AreNotSame(request.MissingRoleNotification, "[email protected]");
|
|
|
|
//Terminated User Checks
|
|
Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()), Times.Exactly(2));
|
|
Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny<AppUser>()), Times.Exactly(2));
|
|
Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()), Times.Exactly(2));
|
|
Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once);
|
|
Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DayForceSync_RequestReportRecipients_Ok()
|
|
{
|
|
//setup for Active Users Email
|
|
var row3 = new Dictionary<string, string>();
|
|
var row4 = new Dictionary<string, string>();
|
|
|
|
row3["EmploymentStatus_ShortName"] = "Active";
|
|
row3["Employee_DisplayName"] = "Test One";
|
|
row3["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
|
row3["IdLibrary_LoginName"] = "[email protected]";
|
|
row3["OrgUnit_ShortName"] = "IT";
|
|
row3["Job_ShortName"] = "ELEPHANT";
|
|
row3["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row3["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row3["OrgUnit_LedgerCode"] = "101";
|
|
|
|
row4["EmploymentStatus_ShortName"] = "Active";
|
|
row4["Employee_DisplayName"] = "Test Two";
|
|
row4["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002";
|
|
row4["IdLibrary_LoginName"] = "[email protected]";
|
|
row4["OrgUnit_ShortName"] = "IT";
|
|
row4["Job_ShortName"] = "Developer";
|
|
row4["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row4["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row4["OrgUnit_LedgerCode"] = "103";
|
|
|
|
Mock.Get(_dayForceClientService).Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceActiveUserReport,
|
|
Rows = new List<Dictionary<string, string>>() { row3, row4 }
|
|
});
|
|
|
|
Mock.Get(_userService).Setup(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]",
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
Role = Role.MISSING_ROLE
|
|
}
|
|
}
|
|
}
|
|
);
|
|
|
|
Mock.Get(_notificationService).Setup(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>())).Verifiable();
|
|
|
|
//Setup for Terminated Email
|
|
Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable();
|
|
|
|
var row1 = new Dictionary<string, string>();
|
|
var row2 = new Dictionary<string, string>();
|
|
|
|
row1["Employee_DisplayName"] = "Test One";
|
|
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
|
row1["IdLibrary_LoginName"] = "[email protected]";
|
|
row1["OrgUnit_ShortName"] = "IT";
|
|
row1["Job_ShortName"] = "ELEPHANT";
|
|
row1["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row1["Employee_TerminationDate"] = "2021-07-01T00:00:00.000";
|
|
|
|
row2["Employee_DisplayName"] = "Test Two";
|
|
row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002";
|
|
row2["IdLibrary_LoginName"] = "[email protected]";
|
|
row2["OrgUnit_ShortName"] = "IT";
|
|
row2["Job_ShortName"] = "Developer";
|
|
row2["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row2["Employee_TerminationDate"] = "2021-07-01T00:00:00.000";
|
|
|
|
Mock.Get(_dayForceClientService).Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceTerminatedUserReport,
|
|
Rows = new List<Dictionary<string, string>>() { row1, row2 }
|
|
});
|
|
|
|
Mock.Get(_userService).Setup(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_userService).Setup(s => s.FindManager(It.IsAny<AppUser>()))
|
|
.ReturnsAsync(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}
|
|
);
|
|
|
|
Mock.Get(_payoutService).Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()))
|
|
.ReturnsAsync(
|
|
new TerminatedEmployeeReceipt(
|
|
new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
}, new PayoutEntry(), new PayoutEntry(), new AppUser()
|
|
{
|
|
AdEmail = "[email protected]"
|
|
})
|
|
);
|
|
|
|
Mock.Get(_notificationService).Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>())).Verifiable();
|
|
|
|
var request = new DayforceProcessRequest();
|
|
request.MissingRoleNotification = new List<string>() { "[email protected]" };
|
|
await _dayForceSyncService.SyncDayForceUsers(request);
|
|
|
|
//Active Role Checks
|
|
Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.AtLeastOnce);
|
|
Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never);
|
|
Mock.Get(_userService).Verify(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()), Times.Exactly(2));
|
|
Mock.Get(_notificationService).Verify(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()), Times.Once);
|
|
|
|
Mock.Equals(request.MissingRoleNotification, "[email protected]");
|
|
Assert.AreNotEqual(request.MissingRoleNotification, _dayForceConfig.DayForceManualReportRecipients);
|
|
|
|
//Terminated User Checks
|
|
Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()), Times.Exactly(2));
|
|
Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny<AppUser>()), Times.Exactly(2));
|
|
Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()), Times.Exactly(2));
|
|
Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once);
|
|
Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetMatchingHcmUsersReturnsEmptyListOnEmptySearch()
|
|
{
|
|
var result = await _dayForceSyncService.GetMatchingHcmUsers();
|
|
Assert.IsEmpty(result);
|
|
}
|
|
|
|
[Test]
|
|
public async Task EmployeeDetailsUpdateInitializesWithNullAppUserAndSuccessSetToFalse()
|
|
{
|
|
var result = new EmployeeDetailsUpdateResult();
|
|
Assert.IsNull(result.AppUser);
|
|
Assert.IsFalse(result.UpdatedSuccessfully);
|
|
}
|
|
|
|
[Test]
|
|
public async Task EmployeeDetailsUpdateFailsWhenNewAndOldDetailsMatch()
|
|
{
|
|
var updateRequest = new EmployeeDetailsUpdate
|
|
{
|
|
OldEmail = "[email protected]",
|
|
OldEmployeeId = "12345",
|
|
OldFullName = "TESTERSON, TEST",
|
|
NewEmail = "[email protected]",
|
|
NewEmployeeId = "12345",
|
|
NewFullName = "TESTERSON, TEST"
|
|
};
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.GetUserByAdEmailAsync("[email protected]"))
|
|
.ReturnsAsync(new AppUser
|
|
{
|
|
AdEmail = "[email protected]",
|
|
Id = Guid.NewGuid(),
|
|
EmployeeId = "12345",
|
|
FullName = "TESTERSON, TEST"
|
|
}
|
|
);
|
|
|
|
var result = await _dayForceSyncService.UpdateEmployeeDetails(updateRequest);
|
|
Assert.IsNotNull(result);
|
|
Assert.IsNotNull(result.AppUser);
|
|
Assert.IsFalse(result.UpdatedSuccessfully);
|
|
}
|
|
|
|
[Test]
|
|
public async Task EmployeeDetailsUpdateFailsWhenNoAppUserFound()
|
|
{
|
|
var updateRequest = new EmployeeDetailsUpdate
|
|
{
|
|
OldEmail = "[email protected]",
|
|
OldEmployeeId = "12345",
|
|
OldFullName = "TESTERSON, TEST",
|
|
NewEmail = "[email protected]",
|
|
NewEmployeeId = "12345",
|
|
NewFullName = "TESTERSON, TEST"
|
|
};
|
|
|
|
var result = await _dayForceSyncService.UpdateEmployeeDetails(updateRequest);
|
|
Assert.IsNotNull(result);
|
|
Assert.IsNull(result.AppUser);
|
|
Assert.IsFalse(result.UpdatedSuccessfully);
|
|
}
|
|
|
|
[Test]
|
|
public async Task EmployeeDetailsUpdateFailsWhenNoHcmUserFound()
|
|
{
|
|
var updateRequest = new EmployeeDetailsUpdate
|
|
{
|
|
OldEmail = "[email protected]",
|
|
OldEmployeeId = "12345",
|
|
OldFullName = "TESTERSON, TEST",
|
|
NewEmail = "[email protected]",
|
|
NewEmployeeId = "12345",
|
|
NewFullName = "TESTERSON, TEST"
|
|
};
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.GetUserByAdEmailAsync("[email protected]"))
|
|
.ReturnsAsync(new AppUser
|
|
{
|
|
AdEmail = "[email protected]",
|
|
Id = Guid.NewGuid(),
|
|
EmployeeId = "12345",
|
|
FullName = "TESTERSON, TEST"
|
|
}
|
|
);
|
|
|
|
var row1 = new Dictionary<string, string>();
|
|
var row2 = new Dictionary<string, string>();
|
|
row1["EmploymentStatus_ShortName"] = "Active";
|
|
row1["Employee_DisplayName"] = "Test One";
|
|
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
|
row1["IdLibrary_LoginName"] = "[email protected]";
|
|
row1["OrgUnit_ShortName"] = "IT";
|
|
row1["Job_ShortName"] = "ELEPHANT";
|
|
row1["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row1["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row1["OrgUnit_LedgerCode"] = "101";
|
|
row2["EmploymentStatus_ShortName"] = "Active";
|
|
row2["Employee_DisplayName"] = "Test Two";
|
|
row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002";
|
|
row2["IdLibrary_LoginName"] = "[email protected]";
|
|
row2["OrgUnit_ShortName"] = "IT";
|
|
row2["Job_ShortName"] = "Developer";
|
|
row2["EmployeeManager_ManagerEmployeeNumber"] = "11771";
|
|
row2["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row2["OrgUnit_LedgerCode"] = "103";
|
|
Mock.Get(_dayForceClientService)
|
|
.Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceActiveUserReport,
|
|
Rows = new List<Dictionary<string, string>>()
|
|
{ row1, row2 }
|
|
});
|
|
|
|
var result = await _dayForceSyncService.UpdateEmployeeDetails(updateRequest);
|
|
Assert.IsNotNull(result);
|
|
Assert.IsNotNull(result.AppUser);
|
|
Assert.IsFalse(result.UpdatedSuccessfully);
|
|
}
|
|
|
|
[Test]
|
|
public async Task EmployeeDetailsUpdateSucceedsWhenOneHcmUserFound()
|
|
{
|
|
var updateRequest = new EmployeeDetailsUpdate
|
|
{
|
|
OldEmail = "[email protected]",
|
|
OldEmployeeId = "12345",
|
|
OldFullName = "TESTERSON, TEST",
|
|
NewEmail = "[email protected]",
|
|
NewEmployeeId = "12345",
|
|
NewFullName = "TESTERSON, TEST"
|
|
};
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.GetUserByAdEmailAsync("[email protected]"))
|
|
.ReturnsAsync(new AppUser
|
|
{
|
|
AdEmail = "[email protected]",
|
|
Id = Guid.NewGuid(),
|
|
EmployeeId = "12345",
|
|
FullName = "TESTERSON, TEST"
|
|
}
|
|
);
|
|
|
|
var row1 = new Dictionary<string, string>();
|
|
var row2 = new Dictionary<string, string>();
|
|
row1["EmploymentStatus_ShortName"] = "Active";
|
|
row1["Employee_DisplayName"] = updateRequest.NewFullName;
|
|
row1["EmployeeEmploymentStatus_EmployeeNumber"] = updateRequest.NewEmployeeId;
|
|
row1["IdLibrary_LoginName"] = updateRequest.NewEmail;
|
|
row1["OrgUnit_ShortName"] = "IT";
|
|
row1["Job_ShortName"] = "ELEPHANT";
|
|
row1["EmployeeManager_ManagerEmployeeNumber"] = "11111";
|
|
row1["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row1["OrgUnit_LedgerCode"] = "101";
|
|
row2["EmploymentStatus_ShortName"] = "Active";
|
|
row2["Employee_DisplayName"] = "Test Two";
|
|
row2["EmployeeEmploymentStatus_EmployeeNumber"] = "98765";
|
|
row2["IdLibrary_LoginName"] = "[email protected]";
|
|
row2["OrgUnit_ShortName"] = "IT";
|
|
row2["Job_ShortName"] = "Developer";
|
|
row2["EmployeeManager_ManagerEmployeeNumber"] = "11111";
|
|
row2["Employee_HireDate"] = "2021-07-01T00:00:00.000";
|
|
row2["OrgUnit_LedgerCode"] = "103";
|
|
Mock.Get(_dayForceClientService)
|
|
.Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport))
|
|
.ReturnsAsync(new Report()
|
|
{
|
|
XRefCode = _dayForceConfig.DayForceActiveUserReport,
|
|
Rows = new List<Dictionary<string, string>>()
|
|
{ row1, row2 }
|
|
});
|
|
|
|
Mock.Get(_userService)
|
|
.Setup(s => s.UpdateEmployeeDetails(updateRequest))
|
|
.ReturnsAsync(new EmployeeDetailsUpdateResult{
|
|
AppUser = new AppUser
|
|
{
|
|
AdEmail = updateRequest.NewEmail,
|
|
Id = Guid.NewGuid(),
|
|
EmployeeId = updateRequest.NewEmployeeId,
|
|
FullName = updateRequest.NewFullName
|
|
},
|
|
UpdateMessage = "Employee Details Update Succeeded",
|
|
UpdatedSuccessfully = true
|
|
}
|
|
);
|
|
|
|
var result = await _dayForceSyncService.UpdateEmployeeDetails(updateRequest);
|
|
Assert.IsNotNull(result);
|
|
Assert.IsNotNull(result.AppUser);
|
|
Assert.AreEqual(result.AppUser.AdEmail, updateRequest.NewEmail);
|
|
Assert.AreEqual(result.AppUser.EmployeeId, updateRequest.NewEmployeeId);
|
|
Assert.AreEqual(result.AppUser.FullName, updateRequest.NewFullName);
|
|
Assert.IsTrue(result.UpdatedSuccessfully);
|
|
}
|
|
}
|
|
}
|