Skip to content

Commit

Permalink
fix review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Jul 23, 2024
1 parent 1c0534e commit 500116d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,22 @@ private async Task CreateWalletInternal(Guid applicationId, CancellationToken ca

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

if (companies.Count(x => x.SubmittedCompanyApplicationId.Count() == 1) != 1)
var companyApplicationIds = companySubmittedApplicationIds.SelectMany(x => x.SubmittedApplicationIds.Select(applicationId => (x.CompanyId, ApplicationId: applicationId)));
if (companyApplicationIds.Count() != 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 (companyId, applicationId) = companyApplicationIds.First();
var context = await _checklistService
.VerifyChecklistEntryAndProcessSteps(
companyApplicationStatusIds.Single(),
applicationId,
ApplicationChecklistEntryTypeId.IDENTITY_WALLET,
[ApplicationChecklistEntryStatusId.IN_PROGRESS],
ProcessStepTypeId.AWAIT_DIM_RESPONSE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void CreateWalletData(Guid companyId, string did, JsonDocument didDocumen
.Select(x => new ValueTuple<bool, JsonDocument>(true, x.DidDocument))
.SingleOrDefaultAsync();

public IAsyncEnumerable<(Guid CompanyId, IEnumerable<Guid> SubmittedCompanyApplicationId)> GetCompanyIdByBpn(string bpn) =>
public IAsyncEnumerable<(Guid CompanyId, IEnumerable<Guid> SubmittedApplicationIds)> GetCompanySubmittedApplicationIdsByBpn(string bpn) =>
context.Companies
.Where(x => x.BusinessPartnerNumber == bpn)
.Select(x => new ValueTuple<Guid, IEnumerable<Guid>>(
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);
IAsyncEnumerable<(Guid CompanyId, IEnumerable<Guid> SubmittedCompanyApplicationId)> GetCompanyIdByBpn(string bpn);
IAsyncEnumerable<(Guid CompanyId, IEnumerable<Guid> SubmittedApplicationIds)> GetCompanySubmittedApplicationIdsByBpn(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 @@ -259,7 +259,7 @@ public async Task ProcessDimResponse_NoCompanyForBpn_ThrowsNotFoundException()
{
// Arrange
var data = _fixture.Create<DimWalletData>();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
A.CallTo(() => _companyRepository.GetCompanySubmittedApplicationIdsByBpn(BPN))
.Returns(Enumerable.Empty<ValueTuple<Guid, IEnumerable<Guid>>>().ToAsyncEnumerable());
async Task Act() => await _logic.ProcessDimResponse(BPN, data, CancellationToken.None);

Expand All @@ -277,7 +277,7 @@ public async Task ProcessDimResponse_WithMultipleSubmittedApplications_ThrowsCon
{
// Arrange
var data = _fixture.Create<DimWalletData>();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
A.CallTo(() => _companyRepository.GetCompanySubmittedApplicationIdsByBpn(BPN))
.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);

Expand All @@ -304,7 +304,7 @@ public async Task ProcessDimResponse_WithDidSchemaInvalid_CallsExpected()
.With(x => x.Did, "did:web:test.com:BPNL0000000000XX")
.Create();
var companyId = Guid.NewGuid();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
A.CallTo(() => _companyRepository.GetCompanySubmittedApplicationIdsByBpn(BPN))
.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 @@ -330,7 +330,7 @@ public async Task ProcessDimResponse_WithFailingSchemaValidation_CallsExpected()
var didDocument = JsonDocument.Parse("{\n \"@context\": [\n \"abc\" ],\n \"id\": \"did:web:example.org:did:BPNL0000000000XX\",\n \"verificationMethod\": [\n {\n \"id\": [\"did:web:example.com:did:BPNL0000000000XX#key-0\"],\n \"publicKeyJwk\": {\n \"kty\": \"JsonWebKey2020\",\n \"crv\": \"Ed25519\",\n \"x\": \"3534354354353\"\n }\n }\n ],\n \"services\": [\n {\n \"id\": [\"did:web:example.com:did:BPNL0000000000XX#key-0\"],\n \"serviceEndpoint\": \"test.org:123\"\n }\n ]\n}");
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))
A.CallTo(() => _companyRepository.GetCompanySubmittedApplicationIdsByBpn(BPN))
.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 @@ -390,7 +390,7 @@ public async Task ProcessDimResponse_WithValid_CallsExpected()
.With(x => x.Did, "did:web:example.org:did:BPNL0000000000XX")
.Create();
var companyId = Guid.NewGuid();
A.CallTo(() => _companyRepository.GetCompanyIdByBpn(BPN))
A.CallTo(() => _companyRepository.GetCompanySubmittedApplicationIdsByBpn(BPN))
.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

0 comments on commit 500116d

Please sign in to comment.