diff --git a/src/EPR.ProducerContentValidation.Application.UnitTests/Services/ValidationServiceTests.cs b/src/EPR.ProducerContentValidation.Application.UnitTests/Services/ValidationServiceTests.cs index 635d368..cd828bd 100644 --- a/src/EPR.ProducerContentValidation.Application.UnitTests/Services/ValidationServiceTests.cs +++ b/src/EPR.ProducerContentValidation.Application.UnitTests/Services/ValidationServiceTests.cs @@ -503,7 +503,7 @@ public async Task ValidateAsync_EnabledSubsidiaryValidation_NoErrorsFromSubsidia } [TestMethod] - public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiaryValidation_AggregatesErrors() + public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiaryValidation_AggregatesErrorsDistinctEntryPerErrorCode() { // Arrange var producerRows = new List @@ -515,11 +515,11 @@ public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiary var expectedErrors = new List { - new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", string.Empty, new List { "Error1" }) + new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", new List { "Error1" }) }; var validationErrors = new List { - new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", ErrorCodes: new List { "Error1" }) + new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", ErrorCodes: new List { "Error1" }) }; _validationServiceProducerRowValidatorMock.Setup(x => x.ProcessRowsForValidationErrors(It.IsAny>(), It.IsAny())).Returns(validationErrors); @@ -532,7 +532,55 @@ public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiary .Callback, List, List, string>((rows, errors, warnings, blob) => { // No warnings - errors.Add(new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", string.Empty, new List { "Error1" })); + errors.Add(new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", new List { "Error2" })); + }); + + _featureManagerMock.Setup(x => x.IsEnabledAsync(FeatureFlags.EnableSubsidiaryValidationPom)).ReturnsAsync(true); + + var service = CreateSystemUnderTest(); + + // Act + var result = await service.ValidateAsync(producer); + + // Assert + result.ValidationWarnings.Should().BeEmpty(); + result.ValidationErrors.Count.Should().Be(1); + result.ValidationErrors[0].ErrorCodes.Count.Should().Be(2); + result.ValidationErrors[0].ErrorCodes[0].Should().Be("Error2"); + result.ValidationErrors[0].ErrorCodes[1].Should().Be("Error1"); + } + + [TestMethod] + public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiaryValidation_AggregatesErrorsSingleEntryForSameErrorCode() + { + // Arrange + var producerRows = new List + { + ModelGenerator.CreateProducerRow(1) + }; + + var producer = new Producer(_submissionId, ProducerId, BlobName, producerRows); + + var expectedErrors = new List + { + new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", new List { "Error1" }) + }; + var validationErrors = new List + { + new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", ErrorCodes: new List { "Error1" }) + }; + + _validationServiceProducerRowValidatorMock.Setup(x => x.ProcessRowsForValidationErrors(It.IsAny>(), It.IsAny())).Returns(validationErrors); + + // Mocking + _issueCountServiceMock.Setup(x => x.GetRemainingIssueCapacityAsync(It.IsAny())).ReturnsAsync(5); + _issueCountServiceMock.Setup(x => x.GetRemainingIssueCapacityAsync(It.IsAny())).ReturnsAsync(5); + + _compositeValidatorMock.Setup(x => x.ValidateAndFetchForIssuesAsync(It.IsAny>(), It.IsAny>(), It.IsAny>(), BlobName)) + .Callback, List, List, string>((rows, errors, warnings, blob) => + { + // No warnings + errors.Add(new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", new List { "Error1" })); }); _featureManagerMock.Setup(x => x.IsEnabledAsync(FeatureFlags.EnableSubsidiaryValidationPom)).ReturnsAsync(true); @@ -544,7 +592,9 @@ public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiary // Assert result.ValidationWarnings.Should().BeEmpty(); - result.ValidationErrors.Count.Should().Be(2); + result.ValidationErrors.Count.Should().Be(1); + result.ValidationErrors[0].ErrorCodes.Count.Should().Be(1); + result.ValidationErrors[0].ErrorCodes[0].Should().Be("Error1"); } [TestMethod]