Skip to content

Commit

Permalink
CON-1654 - Resolved Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
VasanthaKasirajan3008 committed Apr 9, 2020
1 parent 69d1e90 commit d7bf19c
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,9 @@ public void Arrange()
_mockAccountLegalEntityPublicHashingService.Setup(m => m.DecodeValue(It.IsAny<string>())).Returns(_accountLegelEntityId);

_mockEmployerAgreementRepository = new Mock<IEmployerAgreementRepository>();
_mockEmployerAgreementRepository.Setup(m => m.GetOrganisationAgreement(It.IsAny<long>())).ReturnsAsync
(new AccountLegalEntity {

_mockEmployerAgreementRepository.Setup(m => m.GetOrganisationAgreement(It.IsAny<long>())).ReturnsAsync(new AccountLegalEntity {
LegalEntity = new LegalEntity { Id=1, Source= OrganisationType.CompaniesHouse } ,
Agreements = new List<EmployerAgreement>()
{ new EmployerAgreement
{
SignedDate = DateTime.UtcNow,
}

} });
Agreements = new List<EmployerAgreement>() { new EmployerAgreement { SignedDate = DateTime.UtcNow, } }});

_mockhashingService = new Mock<IHashingService>();
_mockhashingService.Setup(m => m.HashValue(It.IsAny<long>())).Returns(hashedId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@ public async Task ThenShouldReturnValidIfRequestIsValid()
}

[Test]
public async Task ThenShouldReturnInValidIfRequestIsNotValid()
public async Task ThenShouldReturnInvaldidIfAccountLegalEntityHashedIdIsEmpty()
{
//Act
var result = await _validator.ValidateAsync(new GetOrganisationAgreementsRequest { AccountLegalEntityHashedId = string.Empty });

//Assert
Assert.IsFalse(result.IsValid());
}


[Test]
public async Task ThenShouldReturnInvaldidIfAccountLegalEntityHashedIdIsNull()
{
//Act
var result = await _validator.ValidateAsync(new GetOrganisationAgreementsRequest { AccountLegalEntityHashedId = null });

//Assert
Assert.IsFalse(result.IsValid());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ public void Arrange()
}
});

var EmployerAgreementViewModelV1 = new List<EmployerAgreementViewModelV1>()
var organisationAgreementViewModel = new List<OrganisationAgreementViewModel>()
{
new EmployerAgreementViewModelV1 { SignedDate = DateTime.UtcNow }
new OrganisationAgreementViewModel { SignedDate = DateTime.UtcNow }
};

_referenceDataService = new Mock<IReferenceDataService>();
_mapper.Setup(m => m.Map<ICollection<EmployerAgreementDto>, ICollection<EmployerAgreementViewModelV1>>(It.IsAny<ICollection<EmployerAgreementDto>>())).Returns(EmployerAgreementViewModelV1);
_mapper.Setup(m => m.Map<ICollection<EmployerAgreementDto>, ICollection<OrganisationAgreementViewModel>>(It.IsAny<ICollection<EmployerAgreementDto>>())).Returns(organisationAgreementViewModel);
_orchestrator = new EmployerAgreementOrchestrator(_mediator.Object, _mapper.Object, _referenceDataService.Object);
}

[Test]
public async Task ThenTheMediatorIsCalledWithAccountLegalEntityId()
public async Task ThenTheRequestForAllOrganisationAgreementsIsMadeForAccountLegalEntity()
{

//Act
Expand Down Expand Up @@ -88,7 +88,7 @@ public async Task ThenIfAUnauthroizedAccessExceptionIsThrownThenTheOrchestratorR
}

