Skip to content

Commit

Permalink
CON-3860 adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hkf-tech committed Aug 27, 2021
1 parent 9566864 commit c63f455
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 @@ -48,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 @@ -155,7 +156,10 @@ public void Arrange()

_mapper = new Mock<IMapper>();

_orchestrator = new EmployerTeamOrchestrator(_mediator.Object, _currentDateTime.Object, _accountApiClient.Object, _mapper.Object, Mock.Of<EmployerAccountsConfiguration>());
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 @@ -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<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

0 comments on commit c63f455

Please sign in to comment.