227 lines
8.8 KiB
C#
227 lines
8.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Internal.NotificationsApiLib.Models;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
|
using LCU.API.Internal.Operations.IncentiveApi.DataAccess;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models.Dayforce;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models.GoalDispersal;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
|
|
namespace Application.UnitTests.Services
|
|
{
|
|
public class NotificationServiceTest
|
|
{
|
|
private INotificationApiService _notificationService;
|
|
private Mock<INotificationApiDao> _mockNotificationsDao;
|
|
private EmailRecipientsConfiguration _emailConfig;
|
|
private Mock<ApiConfiguration> _incentiveApiConfig;
|
|
private Mock<IUserService> _mockUserService;
|
|
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_mockNotificationsDao = new Mock<INotificationApiDao>();
|
|
_mockUserService = new Mock<IUserService>();
|
|
_incentiveApiConfig = new Mock<ApiConfiguration>();
|
|
_emailConfig = new EmailRecipientsConfiguration()
|
|
{
|
|
TransferRequestInitiatedNotification = new List<string> { "[email protected]" }
|
|
};
|
|
_notificationService = new NotificationApiService(_emailConfig, _incentiveApiConfig.Object, _mockNotificationsDao.Object,
|
|
_mockUserService.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendMonthStartGoalDispersalReceipt_Ok()
|
|
{
|
|
var noErrorsReceipt = new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateFromExistingGoals);
|
|
var withErrorsReceipt = new GoalDispersalReceipt(2, GoalDispersalStrategy.ExtrapolateFromExistingGoals);
|
|
withErrorsReceipt.AddNewDispersalError(GoalDispersalError.ErrorsDuringDisperse, "1234", "Error1", "Batmam");
|
|
withErrorsReceipt.AddNewDispersalError(GoalDispersalError.DispersedToUserWithoutPermission, "4567",
|
|
"Error2", "Ironman");
|
|
var defaultReceipt = new GoalDispersalReceipt(3, GoalDispersalStrategy.DefaultDisperseWithWeights);
|
|
var defaultReceiptWithErrors =
|
|
new GoalDispersalReceipt(4, GoalDispersalStrategy.DefaultDisperseWithWeights);
|
|
defaultReceiptWithErrors.AddNewDispersalError(GoalDispersalError.ErrorsDuringDisperse, "8910", "Error3",
|
|
"Superman");
|
|
|
|
var reportData = new Dictionary<string, GoalDispersalReceipt>()
|
|
{
|
|
{ "DeptA - 1", noErrorsReceipt },
|
|
{ "DeptB - 2", withErrorsReceipt },
|
|
{ "DeptC - 3", defaultReceipt },
|
|
{ "DeptD - 4", defaultReceiptWithErrors },
|
|
{ "DeptE - 6", null }
|
|
};
|
|
|
|
_mockNotificationsDao.Setup(x =>
|
|
x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
|
await _notificationService.SendMonthStartGoalDispersalReceipt(reportData, new List<string>());
|
|
|
|
_mockNotificationsDao.Verify(x => x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
|
}
|
|
|
|
[Test]
|
|
public void SendMonthStartGoalDispersalReceipt_Does_Not_Except()
|
|
{
|
|
_mockNotificationsDao.Setup(x => x.SendMessageAsync(It.IsAny<EmailRequest>()))
|
|
.ThrowsAsync(new Exception("Ahhh"));
|
|
|
|
var result = _notificationService.SendMonthStartGoalDispersalReceipt(new Dictionary<string, GoalDispersalReceipt>()
|
|
{
|
|
{ "Test", new GoalDispersalReceipt(10, GoalDispersalStrategy.DefaultDisperseWithWeights) }
|
|
}, new List<string>());
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendMissingRoleNotification_Ok()
|
|
{
|
|
var users = new List<AppUser>()
|
|
{
|
|
new AppUser()
|
|
{
|
|
FullName = "Test One",
|
|
EmployeeId = "11771",
|
|
BaseRole = "Base Role",
|
|
HomeDepartment = "Home"
|
|
},
|
|
new AppUser()
|
|
{
|
|
FullName = "Test Two",
|
|
EmployeeId = "C00002",
|
|
BaseRole = "Base Role",
|
|
HomeDepartment = "Home"
|
|
}
|
|
};
|
|
|
|
_mockNotificationsDao.Setup(x =>
|
|
x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
|
await _notificationService.SendMissingRoleNotification(users, new List<string>());
|
|
|
|
_mockNotificationsDao.Verify(x => x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendTerminatedEmployeeNotification_Ok()
|
|
{
|
|
var employee = new AppUser()
|
|
{
|
|
FullName = "Test One",
|
|
EmployeeId = "11771",
|
|
BaseRole = "Base Role",
|
|
HomeDepartment = "Home",
|
|
Terminated = new DateTime(2020, 3, 1)
|
|
};
|
|
var manager = new AppUser()
|
|
{
|
|
FullName = "Test Two",
|
|
EmployeeId = "C00002",
|
|
BaseRole = "Base Role",
|
|
HomeDepartment = "Home"
|
|
};
|
|
var lastMonth = new PayoutEntry()
|
|
{
|
|
Code = "ABC",
|
|
EmployeeId = "11771",
|
|
EmployeeName = "Test One",
|
|
PayoutTotal = 500
|
|
};
|
|
var thisMonth = new PayoutEntry()
|
|
{
|
|
Code = "ABC",
|
|
EmployeeId = "11771",
|
|
EmployeeName = "Test One",
|
|
PayoutTotal = 200
|
|
};
|
|
|
|
var receipts = new List<TerminatedEmployeeReceipt>()
|
|
{
|
|
new TerminatedEmployeeReceipt(employee,lastMonth,thisMonth,manager)
|
|
};
|
|
|
|
_mockNotificationsDao.Setup(x =>
|
|
x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
|
await _notificationService.SendTerminatedEmployeeNotification(receipts, new List<string>());
|
|
|
|
_mockNotificationsDao.Verify(x => x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendTransferRequestInitiatedNotification_Ok()
|
|
{
|
|
var transferAction = new ActivityTransferAction
|
|
{
|
|
RequestedActivityId = 1,
|
|
RequestedActivity = new Activity
|
|
{
|
|
DepartmentId = 1,
|
|
Product = Product.CheckCard,
|
|
Type = ActivityType.Referral
|
|
},
|
|
CreatedBy = "Employee One",
|
|
NewActivityEmployeeId = "123",
|
|
NewActivityDepartmentId = 2
|
|
};
|
|
var recipients = new List<string> { "[email protected]", "[email protected]" };
|
|
|
|
_mockNotificationsDao.Setup(x =>
|
|
x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
|
|
|
await _notificationService.SendTransferRequestInitiatedNotification(transferAction, recipients);
|
|
|
|
_mockNotificationsDao.Verify(x => x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendTransferRequestInitiatedNotification_OverrideRecipients()
|
|
{
|
|
var transferAction = new ActivityTransferAction
|
|
{
|
|
RequestedActivityId = 1,
|
|
RequestedActivity = new Activity
|
|
{
|
|
DepartmentId = 1,
|
|
Product = Product.CheckCard,
|
|
Type = ActivityType.Referral
|
|
},
|
|
CreatedBy = "Employee One",
|
|
NewActivityEmployeeId = "123",
|
|
NewActivityDepartmentId = 2
|
|
};
|
|
var originalRecipients = new List<string> { "[email protected]", "[email protected]" };
|
|
var actualRecipients = new List<string> { "[email protected]" };
|
|
|
|
_emailConfig.OverrideRecipients = true;
|
|
_emailConfig.TransferRequestInitiatedNotification = actualRecipients;
|
|
|
|
var emailRequest = new EmailRequest
|
|
{
|
|
Recipient = originalRecipients,
|
|
Body = "test",
|
|
Subject = "Test"
|
|
};
|
|
|
|
_mockNotificationsDao.Setup(x => x.SendMessageAsync(emailRequest));
|
|
|
|
await _notificationService.SendTransferRequestInitiatedNotification(transferAction, actualRecipients);
|
|
|
|
emailRequest = new EmailRequest
|
|
{
|
|
Recipient = actualRecipients,
|
|
Body = "test",
|
|
Subject = "Test"
|
|
};
|
|
|
|
_mockNotificationsDao.Verify(notification => notification.SendMessageAsync(It.IsAny<EmailRequest>()), Times.Once);
|
|
}
|
|
}
|
|
}
|
|
|