Skip to content

Commit e0d2d77

Browse files
fix: added logic on bpdm business logic when byow active
1 parent b1da440 commit e0d2d77

File tree

2 files changed

+101
-13
lines changed

2 files changed

+101
-13
lines changed

src/externalsystems/Bpdm.Library/BusinessLogic/BpdmBusinessLogic.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,24 @@ await HandlePullLegalEntityInternal(context, result.CompanyId, result.BpdmData,
151151
});
152152

153153
var registrationValidationFailed = context.Checklist[ApplicationChecklistEntryTypeId.REGISTRATION_VERIFICATION] == ApplicationChecklistEntryStatusId.FAILED;
154+
var createWalletOrTransmitCustomerDidStep = await CreateWalletOrBpnCredentialStepAsync(context.ApplicationId);
154155

155156
return new IApplicationChecklistService.WorkerChecklistProcessStepExecutionResult(
156157
ProcessStepStatusId.DONE,
157158
entry => entry.ApplicationChecklistEntryStatusId = ApplicationChecklistEntryStatusId.DONE,
158159
registrationValidationFailed
159160
? null
160-
: new[] { CreateWalletStep() },
161+
: new[] { createWalletOrTransmitCustomerDidStep },
161162
new[] { ProcessStepTypeId.CREATE_BUSINESS_PARTNER_NUMBER_MANUAL },
162163
true,
163164
null);
164165
}
165166

166167
private ProcessStepTypeId CreateWalletStep() => _settings.UseDimWallet ? ProcessStepTypeId.CREATE_DIM_WALLET : ProcessStepTypeId.CREATE_IDENTITY_WALLET;
168+
169+
private async Task<ProcessStepTypeId> CreateWalletOrBpnCredentialStepAsync(Guid applicationId)
170+
{
171+
var isWalletCustomerProvider = await portalRepositories.GetInstance<ICompanyRepository>().IsBringYourOwnWallet(applicationId);
172+
return isWalletCustomerProvider ? ProcessStepTypeId.TRANSMIT_BPN_DID : CreateWalletStep();
173+
}
167174
}

tests/externalsystems/Bpdm.Library/BpdmBusinessLogicTests.cs

Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,10 @@ public async Task HandlePullLegalEntity_WithSharingStateError_ThrowsServiceExcep
358358
public async Task HandlePullLegalEntity_WithSharingProcessStartedNotSet_ReturnsExpected()
359359
{
360360
// Arrange
361-
var company = new Company(Guid.NewGuid(), "Test Company", CompanyStatusId.ACTIVE, DateTimeOffset.UtcNow)
362-
{
363-
BusinessPartnerNumber = "1"
364-
};
361+
var context = PreparePullLegalEntity();
365362
var checklistEntry = _fixture.Build<ApplicationChecklistEntry>()
366363
.With(x => x.ApplicationChecklistEntryStatusId, ApplicationChecklistEntryStatusId.TO_DO)
367364
.Create();
368-
var checklist = new Dictionary<ApplicationChecklistEntryTypeId, ApplicationChecklistEntryStatusId>
369-
{
370-
{ ApplicationChecklistEntryTypeId.REGISTRATION_VERIFICATION, ApplicationChecklistEntryStatusId.DONE },
371-
{ ApplicationChecklistEntryTypeId.BUSINESS_PARTNER_NUMBER, ApplicationChecklistEntryStatusId.TO_DO }
372-
}
373-
.ToImmutableDictionary();
374-
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithoutSharingProcessStarted, default, checklist, Enumerable.Empty<ProcessStepTypeId>());
375-
SetupForHandlePullLegalEntity(company);
376365

377366
// Act
378367
var result = await _logic.HandlePullLegalEntity(context, CancellationToken.None);
@@ -386,6 +375,78 @@ public async Task HandlePullLegalEntity_WithSharingProcessStartedNotSet_ReturnsE
386375
result.ProcessMessage.Should().Be("SharingProcessStarted was not set");
387376
}
388377

