diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor.Tests/Functions/CompleteNextDataSetVersionImportFunctionTests.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor.Tests/Functions/CompleteNextDataSetVersionImportFunctionTests.cs index 2e3101f0b5e..b8c131e3498 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor.Tests/Functions/CompleteNextDataSetVersionImportFunctionTests.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor.Tests/Functions/CompleteNextDataSetVersionImportFunctionTests.cs @@ -1,5 +1,6 @@ using GovUk.Education.ExploreEducationStatistics.Common.Extensions; using GovUk.Education.ExploreEducationStatistics.Common.Tests.Extensions; +using GovUk.Education.ExploreEducationStatistics.Common.Utils; using GovUk.Education.ExploreEducationStatistics.Content.Model; using GovUk.Education.ExploreEducationStatistics.Content.Model.Database; using GovUk.Education.ExploreEducationStatistics.Content.Model.Tests.Fixtures; @@ -30,6 +31,17 @@ public class CompleteNextDataSetVersionImportTests( ProcessorFunctionsIntegrationTestFixture fixture) : CompleteNextDataSetVersionImportFunctionTests(fixture) { + public static TheoryData NonMappingDataSetVersionStatuses = + new(EnumUtil + .GetEnums() + .Except([DataSetVersionStatus.Mapping])); + + public static TheoryData NonManualMappingStages = + new(EnumUtil + .GetEnums() + .Except([DataSetVersionImportStage.ManualMapping])); + + [Fact] public async Task Success() { @@ -42,7 +54,7 @@ public async Task Success() durableTaskClientMock.Setup(client => client.ScheduleNewOrchestrationInstanceAsync( nameof(ProcessCompletionOfNextDataSetVersionFunction - .CompleteNextDataSetVersionImportProcessing), + .ProcessCompletionOfNextDataSetVersion), It.IsAny(), It.IsAny(), It.IsAny())) @@ -71,6 +83,9 @@ public async Task Success() var responseViewModel = result.AssertOkObjectResult(); + Assert.Equal(nextVersion.Id, responseViewModel.DataSetVersionId); + Assert.Equal(nextVersion.DataSetId, responseViewModel.DataSetId); + // Assert that the pre-existing import entry for the next data set version is re-used. var updatedDataSetVersionImport = publicDataDbContext .DataSetVersionImports @@ -119,8 +134,10 @@ public async Task DataSetVersionIsNotFound_ReturnsNotFound() expectedPath: nameof(NextDataSetVersionCompleteImportRequest.DataSetVersionId).ToLowerFirst()); } - [Fact] - public async Task DataSetVersionNotInMappingStatus_ReturnsValidationProblem() + [Theory] + [MemberData(nameof(NonMappingDataSetVersionStatuses))] + public async Task DataSetVersionNotInMappingStatus_ReturnsValidationProblem( + DataSetVersionStatus status) { var (_, _, nextVersion) = await AddDataSetAndLatestLiveAndNextVersion(); @@ -131,7 +148,7 @@ public async Task DataSetVersionNotInMappingStatus_ReturnsValidationProblem() .DataSetVersions .SingleAsync(dsv => dsv.Id == nextVersion.Id); - nextVersionWithIncorrectStatus.Status = DataSetVersionStatus.Draft; + nextVersionWithIncorrectStatus.Status = status; await publicDataDbContext.SaveChangesAsync(); @@ -221,8 +238,10 @@ public async Task DataSetVersionMappings_FilterOptionsNotComplete_ReturnsValidat expectedCode: ValidationMessages.DataSetVersionMappingsNotComplete.Code); } - [Fact] - public async Task DataSetVersionImportInManualMappingStateNotFound_ReturnsValidationProblem() + [Theory] + [MemberData(nameof(NonManualMappingStages))] + public async Task DataSetVersionImportInManualMappingStateNotFound_ReturnsValidationProblem( + DataSetVersionImportStage importStage) { var (_, _, nextVersion) = await AddDataSetAndLatestLiveAndNextVersion(); @@ -233,7 +252,7 @@ public async Task DataSetVersionImportInManualMappingStateNotFound_ReturnsValida .DataSetVersionImports .SingleAsync(import => import.DataSetVersionId == nextVersion.Id); - importWithIncorrectStatus.Stage = DataSetVersionImportStage.AutoMapping; + importWithIncorrectStatus.Stage = importStage; await publicDataDbContext.SaveChangesAsync(); diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor.Tests/Functions/ProcessCompletionOfNextDataSetVersionImportFunctionTests.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor.Tests/Functions/ProcessCompletionOfNextDataSetVersionImportFunctionTests.cs index b42d74762ee..5b6d2f69bb9 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor.Tests/Functions/ProcessCompletionOfNextDataSetVersionImportFunctionTests.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor.Tests/Functions/ProcessCompletionOfNextDataSetVersionImportFunctionTests.cs @@ -124,7 +124,7 @@ private static Mock DefaultMockOrchestrationContext( } } - public class CompleteInitialDataSetVersionProcessingTests( + public class CompleteNextDataSetVersionImportProcessingTests( ProcessorFunctionsIntegrationTestFixture fixture) : ProcessCompletionOfNextDataSetVersionImportFunctionTests(fixture) { @@ -177,8 +177,8 @@ public async Task DuckDbFileIsDeleted() private async Task CompleteProcessing(Guid instanceId) { - var function = GetRequiredService(); - await function.CompleteInitialDataSetVersionProcessing(instanceId, CancellationToken.None); + var function = GetRequiredService(); + await function.CompleteNextDataSetVersionImportProcessing(instanceId, CancellationToken.None); } } } diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor/Functions/CompleteNextDataSetVersionImportFunction.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor/Functions/CompleteNextDataSetVersionImportFunction.cs index 90a2ef34fd4..283c1eb9db1 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor/Functions/CompleteNextDataSetVersionImportFunction.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Processor/Functions/CompleteNextDataSetVersionImportFunction.cs @@ -143,7 +143,7 @@ private async Task ProcessCompletionOfNextDataSetVersionImport( CancellationToken cancellationToken) { const string orchestratorName = - nameof(ProcessCompletionOfNextDataSetVersionFunction.CompleteNextDataSetVersionImportProcessing); + nameof(ProcessCompletionOfNextDataSetVersionFunction.ProcessCompletionOfNextDataSetVersion); var input = new ProcessDataSetVersionContext { DataSetVersionId = dataSetVersionId };