Files
monorepo/LCU.Api.Internal.DataCleanUp/LCU.Api.Internal.DataCleanUpTest/Services/MaskTransactionExternalDescriptionWithSsnServiceTest.cs
T
2026-03-13 09:28:55 -05:00

251 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Api.Internal.DataCleanUp.Services;
using LCU.Api.Internal.DataCleanUp.DataAccess;
using LCU.Library.Internal.DataCleanUpModel.Enum;
using LCU.Library.Internal.DataCleanUpModel.Models;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreResponses;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Transaction;
namespace LCU.Api.Internal.DataCleanUpTest.Services;
public class MaskTransactionExternalDescriptionWithSsnServiceTest
{
private MaskTransactionExternalDescriptionWithSsnService _maskTransactionExternalDescriptionWithSsnService;
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
[SetUp]
public void Setup()
{
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
_maskTransactionExternalDescriptionWithSsnService = new MaskTransactionExternalDescriptionWithSsnService(_mockCoreApiWrapperService.Object);
}
[Test]
public async Task CleanUp_Success()
{
//Set Up
var testExternalDescriptions = new List<ExternalDescription>()
{
new ExternalDescription()
{
ExternalDescriptionNumber = 1,
ExternalDescriptionText = "State of Wisc - SSI 44444444444 *0000000000*333664444*Tester Test *120422\\"
},
new ExternalDescription()
{
ExternalDescriptionNumber = 1,
ExternalDescriptionText = "State of Wisc - SSI 555555555555 *111111111*444775555*TesterB TestB *120422\\"
}
};
_mockCoreApiWrapperService.Setup(x => x.GetTransactionsExternalDescriptionsWithSsn())
.ReturnsAsync(testExternalDescriptions);
var testBasicResponse = new BasicResponse()
{
Success = true,
Errors = new List<string>()
};
_mockCoreApiWrapperService.Setup(x => x.UpdateTransactionsExternalDescriptions(It.IsAny<ExternalDescription>()))
.ReturnsAsync(testBasicResponse);
var testDataCleanUpRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.MaskTransactionExternalDescriptionWithSsn
};
var result = await _maskTransactionExternalDescriptionWithSsnService
.CleanUp(testDataCleanUpRequest);
Assert.IsTrue(result.Successful);
Assert.AreEqual(0, result.ResponseStack.Count);
}
[Test]
public async Task CleanUp_Fail_BadSsns()
{
//Set Up
var testExternalDescriptions = new List<ExternalDescription>()
{
new ExternalDescription()
{
ExternalDescriptionNumber = 1,
ExternalDescriptionText = "State of Wisc - SSI 44444444444 *0000000000*33364444*Tester Test *120422\\"
},
new ExternalDescription()
{
ExternalDescriptionNumber = 1,
ExternalDescriptionText = "State of Wisc - SSI 555555555555 *111111111*4447755555*TesterB TestB *120422\\"
}
};
_mockCoreApiWrapperService.Setup(x => x.GetTransactionsExternalDescriptionsWithSsn())
.ReturnsAsync(testExternalDescriptions);
var testBasicResponse = new BasicResponse()
{
Success = true,
Errors = new List<string>()
};
_mockCoreApiWrapperService.Setup(x => x.UpdateTransactionsExternalDescriptions(It.IsAny<ExternalDescription>()))
.ReturnsAsync(testBasicResponse);
var testDataCleanUpRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.MaskTransactionExternalDescriptionWithSsn
};
var result = await _maskTransactionExternalDescriptionWithSsnService
.CleanUp(testDataCleanUpRequest);
Assert.IsFalse(result.Successful);
Assert.AreEqual(2, result.ResponseStack.Count);
}
[Test]
public async Task CleanUp_Fail_ExernalDescriptionsNull()
{
//Set Up
List<ExternalDescription> testExternalDescriptions = null;
_mockCoreApiWrapperService.Setup(x => x.GetTransactionsExternalDescriptionsWithSsn())
.ReturnsAsync(testExternalDescriptions);
var testBasicResponse = new BasicResponse()
{
Success = true,
Errors = new List<string>()
};
_mockCoreApiWrapperService.Setup(x => x.UpdateTransactionsExternalDescriptions(It.IsAny<ExternalDescription>()))
.ReturnsAsync(testBasicResponse);
var testDataCleanUpRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.MaskTransactionExternalDescriptionWithSsn
};
var result = await _maskTransactionExternalDescriptionWithSsnService
.CleanUp(testDataCleanUpRequest);
Assert.IsFalse(result.Successful);
Assert.AreEqual(1, result.ResponseStack.Count);
}
[Test]
public async Task HandleMaskingTransactionExternalDescriptionWithSsn_Success()
{
//Set Up
var testBasicResponse = new BasicResponse()
{
Success = true,
Errors = new List<string>()
};
_mockCoreApiWrapperService.Setup(x => x.UpdateTransactionsExternalDescriptions(It.IsAny<ExternalDescription>()))
.ReturnsAsync(testBasicResponse);
var testDataCleanUpRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.MaskTransactionExternalDescriptionWithSsn
};
var testCleanUpResult = new DataCleanUpResult(testDataCleanUpRequest, true, new List<string>());
var descptionWithSsn = "State of Wisc - SSI 44444444444 *0000000000*333664444*Tester Test *120422\\";
var testExternalDescription = new ExternalDescription()
{
ExternalDescriptionNumber = 1,
ExternalDescriptionText = descptionWithSsn
};
var result = await _maskTransactionExternalDescriptionWithSsnService
.HandleMaskingTransactionExternalDescriptionWithSsn(testCleanUpResult, testExternalDescription);
Assert.IsTrue(result.Successful);
Assert.AreEqual(0, result.ResponseStack.Count);
}
[Test]
public async Task HandleMaskingTransactionExternalDescriptionWithSsn_BasicResponseReturnedFail()
{
//Set Up
var testBasicResponse = new BasicResponse()
{
Success = false,
Errors = new List<string>()
{
"Failure"
}
};
_mockCoreApiWrapperService.Setup(x => x.UpdateTransactionsExternalDescriptions(It.IsAny<ExternalDescription>()))
.ReturnsAsync(testBasicResponse);
var testDataCleanUpRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.MaskTransactionExternalDescriptionWithSsn
};
var testCleanUpResult = new DataCleanUpResult(testDataCleanUpRequest, true, new List<string>());
var descptionWithSsn = "State of Wisc - SSI 44444444444 *0000000000*333664444*Tester Test *120422\\";
var testExternalDescription = new ExternalDescription()
{
ExternalDescriptionNumber = 1,
ExternalDescriptionText = descptionWithSsn
};
var result = await _maskTransactionExternalDescriptionWithSsnService
.HandleMaskingTransactionExternalDescriptionWithSsn(testCleanUpResult, testExternalDescription);
Assert.IsFalse (result.Successful);
Assert.AreEqual(1, result.ResponseStack.Count);
}
[Test]
public async Task HandleMaskingTransactionExternalDescriptionWithSsn_Fail_CoreUpdateReturnWasnull()
{
var testDataCleanUpRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.MaskTransactionExternalDescriptionWithSsn
};
var testCleanUpResult = new DataCleanUpResult(testDataCleanUpRequest, true, new List<string>());
var descptionWithSsn = "State of Wisc - SSI 44444444444 *0000000000*333664444*Tester Test *120422\\";
var testExternalDescription = new ExternalDescription()
{
ExternalDescriptionNumber = 1,
ExternalDescriptionText = descptionWithSsn
};
var result = await _maskTransactionExternalDescriptionWithSsnService
.HandleMaskingTransactionExternalDescriptionWithSsn(testCleanUpResult, testExternalDescription);
Assert.IsFalse(result.Successful);
Assert.AreEqual(1, result.ResponseStack.Count);
}
[Test]
public void MaskSsn_Success()
{
var descptionWithSsn = "State of Wisc - SSI 44444444444 *0000000000*333664444*Tester Test *120422\\";
var result = _maskTransactionExternalDescriptionWithSsnService.MaskSsn(descptionWithSsn);
Assert.IsNotNull(result);
Assert.AreEqual("State of Wisc - SSI 44444444444 *0000000000*XXXXX4444*Tester Test *120422\\", result);
}
[Test]
public void MaskSsn_ThrowException_DoesNotMeetPattern()
{
var descptionWithSsn = "State of Wisc - SSI 44444444444 *333664444*Tester Test *120422\\";
var ex = Assert.Throws<Exception>(() => _maskTransactionExternalDescriptionWithSsnService.MaskSsn(descptionWithSsn));
Assert.That(ex.Message, Is.EqualTo("Transaction External Description does not meet the pattern. Was expecting 5 sections split by * but there were 4 sections."));
}
[Test]
public void MaskSsn_ThrowException_SsnPatternContainedHyphens_Length_11()
{
var descptionWithSsn = "State of Wisc - SSI 44444444444 *0000000000*333-66-4444*Tester Test *120422\\";
var ex = Assert.Throws<Exception>(() => _maskTransactionExternalDescriptionWithSsnService.MaskSsn(descptionWithSsn));
Assert.That(ex.Message, Is.EqualTo("The SSN pulled from the Transaction External Description does not meet the pattern." +
$"Was expecting SSN to be a lenght of 9 but it was 11."));
}
}