From fd7dffc4e03cb612f3bd8d52ecc9402f77d87cb0 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Wed, 26 Jul 2023 15:30:51 +0200 Subject: [PATCH] feat(ssi): adjust certificateTypes endpoint enhance businessLogic of the GET /administration/companydata/certificateTypes to return only the possible certificateTypes Refs: CPLP-3002 --- .../BusinessLogic/CompanyDataBusinessLogic.cs | 4 ++-- .../BusinessLogic/ICompanyDataBusinessLogic.cs | 2 +- .../Controllers/CompanyDataController.cs | 2 +- .../Repositories/CompanySsiDetailsRepository.cs | 8 ++++++-- .../Repositories/ICompanySsiDetailsRepository.cs | 2 +- .../CompanyDataBusinessLogicTests.cs | 4 ++-- .../Controllers/CompanyDataControllerTests.cs | 2 +- .../CompanySsiDetailsRepositoryTests.cs | 15 ++++++++++++++- 8 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs index 16116d6a85..2ba39e6ac6 100644 --- a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs @@ -494,6 +494,6 @@ public async Task RejectCredential(Guid userId, Guid credentialId) } /// - public IAsyncEnumerable GetCertificateTypes() => - _portalRepositories.GetInstance().GetCertificateTypes(); + public IAsyncEnumerable GetCertificateTypes(Guid companyId) => + _portalRepositories.GetInstance().GetCertificateTypes(companyId); } diff --git a/src/administration/Administration.Service/BusinessLogic/ICompanyDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/ICompanyDataBusinessLogic.cs index 270d7eac33..2e6cfdc220 100644 --- a/src/administration/Administration.Service/BusinessLogic/ICompanyDataBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/ICompanyDataBusinessLogic.cs @@ -51,5 +51,5 @@ public interface ICompanyDataBusinessLogic Task ApproveCredential(Guid userId, Guid credentialId, CancellationToken cancellationToken); Task RejectCredential(Guid userId, Guid credentialId); - IAsyncEnumerable GetCertificateTypes(); + IAsyncEnumerable GetCertificateTypes(Guid companyId); } diff --git a/src/administration/Administration.Service/Controllers/CompanyDataController.cs b/src/administration/Administration.Service/Controllers/CompanyDataController.cs index 86551c3d94..61e80e99f5 100644 --- a/src/administration/Administration.Service/Controllers/CompanyDataController.cs +++ b/src/administration/Administration.Service/Controllers/CompanyDataController.cs @@ -214,7 +214,7 @@ public Task> GetSsiCertificationData() => [Route("certificateTypes")] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] public IAsyncEnumerable GetCertificateTypes() => - _logic.GetCertificateTypes(); + this.WithCompanyId(companyId => _logic.GetCertificateTypes(companyId)); /// /// Creates the useCaseParticipation diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/CompanySsiDetailsRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/CompanySsiDetailsRepository.cs index 5bc20b8004..2de5e599f6 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/CompanySsiDetailsRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/CompanySsiDetailsRepository.cs @@ -208,9 +208,13 @@ public void AttachAndModifyCompanySsiDetails(Guid id, Action? } /// - public IAsyncEnumerable GetCertificateTypes() => + public IAsyncEnumerable GetCertificateTypes(Guid companyId) => _context.VerifiedCredentialTypes - .Where(x => x.VerifiedCredentialTypeAssignedKind!.VerifiedCredentialTypeKindId == VerifiedCredentialTypeKindId.CERTIFICATE) + .Where(x => + x.VerifiedCredentialTypeAssignedKind!.VerifiedCredentialTypeKindId == VerifiedCredentialTypeKindId.CERTIFICATE && + !x.CompanySsiDetails.Any(ssi => + ssi.CompanyId == companyId && + (ssi.CompanySsiDetailStatusId == CompanySsiDetailStatusId.PENDING || ssi.CompanySsiDetailStatusId == CompanySsiDetailStatusId.ACTIVE))) .Select(x => x.Id) .ToAsyncEnumerable(); } diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/ICompanySsiDetailsRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/ICompanySsiDetailsRepository.cs index 4a19d4bf07..0ff16e40f6 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/ICompanySsiDetailsRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/ICompanySsiDetailsRepository.cs @@ -90,5 +90,5 @@ public interface ICompanySsiDetailsRepository Task<(bool exists, SsiApprovalData data)> GetSsiApprovalData(Guid credentialId); Task<(bool Exists, CompanySsiDetailStatusId Status, VerifiedCredentialTypeId Type, Guid RequesterId, string? RequesterEmail, string? Firstname, string? Lastname)> GetSsiRejectionData(Guid credentialId); void AttachAndModifyCompanySsiDetails(Guid id, Action? initialize, Action updateFields); - IAsyncEnumerable GetCertificateTypes(); + IAsyncEnumerable GetCertificateTypes(Guid companyId); } diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs index 1d01356e54..05226ed93d 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs @@ -1464,11 +1464,11 @@ public async Task RejectCredential_WithoutUserMail_ReturnsExpected() public async Task GetCertificateTypes_WithFilter_ReturnsList() { // Arrange - A.CallTo(() => _companySsiDetailsRepository.GetCertificateTypes()) + A.CallTo(() => _companySsiDetailsRepository.GetCertificateTypes(_identity.CompanyId)) .Returns(new[] { VerifiedCredentialTypeId.DISMANTLER_CERTIFICATE }.ToAsyncEnumerable()); // Act - var result = await _sut.GetCertificateTypes().ToListAsync().ConfigureAwait(false); + var result = await _sut.GetCertificateTypes(_identity.CompanyId).ToListAsync().ConfigureAwait(false); // Assert result.Should().HaveCount(1); diff --git a/tests/administration/Administration.Service.Tests/Controllers/CompanyDataControllerTests.cs b/tests/administration/Administration.Service.Tests/Controllers/CompanyDataControllerTests.cs index f10784205d..b6f029e857 100644 --- a/tests/administration/Administration.Service.Tests/Controllers/CompanyDataControllerTests.cs +++ b/tests/administration/Administration.Service.Tests/Controllers/CompanyDataControllerTests.cs @@ -282,7 +282,7 @@ public async Task GetCredentials_CallsExpected() public async Task GetCredentialTypes() { // Arrange - A.CallTo(() => _logic.GetCertificateTypes()) + A.CallTo(() => _logic.GetCertificateTypes(_identity.CompanyId)) .Returns(new[] { VerifiedCredentialTypeId.DISMANTLER_CERTIFICATE }.ToAsyncEnumerable()); //Act diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/CompanySsiDetailsRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/CompanySsiDetailsRepositoryTests.cs index 55bd8fea5e..1525e329a5 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/CompanySsiDetailsRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/CompanySsiDetailsRepositoryTests.cs @@ -397,7 +397,20 @@ public async Task GetCertificateTypes_ReturnsExpected() var sut = await CreateSut(); // Act - var result = await sut.GetCertificateTypes().ToListAsync().ConfigureAwait(false); + var result = await sut.GetCertificateTypes(_validCompanyId).ToListAsync().ConfigureAwait(false); + + // Assert + result.Should().BeEmpty(); + } + + [Fact] + public async Task GetCertificateTypes_WithoutCertificate_ReturnsExpected() + { + // Arrange + var sut = await CreateSut(); + + // Act + var result = await sut.GetCertificateTypes(Guid.NewGuid()).ToListAsync().ConfigureAwait(false); // Assert result.Should().ContainSingle().Which.Should().Be(VerifiedCredentialTypeId.DISMANTLER_CERTIFICATE);