Skip to content

Commit

Permalink
alias update, clean get response (#1380)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):
- refactored `get` response object and removed unnecessary data
- generated method for handling updating personal information (contact,
address, aliases), prevent history record in partial save mode
- refactored manager test
- endpoint for update application
- cleanup, mappings and validation
  • Loading branch information
esdd1995 authored Sep 11, 2024
1 parent cf5e533 commit 4740fcf
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using AutoMapper;
using Microsoft.Dynamics.CRM;
using Moq;
using Spd.Manager.Licence;
using Spd.Resource.Repository;
using Spd.Resource.Repository.ApplicationInvite;
using Spd.Resource.Repository.Contact;
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;
using Spd.Resource.Repository.LicenceFee;
using Spd.Resource.Repository.Tasks;
using Spd.Utilities.FileStorage;
using Spd.Utilities.Shared.Exceptions;
using Mappings = Spd.Manager.Licence.Mappings;

namespace Spd.Manager.Licence.UnitTest;
public class ControllingMemberCrcAppManagerTests
{
private readonly Mock<ControllingMemberCrcAppManager> _managerMock;
private readonly Mock<IMapper> _mapperMock;
private readonly Mock<IDocumentRepository> _documentRepositoryMock;
private readonly Mock<ILicenceFeeRepository> _feeRepositoryMock;
Expand All @@ -26,6 +28,8 @@ public class ControllingMemberCrcAppManagerTests
private readonly Mock<IControllingMemberCrcRepository> _controllingMemberCrcRepositoryMock;
private readonly Mock<ILicAppRepository> _licAppRepositoryMock;
private readonly Mock<IControllingMemberInviteRepository> _cmInviteRepositoryMock;
private readonly Mock<IContactRepository> _contactRepositroyMock;
private readonly Mock<ITaskRepository> _taskRepositoryMock;

private ControllingMemberCrcAppManager sut;

Expand All @@ -40,6 +44,8 @@ public ControllingMemberCrcAppManagerTests()
_controllingMemberCrcRepositoryMock = new Mock<IControllingMemberCrcRepository>();
_licAppRepositoryMock = new Mock<ILicAppRepository>();
_cmInviteRepositoryMock = new Mock<IControllingMemberInviteRepository>();
_contactRepositroyMock = new Mock<IContactRepository>();
_taskRepositoryMock = new Mock<ITaskRepository>();
var mapperConfig = new MapperConfiguration(x =>
{
x.AddProfile<Mappings>();
Expand All @@ -50,7 +56,8 @@ public ControllingMemberCrcAppManagerTests()
_feeRepositoryMock.Object,
_licenceRepositoryMock.Object,
_mainFileServiceMock.Object,
_transientFileServiceMock.Object, _controllingMemberCrcRepositoryMock.Object, _cmInviteRepositoryMock.Object, _licAppRepositoryMock.Object);
_transientFileServiceMock.Object, _controllingMemberCrcRepositoryMock.Object,
_cmInviteRepositoryMock.Object,_contactRepositroyMock.Object, _taskRepositoryMock.Object, _licAppRepositoryMock.Object);
}

[Fact]
Expand All @@ -59,6 +66,12 @@ public async Task Handle_anonymous_submit_WhithValidRequest()
Guid applicantId = Guid.NewGuid();
Guid controllingMemberAppId = Guid.NewGuid();
Guid inviteId = Guid.NewGuid();
ContactResp contact = new()
{
Id = applicantId
};
SetupMockRepositories(applicantId, controllingMemberAppId, contact, inviteId);

// Arrange
var request = new ControllingMemberCrcAppSubmitRequest
{
Expand All @@ -76,34 +89,6 @@ public async Task Handle_anonymous_submit_WhithValidRequest()
new LicAppFileInfo { LicenceDocumentTypeCode = LicenceDocumentTypeCode.CanadianPassport }
});