378+
[Fact]
379+
public async Task HandlePullLegalEntity_BringYourOwnWallet_True_ReturnsExpected()
380+
{
381+
// Arrange
382+
var context = PreparePullLegalEntity();
383+
384+
A.CallTo(() => _bpdmService.GetSharingState(A<Guid>._, A<CancellationToken>._))
385+
.Returns(Task.FromResult(new BpdmSharingState(
386+
Guid.NewGuid(),
387+
BpdmSharingStateType.Success,
388+
null,
389+
null,
390+
DateTimeOffset.UtcNow,
391+
null
392+
)));
393+
var bpdmLegalEntityOutputData = _fixture.Build<BpdmLegalEntityOutputData>()
394+
.With(x => x.LegalEntity,
395+
new BpdmLegelEntityData("CAXSDUMMYCATENAZZ",
396+
null,
397+
null,
398+
null,
399+
_fixture.Create<BpdmConfidenceCriteria>(), Enumerable.Empty<BpdmStatus>())
400+
).Create();
401+
402+
A.CallTo(() => _bpdmService.FetchInputLegalEntity(context.ApplicationId.ToString(), A<CancellationToken>._))
403+
.Returns(bpdmLegalEntityOutputData);
404+
405+
A.CallTo(() => _companyRepository.IsBringYourOwnWallet(A<Guid>._)).Returns(true);
406+
407+
// Act
408+
var result = await _logic.HandlePullLegalEntity(context, CancellationToken.None);
409+
410+
// Assert
411+
result.ScheduleStepTypeIds.Should().ContainSingle(x => x == ProcessStepTypeId.TRANSMIT_BPN_DID);
412+
}
413+
414+
[Fact]
415+
public async Task HandlePullLegalEntity_BringYourOwnWallet_False_ReturnsExpected()
416+
{
417+
// Arrange
418+
var context = PreparePullLegalEntity();
419+
420+
A.CallTo(() => _bpdmService.GetSharingState(A<Guid>._, A<CancellationToken>._))
421+
.Returns(Task.FromResult(new BpdmSharingState(
422+
Guid.NewGuid(),
423+
BpdmSharingStateType.Success,
424+
null,
425+
null,
426+
DateTimeOffset.UtcNow,
427+
null
428+
)));
429+
var bpdmLegalEntityOutputData = _fixture.Build<BpdmLegalEntityOutputData>()
430+
.With(x => x.LegalEntity,
431+
new BpdmLegelEntityData("CAXSDUMMYCATENAZZ",
432+
null,
433+
null,
434+
null,
435+
_fixture.Create<BpdmConfidenceCriteria>(), Enumerable.Empty<BpdmStatus>())
436+
).Create();
437+
438+
A.CallTo(() => _bpdmService.FetchInputLegalEntity(context.ApplicationId.ToString(), A<CancellationToken>._))
439+
.Returns(bpdmLegalEntityOutputData);
440+
441+
A.CallTo(() => _companyRepository.IsBringYourOwnWallet(A<Guid>._)).Returns(false);
442+
443+
// Act
444+
var result = await _logic.HandlePullLegalEntity(context, CancellationToken.None);
445+
446+
// Assert
447+
result.ScheduleStepTypeIds.Should().ContainSingle(x => x == ProcessStepTypeId.CREATE_IDENTITY_WALLET);
448+
}
449+
389450
[Fact]
390451
public async Task HandlePullLegalEntity_WithSharingTypePending_ReturnsExpected()
391452
{
@@ -576,4 +637,24 @@ private void SetupForHandlePullLegalEntity(Company? company = null)
576637
}
577638

578639
#endregion
640+
641+
private IApplicationChecklistService.WorkerChecklistProcessStepData PreparePullLegalEntity()
642+
{
643+
var company = new Company(Guid.NewGuid(), "Test Company", CompanyStatusId.ACTIVE, DateTimeOffset.UtcNow)
644+
{
645+
BusinessPartnerNumber = "1"
646+
};
647+
var checklistEntry = _fixture.Build<ApplicationChecklistEntry>()
648+
.With(x => x.ApplicationChecklistEntryStatusId, ApplicationChecklistEntryStatusId.TO_DO)
649+
.Create();
650+
var checklist = new Dictionary<ApplicationChecklistEntryTypeId, ApplicationChecklistEntryStatusId>
651+
{
652+
{ ApplicationChecklistEntryTypeId.REGISTRATION_VERIFICATION, ApplicationChecklistEntryStatusId.DONE },
653+
{ ApplicationChecklistEntryTypeId.BUSINESS_PARTNER_NUMBER, ApplicationChecklistEntryStatusId.TO_DO }
654+
}
655+
.ToImmutableDictionary();
656+
var context = new IApplicationChecklistService.WorkerChecklistProcessStepData(IdWithoutSharingProcessStarted, default, checklist, Enumerable.Empty<ProcessStepTypeId>());
657+
SetupForHandlePullLegalEntity(company);
658+
return context;
659+
}
579660
}

0 commit comments

Comments
 (0)