diff --git a/src/externalsystems/Bpdm.Library/BusinessLogic/BpdmBusinessLogic.cs b/src/externalsystems/Bpdm.Library/BusinessLogic/BpdmBusinessLogic.cs index a197ddf291..e0ce7487c1 100644 --- a/src/externalsystems/Bpdm.Library/BusinessLogic/BpdmBusinessLogic.cs +++ b/src/externalsystems/Bpdm.Library/BusinessLogic/BpdmBusinessLogic.cs @@ -108,6 +108,11 @@ public BpdmBusinessLogic(IPortalRepositories portalRepositories, IBpdmService bp } var sharingState = await _bpdmService.GetSharingState(context.ApplicationId, cancellationToken).ConfigureAwait(false); + if (sharingState.SharingProcessStarted == null) + { + return new IApplicationChecklistService.WorkerChecklistProcessStepExecutionResult(ProcessStepStatusId.TODO, null, null, null, false, "SharingProcessStarted was not set"); + } + return sharingState.SharingStateType switch { BpdmSharingStateType.Success => diff --git a/src/externalsystems/Bpdm.Library/Models/BpdmSharingState.cs b/src/externalsystems/Bpdm.Library/Models/BpdmSharingState.cs index dc6086a8a8..0f2ecba27e 100644 --- a/src/externalsystems/Bpdm.Library/Models/BpdmSharingState.cs +++ b/src/externalsystems/Bpdm.Library/Models/BpdmSharingState.cs @@ -24,13 +24,13 @@ public record BpdmPaginationSharingStateOutput( ); public record BpdmSharingState( - BpdmSharingStateBusinessPartnerType BusinessPartnerType, + BpdmSharingStateBusinessPartnerType? BusinessPartnerType, Guid ExternalId, - BpdmSharingStateType SharingStateType, + BpdmSharingStateType? SharingStateType, string? SharingErrorCode, string? SharingErrorMessage, string? Bpn, - DateTimeOffset SharingProcessStarted + DateTimeOffset? SharingProcessStarted ); public enum BpdmSharingStateType diff --git a/tests/externalsystems/Bpdm.Library/BpdmBusinessLogicTests.cs b/tests/externalsystems/Bpdm.Library/BpdmBusinessLogicTests.cs index 5b81c02415..701f66a150 100644 --- a/tests/externalsystems/Bpdm.Library/BpdmBusinessLogicTests.cs +++ b/tests/externalsystems/Bpdm.Library/BpdmBusinessLogicTests.cs @@ -38,6 +38,7 @@ public class BpdmBusinessLogicTests private static readonly Guid IdWithBpn = new("c244f79a-7faf-4c59-bb85-fbfdf72ce46f"); private static readonly Guid IdWithSharingPending = new("920AF606-9581-4EAD-A7FD-78480F42D3A1"); private static readonly Guid IdWithSharingError = new("9460ED6B-2DD3-4446-9B9D-9AE3640717F4"); + private static readonly Guid IdWithoutSharingProcessStarted = new("f167835a-9859-4ae4-8f1d-b5d682e2562c"); private static readonly Guid IdWithStateCreated = new("bda6d1b5-042e-493a-894c-11f3a89c12b1"); private static readonly Guid IdWithoutZipCode = new("beaa6de5-d411-4da8-850e-06047d3170be"); private static readonly Guid ValidCompanyId = new("abf990f8-0c27-43dc-bbd0-b1bce964d8f4"); @@ -335,6 +336,38 @@ public async Task HandlePullLegalEntity_WithSharingStateError_ThrowsServiceExcep ex.Message.Should().Be($"ErrorCode: Code 43, ErrorMessage: This is a test sharing state error"); } + [Fact] + public async Task HandlePullLegalEntity_WithSharingProcessStartedNotSet_ReturnsExpected() + { + // Arrange + var company = new Company(Guid.NewGuid(), "Test Company", CompanyStatusId.ACTIVE, DateTimeOffset.UtcNow) + { + BusinessPartnerNumber = "1" + }; + var checklistEntry = _fixture.Build() + .With(x => x.ApplicationChecklistEntryStatusId, ApplicationChecklistEntryStatusId.TO_DO) + .Create(); + var checklist = new Dictionary + { + {ApplicationChecklistEntryTypeId.REGISTRATION_VERIFICATION, ApplicationChecklistEntryStatusId.DONE}, + {ApplicationChecklistEntryTypeId.BUSINESS_PARTNER_NUMBER, ApplicationChecklistEntryStatusId.TO_DO}, + } + .ToImmutableDictionary(); + var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithoutSharingProcessStarted, default, checklist, Enumerable.Empty()); + SetupForHandlePullLegalEntity(company); + + // Act + var result = await _logic.HandlePullLegalEntity(context, CancellationToken.None).ConfigureAwait(false); + + // Assert + result.ModifyChecklistEntry?.Invoke(checklistEntry); + checklistEntry.ApplicationChecklistEntryStatusId.Should().Be(ApplicationChecklistEntryStatusId.TO_DO); + result.ScheduleStepTypeIds.Should().BeNull(); + result.SkipStepTypeIds.Should().BeNull(); + result.Modified.Should().BeFalse(); + result.ProcessMessage.Should().Be("SharingProcessStarted was not set"); + } + [Fact] public async Task HandlePullLegalEntity_WithSharingTypePending_ReturnsExpected() { @@ -469,13 +502,13 @@ private void SetupForHandlePullLegalEntity(Company? company = null) .With(x => x.BusinessPartnerNumber, (string?)null) .Create(); - A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A.That.Matches(x => x == IdWithBpn || x == IdWithSharingError || x == IdWithSharingPending))) + A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A.That.Matches(x => x == IdWithBpn || x == IdWithSharingError || x == IdWithSharingPending || x == IdWithoutSharingProcessStarted))) .Returns((ValidCompanyId, validData)); A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A.That.Matches(x => x == IdWithStateCreated))) .Returns((ValidCompanyId, new BpdmData(ValidCompanyName, null!, null!, "DE", null!, "Test", "test", null!, null!, new List<(BpdmIdentifierId UniqueIdentifierId, string Value)>()))); A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A.That.Matches(x => x == IdWithoutZipCode))) .Returns((ValidCompanyId, new BpdmData(ValidCompanyName, null!, null!, null!, null!, "Test", "test", null!, null!, new List<(BpdmIdentifierId UniqueIdentifierId, string Value)>()))); - A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A.That.Not.Matches(x => x == IdWithStateCreated || x == IdWithBpn || x == IdWithoutZipCode || x == IdWithSharingError || x == IdWithSharingPending))) + A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A.That.Not.Matches(x => x == IdWithStateCreated || x == IdWithBpn || x == IdWithoutZipCode || x == IdWithSharingError || x == IdWithSharingPending || x == IdWithoutSharingProcessStarted))) .Returns(new ValueTuple()); A.CallTo(() => _bpdmService.FetchInputLegalEntity(A.That.Matches(x => x == IdWithStateCreated.ToString()), A._)) @@ -484,15 +517,26 @@ private void SetupForHandlePullLegalEntity(Company? company = null) .Returns(_fixture.Build().With(x => x.Bpn, (string?)null).Create()); A.CallTo(() => _bpdmService.FetchInputLegalEntity(A.That.Matches(x => x == IdWithBpn.ToString()), A._)) .Returns(_fixture.Build().With(x => x.Bpn, "CAXSDUMMYCATENAZZ").Create()); - A.CallTo(() => _bpdmService.GetSharingState(A.That.Matches(x => x == IdWithBpn || x == IdWithStateCreated || x == IdWithoutZipCode), A._)) - .Returns(_fixture.Build().With(x => x.SharingStateType, BpdmSharingStateType.Success).Create()); + A.CallTo(() => _bpdmService.GetSharingState(A.That.Matches(x => x == IdWithBpn || x == IdWithStateCreated || x == IdWithoutZipCode || x == IdWithoutSharingProcessStarted), A._)) + .Returns(_fixture.Build() + .With(x => x.SharingStateType, BpdmSharingStateType.Success) + .With(x => x.SharingProcessStarted, DateTimeOffset.UtcNow) + .Create()); A.CallTo(() => _bpdmService.GetSharingState(IdWithSharingPending, A._)) - .Returns(_fixture.Build().With(x => x.SharingStateType, BpdmSharingStateType.Pending).Create()); + .Returns(_fixture.Build() + .With(x => x.SharingStateType, BpdmSharingStateType.Pending) + .With(x => x.SharingProcessStarted, DateTimeOffset.UtcNow) + .Create()); A.CallTo(() => _bpdmService.GetSharingState(IdWithSharingError, A._)) .Returns(_fixture.Build() .With(x => x.SharingStateType, BpdmSharingStateType.Error) .With(x => x.SharingErrorMessage, "This is a test sharing state error") .With(x => x.SharingErrorCode, "Code 43") + .With(x => x.SharingProcessStarted, DateTimeOffset.UtcNow) + .Create()); + A.CallTo(() => _bpdmService.GetSharingState(IdWithoutSharingProcessStarted, A._)) + .Returns(_fixture.Build() + .With(x => x.SharingProcessStarted, (DateTimeOffset?)null) .Create()); if (company != null)