_licAppRepositoryMock.Setup(a => a.QueryAsync(It.IsAny<LicenceAppQuery>(), CancellationToken.None))
.ReturnsAsync(new List<LicenceAppListResp>()); //no dup lic app
_licenceRepositoryMock.Setup(a => a.QueryAsync(It.IsAny<LicenceQry>(), CancellationToken.None)) //no dup lic
.ReturnsAsync(new LicenceListResp()
{
Items = new List<LicenceResp> { }
});
_controllingMemberCrcRepositoryMock.Setup(a => a.SaveControllingMemberCrcApplicationAsync(It.IsAny<SaveControllingMemberCrcAppCmd>(), CancellationToken.None))
.ReturnsAsync(new ControllingMemberCrcApplicationCmdResp(controllingMemberAppId, applicantId));
_documentRepositoryMock.Setup(m => m.QueryAsync(It.Is<DocumentQry>(q => q.ApplicationId == controllingMemberAppId), It.IsAny<CancellationToken>()))
.ReturnsAsync(new DocumentListResp()
{
Items = new List<DocumentResp> { new() }
});
_transientFileServiceMock.Setup(m => m.HandleQuery(It.IsAny<FileMetadataQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new FileMetadataQueryResult("key", "folder", null));
_mainFileServiceMock.Setup(m => m.HandleCopyStorageFromTransientToMainCommand(It.IsAny<CopyStorageFromTransientToMainCommand>(), It.IsAny<CancellationToken>()))
.ReturnsAsync("string");
_transientFileServiceMock.Setup(m => m.HandleDeleteCommand(It.IsAny<StorageDeleteCommand>(), It.IsAny<CancellationToken>()))
.ReturnsAsync("string");
_cmInviteRepositoryMock.Setup(i => i.QueryAsync(It.IsAny<ControllingMemberInviteQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new List<ControllingMemberInviteResp>()
{
new ControllingMemberInviteResp()
{
Status = ApplicationInviteStatusEnum.Sent
}
});

// Act
var result = await sut.Handle(command, CancellationToken.None);
Expand All @@ -117,17 +102,26 @@ public async Task Handle_anonymous_submit_WhithValidRequest()
_transientFileServiceMock.Verify();
}


[Fact]
public async Task Handle_anonymous_submit_WhithoutFingerPrint_ShouldReturnError()
{
Guid applicantId = Guid.NewGuid();
Guid controllingMemberAppId = Guid.NewGuid();
Guid inviteId = Guid.NewGuid();
ContactResp contact = new()
{
Id = applicantId,
};
SetupMockRepositories(applicantId, controllingMemberAppId, contact, inviteId);

// Arrange
var request = new ControllingMemberCrcAppSubmitRequest
{
IsCanadianCitizen = true,
IsPoliceOrPeaceOfficer = true,
IsTreatedForMHC = false,
InviteId = inviteId,
};

var command = new ControllingMemberCrcAppNewCommand(request,
Expand All @@ -137,6 +131,13 @@ public async Task Handle_anonymous_submit_WhithoutFingerPrint_ShouldReturnError(
new LicAppFileInfo { LicenceDocumentTypeCode = LicenceDocumentTypeCode.CanadianPassport }
});


// Act and Assert
Func<Task> act = () => sut.Handle(command, CancellationToken.None);
await Assert.ThrowsAsync<ApiException>(act);
}
private void SetupMockRepositories(Guid applicantId, Guid controllingMemberAppId, ContactResp contact, Guid inviteId)
{
_licAppRepositoryMock.Setup(a => a.QueryAsync(It.IsAny<LicenceAppQuery>(), CancellationToken.None))
.ReturnsAsync(new List<LicenceAppListResp>()); //no dup lic app
_licenceRepositoryMock.Setup(a => a.QueryAsync(It.IsAny<LicenceQry>(), CancellationToken.None)) //no dup lic
Expand All @@ -157,9 +158,26 @@ public async Task Handle_anonymous_submit_WhithoutFingerPrint_ShouldReturnError(
.ReturnsAsync("string");
_transientFileServiceMock.Setup(m => m.HandleDeleteCommand(It.IsAny<StorageDeleteCommand>(), It.IsAny<CancellationToken>()))
.ReturnsAsync("string");

// Act and Assert
Func<Task> act = () => sut.Handle(command, CancellationToken.None);
await Assert.ThrowsAsync<ApiException>(act);
_cmInviteRepositoryMock.Setup(i => i.QueryAsync(It.IsAny<ControllingMemberInviteQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new List<ControllingMemberInviteResp>()
{
new ControllingMemberInviteResp()
{
Status = ApplicationInviteStatusEnum.Sent
}
});
_contactRepositroyMock.Setup(c => c.GetAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(contact);

_contactRepositroyMock.Setup(c => c.ManageAsync(It.IsAny<CreateContactCmd>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(contact);
_cmInviteRepositoryMock.Setup(i => i.QueryAsync(It.IsAny<ControllingMemberInviteQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new List<ControllingMemberInviteResp>()
{
new ControllingMemberInviteResp()
{
Id = inviteId
}
});
}
}
38 changes: 33 additions & 5 deletions src/Spd.Manager.Licence/ControllingMemberCrcAppContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ public interface IControllingMemberCrcAppManager
public Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemberCrcAppNewCommand command, CancellationToken ct);
public Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemberCrcUpsertCommand command, CancellationToken ct);
public Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemberCrcSubmitCommand command, CancellationToken ct);
public Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemberCrcAppUpdateCommand command, CancellationToken ct);

public Task<ControllingMemberCrcAppResponse> Handle(GetControllingMemberCrcApplicationQuery query, CancellationToken ct);
}
public record ControllingMemberCrcAppBase
{
public WorkerLicenceTypeCode? WorkerLicenceTypeCode { get; set; }
public ApplicationTypeCode? ApplicationTypeCode { get; set; }
public Guid? ParentBizLicApplicationId { get; set; }
public string? GivenName { get; set; }
public string? MiddleName1 { get; set; }
public string? MiddleName2 { get; set; }
Expand All @@ -42,30 +43,48 @@ public record ControllingMemberCrcAppBase
public string? BankruptcyHistoryDetail { get; set; }
public bool? IsTreatedForMHC { get; set; }
public Address? ResidentialAddress { get; set; }
public Guid BizContactId { get; set; }
public Guid InviteId { get; set; }
}


#region authenticated
public record ControllingMemberCrcUpsertCommand(ControllingMemberCrcAppUpsertRequest ControllingMemberCrcAppUpsertRequest) : IRequest<ControllingMemberCrcAppCommandResponse>;
public record ControllingMemberCrcSubmitCommand(ControllingMemberCrcAppUpsertRequest ControllingMemberCrcUpsertRequest)
: ControllingMemberCrcUpsertCommand(ControllingMemberCrcUpsertRequest), IRequest<ControllingMemberCrcAppCommandResponse>;
public record ControllingMemberCrcAppUpdateCommand(
ControllingMemberCrcAppUpdateRequest ControllingMemberCrcAppRequest,
IEnumerable<LicAppFileInfo> LicAppFileInfos)
: IRequest<ControllingMemberCrcAppCommandResponse>;
public record ControllingMemberCrcAppUpsertRequest : ControllingMemberCrcAppBase
{
public IEnumerable<Document>? DocumentInfos { get; set; }
public Guid? ControllingMemberAppId { get; set; }
public Guid? ApplicantId { get; set; }
public Guid BizContactId { get; set; }
public Guid InviteId { get; set; }
public Guid? ParentBizLicApplicationId { get; set; }
};
#endregion
#region anonymous user
public record ControllingMemberCrcAppSubmitRequest : ControllingMemberCrcAppBase
{
public Guid? ControllingMemberAppId { get; set; }
public Guid BizContactId { get; set; }
public Guid InviteId { get; set; }
public Guid? ParentBizLicApplicationId { get; set; }
public IEnumerable<Guid>? DocumentKeyCodes { get; set; }
public IEnumerable<DocumentExpiredInfo> DocumentExpiredInfos { get; set; } = Enumerable.Empty<DocumentExpiredInfo>();

};

public record ControllingMemberCrcAppUpdateRequest : ControllingMemberCrcAppSubmitRequest
{
public IEnumerable<Guid>? PreviousDocumentIds { get; set; }
public bool? HasLegalNameChanged { get; set; }
public bool? HasNewCriminalRecordCharge { get; set; }
public bool? HasNewMentalHealthCondition { get; set; }
}


public record ControllingMemberCrcAppNewCommand(ControllingMemberCrcAppSubmitRequest ControllingMemberCrcAppSubmitRequest,
IEnumerable<LicAppFileInfo> LicAppFileInfos) : IRequest<ControllingMemberCrcAppCommandResponse>;
public record GetControllingMemberCrcApplicationQuery(Guid ControllingMemberApplicationId) : IRequest<ControllingMemberCrcAppResponse>;
Expand All @@ -81,4 +100,13 @@ public record ControllingMemberCrcAppResponse : ControllingMemberCrcAppBase
public IEnumerable<Document> DocumentInfos { get; set; } = Enumerable.Empty<Document>();
}

#endregion
#endregion
public sealed record ChangeSpec
{
public bool PeaceOfficerStatusChanged { get; set; } //task
public Guid? PeaceOfficerStatusChangeTaskId { get; set; }
public bool MentalHealthStatusChanged { get; set; } //task
public Guid? MentalHealthStatusChangeTaskId { get; set; }
public bool CriminalHistoryChanged { get; set; } //task
public Guid? CriminalHistoryStatusChangeTaskId { get; set; }
}
Loading

0 comments on commit 4740fcf

Please sign in to comment.