diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/HomeControllerTests/WhenIViewTheHomePage.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/HomeControllerTests/WhenIViewTheHomePage.cs index 59d18d773b..e48451e151 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/HomeControllerTests/WhenIViewTheHomePage.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/HomeControllerTests/WhenIViewTheHomePage.cs @@ -221,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())).ReturnsAsync( + new OrchestratorResponse + { + Data = new UserAccountsViewModel + { + Accounts = new Accounts + { + AccountList = new List { 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>(viewModel); + var userAccountsViewModel = (OrchestratorResponse)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())).ReturnsAsync( + new OrchestratorResponse + { + Data = new UserAccountsViewModel + { + Accounts = new Accounts + { + AccountList = new List { 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>(viewModel); + var userAccountsViewModel = (OrchestratorResponse)viewModel; + + Assert.AreEqual(false, userAccountsViewModel.Data.ShowTermsAndConditionBanner); + } } } diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs index 5806c0b6b7..fb86277887 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs @@ -48,6 +48,7 @@ public class WhenGettingAccount private Mock _mapper; private List _tasks; private AccountTask _testTask; + private DateTime LastTermsAndConditionsUpdate; [SetUp] public void Arrange() @@ -155,7 +156,10 @@ public void Arrange() _mapper = new Mock(); - _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, _currentDateTime.Object, _accountApiClient.Object, _mapper.Object, Mock.Of()); + LastTermsAndConditionsUpdate = DateTime.Now.AddDays(-10); + var employerAccountsConfiguration = new EmployerAccountsConfiguration { LastTermsAndConditionsUpdate = LastTermsAndConditionsUpdate }; + + _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, _currentDateTime.Object, _accountApiClient.Object, _mapper.Object, employerAccountsConfiguration); } [Test] @@ -171,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())) + .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())) + .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() {