Skip to content

Commit

Permalink
feat(ssi): adjust certificateTypes endpoint
Browse files Browse the repository at this point in the history
enhance businessLogic of the GET /administration/companydata/certificateTypes to return only the possible certificateTypes

Refs: CPLP-3002
  • Loading branch information
Phil91 committed Jul 26, 2023
1 parent 0e21972 commit fd7dffc
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,6 @@ public async Task RejectCredential(Guid userId, Guid credentialId)
}

/// <inheritdoc />
public IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes() =>
_portalRepositories.GetInstance<ICompanySsiDetailsRepository>().GetCertificateTypes();
public IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes(Guid companyId) =>
_portalRepositories.GetInstance<ICompanySsiDetailsRepository>().GetCertificateTypes(companyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ public interface ICompanyDataBusinessLogic
Task ApproveCredential(Guid userId, Guid credentialId, CancellationToken cancellationToken);

Task RejectCredential(Guid userId, Guid credentialId);
IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes();
IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes(Guid companyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public Task<IEnumerable<SsiCertificateData>> GetSsiCertificationData() =>
[Route("certificateTypes")]
[ProducesResponseType(typeof(IEnumerable<SsiCertificateTransferData>), StatusCodes.Status200OK)]
public IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes() =>
_logic.GetCertificateTypes();
this.WithCompanyId(companyId => _logic.GetCertificateTypes(companyId));

/// <summary>
/// Creates the useCaseParticipation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ public void AttachAndModifyCompanySsiDetails(Guid id, Action<CompanySsiDetail>?
}

/// <inheritdoc />
public IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes() =>
public IAsyncEnumerable<VerifiedCredentialTypeId> 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompanySsiDetail>? initialize, Action<CompanySsiDetail> updateFields);
IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes();
IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes(Guid companyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fd7dffc

Please sign in to comment.