Skip to content

Commit

Permalink
fix(bpdm): handle nullable SharingProcessStarted (#289)
Browse files Browse the repository at this point in the history
Refs: CPLP-3226
Reviewed-by: Norbert Truchsess <[email protected]>
  • Loading branch information
Phil91 authored Oct 10, 2023
1 parent cac5fd6 commit 0ad522e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
6 changes: 3 additions & 3 deletions src/externalsystems/Bpdm.Library/Models/BpdmSharingState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 49 additions & 5 deletions tests/externalsystems/Bpdm.Library/BpdmBusinessLogicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<ApplicationChecklistEntry>()
.With(x => x.ApplicationChecklistEntryStatusId, ApplicationChecklistEntryStatusId.TO_DO)
.Create();
var checklist = new Dictionary<ApplicationChecklistEntryTypeId, ApplicationChecklistEntryStatusId>
{
{ApplicationChecklistEntryTypeId.REGISTRATION_VERIFICATION, ApplicationChecklistEntryStatusId.DONE},
{ApplicationChecklistEntryTypeId.BUSINESS_PARTNER_NUMBER, ApplicationChecklistEntryStatusId.TO_DO},
}
.ToImmutableDictionary();
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithoutSharingProcessStarted, default, checklist, Enumerable.Empty<ProcessStepTypeId>());
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()
{
Expand Down Expand Up @@ -469,13 +502,13 @@ private void SetupForHandlePullLegalEntity(Company? company = null)
.With(x => x.BusinessPartnerNumber, (string?)null)
.Create();

A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A<Guid>.That.Matches(x => x == IdWithBpn || x == IdWithSharingError || x == IdWithSharingPending)))
A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A<Guid>.That.Matches(x => x == IdWithBpn || x == IdWithSharingError || x == IdWithSharingPending || x == IdWithoutSharingProcessStarted)))
.Returns((ValidCompanyId, validData));
A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A<Guid>.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<Guid>.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<Guid>.That.Not.Matches(x => x == IdWithStateCreated || x == IdWithBpn || x == IdWithoutZipCode || x == IdWithSharingError || x == IdWithSharingPending)))
A.CallTo(() => _applicationRepository.GetBpdmDataForApplicationAsync(A<Guid>.That.Not.Matches(x => x == IdWithStateCreated || x == IdWithBpn || x == IdWithoutZipCode || x == IdWithSharingError || x == IdWithSharingPending || x == IdWithoutSharingProcessStarted)))
.Returns(new ValueTuple<Guid, BpdmData>());

A.CallTo(() => _bpdmService.FetchInputLegalEntity(A<string>.That.Matches(x => x == IdWithStateCreated.ToString()), A<CancellationToken>._))
Expand All @@ -484,15 +517,26 @@ private void SetupForHandlePullLegalEntity(Company? company = null)
.Returns(_fixture.Build<BpdmLegalEntityOutputData>().With(x => x.Bpn, (string?)null).Create());
A.CallTo(() => _bpdmService.FetchInputLegalEntity(A<string>.That.Matches(x => x == IdWithBpn.ToString()), A<CancellationToken>._))
.Returns(_fixture.Build<BpdmLegalEntityOutputData>().With(x => x.Bpn, "CAXSDUMMYCATENAZZ").Create());
A.CallTo(() => _bpdmService.GetSharingState(A<Guid>.That.Matches(x => x == IdWithBpn || x == IdWithStateCreated || x == IdWithoutZipCode), A<CancellationToken>._))
.Returns(_fixture.Build<BpdmSharingState>().With(x => x.SharingStateType, BpdmSharingStateType.Success).Create());
A.CallTo(() => _bpdmService.GetSharingState(A<Guid>.That.Matches(x => x == IdWithBpn || x == IdWithStateCreated || x == IdWithoutZipCode || x == IdWithoutSharingProcessStarted), A<CancellationToken>._))
.Returns(_fixture.Build<BpdmSharingState>()
.With(x => x.SharingStateType, BpdmSharingStateType.Success)
.With(x => x.SharingProcessStarted, DateTimeOffset.UtcNow)
.Create());
A.CallTo(() => _bpdmService.GetSharingState(IdWithSharingPending, A<CancellationToken>._))
.Returns(_fixture.Build<BpdmSharingState>().With(x => x.SharingStateType, BpdmSharingStateType.Pending).Create());
.Returns(_fixture.Build<BpdmSharingState>()
.With(x => x.SharingStateType, BpdmSharingStateType.Pending)
.With(x => x.SharingProcessStarted, DateTimeOffset.UtcNow)
.Create());
A.CallTo(() => _bpdmService.GetSharingState(IdWithSharingError, A<CancellationToken>._))
.Returns(_fixture.Build<BpdmSharingState>()
.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<CancellationToken>._))
.Returns(_fixture.Build<BpdmSharingState>()
.With(x => x.SharingProcessStarted, (DateTimeOffset?)null)
.Create());

if (company != null)
Expand Down

0 comments on commit 0ad522e

Please sign in to comment.