-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from cabinetoffice/feature/DP-433-DataSharing…
…-verification-endpoint Feature/dp 433 data sharing verification endpoint
- Loading branch information
Showing
14 changed files
with
318 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Services/CO.CDP.DataSharing.WebApi.Tests/UseCase/GetShareCodeVerifyUseCaseTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using CO.CDP.DataSharing.WebApi.Model; | ||
using CO.CDP.DataSharing.WebApi.UseCase; | ||
using CO.CDP.DataSharing.WebApi.Tests.AutoMapper; | ||
using CO.CDP.OrganisationInformation.Persistence; | ||
using FluentAssertions; | ||
using Moq; | ||
using CO.CDP.Authentication; | ||
using CO.CDP.DataSharing.WebApi.Extensions; | ||
|
||
namespace CO.CDP.DataSharing.WebApi.Tests.UseCase; | ||
|
||
public class GetShareCodeVerifyUseCaseTest() : IClassFixture<AutoMapperFixture> | ||
{ | ||
private readonly Mock<IFormRepository> _formRepository = new(); | ||
private readonly Mock<IShareCodeRepository> _shareCodeRepository = new(); | ||
private GetShareCodeVerifyUseCase UseCase => new(_shareCodeRepository.Object); | ||
|
||
[Fact] | ||
public async Task ThrowsSharedConsentNotFoundException_WhenShareCodeRequestedNotFound() | ||
{ | ||
var formVersionId = "default"; | ||
var shareCode = ShareCodeExtensions.GenerateShareCode(); | ||
|
||
var shareVerificationRequest = EntityFactory.GetShareVerificationRequest(formVersionId: formVersionId, shareCode: shareCode); | ||
|
||
var response = async () => await UseCase.Execute(shareVerificationRequest); | ||
|
||
await response.Should().ThrowAsync<SharedConsentNotFoundException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task ReturnsTrue_WhenShareVerificationRequestForValidExistingShareCodeAndFormVersion() | ||
{ | ||
var formVersionId = "V1.0"; | ||
var shareCode = ShareCodeExtensions.GenerateShareCode(); | ||
|
||
var shareVerificationRequest = EntityFactory.GetShareVerificationRequest(formVersionId: formVersionId, shareCode: shareCode); | ||
|
||
_shareCodeRepository.Setup(r => r.GetShareCodeVerifyAsync(shareVerificationRequest.FormVersionId, shareVerificationRequest.ShareCode)).ReturnsAsync(true); | ||
|
||
var response = await UseCase.Execute(shareVerificationRequest); | ||
|
||
response.Should().NotBeNull(); | ||
|
||
response.As<CO.CDP.DataSharing.WebApi.Model.ShareVerificationReceipt>().ShareCode.Should().Be(shareVerificationRequest.ShareCode); | ||
response.As<CO.CDP.DataSharing.WebApi.Model.ShareVerificationReceipt>().FormVersionId.Should().Be(shareVerificationRequest.FormVersionId); | ||
response.As<CO.CDP.DataSharing.WebApi.Model.ShareVerificationReceipt>().IsLatest.Should().Be(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Services/CO.CDP.DataSharing.WebApi/UseCase/GetShareCodeVerifyUseCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using AutoMapper; | ||
using CO.CDP.DataSharing.WebApi.Model; | ||
using CO.CDP.OrganisationInformation.Persistence; | ||
|
||
namespace CO.CDP.DataSharing.WebApi.UseCase; | ||
|
||
public class GetShareCodeVerifyUseCase( | ||
IShareCodeRepository shareCodeRepository) | ||
: IUseCase<ShareVerificationRequest, | ||
ShareVerificationReceipt> | ||
{ | ||
public async Task<ShareVerificationReceipt> Execute(ShareVerificationRequest shareRequest) | ||
{ | ||
var details = await shareCodeRepository.GetShareCodeVerifyAsync(shareRequest.FormVersionId, shareRequest.ShareCode); | ||
|
||
if (details == null) | ||
{ | ||
throw new SharedConsentNotFoundException("Shared Code not found."); | ||
} | ||
|
||
return new ShareVerificationReceipt | ||
{ | ||
FormVersionId = shareRequest.FormVersionId, | ||
ShareCode = shareRequest.ShareCode, | ||
IsLatest = details.Value | ||
}; | ||
} | ||
} |
Oops, something went wrong.