Skip to content

Commit

Permalink
CDMS-223 adds additional scenarios and tests for incorrect decisions
Browse files Browse the repository at this point in the history
  • Loading branch information
craigedmunds committed Jan 10, 2025
1 parent 1095b36 commit c8a6064
Show file tree
Hide file tree
Showing 42 changed files with 490 additions and 27 deletions.
8 changes: 3 additions & 5 deletions Btms.Analytics.Tests/MovementsByDecisionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
namespace Btms.Analytics.Tests;

public class MovementsByDecisionsTests(ITestOutputHelper output)
: ScenarioDatasetBaseTest(output, Datasets.FunctionalAnalyticsDatasetName)
: ScenarioDatasetBaseTest(output, Datasets.FunctionalAnalyticsDecisionsDatasetName)
{

[Fact(Skip = "Needs revisiting - needs more assertions, perhaps switch to individual scenario test")]
[Fact]
// [Fact(Skip = "Needs revisiting - needs more assertions, perhaps switch to individual scenario test")]
public async Task WhenCalled_ReturnExpectedAggregation()
{
TestOutputHelper.WriteLine("Querying for aggregated data");
Expand All @@ -25,7 +25,5 @@ public async Task WhenCalled_ReturnExpectedAggregation()
TestOutputHelper.WriteLine("{0} aggregated items found", result.Count);

result.Count.Should().BeGreaterThan(1);
// result.Select(r => r.Key).Order().Should()
// .Equal("ALVS Linked : H01", "BTMS Linked : C03", "BTMS Linked : X00", "BTMS Not Linked : X00");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
namespace Btms.Analytics.Tests;

public class MovementsByUniqueDocumentReferenceTests(ITestOutputHelper output)
: ScenarioDatasetBaseTest(output, Datasets.FunctionalAnalyticsDatasetName)
: ScenarioGeneratorBaseTest<>(output)

Check failure on line 14 in Btms.Analytics.Tests/MovementsByUniqueDocumentReferenceTests.cs

View workflow job for this annotation

GitHub Actions / Run Pull Request Checks

Unexpected use of an unbound generic name

Check failure on line 14 in Btms.Analytics.Tests/MovementsByUniqueDocumentReferenceTests.cs

View workflow job for this annotation

GitHub Actions / Run Pull Request Checks

Unexpected use of an unbound generic name
{

[Fact(Skip = "Needs revisiting - needs more assertions, perhaps switch to individual scenario test")]
[Fact]
// [Fact(Skip = "Needs revisiting - needs more assertions, perhaps switch to individual scenario test")]
public async Task WhenCalledLastWeek_ReturnExpectedAggregation()
{
TestOutputHelper.WriteLine("Querying for aggregated data");
Expand Down
24 changes: 18 additions & 6 deletions Btms.Analytics/MovementsAggregationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,26 @@ public Task<SummarisedDataset<SingleSeriesDataset, StringBucketDimensionResult>>
var mongoQuery = context
.Movements
.WhereFilteredByCreatedDateAndParams(from, to, chedTypes, country)
.SelectMany(m => m.AlvsDecisionStatus.Decisions.Select(
d => new {Decision = d, Movement = m } ))
.SelectMany(d => d.Decision.Context.DecisionComparison!.Checks.Select(c => new { d.Decision, d.Movement, Check = c}))
// .SelectMany(d => d.Decision.Context.Checks.Select(c => new { d.Decision, d.Movement, Check = c}))
.SelectMany(d => d
.AlvsDecisionStatus.Context.DecisionComparison!.Checks
.Select(c => new
{
Movement = d, Check = c,
DecisionStatus = d.AlvsDecisionStatus.Context.DecisionComparison!.DecisionStatus ==
DecisionStatusEnum.BtmsMadeSameDecisionAsAlvs ?
DecisionStatusEnum.BtmsMadeSameDecisionAsAlvs :
d.BtmsStatus.ChedTypes.Length > 1 ? DecisionStatusEnum.HasMultipleChedTypes :
d.Relationships.Notifications.Data.Count > 1 ? DecisionStatusEnum.HasMultipleCheds :
d.AlvsDecisionStatus.Context.DecisionComparison!.DecisionStatus
}))
.GroupBy(d => new
{
d.Decision.Context.DecisionComparison!.DecisionStatus,
//Trying to quickly analyse further before building it into the write time analysis
// d.Movement.AlvsDecisionStatus.Context.DecisionComparison!.DecisionStatus
// == DecisionStatusEnum.BtmsMadeSameDecisionAsAlvs
// ? DecisionStatusEnum.BtmsMadeSameDecisionAsAlvs :
// DecisionStatusEnum.BtmsMadeSameDecisionAsAlvs
d.DecisionStatus,
d.Check.CheckCode,
d.Check.AlvsDecisionCode,
d.Check.BtmsDecisionCode
Expand All @@ -305,7 +318,6 @@ public Task<SummarisedDataset<SingleSeriesDataset, StringBucketDimensionResult>>

var enumLookup = new JsonStringEnumConverterEx<DecisionStatusEnum>();
var summaryValues = mongoQuery
// .GroupBy(q => enumLookup.GetValue(q.Key.DecisionStatus))
.GroupBy(q => q.Key.DecisionStatus)
.Select(g => new {g.Key, Sum = g.Sum(k => k.Count)})
.OrderBy(s => s.Key)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
using System.Net;
using Btms.Backend.IntegrationTests.Helpers;
using Btms.Common.Extensions;
using Btms.Model;
using Btms.Model.Cds;
using Btms.Types.Ipaffs;
using FluentAssertions;
using TestDataGenerator.Scenarios.ChedP;
using TestDataGenerator.Scenarios.SpecificFiles;
using TestGenerator.IntegrationTesting.Backend;
using TestGenerator.IntegrationTesting.Backend.Extensions;
using TestGenerator.IntegrationTesting.Backend.Fixtures;
using Xunit;
using Xunit.Abstractions;
using ImportNotificationTypeEnum = Btms.Model.Ipaffs.ImportNotificationTypeEnum;

namespace Btms.Backend.IntegrationTests.DecisionTests;

[Trait("Category", "Integration")]
public class Mrn24GBDDJER3ZFRMZAR9Tests(ITestOutputHelper output)
: ScenarioGeneratorBaseTest<Mrn24GBDDJER3ZFRMZAR9ScenarioGenerator>(output)
{

// [Fact]
[Fact(Skip="Wrong decision being made")]
public void ShouldHaveCorrectAlvsDecisionMatchedStatusOnDecison()
{
Client
.GetSingleMovement()
.AlvsDecisionStatus.Decisions
.First(d => d.Context.AlvsDecisionNumber == 2)
.Context.DecisionComparison!.DecisionMatched
.Should().BeTrue();
}

// [Fact]
[Fact(Skip="Wrong decision being made")]
public void ShouldHaveCorrectAlvsDecisionStatusAtGlobalLevel()
{
Client
.GetSingleMovement()
.AlvsDecisionStatus
.Context.DecisionComparison!.DecisionStatus
.Should().Be(DecisionStatusEnum.BtmsMadeSameDecisionAsAlvs);
}

// [Fact]
[Fact(Skip="Wrong decision being made")]
public void ShouldHaveCorrectAlvsDecisionMatchedStatusAtGlobalLevel()
{
Client
.GetSingleMovement()
.AlvsDecisionStatus
.Context.DecisionComparison!.DecisionMatched
.Should().BeTrue();
}

[Fact(Skip = "This should be making multiple decisions at the momennt given the complexity. Currently only making one")]
public void ShouldHaveTbcBtmsDecisions()
{
//
Client
.GetSingleMovement()
.Decisions.Count
.Should().Be(1);
}

[Fact]
public void ShouldHaveCorrectDecisionAuditEntries()
{
var notification = (ImportNotification)LoadedData
.First(d =>
d is { Message: ImportNotification }
)
.Message;

// Assert
var movement = Client
.GetSingleMovement();

var decisionWithLinkAndContext = movement.AuditEntries
.Where(a => a is { CreatedBy: "Btms", Status: "Decision" })
.MaxBy(a => a.Version)!;

decisionWithLinkAndContext.Context!.ImportNotifications
.Should().NotBeNull();

decisionWithLinkAndContext.Context!.ImportNotifications!
.Select(n => (n.Id, n.Version))
.Distinct()
.Count()
.Should()
.Be(9);
}

[Fact]
public void ShouldHave1AlvsDecisions()
{
Client
.GetSingleMovement()
.AlvsDecisionStatus.Decisions.Count
.Should()
.Be(1);
}


[Fact]
public void ShouldHave3AlvsDecisionChecks()
{
Client
.GetSingleMovement()
.AlvsDecisionStatus.Context.DecisionComparison!.Checks.Count
.Should()
.Be(3);
}

[Fact]
public void ShouldHaveCorrectAuditTrail()
{
Client
.GetSingleMovement()
.AuditEntries
.Select(a => (a.CreatedBy, a.Status, a.Version))
.Should()
.Equal([
("Cds", "Created", 1),
("Btms", "Linked", null),
("Btms", "Linked", null),
("Btms", "Linked", null),
("Btms", "Linked", null),
("Btms", "Linked", null),
("Btms", "Linked", null),
("Btms", "Linked", null),
("Btms", "Linked", null),
("Btms", "Linked", null),
("Btms", "Decision", 1),
("Cds", "Updated", 2),
("Alvs", "Decision", 1)

]);
}

[Fact(Skip="Wrong decision being made")]
// [Fact]
public void ShouldHaveDecisionMatched()
{
var movement = Client
.GetSingleMovement()
.AlvsDecisionStatus.Context!.DecisionComparison!.DecisionMatched
.Should().BeTrue();
}

[Fact]
public void ShouldHaveChedPpDecisionStatus()
{
Client
.GetSingleMovement()
.AlvsDecisionStatus.Context.DecisionComparison!.DecisionStatus
.Should().Be(DecisionStatusEnum.HasChedppChecks);
}

[Fact]
public void ShouldHaveChedType()
{
Client
.GetSingleMovement()
.BtmsStatus.ChedTypes
.Should().Equal(ImportNotificationTypeEnum.Chedpp);
}

[Fact]
public void ShouldBeLinked()
{
Client
.GetSingleMovement()
.BtmsStatus.LinkStatus
.Should().Be("Linked");
}

[Fact]
public async Task ShouldNotHaveExceptions()
{
// TestOutputHelper.WriteLine("Querying for aggregated data");

var result = await Client
.GetExceptions();

TestOutputHelper.WriteLine($"{result.StatusCode} status");
result.IsSuccessStatusCode.Should().BeTrue(result.StatusCode.ToString());

(await result.GetString())
.Should()
.Be("[]");
}

[Fact(Skip="Wrong decision being made")]
public void AlvsDecisionShouldHaveCorrectChecks()
{
Client
.GetSingleMovement()
.AlvsDecisionStatus.Context.DecisionComparison!.Checks
.Should().BeEquivalentTo([
new {
ItemNumber = 1,
CheckCode = "H219",
AlvsDecisionCode = "C03",
BtmsDecisionCode = "C03"
},
new {
ItemNumber = 2,
CheckCode = "H219",
AlvsDecisionCode = "C03",
BtmsDecisionCode = "C03"
},
new {
ItemNumber = 3,
CheckCode = "H219",
AlvsDecisionCode = "C03",
BtmsDecisionCode = "C03"
}
]);
}

[Fact]
public async Task AlvsDecisionShouldReturnCorrectlyFromAnalytics()
{
var result = await (await Client
.GetAnalyticsDashboard(["decisionsByDecisionCode"]))
.ToJsonDictionary();

// TODO would be nice to deserialise this into our dataset structures from analytics...
result["decisionsByDecisionCode"]?["summary"]?["values"]?[
"Btms Made Same Decision As Alvs"]?
.GetValue<int>()
.Should().Be(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public void ShouldHaveCorrectAlvsDecisionMatchedStatusOnPreviousDecison()
.Should().BeNull();
}

[Fact]
public void ShouldHaveCorrectAlvsDecisionStatusAtGlobalLevel()
{
Client
.GetSingleMovement()
.AlvsDecisionStatus
.Context.DecisionComparison!.DecisionStatus
.Should().Be(DecisionStatusEnum.AlvsClearanceRequestVersion1NotPresent);
}

[Fact(Skip="Wrong decision being made")]
public void ShouldHaveCorrectAlvsDecisionMatchedStatusAtGlobalLevel()
{
Expand Down
12 changes: 9 additions & 3 deletions Btms.Model/Cds/AlvsDecision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ public enum DecisionStatusEnum {
[EnumMember(Value = "No Alvs Decisions")]
NoAlvsDecisions,

[EnumMember(Value = "Investigation Needed")]
InvestigationNeeded,
[EnumMember(Value = "Has Multiple Ched Types")]
HasMultipleChedTypes,

[EnumMember(Value = "Has Multiple Cheds")]
HasMultipleCheds,

[EnumMember(Value = "Alvs Clearance Request Version 1 Not Present")]
AlvsClearanceRequestVersion1NotPresent,
Expand All @@ -155,7 +158,10 @@ public enum DecisionStatusEnum {
AlvsDecisionVersion1NotPresent,

[EnumMember(Value = "Alvs Decision Versions Not Complete")]
AlvsDecisionVersionsNotComplete
AlvsDecisionVersionsNotComplete,

[EnumMember(Value = "Investigation Needed")]
InvestigationNeeded,
}

public partial class SummarisedDecisionContext //
Expand Down
Loading

0 comments on commit c8a6064

Please sign in to comment.