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: Implement Expiry Date for BPNL and Membership #192

Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -337,14 +337,15 @@ public async Task<Guid> CreateBpnCredential(CreateBpnCredentialRequest requestDa
{
var companyCredentialDetailsRepository = _repositories.GetInstance<ICompanySsiDetailsRepository>();
var holderDid = await GetHolderInformation(requestData.Holder, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
var expiryDate = DateTimeOffset.UtcNow.AddMonths(12);
var schemaData = new BpnCredential(
Guid.NewGuid(),
Context,
new[] { "VerifiableCredential", "BpnCredential" },
"BpnCredential",
"Bpn Credential",
DateTimeOffset.UtcNow,
DateTimeOffset.UtcNow.AddMonths(12),
expiryDate,
_settings.IssuerDid,
new BpnCredentialSubject(
holderDid,
Expand All @@ -356,22 +357,23 @@ public async Task<Guid> CreateBpnCredential(CreateBpnCredentialRequest requestDa
StatusList)
);
var schema = JsonSerializer.Serialize(schemaData, Options);
return await HandleCredentialProcessCreation(requestData.BusinessPartnerNumber, VerifiedCredentialTypeKindId.BPN, VerifiedCredentialTypeId.BUSINESS_PARTNER_NUMBER, schema, requestData.TechnicalUserDetails, null, requestData.CallbackUrl, companyCredentialDetailsRepository);
return await HandleCredentialProcessCreation(requestData.BusinessPartnerNumber, VerifiedCredentialTypeKindId.BPN, VerifiedCredentialTypeId.BUSINESS_PARTNER_NUMBER, expiryDate, schema, requestData.TechnicalUserDetails, null, requestData.CallbackUrl, companyCredentialDetailsRepository);
}

public async Task<Guid> CreateMembershipCredential(CreateMembershipCredentialRequest requestData, CancellationToken cancellationToken)
{
var companyCredentialDetailsRepository = _repositories.GetInstance<ICompanySsiDetailsRepository>();

var holderDid = await GetHolderInformation(requestData.Holder, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
var expiryDate = DateTimeOffset.UtcNow.AddMonths(12);
var schemaData = new MembershipCredential(
Guid.NewGuid(),
Context,
new[] { "VerifiableCredential", "MembershipCredential" },
"MembershipCredential",
"Membership Credential",
DateTimeOffset.UtcNow,
DateTimeOffset.UtcNow.AddMonths(12),
expiryDate,
_settings.IssuerDid,
new MembershipCredentialSubject(
holderDid,
Expand All @@ -383,7 +385,7 @@ public async Task<Guid> CreateMembershipCredential(CreateMembershipCredentialReq
StatusList)
);
var schema = JsonSerializer.Serialize(schemaData, Options);
return await HandleCredentialProcessCreation(requestData.HolderBpn, VerifiedCredentialTypeKindId.MEMBERSHIP, VerifiedCredentialTypeId.MEMBERSHIP_CERTIFICATE, schema, requestData.TechnicalUserDetails, null, requestData.CallbackUrl, companyCredentialDetailsRepository);
return await HandleCredentialProcessCreation(requestData.HolderBpn, VerifiedCredentialTypeKindId.MEMBERSHIP, VerifiedCredentialTypeId.MEMBERSHIP_CERTIFICATE, expiryDate, schema, requestData.TechnicalUserDetails, null, requestData.CallbackUrl, companyCredentialDetailsRepository);
}

public async Task<Guid> CreateFrameworkCredential(CreateFrameworkCredentialRequest requestData, CancellationToken cancellationToken)
Expand Down Expand Up @@ -454,7 +456,7 @@ public async Task<Guid> CreateFrameworkCredential(CreateFrameworkCredentialReque
StatusList)
);
var schema = JsonSerializer.Serialize(schemaData, Options);
return await HandleCredentialProcessCreation(requestData.HolderBpn, VerifiedCredentialTypeKindId.FRAMEWORK, requestData.UseCaseFrameworkId, schema, requestData.TechnicalUserDetails, requestData.UseCaseFrameworkVersionId, requestData.CallbackUrl, companyCredentialDetailsRepository);
return await HandleCredentialProcessCreation(requestData.HolderBpn, VerifiedCredentialTypeKindId.FRAMEWORK, requestData.UseCaseFrameworkId, result.Expiry, schema, requestData.TechnicalUserDetails, requestData.UseCaseFrameworkVersionId, requestData.CallbackUrl, companyCredentialDetailsRepository);
}

private async Task<string> GetHolderInformation(string didDocumentLocation, CancellationToken cancellationToken)
Expand All @@ -480,6 +482,7 @@ private async Task<Guid> HandleCredentialProcessCreation(
string bpnl,
VerifiedCredentialTypeKindId kindId,
VerifiedCredentialTypeId typeId,
DateTimeOffset expiryDate,
string schema,
TechnicalUserDetails? technicalUserDetails,
Guid? detailVersionId,
Expand Down Expand Up @@ -514,6 +517,7 @@ private async Task<Guid> HandleCredentialProcessCreation(
{
c.VerifiedCredentialExternalTypeDetailVersionId = detailVersionId;
c.ProcessId = processId;
c.ExpiryDate = expiryDate;
}).Id;
documentRepository.AssignDocumentToCompanySsiDetails(docId, ssiDetailId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,18 @@ public async Task CreateBpnCredential_ReturnsExpected()
var didId = Guid.NewGuid().ToString();
var didDocument = new DidDocument(didId);
var data = new CreateBpnCredentialRequest("https://example.org/holder/BPNL12343546/did.json", Bpnl, null, null);
var detail = new CompanySsiDetail(CredentialId, _identity.Bpnl, VerifiedCredentialTypeId.BUSINESS_PARTNER_NUMBER, CompanySsiDetailStatusId.ACTIVE, IssuerBpnl, _identity.IdentityId, DateTimeOffset.Now);

HttpRequestMessage? request = null;
ConfigureHttpClientFactoryFixture(new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(JsonSerializer.Serialize(didDocument))
}, requestMessage => request = requestMessage);

A.CallTo(() => _companySsiDetailsRepository.CreateSsiDetails(_identity.Bpnl, VerifiedCredentialTypeId.BUSINESS_PARTNER_NUMBER, CompanySsiDetailStatusId.ACTIVE, IssuerBpnl, _identity.IdentityId, A<Action<CompanySsiDetail>>._))
.Invokes((string bpnl, VerifiedCredentialTypeId verifiedCredentialTypeId, CompanySsiDetailStatusId companySsiDetailStatusId, string issuerBpn, string userId, Action<CompanySsiDetail>? setOptionalFields) => setOptionalFields?.Invoke(detail));

// Act
await _sut.CreateBpnCredential(data, CancellationToken.None);

Expand All @@ -694,6 +699,7 @@ public async Task CreateBpnCredential_ReturnsExpected()
A.CallTo(() => _documentRepository.AssignDocumentToCompanySsiDetails(A<Guid>._, A<Guid>._))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _issuerRepositories.SaveAsync()).MustHaveHappenedOnceExactly();
Assert.NotNull(detail.ExpiryDate);
}

[Theory]
Expand Down Expand Up @@ -746,6 +752,8 @@ public async Task CreateMembershipCredential_ReturnsExpected()
var didId = Guid.NewGuid().ToString();
var didDocument = new DidDocument(didId);
var data = new CreateMembershipCredentialRequest("https://example.org/holder/BPNL12343546/did.json", Bpnl, "Test", null, null);
var detail = new CompanySsiDetail(CredentialId, _identity.Bpnl, VerifiedCredentialTypeId.MEMBERSHIP_CERTIFICATE, CompanySsiDetailStatusId.ACTIVE, IssuerBpnl, _identity.IdentityId, DateTimeOffset.Now);

HttpRequestMessage? request = null;
A.CallTo(() => _companySsiDetailsRepository.GetCertificateTypes(A<string>._))
.Returns(Enum.GetValues<VerifiedCredentialTypeId>().ToAsyncEnumerable());
Expand All @@ -755,6 +763,9 @@ public async Task CreateMembershipCredential_ReturnsExpected()
Content = new StringContent(JsonSerializer.Serialize(didDocument))
}, requestMessage => request = requestMessage);

A.CallTo(() => _companySsiDetailsRepository.CreateSsiDetails(_identity.Bpnl, VerifiedCredentialTypeId.MEMBERSHIP_CERTIFICATE, CompanySsiDetailStatusId.ACTIVE, IssuerBpnl, _identity.IdentityId, A<Action<CompanySsiDetail>>._))
.Invokes((string bpnl, VerifiedCredentialTypeId verifiedCredentialTypeId, CompanySsiDetailStatusId companySsiDetailStatusId, string issuerBpn, string userId, Action<CompanySsiDetail>? setOptionalFields) => setOptionalFields?.Invoke(detail));

// Act
await _sut.CreateMembershipCredential(data, CancellationToken.None);

Expand All @@ -766,6 +777,7 @@ public async Task CreateMembershipCredential_ReturnsExpected()
A.CallTo(() => _documentRepository.AssignDocumentToCompanySsiDetails(A<Guid>._, A<Guid>._))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _issuerRepositories.SaveAsync()).MustHaveHappenedOnceExactly();
Assert.NotNull(detail.ExpiryDate);
}

#endregion
Expand Down