From 63b59b1b14d830eebbb6042deff8412400f40eef Mon Sep 17 00:00:00 2001 From: Thomas Anderson Date: Wed, 5 Feb 2025 07:21:24 +0000 Subject: [PATCH] Updated tests which look at the relationships on the API response rather than the model, as the API moves the relationships to a different level --- .../DecisionTests/ChedPP/ChedPpHmiTests.cs | 5 ++++- .../DecisionTests/ChedPP/ChedPpPhsiTests.cs | 5 ++++- .../PreprocessingTests/IpaffsCancelledTests.cs | 7 +++++-- .../PreprocessingTests/IpaffsDeletedTests.cs | 18 +++++++++++------- .../Extensions/JsonApiClientExtensions.cs | 16 ++++++---------- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Btms.Backend.IntegrationTests/DecisionTests/ChedPP/ChedPpHmiTests.cs b/Btms.Backend.IntegrationTests/DecisionTests/ChedPP/ChedPpHmiTests.cs index 0da7e70a..dfb9e28d 100644 --- a/Btms.Backend.IntegrationTests/DecisionTests/ChedPP/ChedPpHmiTests.cs +++ b/Btms.Backend.IntegrationTests/DecisionTests/ChedPP/ChedPpHmiTests.cs @@ -1,3 +1,4 @@ +using Btms.Model; using FluentAssertions; using TestDataGenerator.Scenarios.SpecificFiles; using TestGenerator.IntegrationTesting.Backend; @@ -25,9 +26,11 @@ public void DecisionShouldHaveCorrectDecisionCodeForSingleNotification(Type gene base.TestOutputHelper.WriteLine("Generator : {0}, Decision Code : {1}", generatorType!.FullName, decisionCode); EnsureEnvironmentInitialised(generatorType); - var movement = Client + var apiResponse = Client .GetMovementByMrn(mrn); + var movement = apiResponse.GetResourceObject(); + var lastDecision = movement.Decisions.OrderByDescending(x => x.ServiceHeader?.ServiceCalled).First(); diff --git a/Btms.Backend.IntegrationTests/DecisionTests/ChedPP/ChedPpPhsiTests.cs b/Btms.Backend.IntegrationTests/DecisionTests/ChedPP/ChedPpPhsiTests.cs index 5c7ba97b..0f1d275d 100644 --- a/Btms.Backend.IntegrationTests/DecisionTests/ChedPP/ChedPpPhsiTests.cs +++ b/Btms.Backend.IntegrationTests/DecisionTests/ChedPP/ChedPpPhsiTests.cs @@ -1,3 +1,4 @@ +using Btms.Model; using Btms.Model.Auditing; using Btms.Model.Cds; using Btms.Types.Ipaffs; @@ -26,9 +27,11 @@ public void DecisionShouldHaveCorrectDecisionCodeForSingleNotification(Type gene base.TestOutputHelper.WriteLine("Generator : {0}, Decision Code : {1}", generatorType!.FullName, decisionCode); EnsureEnvironmentInitialised(generatorType); - var movement = Client + var apiResponse = Client .GetMovementByMrn(mrn); + var movement = apiResponse.GetResourceObject(); + var lastDecision = movement.Decisions.OrderByDescending(x => x.ServiceHeader?.ServiceCalled).First(); diff --git a/Btms.Backend.IntegrationTests/PreprocessingTests/IpaffsCancelledTests.cs b/Btms.Backend.IntegrationTests/PreprocessingTests/IpaffsCancelledTests.cs index b24075db..6c987c9b 100644 --- a/Btms.Backend.IntegrationTests/PreprocessingTests/IpaffsCancelledTests.cs +++ b/Btms.Backend.IntegrationTests/PreprocessingTests/IpaffsCancelledTests.cs @@ -17,11 +17,14 @@ public class IpaffsCancelledTests(ITestOutputHelper output) public void NotificationShouldBeDeleted_AndRelationshipsRemoved_AndHaveAuditEntries() { // Assert - var notification = Client + var resource = Client .GetNotificationById("CHEDD.GB.2024.5246106"); + var notification = resource.GetResourceObject(); + + resource.Data.Relationships!.First().Value!.Data.ManyValue!.Count.Should().Be(1); + notification.Status.Should().Be(ImportNotificationStatusEnum.Cancelled); - notification.Relationships.Should().BeEquivalentTo(new NotificationTdmRelationships()); notification.AuditEntries.Count(x => x.Status == "Unlinked").Should().Be(0); notification.AuditEntries.Count(x => x.Status == "Cancelled").Should().Be(1); } diff --git a/Btms.Backend.IntegrationTests/PreprocessingTests/IpaffsDeletedTests.cs b/Btms.Backend.IntegrationTests/PreprocessingTests/IpaffsDeletedTests.cs index 096b7b60..7e97847c 100644 --- a/Btms.Backend.IntegrationTests/PreprocessingTests/IpaffsDeletedTests.cs +++ b/Btms.Backend.IntegrationTests/PreprocessingTests/IpaffsDeletedTests.cs @@ -1,3 +1,4 @@ +using Btms.Model; using Btms.Model.Auditing; using Btms.Model.Ipaffs; using Btms.Model.Relationships; @@ -18,11 +19,14 @@ public class IpaffsDeletedTests(ITestOutputHelper output) public void NotificationShouldBeDeleted_AndRelationshipsRemoved_AndHaveAuditEntries() { // Assert - var notification = Client - .GetFirstImportNotification(); + var resource = Client + .GetNotificationById("CHEDD.GB.2024.5256764"); + + var notification = resource.GetResourceObject(); + + resource.Data.Relationships!.First().Value!.Data.ManyValue!.Count.Should().Be(0); notification.Status.Should().Be(ImportNotificationStatusEnum.Deleted); - notification.Relationships.Should().BeEquivalentTo(new NotificationTdmRelationships()); notification.AuditEntries.Count(x => x.Status == "Unlinked").Should().Be(1); notification.AuditEntries.Count(x => x.Status == "Deleted").Should().Be(1); } @@ -34,10 +38,10 @@ public void MovementShouldHaveRelationshipsRemoved_AndHaveAuditEntries() var movement1 = Client.GetMovementByMrn("24GBDHDJXQ5TCDBAR1"); var movement2 = Client.GetMovementByMrn("24GBDPN9J48XRW5AR0"); - movement1.Relationships.Should().BeEquivalentTo(new MovementTdmRelationships()); - movement1.AuditEntries.Count(x => x.Status == "Unlinked").Should().Be(1); + movement1.Data.Relationships!.First().Value!.Data.ManyValue!.Count.Should().Be(0); + movement1.GetResourceObject().AuditEntries.Count(x => x.Status == "Unlinked").Should().Be(1); - movement2.Relationships.Should().BeEquivalentTo(new MovementTdmRelationships()); - movement2.AuditEntries.Count(x => x.Status == "Unlinked").Should().Be(1); + movement2.Data.Relationships!.First().Value!.Data.ManyValue!.Count.Should().Be(0); + movement2.GetResourceObject().AuditEntries.Count(x => x.Status == "Unlinked").Should().Be(1); } } \ No newline at end of file diff --git a/TestGenerator.IntegrationTesting.Backend/Extensions/JsonApiClientExtensions.cs b/TestGenerator.IntegrationTesting.Backend/Extensions/JsonApiClientExtensions.cs index 70802382..b8bb6aa1 100644 --- a/TestGenerator.IntegrationTesting.Backend/Extensions/JsonApiClientExtensions.cs +++ b/TestGenerator.IntegrationTesting.Backend/Extensions/JsonApiClientExtensions.cs @@ -2,6 +2,7 @@ using Btms.Model.Ipaffs; // using Btms.Types.Ipaffs; using TestGenerator.IntegrationTesting.Backend.Fixtures; +using TestGenerator.IntegrationTesting.Backend.JsonApiClient; namespace TestGenerator.IntegrationTesting.Backend.Extensions; @@ -15,12 +16,10 @@ public static Movement GetSingleMovement(this BtmsClient client) .Single(); } - public static Movement GetMovementByMrn(this BtmsClient client, string mrn) + public static SingleItemJsonApiDocument GetMovementByMrn(this BtmsClient client, string mrn) { return client.AsJsonApiClient() - .Get("api/movements") - .GetResourceObjects() - .Single(x => x.EntryReference == mrn); + .GetById(mrn, "api/movements"); } public static ImportNotification GetFirstImportNotification(this BtmsClient client) @@ -32,13 +31,10 @@ public static ImportNotification GetFirstImportNotification(this BtmsClient clie return results.First(); } - public static ImportNotification GetNotificationById(this BtmsClient client, string id) + public static SingleItemJsonApiDocument GetNotificationById(this BtmsClient client, string id) { - var results = client.AsJsonApiClient() - .Get("api/import-notifications") - .GetResourceObjects(); - - return results.First(x => x.Id == id); + return client.AsJsonApiClient() + .GetById(id, "api/import-notifications"); } public static ImportNotification GetSingleImportNotification(this BtmsClient client)