Skip to content

Commit

Permalink
fix IControllingMemberInviteRepository replacement error
Browse files Browse the repository at this point in the history
  • Loading branch information
esdd1995 committed Sep 9, 2024
1 parent d4c5df0 commit 3b82d5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Spd.Resource.Repository;
using Spd.Resource.Repository.ApplicationInvite;
using Spd.Resource.Repository.ControllingMemberCrcApplication;
using Spd.Resource.Repository.ControllingMemberInvite;
using Spd.Resource.Repository.Document;
using Spd.Resource.Repository.LicApp;
using Spd.Resource.Repository.Licence;
Expand All @@ -12,6 +13,7 @@
using Spd.Utilities.Shared.Exceptions;
using Mappings = Spd.Manager.Licence.Mappings;

namespace Spd.Manager.Licence.UnitTest;
public class ControllingMemberCrcAppManagerTests
{
private readonly Mock<ControllingMemberCrcAppManager> _managerMock;
Expand All @@ -23,7 +25,7 @@ public class ControllingMemberCrcAppManagerTests
private readonly Mock<ITransientFileStorageService> _transientFileServiceMock;
private readonly Mock<IControllingMemberCrcRepository> _controllingMemberCrcRepositoryMock;
private readonly Mock<ILicAppRepository> _licAppRepositoryMock;
private readonly Mock<IApplicationInviteRepository> _applicationInviteRepositoryMock;
private readonly Mock<IControllingMemberInviteRepository> _cmInviteRepositoryMock;

private ControllingMemberCrcAppManager sut;

Expand All @@ -37,7 +39,7 @@ public ControllingMemberCrcAppManagerTests()
_transientFileServiceMock = new Mock<ITransientFileStorageService>();
_controllingMemberCrcRepositoryMock = new Mock<IControllingMemberCrcRepository>();
_licAppRepositoryMock = new Mock<ILicAppRepository>();
_applicationInviteRepositoryMock = new Mock<IApplicationInviteRepository>();
_cmInviteRepositoryMock = new Mock<IControllingMemberInviteRepository>();
var mapperConfig = new MapperConfiguration(x =>
{
x.AddProfile<Mappings>();
Expand All @@ -48,7 +50,7 @@ public ControllingMemberCrcAppManagerTests()
_feeRepositoryMock.Object,
_licenceRepositoryMock.Object,
_mainFileServiceMock.Object,
_transientFileServiceMock.Object, _controllingMemberCrcRepositoryMock.Object, _applicationInviteRepositoryMock.Object, _licAppRepositoryMock.Object);
_transientFileServiceMock.Object, _controllingMemberCrcRepositoryMock.Object, _cmInviteRepositoryMock.Object, _licAppRepositoryMock.Object);
}

