Skip to content

Commit

Permalink
Feature/cdms 246 (#73)
Browse files Browse the repository at this point in the history
* Created ChedPPPhsiDecision finder along with tests

* Fixed broken tests

* updated check code

* added in ChedPP integration tests

* commented out test for the moment

* added missing files

* added chepp decision finder for HMI, along with tests

* fixed up some test data

* fixed missing file

* changed to expression

* fixed merge issue

* merge conflict

* reordered decisions codes

* fixed failing tests

* fixed merge issue

* reorder the decision codes

* PR feedback

---------

Co-authored-by: Thomas Anderson <[email protected]>
  • Loading branch information
t11omas and Thomas Anderson authored Jan 24, 2025
1 parent 354e3aa commit c8cc55e
Show file tree
Hide file tree
Showing 35 changed files with 1,194 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using FluentAssertions;
using TestDataGenerator.Scenarios.SpecificFiles;
using TestGenerator.IntegrationTesting.Backend;
using TestGenerator.IntegrationTesting.Backend.Extensions;
using Xunit;
using Xunit.Abstractions;

namespace Btms.Backend.IntegrationTests.DecisionTests.ChedPP;


[Trait("Category", "Integration")]
public class ChedPpHmiTests(ITestOutputHelper output) : MultipleScenarioGeneratorBaseTest(output)
{
[Theory]
[InlineData(typeof(ChedPpHmiDecisionTestsScenarioGenerator), "24GBD447SAPD7NTAR9", "C03")]

[InlineData(typeof(ChedPpHmiDecisionTestsScenarioGenerator), "24GBD69TMXZ2TYCAR9", "N02")]
[InlineData(typeof(ChedPpHmiDecisionTestsScenarioGenerator), "24GBD69TMXZ2TYCAR8", "H01")]
[InlineData(typeof(ChedPpHmiDecisionTestsScenarioGenerator), "24GBD69TMXZ2TYCAR7", "H02")]
public void DecisionShouldHaveCorrectDecisionCodeForSingleNotification(Type generatorType, string mrn, string decisionCode)
{
base.TestOutputHelper.WriteLine("Generator : {0}, Decision Code : {1}", generatorType!.FullName, decisionCode);
EnsureEnvironmentInitialised(generatorType);

var movement = Client
.GetMovementByMrn(mrn);

var lastDecision = movement.Decisions.OrderByDescending(x => x.ServiceHeader?.ServiceCalled).First();


foreach (var item in lastDecision.Items!)
{
foreach (var itemCheck in item.Checks!)
{
itemCheck.DecisionCode.Should().Be(decisionCode);
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ChedPpPhsiTests(ITestOutputHelper output) : MultipleScenarioGenerat
[InlineData(typeof(ChedPpPhsiDecisionTestsScenarioGenerator), "24GBDC4TW6DUQYIAR5", "N02")]
[InlineData(typeof(ChedPpPhsiDecisionTestsScenarioGenerator), "24GBDN3EZ714MBIAR9", "H01")]
[InlineData(typeof(ChedPpPhsiDecisionTestsScenarioGenerator), "24GBDCVPBWY0GE9AR8", "H02")]
////[InlineData(typeof(ChedPpPhsiDecisionTestsScenarioGenerator), "24GBDB6P6GWPVLKAR7", "C03")] put scenario in once HMI has been implemented
[InlineData(typeof(ChedPpPhsiDecisionTestsScenarioGenerator), "24GBDB6P6GWPVLKAR7", "C03")]
public void DecisionShouldHaveCorrectDecisionCodeForSingleNotification(Type generatorType, string mrn, string decisionCode)
{
base.TestOutputHelper.WriteLine("Generator : {0}, Decision Code : {1}", generatorType!.FullName, decisionCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public async Task When_building_items_and_checks_for_a_set_of_decision_codes_The

decisions[0].Items?[1].Checks.Should().HaveCount(1);
decisions[0].Items?[1].Checks?[0].CheckCode.Should().Be("H111");
decisions[0].Items?[1].Checks?[0].DecisionCode.Should().Be("C06");
decisions[0].Items?[1].Checks?[0].DecisionCode.Should().Be("H01");
decisions[0].Items?[1].Checks?[0].DecisionReasons.Should().HaveCount(1);
decisions[0].Items?[1].Checks?[0].DecisionReasons?[0].Should().Be("reason-4");
decisions[0].Items?[1].Checks?[0].DecisionReasons?[0].Should().Be("reason-3");

decisions[1].Items.Should().HaveCount(2);
decisions[1].Items?[0].Checks.Should().HaveCount(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private ServiceProvider ConfigureDecisionFinders(ImportNotification notification
ConfigureDecisionFinders<ChedDDecisionFinder>(notification, ChedDDecisionCode, checkCodes);
ConfigureDecisionFinders<ChedADecisionFinder>(notification, ChedADecisionCode, checkCodes);
ConfigureDecisionFinders<ChedPDecisionFinder>(notification, ChedPDecisionCode, checkCodes);
ConfigureDecisionFinders<ChedPpPhsiDecisionFinder>(notification, ChedPPDecisionCode, checkCodes);
ConfigureDecisionFinders<ChedPPDecisionFinder>(notification, ChedPPDecisionCode, checkCodes);
ConfigureDecisionFinders<IuuDecisionFinder>(notification, IuuDecisionCode, checkCodes);
return _serviceCollection.BuildServiceProvider();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ public class ChedPpPhsiDecisionFinderTests
[InlineData(ImportNotificationTypeEnum.Ced, false, "H219")]
[InlineData(ImportNotificationTypeEnum.Cvedp, false, "H219")]
[InlineData(ImportNotificationTypeEnum.Chedpp, true, "H219")]
[InlineData(ImportNotificationTypeEnum.Chedpp, false, "H220")]
[InlineData(ImportNotificationTypeEnum.Chedpp, true, "H218")]
[InlineData(ImportNotificationTypeEnum.Chedpp, true, "H220")]
[InlineData(ImportNotificationTypeEnum.Chedpp, false, null)]
public void CanFindDecisionTest(ImportNotificationTypeEnum? importNotificationType, bool expectedResult, string? checkCode)
{
var notification = new ImportNotification
{
ImportNotificationType = importNotificationType,
};
var sut = new ChedPpPhsiDecisionFinder();
var sut = new ChedPPDecisionFinder();

var result = sut.CanFindDecision(notification, checkCode);

Expand All @@ -47,7 +48,7 @@ public void DecisionFinderTest(ImportNotificationStatusEnum status, DecisionCode
{
Status = status
};
var sut = new ChedPpPhsiDecisionFinder();
var sut = new ChedPPDecisionFinder();

var result = sut.FindDecision(notification, null);

Expand Down
2 changes: 1 addition & 1 deletion Btms.Business/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static IServiceCollection AddBusinessServices(this IServiceCollection ser
services.AddScoped<IDecisionFinder, ChedADecisionFinder>();
services.AddScoped<IDecisionFinder, ChedDDecisionFinder>();
services.AddScoped<IDecisionFinder, ChedPDecisionFinder>();
services.AddScoped<IDecisionFinder, ChedPpPhsiDecisionFinder>();
services.AddScoped<IDecisionFinder, ChedPPDecisionFinder>();
services.AddScoped<IDecisionFinder, IuuDecisionFinder>();

services.AddTransient<MovementBuilderFactory>();
Expand Down
12 changes: 8 additions & 4 deletions Btms.Business/Services/Decisions/DecisionCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ namespace Btms.Business.Services.Decisions;

public enum DecisionCode
{
H01,
H02,
E03,
C03,
C05,
C06,
C07,
C08,

H01,
H02,

X00,

N02,
N03,
N04,
N07,
X00,

E03,

E94, // IUU not indicated in PartTwo?.ControlAuthority?.IuuCheckRequired but "H224" requested in Items[]?.Checks[]?.CheckCode
E95, // Unexpected value in PartTwo?.Decision?.IuuOption
Expand Down
29 changes: 11 additions & 18 deletions Btms.Business/Services/Decisions/Finders/ChedPPDecisionFinder.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
using Btms.Business.Extensions;
using Btms.Model.Ipaffs;

namespace Btms.Business.Services.Decisions.Finders;

// ReSharper disable once InconsistentNaming
public class ChedPpPhsiDecisionFinder : IDecisionFinder
public class ChedPPDecisionFinder : IDecisionFinder
{
public const string CheckCode = "H219";
public bool CanFindDecision(ImportNotification notification, string? checkCode) =>
notification.ImportNotificationType == ImportNotificationTypeEnum.Chedpp && checkCode == CheckCode;
notification.ImportNotificationType == ImportNotificationTypeEnum.Chedpp && checkCode?.GetChedTypeFromCheckCode() == ImportNotificationTypeEnum.Chedpp;

public DecisionFinderResult FindDecision(ImportNotification notification, string? checkCode)
{
switch (notification.Status)
return notification.Status switch
{
case ImportNotificationStatusEnum.Draft:
break;
case ImportNotificationStatusEnum.Submitted:
case ImportNotificationStatusEnum.InProgress:
return new DecisionFinderResult(DecisionCode.H02, checkCode);
case ImportNotificationStatusEnum.Validated:
return new DecisionFinderResult(DecisionCode.C03, checkCode);
case ImportNotificationStatusEnum.Rejected:
return new DecisionFinderResult(DecisionCode.N02, checkCode);
case ImportNotificationStatusEnum.PartiallyRejected:
return new DecisionFinderResult(DecisionCode.H01, checkCode);
}

return new DecisionFinderResult(DecisionCode.E99, checkCode);
ImportNotificationStatusEnum.Submitted or ImportNotificationStatusEnum.InProgress =>
new DecisionFinderResult(DecisionCode.H02, checkCode),
ImportNotificationStatusEnum.Validated => new DecisionFinderResult(DecisionCode.C03, checkCode),
ImportNotificationStatusEnum.Rejected => new DecisionFinderResult(DecisionCode.N02, checkCode),
ImportNotificationStatusEnum.PartiallyRejected => new DecisionFinderResult(DecisionCode.H01, checkCode),
_ => new DecisionFinderResult(DecisionCode.E99, checkCode)
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"serviceHeader":{"sourceSystem":"CDS","destinationSystem":"ALVS","correlationId":"1306651","serviceCallTimestamp":1733068760000},"header":{"entryReference":"24GBD447SAPD7NTAR9","entryVersionNumber":2,"previousVersionNumber":1,"declarationUCR":"4GB460344665000-SIJ2411010147","declarationPartNumber":null,"declarationType":"S","arrivalDateTime":null,"submitterTURN":"GB460344665000","declarantId":"GB460344665000","declarantName":"GB460344665000","dispatchCountryCode":"PE","goodsLocationCode":"LGPLGPLGP","masterUCR":"LGP1C7LL600100"},"items":[{"itemNumber":1,"customsProcedureCode":"4000000","taricCommodityCode":"0806101090","goodsDescription":"FRESH GRAPES","consigneeId":"GB263389184000","consigneeName":"GB263389184000","itemNetMass":17712,"itemSupplementaryUnits":0,"itemThirdQuantity":null,"itemOriginCountryCode":"PE","documents":[{"documentCode":"N002","documentReference":"GBCHD2024.5167633","documentStatus":"AG","documentControl":"P","documentQuantity":null},{"documentCode":"N851","documentReference":"GBCHD2024.5167633","documentStatus":"AG","documentControl":"P","documentQuantity":null}],"checks":[{"checkCode":"H218","departmentCode":"HMI"},{"checkCode":"H219","departmentCode":"PHSI"}]}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"serviceHeader": {
"sourceSystem": "CDS",
"destinationSystem": "ALVS",
"correlationId": "1319088",
"serviceCallTimestamp": 1733395701000
},
"header": {
"entryReference": "24GBD69TMXZ2TYCAR9",
"entryVersionNumber": 3,
"previousVersionNumber": 2,
"declarationUCR": "4GB361840501000-0160-25",
"declarationPartNumber": null,
"declarationType": "S",
"arrivalDateTime": null,
"submitterTURN": "GB378038429000",
"declarantId": "GB378038429000",
"declarantName": "GB378038429000",
"dispatchCountryCode": "MA",
"goodsLocationCode": "DEUDEUDEU",
"masterUCR": null
},
"items": [
{
"itemNumber": 1,
"customsProcedureCode": "4000000",
"taricCommodityCode": "0810100000",
"goodsDescription": "STRAWBERRIES",
"consigneeId": "GB651900746000",
"consigneeName": "GB651900746000",
"itemNetMass": 771.8,
"itemSupplementaryUnits": 0,
"itemThirdQuantity": null,
"itemOriginCountryCode": "MA",
"documents": [
{
"documentCode": "N002",
"documentReference": "GBCHD2024.5202739",
"documentStatus": "AE",
"documentControl": "P",
"documentQuantity": null
},
{
"documentCode": "N851",
"documentReference": "GBCHD2024.5202739",
"documentStatus": "AE",
"documentControl": "P",
"documentQuantity": null
}
],
"checks": [
{
"checkCode": "H218",
"departmentCode": "HMI"
},
{
"checkCode": "H219",
"departmentCode": "PHSI"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"serviceHeader":{"sourceSystem":"CDS","destinationSystem":"ALVS","correlationId":"1319121","serviceCallTimestamp":1733396353000},"header":{"entryReference":"24GBD69TMXZ2TYCAR7","entryVersionNumber":4,"previousVersionNumber":3,"declarationUCR":"4GB361840501000-0160-25","declarationPartNumber":null,"declarationType":"S","arrivalDateTime":null,"submitterTURN":"GB378038429000","declarantId":"GB378038429000","declarantName":"GB378038429000","dispatchCountryCode":"MA","goodsLocationCode":"DEUDEUDEU","masterUCR":null},"items":[{"itemNumber":1,"customsProcedureCode":"4000000","taricCommodityCode":"0810100000","goodsDescription":"STRAWBERRIES","consigneeId":"GB651900746000","consigneeName":"GB651900746000","itemNetMass":771.8,"itemSupplementaryUnits":0,"itemThirdQuantity":null,"itemOriginCountryCode":"MA","documents":[{"documentCode":"N002","documentReference":"GBCHD2024.5202737","documentStatus":"AE","documentControl":"P","documentQuantity":null},{"documentCode":"N851","documentReference":"GBCHD2024.5202737","documentStatus":"AE","documentControl":"P","documentQuantity":null}],"checks":[{"checkCode":"H218","departmentCode":"HMI"},{"checkCode":"H219","departmentCode":"PHSI"}]}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"serviceHeader":{"sourceSystem":"CDS","destinationSystem":"ALVS","correlationId":"1319088","serviceCallTimestamp":1733395701000},"header":{"entryReference":"24GBD69TMXZ2TYCAR7","entryVersionNumber":3,"previousVersionNumber":2,"declarationUCR":"4GB361840501000-0160-25","declarationPartNumber":null,"declarationType":"S","arrivalDateTime":null,"submitterTURN":"GB378038429000","declarantId":"GB378038429000","declarantName":"GB378038429000","dispatchCountryCode":"MA","goodsLocationCode":"DEUDEUDEU","masterUCR":null},"items":[{"itemNumber":1,"customsProcedureCode":"4000000","taricCommodityCode":"0810100000","goodsDescription":"STRAWBERRIES","consigneeId":"GB651900746000","consigneeName":"GB651900746000","itemNetMass":771.8,"itemSupplementaryUnits":0,"itemThirdQuantity":null,"itemOriginCountryCode":"MA","documents":[{"documentCode":"N002","documentReference":"GBCHD2024.5202737","documentStatus":"AE","documentControl":"P","documentQuantity":null},{"documentCode":"N851","documentReference":"GBCHD2024.5202737","documentStatus":"AE","documentControl":"P","documentQuantity":null}],"checks":[{"checkCode":"H218","departmentCode":"HMI"},{"checkCode":"H219","departmentCode":"PHSI"}]}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"serviceHeader": {
"sourceSystem": "CDS",
"destinationSystem": "ALVS",
"correlationId": "1319121",
"serviceCallTimestamp": 1733396353000
},
"header": {
"entryReference": "24GBD69TMXZ2TYCAR8",
"entryVersionNumber": 4,
"previousVersionNumber": 3,
"declarationUCR": "4GB361840501000-0160-25",
"declarationPartNumber": null,
"declarationType": "S",
"arrivalDateTime": null,
"submitterTURN": "GB378038429000",
"declarantId": "GB378038429000",
"declarantName": "GB378038429000",
"dispatchCountryCode": "MA",
"goodsLocationCode": "DEUDEUDEU",
"masterUCR": null
},
"items": [
{
"itemNumber": 1,
"customsProcedureCode": "4000000",
"taricCommodityCode": "0810100000",
"goodsDescription": "STRAWBERRIES",
"consigneeId": "GB651900746000",
"consigneeName": "GB651900746000",
"itemNetMass": 771.8,
"itemSupplementaryUnits": 0,
"itemThirdQuantity": null,
"itemOriginCountryCode": "MA",
"documents": [
{
"documentCode": "N002",
"documentReference": "GBCHD2024.5202738",
"documentStatus": "AE",
"documentControl": "P",
"documentQuantity": null
},
{
"documentCode": "N851",
"documentReference": "GBCHD2024.5202738",
"documentStatus": "AE",
"documentControl": "P",
"documentQuantity": null
}
],
"checks": [
{
"checkCode": "H218",
"departmentCode": "HMI"
},
{
"checkCode": "H219",
"departmentCode": "PHSI"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"serviceHeader": {
"sourceSystem": "CDS",
"destinationSystem": "ALVS",
"correlationId": "1319088",
"serviceCallTimestamp": 1733395701000
},
"header": {
"entryReference": "24GBD69TMXZ2TYCAR8",
"entryVersionNumber": 3,
"previousVersionNumber": 2,
"declarationUCR": "4GB361840501000-0160-25",
"declarationPartNumber": null,
"declarationType": "S",
"arrivalDateTime": null,
"submitterTURN": "GB378038429000",
"declarantId": "GB378038429000",
"declarantName": "GB378038429000",
"dispatchCountryCode": "MA",
"goodsLocationCode": "DEUDEUDEU",
"masterUCR": null
},
"items": [
{
"itemNumber": 1,
"customsProcedureCode": "4000000",
"taricCommodityCode": "0810100000",
"goodsDescription": "STRAWBERRIES",
"consigneeId": "GB651900746000",
"consigneeName": "GB651900746000",
"itemNetMass": 771.8,
"itemSupplementaryUnits": 0,
"itemThirdQuantity": null,
"itemOriginCountryCode": "MA",
"documents": [
{
"documentCode": "N002",
"documentReference": "GBCHD2024.5202738",
"documentStatus": "AE",
"documentControl": "P",
"documentQuantity": null
},
{
"documentCode": "N851",
"documentReference": "GBCHD2024.5202738",
"documentStatus": "AE",
"documentControl": "P",
"documentQuantity": null
}
],
"checks": [
{
"checkCode": "H218",
"departmentCode": "HMI"
},
{
"checkCode": "H219",
"departmentCode": "PHSI"
}
]
}
]
}
Loading

0 comments on commit c8cc55e

Please sign in to comment.