[Test]
public async Task ThenTheValuesAreReturnedInTheResponseFromTheMediatorCall()
public async Task ThenTheValuesAreReturnedInTheResponseFromTheRequestForAllOrganisationAgreementsIsMadeForAccountLegalEntity()
{
//Act
var actual = await _orchestrator.GetOrganisationAgreements(AccountLegalEntityHashedId);
Expand Down
14 changes: 2 additions & 12 deletions src/SFA.DAS.EmployerAccounts.Web/Helpers/HtmlHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,13 @@ public static string GetClaimsHashedAccountId(this HtmlHelper htmlHelper)

public static string GetAgreementHistoryTabTitle(this HtmlHelper htmlHelper , int versionNumber)
{
if (versionNumber == 1) return "Published 9 January 2020";
if (versionNumber == 3) return "Published 9 January 2020";
if (versionNumber == 2) return "Published 1 May 2018";
if (versionNumber == 3) return "Published 1 May 2017";
if (versionNumber == 1) return "Published 1 May 2017";

return string.Empty;
}

public static string GetAgreementTabListId(this HtmlHelper htmlHelper, int versionNumber)
{
return $"#v{versionNumber}-agreement";
}

public static string GetAgreementTabPanelId(this HtmlHelper htmlHelper, int versionNumber)
{
return $"v{versionNumber}-agreement";
}

public static bool ViewExists(this HtmlHelper html, string viewName)
{
var controllerContext = html.ViewContext.Controller.ControllerContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public AgreementMappings()
CreateMap<AccountDetailViewModel, AgreementInfoViewModel>()
.ConvertUsing(new AgreementInfoConverter());

CreateMap<EmployerAgreementDto, EmployerAgreementViewModelV1>()
CreateMap<EmployerAgreementDto, OrganisationAgreementViewModel>()
.ForMember(dest => dest.SignedDateText, opt => opt.MapFrom(src => src.SignedDate.HasValue ? src.SignedDate.Value.ToString("dd MMMM yyyy") : ""))
.ForMember(dest => dest.AccountLegalEntityPublicHashedId, opts => opts.Ignore());
.ForMember(dest => dest.AccountLegalEntityPublicHashedId, opts => opts.Ignore())
.ForMember(dest => dest.GetAgreementTabListId, opts => opts.Ignore())
.ForMember(dest => dest.GetAgreementTabPanelId, opts => opts.Ignore());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ public virtual async Task<OrchestratorResponse<ConfirmLegalAgreementToRemoveView
return response;
}

public virtual async Task<OrchestratorResponse<ICollection<EmployerAgreementViewModelV1>>> GetOrganisationAgreements(string accountLegalEntityHashedId)
public virtual async Task<OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>> GetOrganisationAgreements(string accountLegalEntityHashedId)
{
var response = new OrchestratorResponse<ICollection<EmployerAgreementViewModelV1>>();
var response = new OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>();

try
{
Expand All @@ -380,20 +380,20 @@ public virtual async Task<OrchestratorResponse<ICollection<EmployerAgreementView
AccountLegalEntityHashedId = accountLegalEntityHashedId
});

response.Data = _mapper.Map<ICollection<EmployerAgreementDto>, ICollection<EmployerAgreementViewModelV1>>(result.Agreements);
response.Data = _mapper.Map<ICollection<EmployerAgreementDto>, ICollection<OrganisationAgreementViewModel>>(result.Agreements);
}
catch (InvalidRequestException ex)
{
return new OrchestratorResponse<ICollection<EmployerAgreementViewModelV1>>
return new OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>
{
Status = HttpStatusCode.BadRequest,
Data = new List<EmployerAgreementViewModelV1>(),
Data = new List<OrganisationAgreementViewModel>(),
Exception = ex
};
}
catch (UnauthorizedAccessException)
{
return new OrchestratorResponse<ICollection<EmployerAgreementViewModelV1>>
return new OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>
{
Status = HttpStatusCode.Unauthorized
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
<Compile Include="ViewModels\CallToActionViewModel.cs" />
<Compile Include="ViewModels\CohortViewModel.cs" />
<Compile Include="ViewModels\CreateUserAccountViewModel.cs" />
<Compile Include="ViewModels\EmployerAgreementViewModelV1.cs" />
<Compile Include="ViewModels\OrganisationAgreementViewModel.cs" />
<Compile Include="ViewModels\SignEmployerAgreementViewModel.cs" />
<Compile Include="ViewModels\PensionRegulatorDetailsViewModel.cs" />
<Compile Include="ViewModels\PanelViewModel.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using SFA.DAS.EmployerAccounts.Models.EmployerAgreement;
namespace SFA.DAS.EmployerAccounts.Web.ViewModels
{
public class EmployerAgreementViewModelV1
public class OrganisationAgreementViewModel
{
public long Id { get; set; }
public DateTime? ExpiredDate { get; set; }
Expand All @@ -21,7 +21,10 @@ public class EmployerAgreementViewModelV1
public string HashedAgreementId { get; set; }

public string AccountLegalEntityPublicHashedId => AccountLegalEntity.PublicHashedId;

public string SignedDateText { get; set; }
public string GetAgreementTabListId => $"#v{Template.VersionNumber}-agreement";
public string GetAgreementTabPanelId => $"#v{Template.VersionNumber}-agreement";


}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{Layout = "~/Views/Shared/_Layout_CDN.cshtml"; }
@using SFA.DAS.EmployerAccounts.Web.Helpers
@model OrchestratorResponse<ICollection<EmployerAgreementViewModelV1>>
@model OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>
@{
ViewBag.PageID = "organisations-agreements-details";
ViewBag.Title = "ViewAllAgreements";
Expand All @@ -19,15 +19,15 @@

@foreach (var item in Model.Data)
{
<ul class="govuk-tabs__list">
<ul class="govuk-tabs__list">
<li class="govuk-tabs__list-item govuk-tabs__list-item--selected">
<a class="govuk-tabs__tab" href=@Html.GetAgreementTabListId(@item.Template.VersionNumber)>
<a class="govuk-tabs__tab" href=@item.GetAgreementTabListId>
@Html.GetAgreementHistoryTabTitle(@item.Template.VersionNumber)
</a>
</li>
</ul>

<div class="govuk-tabs__panel" id=@Html.GetAgreementTabPanelId(@item.Template.VersionNumber)>
<div class="govuk-tabs__panel" id=@item.GetAgreementTabPanelId>

@if (item.SignedDate != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model SFA.DAS.EmployerAccounts.Web.ViewModels.EmployerAgreementViewModelV1
@model SFA.DAS.EmployerAccounts.Web.ViewModels.OrganisationAgreementViewModel


<p>This agreement allows you to spend funds for <strong> @Model.AccountLegalEntity.Name</strong>.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

@model SFA.DAS.EmployerAccounts.Web.ViewModels.EmployerAgreementViewModelV1
@model SFA.DAS.EmployerAccounts.Web.ViewModels.OrganisationAgreementViewModel


<insettext>This is a new agreement.</insettext>
Expand Down
11 changes: 7 additions & 4 deletions src/SFA.DAS.EmployerAccounts/Data/EmployerAgreementRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ public async Task SetAccountLegalEntityAgreementDetails(long accountLegalEntityI
public async Task<AccountLegalEntity> GetOrganisationAgreement(long accountLegalEntityId)
{
var accountLegalEntity = await _db.Value.AccountLegalEntities
.Include(x => x.LegalEntity)
.Include(x => x.Agreements.Select(y => y.Template))
.SingleOrDefaultAsync(x => x.Id == accountLegalEntityId);
.Where(ale => ale.Id == accountLegalEntityId
&& ale.Deleted == null
&& ale.Agreements.Any(ea =>
ea.StatusId == EmployerAgreementStatus.Pending ||
ea.StatusId == EmployerAgreementStatus.Signed))
.SingleOrDefaultAsync()
.ConfigureAwait(false);

return accountLegalEntity;

}
}
}
6 changes: 2 additions & 4 deletions src/SFA.DAS.EmployerAccounts/Models/Account/LegalEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ public class LegalEntity
{
public virtual long Id { get; set; }
public virtual string Code { get; set; }
public virtual DateTime? DateOfIncorporation { get; set; }
//public virtual string Name { get; set; }
public virtual byte? PublicSectorDataSource { get; set; }
//public virtual string RegisteredAddress { get; set; }
public virtual DateTime? DateOfIncorporation { get; set; }
public virtual byte? PublicSectorDataSource { get; set; }
public virtual string Sector { get; set; }
public virtual OrganisationType Source { get; set; }
public virtual string Status { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using SFA.DAS.EmployerAccounts.Models.EmployerAgreement;
using System.Collections.Generic;
using System.Collections.Generic;
using SFA.DAS.EmployerAccounts.Dtos;

namespace SFA.DAS.EmployerAccounts.Queries.GetOrganisationAgreements
{
public class GetOrganisationAgreementsResponse
{
//public OrganisationAgreement OrganisationAgreements { get; set; }

public virtual ICollection<EmployerAgreementDto> Agreements { get; set; } = new List<EmployerAgreementDto>();
}
}

0 comments on commit d7bf19c

Please sign in to comment.