Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…mployerapprenticeshipsservice into TM-133-Hide_the_option_to_create_a_transfers_pledge_from_levy_receivers_and_non-levy_employers
  • Loading branch information
sscaife committed Sep 15, 2021
2 parents 8d54d43 + d1d88b4 commit 0c2bce6
Show file tree
Hide file tree
Showing 38 changed files with 948 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<None Include="Scripts\PostDeployment\AML-3762-EOI-API.sql" />
<None Include="Scripts\Manual\AML-3655_GenerateFinanceDataInserts.sql" />
<None Include="Scripts\PostDeployment\UpdateAgreementTemplateV3.sql" />
<None Include="Scripts\Manual\CON-3921-DataFixForTermAndConditionsAcceptedOn.sql" />
</ItemGroup>
<ItemGroup>
<Build Include="Tables\Invitation.sql" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Update TermsAndConditionsAcceptedOn for all users created afer 28th July 2021
Update U
Set U.TermAndConditionsAcceptedOn = T.CreatedDate
From [employer_account].[User] U
Inner join (
Select UserId, CreatedDate from (
Select *, ROW_NUMBER() over (partition by M.UserId order by M.CreatedDate) As Rank2
from [employer_account].[Membership] M
) Result
Where Result.Rank2 = 1
and CreatedDate >= CONVERT(DATETIME,'28/07/2021',103) --dd/MM/yyyy
) T on U.Id = T.UserId
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ AS
USING (SELECT @userRef AS UserRef) AS [Source]
ON [Target].UserRef = [Source].UserRef
WHEN MATCHED THEN UPDATE SET [Target].Email = @email, [Target].FirstName = @firstName, [Target].LastName = @lastName, [Target].CorrelationId = COALESCE(@correlationId, [Target].CorrelationId)
WHEN NOT MATCHED THEN INSERT (UserRef, Email, FirstName, LastName, CorrelationId) VALUES (@userRef, @email, @firstName, @lastName, @correlationId);
WHEN NOT MATCHED THEN INSERT (UserRef, Email, FirstName, LastName, CorrelationId, TermAndConditionsAcceptedOn) VALUES (@userRef, @email, @firstName, @lastName, @correlationId, GETDATE());
3 changes: 2 additions & 1 deletion src/SFA.DAS.EAS.Employer_Account.Database/Tables/User.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[Email] NVARCHAR(255) NOT NULL UNIQUE,
[FirstName] NVARCHAR(MAX) NULL,
[LastName] NVARCHAR(MAX) NULL,
[CorrelationId] NVARCHAR(255) NULL
[CorrelationId] NVARCHAR(255) NULL,
[TermAndConditionsAcceptedOn] DATETIME NULL
)
GO

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Threading.Tasks;
using System.Web.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.EmployerAccounts.Configuration;
using SFA.DAS.EmployerAccounts.Interfaces;
using SFA.DAS.EmployerAccounts.Web.Controllers;
using SFA.DAS.EmployerAccounts.Web.Orchestrators;
using SFA.DAS.EmployerAccounts.Web.ViewModels;
using SFA.DAS.EmployerUsers.WebClientComponents;
using SFA.DAS.Authentication;
using SFA.DAS.EmployerAccounts.Web.Models;
using SFA.DAS.NLog.Logger;

namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Controllers.HomeControllerTests
{
public class WhenIViewTermsAndCondition : ControllerTestBase
{
private Mock<IAuthenticationService> _owinWrapper;
private Mock<HomeOrchestrator> _homeOrchestrator;
private EmployerAccountsConfiguration _configuration;
private Mock<IMultiVariantTestingService> _userViewTestingService;
private HomeController _homeController;
private Mock<ICookieStorageService<FlashMessageViewModel>> _flashMessage;

[SetUp]
public void Arrage()
{
base.Arrange();

_owinWrapper = new Mock<IAuthenticationService>();
_homeOrchestrator = new Mock<HomeOrchestrator>();
_userViewTestingService = new Mock<IMultiVariantTestingService>();
_flashMessage = new Mock<ICookieStorageService<FlashMessageViewModel>>();
_configuration = new EmployerAccountsConfiguration();

_homeController = new HomeController(
_owinWrapper.Object,
_homeOrchestrator.Object,
_configuration,
_userViewTestingService.Object,
_flashMessage.Object,
Mock.Of<ICookieStorageService<ReturnUrlModel>>(),
Mock.Of<ILog>())
{
ControllerContext = _controllerContext.Object
};
}

[Test]
public void ThenTheViewIsReturned()
{
//Act
var actual = _homeController.TermsAndConditions("returnUrl", "hashedId");

//Assert
Assert.IsNotNull(actual);
Assert.IsAssignableFrom<ViewResult>(actual);
}

[Test]
public void ThenTheViewModelIsMappedCorrectly()
{
//Act
var result = _homeController.TermsAndConditions("returnUrl", "hashedId");

//Assert
var viewResult = (ViewResult)result;
var viewModel = viewResult.Model;

Assert.IsInstanceOf<TermsAndConditionViewModel>(viewModel);
var termsAndConditionViewModel = (TermsAndConditionViewModel)viewModel;

Assert.AreEqual("returnUrl", termsAndConditionViewModel.ReturnUrl);
Assert.AreEqual("hashedId", termsAndConditionViewModel.HashedAccountId);
}


[Test]
public async Task ThenIsRedirectedToEmployerTeamController()
{
var termsAndConditionViewModel = new TermsAndConditionViewModel() { HashedAccountId = "HashedId", ReturnUrl = "EmployerTeam" };
//Act
var result = await _homeController.TermsAndConditions(termsAndConditionViewModel);

//Assert
var redirectResult = (RedirectToRouteResult)result;

Assert.AreEqual("Index", redirectResult.RouteValues["action"].ToString());
Assert.AreEqual("EmployerTeam", redirectResult.RouteValues["controller"].ToString());
}

[Test]
public async Task ThenIsRedirectedToHomeController()
{
var termsAndConditionViewModel = new TermsAndConditionViewModel() { HashedAccountId = "HashedId", ReturnUrl = "Home" };
//Act
var result = await _homeController.TermsAndConditions(termsAndConditionViewModel);

//Assert
var redirectResult = (RedirectToRouteResult)result;

Assert.AreEqual("Index", redirectResult.RouteValues["action"].ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using SFA.DAS.Authentication;
using SFA.DAS.EmployerAccounts.Web.Models;
using SFA.DAS.NLog.Logger;
using System;

namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Controllers.HomeControllerTests
{
Expand All @@ -41,7 +42,7 @@ public void Arrange()

_homeOrchestrator = new Mock<HomeOrchestrator>();
_homeOrchestrator.Setup(x => x.GetUsers()).ReturnsAsync(new SignInUserViewModel());
_homeOrchestrator.Setup(x => x.GetUserAccounts(ExpectedUserId)).ReturnsAsync(
_homeOrchestrator.Setup(x => x.GetUserAccounts(ExpectedUserId, null)).ReturnsAsync(
new OrchestratorResponse<UserAccountsViewModel>
{
Data = new UserAccountsViewModel
Expand Down Expand Up @@ -92,7 +93,7 @@ public async Task ThenTheAccountsAreNotReturnedWhenYouAreNotAuthenticated()
await _homeController.Index();

//Assert
_homeOrchestrator.Verify(x => x.GetUserAccounts(It.IsAny<string>()), Times.Never);
_homeOrchestrator.Verify(x => x.GetUserAccounts(It.IsAny<string>(), It.IsAny<DateTime?>()), Times.Never);
}

[Test]
Expand Down Expand Up @@ -127,7 +128,7 @@ public async Task ThenTheAccountsAreReturnedForThatUserWhenAuthenticated()
await _homeController.Index();

//Assert
_homeOrchestrator.Verify(x => x.GetUserAccounts(ExpectedUserId), Times.Once);
_homeOrchestrator.Verify(x => x.GetUserAccounts(ExpectedUserId, It.IsAny<DateTime?>()), Times.Once);
}

[Test]
Expand Down Expand Up @@ -199,7 +200,7 @@ public async Task ThenIfIHaveMoreThanOneAccountIAmRedirectedToTheAccountsIndexPa
{
//Arrange
_owinWrapper.Setup(x => x.GetClaimValue("sub")).Returns(ExpectedUserId);
_homeOrchestrator.Setup(x => x.GetUserAccounts(ExpectedUserId)).ReturnsAsync(
_homeOrchestrator.Setup(x => x.GetUserAccounts(ExpectedUserId, It.IsAny<DateTime?>())).ReturnsAsync(
new OrchestratorResponse<UserAccountsViewModel>
{
Data = new UserAccountsViewModel
Expand All @@ -220,5 +221,75 @@ public async Task ThenIfIHaveMoreThanOneAccountIAmRedirectedToTheAccountsIndexPa
Assert.IsNotNull(actualViewResult);
Assert.AreEqual("", actualViewResult.ViewName);
}

[Test]
public async Task ThenIfIHaveMoreThanOneAccountIAmRedirectedToTheAccountsIndexPage_WithTermsAndConditionBannerDisplayed()
{
//Arrange
_owinWrapper.Setup(x => x.GetClaimValue("sub")).Returns(ExpectedUserId);
_homeOrchestrator.Setup(x => x.GetUserAccounts(ExpectedUserId, It.IsAny<DateTime?>())).ReturnsAsync(
new OrchestratorResponse<UserAccountsViewModel>
{
Data = new UserAccountsViewModel
{
Accounts = new Accounts<Account>
{
AccountList = new List<Account> { new Account(), new Account() }
},

LastTermsAndConditionsUpdate = DateTime.Now,
TermAndConditionsAcceptedOn = DateTime.Now.AddDays(-20)
}
});

//Act
var actual = await _homeController.Index();

//Assert
Assert.IsNotNull(actual);
var actualViewResult = actual as ViewResult;
Assert.IsNotNull(actualViewResult);

var viewModel = actualViewResult.Model;
Assert.IsInstanceOf<OrchestratorResponse<UserAccountsViewModel>>(viewModel);
var userAccountsViewModel = (OrchestratorResponse<UserAccountsViewModel>)viewModel;

Assert.AreEqual(true, userAccountsViewModel.Data.ShowTermsAndConditionBanner);
}

[Test]
public async Task ThenIfIHaveMoreThanOneAccountIAmRedirectedToTheAccountsIndexPage_WithTermsAndConditionBannerNotDisplayed()
{
//Arrange
_owinWrapper.Setup(x => x.GetClaimValue("sub")).Returns(ExpectedUserId);
_homeOrchestrator.Setup(x => x.GetUserAccounts(ExpectedUserId, It.IsAny<DateTime?>())).ReturnsAsync(
new OrchestratorResponse<UserAccountsViewModel>
{
Data = new UserAccountsViewModel
{
Accounts = new Accounts<Account>
{
AccountList = new List<Account> { new Account(), new Account() }
},

LastTermsAndConditionsUpdate = DateTime.Now.AddDays(-20),
TermAndConditionsAcceptedOn = DateTime.Now
}
});

//Act
var actual = await _homeController.Index();

//Assert
Assert.IsNotNull(actual);
var actualViewResult = actual as ViewResult;
Assert.IsNotNull(actualViewResult);

var viewModel = actualViewResult.Model;
Assert.IsInstanceOf<OrchestratorResponse<UserAccountsViewModel>>(viewModel);
var userAccountsViewModel = (OrchestratorResponse<UserAccountsViewModel>)viewModel;

Assert.AreEqual(false, userAccountsViewModel.Data.ShowTermsAndConditionBanner);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
using SFA.DAS.EmployerAccounts.Web.Orchestrators;
using SFA.DAS.EmployerAccounts.Web.ViewModels;
using SFA.DAS.EmployerAccounts.Queries.GetApprenticeship;
using SFA.DAS.EmployerAccounts.Configuration;
using SFA.DAS.EmployerAccounts.Queries.GetUserByRef;

namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Orchestrators.EmployerTeamOrchestratorTests
{
Expand All @@ -46,6 +48,7 @@ public class WhenGettingAccount
private Mock<IMapper> _mapper;
private List<AccountTask> _tasks;
private AccountTask _testTask;
private DateTime LastTermsAndConditionsUpdate;

[SetUp]
public void Arrange()
Expand Down Expand Up @@ -93,6 +96,15 @@ public void Arrange()
UserRole = Role.Owner
});

_mediator.Setup(m => m.SendAsync(It.IsAny<GetUserByRefQuery>()))
.ReturnsAsync(new GetUserByRefResponse
{
User = new SFA.DAS.EmployerAccounts.Models.UserProfile.User
{
TermAndConditionsAcceptedOn = DateTime.Now
}
});

_mediator.Setup(m => m.SendAsync(It.Is<GetAccountEmployerAgreementsRequest>(q => q.HashedAccountId == HashedAccountId)))
.ReturnsAsync(new GetAccountEmployerAgreementsResponse
{
Expand Down Expand Up @@ -144,7 +156,10 @@ public void Arrange()

_mapper = new Mock<IMapper>();

_orchestrator = new EmployerTeamOrchestrator(_mediator.Object, _currentDateTime.Object, _accountApiClient.Object, _mapper.Object);
LastTermsAndConditionsUpdate = DateTime.Now.AddDays(-10);
var employerAccountsConfiguration = new EmployerAccountsConfiguration { LastTermsAndConditionsUpdate = LastTermsAndConditionsUpdate };

_orchestrator = new EmployerTeamOrchestrator(_mediator.Object, _currentDateTime.Object, _accountApiClient.Object, _mapper.Object, employerAccountsConfiguration);
}

[Test]
Expand All @@ -160,6 +175,46 @@ public async Task ThenShouldGetAccountStats()
Assert.AreEqual(_accountStats.TeamMemberCount, actual.Data.TeamMemberCount);
}

[Test]
public async Task ThenShouldDispayTermsAndConditionBanner()
{
_mediator.Setup(m => m.SendAsync(It.IsAny<GetUserByRefQuery>()))
.ReturnsAsync(new GetUserByRefResponse
{
User = new SFA.DAS.EmployerAccounts.Models.UserProfile.User
{
TermAndConditionsAcceptedOn = LastTermsAndConditionsUpdate.AddDays(-1)
}
});

// Act
var actual = await _orchestrator.GetAccount(HashedAccountId, UserId);

//Assert
Assert.IsNotNull(actual.Data);
Assert.AreEqual(true, actual.Data.ShowTermsAndConditionBanner);
}

[Test]
public async Task ThenShouldNotDispayTermsAndConditionBanner()
{
_mediator.Setup(m => m.SendAsync(It.IsAny<GetUserByRefQuery>()))
.ReturnsAsync(new GetUserByRefResponse
{
User = new SFA.DAS.EmployerAccounts.Models.UserProfile.User
{
TermAndConditionsAcceptedOn = LastTermsAndConditionsUpdate.AddDays(1)
}
});

// Act
var actual = await _orchestrator.GetAccount(HashedAccountId, UserId);

//Assert
Assert.IsNotNull(actual.Data);
Assert.AreEqual(false, actual.Data.ShowTermsAndConditionBanner);
}

[Test]
public async Task ThenShouldReturnTasks()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NUnit.Framework;
using SFA.DAS.EAS.Account.Api.Client;
using SFA.DAS.EmployerAccounts.Commands.ChangeTeamMemberRole;
using SFA.DAS.EmployerAccounts.Configuration;
using SFA.DAS.EmployerAccounts.Interfaces;
using SFA.DAS.EmployerAccounts.Models;
using SFA.DAS.EmployerAccounts.Queries.GetAccountTeamMembers;
Expand All @@ -30,7 +31,7 @@ public void Arrange()
_accountApiClient = new Mock<IAccountApiClient>();
_mapper = new Mock<IMapper>();

_orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of<ICurrentDateTime>(), _accountApiClient.Object, _mapper.Object);
_orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of<ICurrentDateTime>(), _accountApiClient.Object, _mapper.Object, Mock.Of<EmployerAccountsConfiguration>());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Moq;
using NUnit.Framework;
using SFA.DAS.EAS.Account.Api.Client;
using SFA.DAS.EmployerAccounts.Configuration;
using SFA.DAS.EmployerAccounts.Interfaces;
using SFA.DAS.EmployerAccounts.Models;
using SFA.DAS.EmployerAccounts.Models.AccountTeam;
Expand Down Expand Up @@ -43,7 +44,7 @@ public void Arrange()
_accountApiClient = new Mock<IAccountApiClient>();
_mapper = new Mock<IMapper>();

_orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of<ICurrentDateTime>(), _accountApiClient.Object, _mapper.Object);
_orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of<ICurrentDateTime>(), _accountApiClient.Object, _mapper.Object, Mock.Of<EmployerAccountsConfiguration>());

_mediator.Setup(x => x.SendAsync(It.IsAny<GetMemberRequest>()))
.ReturnsAsync(_teamMemberResponse);
Expand Down
Loading

0 comments on commit 0c2bce6

Please sign in to comment.