[Fact]
Expand Down Expand Up @@ -94,15 +96,12 @@ public async Task Handle_anonymous_submit_WhithValidRequest()
.ReturnsAsync("string");
_transientFileServiceMock.Setup(m => m.HandleDeleteCommand(It.IsAny<StorageDeleteCommand>(), It.IsAny<CancellationToken>()))
.ReturnsAsync("string");
_applicationInviteRepositoryMock.Setup(i => i.QueryAsync(It.IsAny<ApplicationInviteQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new ApplicationInviteListResp()
_cmInviteRepositoryMock.Setup(i => i.QueryAsync(It.IsAny<ControllingMemberInviteQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new List<ControllingMemberInviteResp>()
{
ApplicationInvites = new List<ApplicationInviteResult>()
new ControllingMemberInviteResp()
{
new()
{
Status = ApplicationInviteStatusEnum.Sent
}
Status = ApplicationInviteStatusEnum.Sent
}
});

Expand Down
28 changes: 14 additions & 14 deletions src/Spd.Manager.Licence/ControllingMemberCrcAppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class ControllingMemberCrcAppManager :
IControllingMemberCrcAppManager
{
private readonly IControllingMemberCrcRepository _controllingMemberCrcRepository;
private readonly IControllingMemberInviteRepository _applicationInviteRepository;
private readonly IControllingMemberInviteRepository _cmInviteRepository;

public ControllingMemberCrcAppManager(IMapper mapper,
IDocumentRepository documentRepository,
Expand All @@ -41,7 +41,7 @@ public ControllingMemberCrcAppManager(IMapper mapper,
IMainFileStorageService mainFileService,
ITransientFileStorageService transientFileService,
IControllingMemberCrcRepository controllingMemberCrcRepository,
IControllingMemberInviteRepository applicationInviteRepository,
IControllingMemberInviteRepository cmInviteRepository,
ILicAppRepository licAppRepository) : base(
mapper,
documentRepository,
Expand All @@ -52,7 +52,7 @@ public ControllingMemberCrcAppManager(IMapper mapper,
licAppRepository)
{
_controllingMemberCrcRepository = controllingMemberCrcRepository;
_applicationInviteRepository = applicationInviteRepository;
_cmInviteRepository = cmInviteRepository;
}
public async Task<ControllingMemberCrcAppResponse> Handle(GetControllingMemberCrcApplicationQuery query, CancellationToken ct)
{
Expand All @@ -65,7 +65,9 @@ public async Task<ControllingMemberCrcAppResponse> Handle(GetControllingMemberCr
#region anonymous new
public async Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemberCrcAppNewCommand cmd, CancellationToken ct)
{
await ValidateInviteIdAsync(cmd.ControllingMemberCrcAppSubmitRequest.InviteId, ct);
await ValidateInviteIdAsync(cmd.ControllingMemberCrcAppSubmitRequest.InviteId,
cmd.ControllingMemberCrcAppSubmitRequest.BizContactId,
ct);
ValidateFilesForNewApp(cmd);

ControllingMemberCrcAppSubmitRequest request = cmd.ControllingMemberCrcAppSubmitRequest;
Expand All @@ -90,7 +92,8 @@ public async Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemb
#region authenticated
public async Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemberCrcUpsertCommand cmd, CancellationToken ct)
{
await ValidateInviteIdAsync(cmd.ControllingMemberCrcAppUpsertRequest.InviteId, ct);
await ValidateInviteIdAsync(cmd.ControllingMemberCrcAppUpsertRequest.InviteId,
cmd.ControllingMemberCrcAppUpsertRequest.BizContactId, ct);

SaveControllingMemberCrcAppCmd saveCmd = _mapper.Map<SaveControllingMemberCrcAppCmd>(cmd.ControllingMemberCrcAppUpsertRequest);

Expand Down Expand Up @@ -149,18 +152,15 @@ private static void ValidateFilesForNewApp(ControllingMemberCrcAppNewCommand cmd
}
}

private async Task ValidateInviteIdAsync(Guid? inviteId, CancellationToken ct)
private async Task ValidateInviteIdAsync(Guid inviteId, Guid bizContactId, CancellationToken ct)
{
ApplicationInviteResult? invite = null;
ControllingMemberInviteResp? invite = null;
//check if invite is still valid
if (inviteId != null)
{
var invites = await _applicationInviteRepository.QueryAsync(
new ApplicationInviteQuery()
{
FilterBy = new AppInviteFilterBy(null, null, AppInviteId: inviteId)
}, ct);
invite = invites.ApplicationInvites.FirstOrDefault();
var invites = await _cmInviteRepository.QueryAsync(
new ControllingMemberInviteQuery(bizContactId), ct);
invite = invites.Where(i => i.Id == inviteId).SingleOrDefault();
if (invite != null && (invite.Status == ApplicationInviteStatusEnum.Completed ||
invite.Status == ApplicationInviteStatusEnum.Cancelled || invite.Status == ApplicationInviteStatusEnum.Expired))
throw new ArgumentException("Invalid Invite status.");
Expand All @@ -171,7 +171,7 @@ private async Task DeactiveInviteAsync(Guid? inviteId, CancellationToken ct)
//inactivate invite
if (inviteId != null)
{
await _applicationInviteRepository.ManageAsync(
await _cmInviteRepository.ManageAsync(
new ControllingMemberInviteUpdateCmd()
{
ApplicationInviteStatusEnum = ApplicationInviteStatusEnum.Completed,
Expand Down

0 comments on commit 3b82d5e

Please sign in to comment.