Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dim): fix callback logic for dim requests #863

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,18 @@ private async Task CreateWalletInternal(Guid applicationId, CancellationToken ca

public async Task ProcessDimResponse(string bpn, DimWalletData data, CancellationToken cancellationToken)
{
var (exists, companyId, companyApplicationStatusIds) = await _portalRepositories.GetInstance<ICompanyRepository>().GetCompanyIdByBpn(bpn).ConfigureAwait(ConfigureAwaitOptions.None);
if (!exists)
var companies = await _portalRepositories.GetInstance<ICompanyRepository>().GetCompanyIdByBpn(bpn).ToListAsync(cancellationToken).ConfigureAwait(false);
if (!companies.Any())
{
throw new NotFoundException($"No company found for bpn {bpn}");
}

if (companyApplicationStatusIds.Count() != 1)
if (companies.Count(x => x.SubmittedCompanyApplicationId.Count() == 1) != 1)
{
throw new ConflictException($"There must be exactly one company application in state {CompanyApplicationStatusId.SUBMITTED}");
}

var (companyId, companyApplicationStatusIds) = companies.SingleOrDefault(x => x.SubmittedCompanyApplicationId.Count() == 1);
var context = await _checklistService
.VerifyChecklistEntryAndProcessSteps(
companyApplicationStatusIds.Single(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,15 @@ public void CreateWalletData(Guid companyId, string did, JsonDocument didDocumen
.Select(x => new ValueTuple<bool, JsonDocument>(true, x.DidDocument))
.SingleOrDefaultAsync();

public Task<(bool Exists, Guid CompanyId, IEnumerable<Guid> SubmittedCompanyApplicationId)> GetCompanyIdByBpn(string bpn) =>
public IAsyncEnumerable<(Guid CompanyId, IEnumerable<Guid> SubmittedCompanyApplicationId)> GetCompanyIdByBpn(string bpn) =>
context.Companies
.Where(x => x.BusinessPartnerNumber == bpn)
.Select(x => new ValueTuple<bool, Guid, IEnumerable<Guid>>(
true,
.Select(x => new ValueTuple<Guid, IEnumerable<Guid>>(
x.Id,
x.CompanyApplications
.Where(ca => ca.ApplicationStatusId == CompanyApplicationStatusId.SUBMITTED)
.Select(ca => ca.Id)))
.SingleOrDefaultAsync();
.ToAsyncEnumerable();

public Task<(string? Bpn, string? Did, string? WalletUrl)> GetDimServiceUrls(Guid companyId) =>
context.Companies.Where(x => x.Id == companyId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public interface ICompanyRepository
Task<bool> CheckBpnExists(string bpn);
void CreateWalletData(Guid companyId, string did, JsonDocument didDocument, string clientId, byte[] clientSecret, byte[]? initializationVector, int encryptionMode, string authenticationServiceUrl);
Task<(bool Exists, JsonDocument DidDocument)> GetDidDocumentById(string bpn);
Task<(bool Exists, Guid CompanyId, IEnumerable<Guid> SubmittedCompanyApplicationId)> GetCompanyIdByBpn(string bpn);
IAsyncEnumerable<(Guid CompanyId, IEnumerable<Guid> SubmittedCompanyApplicationId)> GetCompanyIdByBpn(string bpn);
Task<(string? Bpn, string? Did, string? WalletUrl)> GetDimServiceUrls(Guid companyId);
Task<(string? Holder, string? BusinessPartnerNumber, WalletInformation? WalletInformation)> GetWalletData(Guid identityId);
void RemoveProviderCompanyDetails(Guid providerCompanyDetailId);
Expand Down
10 changes: 5 additions & 5 deletions tests/externalsystems/Dim.Library.Tests/DimBusinessLogicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public async Task ProcessDimResponse_NoCompanyForBpn_ThrowsNotFoundException()
// Arrange
var data = _fixture.Create<DimWalletData>();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
.Returns(new ValueTuple<bool, Guid, IEnumerable<Guid>>(false, default, Enumerable.Empty<Guid>()));
.Returns(Enumerable.Empty<ValueTuple<Guid, IEnumerable<Guid>>>().ToAsyncEnumerable());
async Task Act() => await _logic.ProcessDimResponse(BPN, data, CancellationToken.None);

// Act
Expand All @@ -278,7 +278,7 @@ public async Task ProcessDimResponse_WithMultipleSubmittedApplications_ThrowsCon
// Arrange
var data = _fixture.Create<DimWalletData>();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
.Returns(new ValueTuple<bool, Guid, IEnumerable<Guid>>(true, default, _fixture.CreateMany<Guid>(2)));
.Returns(Enumerable.Repeat(new ValueTuple<Guid, IEnumerable<Guid>>(default, _fixture.CreateMany<Guid>(2)), 1).ToAsyncEnumerable());
async Task Act() => await _logic.ProcessDimResponse(BPN, data, CancellationToken.None);

// Act
Expand All @@ -305,7 +305,7 @@ public async Task ProcessDimResponse_WithDidSchemaInvalid_CallsExpected()
.Create();
var companyId = Guid.NewGuid();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
.Returns(new ValueTuple<bool, Guid, IEnumerable<Guid>>(true, companyId, Enumerable.Repeat(ApplicationId, 1)));
.Returns(Enumerable.Repeat(new ValueTuple<Guid, IEnumerable<Guid>>(companyId, Enumerable.Repeat(ApplicationId, 1)), 1).ToAsyncEnumerable());
A.CallTo(() => _checklistService.VerifyChecklistEntryAndProcessSteps(ApplicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, A<IEnumerable<ApplicationChecklistEntryStatusId>>._, ProcessStepTypeId.AWAIT_DIM_RESPONSE, A<IEnumerable<ApplicationChecklistEntryTypeId>?>._, A<IEnumerable<ProcessStepTypeId>?>._))
.Returns(context);

Expand All @@ -331,7 +331,7 @@ public async Task ProcessDimResponse_WithFailingSchemaValidation_CallsExpected()
var data = _fixture.Build<DimWalletData>().With(x => x.DidDocument, didDocument).With(x => x.Did, "did:web:example.org:did:BPNL0000000000XX").Create();
var companyId = Guid.NewGuid();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
.Returns(new ValueTuple<bool, Guid, IEnumerable<Guid>>(true, companyId, Enumerable.Repeat(ApplicationId, 1)));
.Returns(Enumerable.Repeat(new ValueTuple<Guid, IEnumerable<Guid>>(companyId, Enumerable.Repeat(ApplicationId, 1)), 1).ToAsyncEnumerable());
A.CallTo(() => _checklistService.VerifyChecklistEntryAndProcessSteps(ApplicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, A<IEnumerable<ApplicationChecklistEntryStatusId>>._, ProcessStepTypeId.AWAIT_DIM_RESPONSE, A<IEnumerable<ApplicationChecklistEntryTypeId>?>._, A<IEnumerable<ProcessStepTypeId>?>._))
.Returns(context);

Expand Down Expand Up @@ -391,7 +391,7 @@ public async Task ProcessDimResponse_WithValid_CallsExpected()
.Create();
var companyId = Guid.NewGuid();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
.Returns(new ValueTuple<bool, Guid, IEnumerable<Guid>>(true, companyId, Enumerable.Repeat(ApplicationId, 1)));
.Returns(Enumerable.Repeat(new ValueTuple<Guid, IEnumerable<Guid>>(companyId, Enumerable.Repeat(ApplicationId, 1)), 1).ToAsyncEnumerable());
A.CallTo(() => _checklistService.VerifyChecklistEntryAndProcessSteps(ApplicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, A<IEnumerable<ApplicationChecklistEntryStatusId>>._, ProcessStepTypeId.AWAIT_DIM_RESPONSE, A<IEnumerable<ApplicationChecklistEntryTypeId>?>._, A<IEnumerable<ProcessStepTypeId>?>._))
.Returns(context);
byte[]? encrypted = null;
Expand Down
Loading