Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cv 588 Select New employer #119

Open
wants to merge 46 commits into
base: CV-587_InformPage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b4f19f2
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
Feb 19, 2020
a271771
CV-588 Change Of Employer
Feb 20, 2020
6f1fb67
CV-588 Added more test.
Feb 21, 2020
67b3319
CV-588 Code Refactoring.
Feb 24, 2020
5d1298d
Merge branch 'master' into CV-588-Change-Employer
Feb 24, 2020
948449a
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
Feb 24, 2020
57517ff
CV-588 Code refactoring.
Feb 24, 2020
1ef7abf
Cv-588 Cohort Refactoring
Feb 24, 2020
e83af2f
CV-588 Code Refactoring.
Feb 24, 2020
1230c77
cv-588
Feb 24, 2020
5d20081
CV-588 Code review changes.
Feb 25, 2020
46216c7
Confirm employer WIP
chrisfoster76 Feb 26, 2020
6b94477
Merge branch 'CV-588-Change-Employer' into CV-589-Confirm-Employer
Feb 26, 2020
fc7b512
Merge branch 'master' into CV-588-Change-Employer
Feb 27, 2020
217dd73
Merge branch 'CV-856_ChangeEmployerLink' into CV-588-Change-Employer
Feb 27, 2020
f218315
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
Feb 27, 2020
80450bc
CV-589 Adding views
Feb 27, 2020
abb6a87
CV-589 Added tests and validator
Feb 27, 2020
ba10cfa
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
Pauljgraham Feb 28, 2020
3076ccf
CV-589 Fix url
Feb 28, 2020
6ed9855
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
Pauljgraham Feb 28, 2020
0b850bc
CV-589 More tests.
Feb 28, 2020
37e3ee7
removed extra title after merge
Pauljgraham Feb 28, 2020
294fe71
CV-589 Removed commented code
Feb 28, 2020
c79cb70
CV-589 Renamed folder
Feb 28, 2020
2509810
CV-589 Refactoring
Feb 28, 2020
14085de
CV-589
Feb 28, 2020
a713cb9
Merge branch 'master' into CV-589-Confirm-Employer
Mar 2, 2020
95f9170
Merge branch 'master' into CV-589-Reactoring-Changes
Mar 2, 2020
00e010a
Merge branch 'CV-588-Change-Employer' into CV-589-Confirm-Employer
Mar 2, 2020
5011e70
Merge branch 'CV-588-Change-Employer' into CV-589-Reactoring-Changes
Mar 2, 2020
66e1076
Merge branch 'CV-589-Confirm-Employer' into CV-589-Reactoring-Changes
Mar 2, 2020
db5b2c4
Test Review: added id's to apprentice details v2
AkshayBanifatsyevichChugh Mar 2, 2020
6869ebc
CV-589 Tech review changes.
Mar 2, 2020
a1d1bd3
CV-589 Test fix
Mar 2, 2020
323caaa
Merge pull request #127 from SkillsFundingAgency/CV-589-Reactoring-Ch…
hkf-tech Mar 2, 2020
36ba3fd
CV-589 Test file name changed.
Mar 2, 2020
d15a35c
CV-589 Tech review changes.
Mar 2, 2020
829c4a5
Merge pull request #128 from SkillsFundingAgency/CV-583-DataLock-Tria…
Najamuddin-Muhammad Mar 2, 2020
04dabc7
Merge branch 'master' into CV-589-Confirm-Employer
Mar 3, 2020
af5535f
CV-635 Footer Changes.
Mar 4, 2020
ab27751
CV-635 Updated the shared UI package.
Mar 5, 2020
f2ff117
Merge pull request #130 from SkillsFundingAgency/CV-635-Footer
hkf-tech Mar 5, 2020
c63c2ed
CV-586 Bug Fix
Mar 6, 2020
7d85785
CV-589
Mar 6, 2020
c251197
Merge pull request #126 from SkillsFundingAgency/CV-589-Confirm-Employer
Najamuddin-Muhammad Mar 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.ProviderCommitments.Web.Controllers;
using SFA.DAS.ProviderCommitments.Web.Models.Apprentice;
using SFA.DAS.ProviderCommitments.Web.Models.Shared;
using SFA.DAS.ProviderCommitments.Web.Requests.Apprentice;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Controllers.ApprenticesControllerTests
{
[TestFixture]
public class WhenGettingSelectEmployer
{
[Test]
public async Task ThenCallsModelMapper()
{
var fixture = new SelectEmployerFixture();

await fixture.Act();

fixture.VerifyMapperWasCalled();
}

[Test]
public async Task ThenReturnsView()
{
var fixture = new SelectEmployerFixture();

var result = await fixture.Act() as ViewResult;

Assert.NotNull(result);
Assert.AreEqual(typeof(SelectEmployerViewModel), result.Model.GetType());
}
}

public class SelectEmployerFixture
{
public ApprenticeController Sut { get; set; }

private readonly Mock<IModelMapper> _modelMapperMock;
private readonly SelectEmployerViewModel _viewModel;
private readonly SelectEmployerRequest _request;

public SelectEmployerFixture()
{
_request = new SelectEmployerRequest { ProviderId = 1, ApprenticeshipId = 1 };
_modelMapperMock = new Mock<IModelMapper>();
_viewModel = new SelectEmployerViewModel
{
AccountProviderLegalEntities = new List<AccountProviderLegalEntityViewModel>(),
};

_modelMapperMock
.Setup(x => x.Map<SelectEmployerViewModel>(_request))
.ReturnsAsync(_viewModel);

Sut = new ApprenticeController(_modelMapperMock.Object);
}

public SelectEmployerFixture WithModelStateErrors()
{
Sut.ControllerContext.ModelState.AddModelError("TestError", "Test Error");
return this;
}

public void VerifyMapperWasCalled()
{
_modelMapperMock.Verify(x => x.Map<SelectEmployerViewModel>(_request));
}

public async Task<IActionResult> Act() => await Sut.SelectEmployer(_request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.ProviderCommitments.Web.Controllers;
using SFA.DAS.ProviderCommitments.Web.Models;
using SFA.DAS.ProviderCommitments.Web.Requests;
using SFA.DAS.ProviderUrlHelper;
using AutoFixture;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.ProviderCommitments.Web.Requests.Cohort;
using SFA.DAS.ProviderCommitments.Web.Models.Cohort;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Controllers.CohortControllerTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.ProviderCommitments.Web.Controllers;
using SFA.DAS.ProviderCommitments.Web.Models;
using SFA.DAS.ProviderCommitments.Web.Requests;
using SFA.DAS.ProviderCommitments.Web.Models.Cohort;
using SFA.DAS.ProviderCommitments.Web.Models.Shared;
using SFA.DAS.ProviderCommitments.Web.Requests.Cohort;
using SFA.DAS.ProviderUrlHelper;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Controllers.CohortControllerTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using System.Threading;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.ProviderCommitments.Web.Models.Cohort;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Controllers.CohortControllerTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.ProviderCommitments.Web.Mappers;
using SFA.DAS.ProviderCommitments.Web.Models;
using SFA.DAS.ProviderCommitments.Web.Requests;
using SFA.DAS.ProviderCommitments.Web.Mappers.Cohort;
using SFA.DAS.ProviderCommitments.Web.Models.Cohort;
using SFA.DAS.ProviderCommitments.Web.Requests.Cohort;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.ProviderCommitments.Web.Mappers;
using SFA.DAS.ProviderCommitments.Web.Models;
using SFA.DAS.ProviderCommitments.Web.Mappers.Cohort;
using SFA.DAS.ProviderCommitments.Web.Models.Cohort;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.ProviderCommitments.Web.Mappers.Apprentice;
using SFA.DAS.ProviderCommitments.Web.Models.Apprentice;
using SFA.DAS.ProviderCommitments.Web.Requests.Apprentice;
using SFA.DAS.ProviderRelationships.Api.Client;
using SFA.DAS.ProviderRelationships.Types.Dtos;
using SFA.DAS.ProviderRelationships.Types.Models;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Mappers.SelectApprenticeEmployerRequestToViewModelTests
{
[TestFixture]
public class WhenIMapSelectEmployerRequestToViewModel
{
[Test]
public async Task ThenCallsProviderRelationshipsApiClient()
{
var fixture = new SelectEmployerViewModelMapperFixture();

await fixture.Act();

fixture.Verify_ProviderRelationshipsApiClientWasCalled_Once();
}

[Test]
public async Task ThenCallsCommitmentsApiClient()
{
var fixture = new SelectEmployerViewModelMapperFixture();

await fixture.Act();

fixture.Verify_CommitmentApiClientWasCalled_Once();
}

[Test]
public async Task ThenCorrectlyMapsApiResponseToViewModel()
{
var fixture = new SelectEmployerViewModelMapperFixture();

var result = await fixture.Act();

fixture.Assert_SelectEmployerViewModelCorrectlyMapped(result);
}

[Test]
public async Task ThenDontReturnTheExistingEmployer()
{
var fixture = new SelectEmployerViewModelMapperFixture();

var result = await fixture.Act();

fixture.Assert_SelectEmployerViewModelCorrectlyMapped(result);
}

[Test]
public async Task ThenCorrectlyMapsEmptyApiResponseToViewModel()
{
var fixture = new SelectEmployerViewModelMapperFixture().WithNoMatchingEmployers();

var result = await fixture.Act();

fixture.Assert_ListOfEmployersIsEmpty(result);
}
}

public class SelectEmployerViewModelMapperFixture
{
private readonly SelectEmployerViewModelMapper _sut;
private readonly Mock<IProviderRelationshipsApiClient> _providerRelationshipsApiClientMock;
private readonly Mock<ICommitmentsApiClient> _commitmentApiClientMock;
private readonly SelectEmployerRequest _request;
private readonly long _providerId;
private readonly long _accountLegalEntityId;
private readonly long _apprenticeshipId;
private readonly GetAccountProviderLegalEntitiesWithPermissionResponse _apiResponse;

public SelectEmployerViewModelMapperFixture()
{
_providerId = 123;
_accountLegalEntityId = 457;
_apprenticeshipId = 1;
_request = new SelectEmployerRequest { ProviderId = _providerId, ApprenticeshipId = _apprenticeshipId};
_apiResponse = new GetAccountProviderLegalEntitiesWithPermissionResponse
{
AccountProviderLegalEntities = new List<AccountProviderLegalEntityDto>
{
new AccountProviderLegalEntityDto
{
AccountId = 123,
AccountLegalEntityPublicHashedId = "DSFF23",
AccountLegalEntityName = "TestAccountLegalEntityName",
AccountPublicHashedId = "DFKFK66",
AccountName = "TestAccountName",
AccountLegalEntityId = 456,
AccountProviderId = 234
},
new AccountProviderLegalEntityDto
{
AccountId = 124,
AccountLegalEntityPublicHashedId = "DSFF24",
AccountLegalEntityName = "TestAccountLegalEntityName2",
AccountPublicHashedId = "DFKFK67",
AccountName = "TestAccountNam2",
AccountLegalEntityId = _accountLegalEntityId,
AccountProviderId = 235
}
}
};

_providerRelationshipsApiClientMock = new Mock<IProviderRelationshipsApiClient>();
_providerRelationshipsApiClientMock
.Setup(x => x.GetAccountProviderLegalEntitiesWithPermission(
It.IsAny<GetAccountProviderLegalEntitiesWithPermissionRequest>(),
CancellationToken.None))
.ReturnsAsync(_apiResponse);

_commitmentApiClientMock = new Mock<ICommitmentsApiClient>();

_commitmentApiClientMock.Setup(x => x.GetApprenticeship(_apprenticeshipId, It.IsAny<CancellationToken>()))
.ReturnsAsync(new CommitmentsV2.Api.Types.Responses.GetApprenticeshipResponse
{
AccountLegalEntityId = _accountLegalEntityId
});

_sut = new SelectEmployerViewModelMapper(_providerRelationshipsApiClientMock.Object, _commitmentApiClientMock.Object);
}

public async Task<SelectEmployerViewModel> Act() => await _sut.Map(_request);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra lines not needed


public SelectEmployerViewModelMapperFixture WithNoMatchingEmployers()
{
_providerRelationshipsApiClientMock
.Setup(x => x.GetAccountProviderLegalEntitiesWithPermission(
It.IsAny<GetAccountProviderLegalEntitiesWithPermissionRequest>(),
CancellationToken.None))
.ReturnsAsync(new GetAccountProviderLegalEntitiesWithPermissionResponse());

return this;
}

public void Verify_ProviderRelationshipsApiClientWasCalled_Once()
{
_providerRelationshipsApiClientMock.Verify(x => x.GetAccountProviderLegalEntitiesWithPermission(
It.Is<GetAccountProviderLegalEntitiesWithPermissionRequest>(y =>
y.Ukprn == _request.ProviderId &&
y.Operation == Operation.CreateCohort), CancellationToken.None), Times.Once);
}

public void Verify_CommitmentApiClientWasCalled_Once()
{
_commitmentApiClientMock.Verify(x => x.GetApprenticeship(_apprenticeshipId, CancellationToken.None), Times.Once);
}

public void Assert_SelectEmployerViewModelCorrectlyMapped(Web.Models.Apprentice.SelectEmployerViewModel result)
{
var filteredLegalEntities = _apiResponse.AccountProviderLegalEntities.Where(x => x.AccountLegalEntityId != _accountLegalEntityId);
Assert.AreEqual(filteredLegalEntities.Count(), result.AccountProviderLegalEntities.Count());

foreach (var entity in filteredLegalEntities)
{
Assert.True(result.AccountProviderLegalEntities.Any(x =>
x.EmployerAccountLegalEntityName == entity.AccountLegalEntityName &&
x.EmployerAccountLegalEntityPublicHashedId == entity.AccountLegalEntityPublicHashedId &&
x.EmployerAccountName == entity.AccountName &&
x.EmployerAccountPublicHashedId == entity.AccountPublicHashedId));
}
}

public void Assert_ListOfEmployersIsEmpty(SelectEmployerViewModel result)
{
Assert.AreEqual(0, result.AccountProviderLegalEntities.Count());
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using SFA.DAS.ProviderCommitments.Web.Mappers;
using SFA.DAS.ProviderCommitments.Web.Models;
using SFA.DAS.ProviderCommitments.Web.Requests;
using SFA.DAS.ProviderCommitments.Web.Mappers.Cohort;
using SFA.DAS.ProviderCommitments.Web.Models.Cohort;
using SFA.DAS.ProviderCommitments.Web.Requests.Cohort;
using SFA.DAS.ProviderRelationships.Api.Client;
using SFA.DAS.ProviderRelationships.Types.Dtos;
using SFA.DAS.ProviderRelationships.Types.Models;
using SFA.DAS.ProviderUrlHelper;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Mappers.SelectEmployerRequestToViewModelTests
namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Mappers.SelectCohortEmployerRequestToViewModelTests
{
[TestFixture]
public class WhenIMapSelectEmployerRequestToViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using NUnit.Framework;
using SFA.DAS.ProviderCommitments.Web.Requests.Apprentice;
using System;
using System.Linq.Expressions;
using FluentValidation.TestHelper;
using SFA.DAS.ProviderCommitments.Web.Validators.Apprentice;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Validators.Apprentice
{
[TestFixture]
public class SelectEmployerRequestValidatorTests
{

[TestCase(0, false)]
[TestCase(1, true)]
public void ThenProviderIdIsValidated(long providerId, bool expectedValid)
{
var request = new SelectEmployerRequest { ProviderId = providerId };
AssertValidationResult(x => x.ProviderId, request, expectedValid);
}

[TestCase(0, false)]
[TestCase(1, true)]
public void ThenApprenticeshipIdIsValidated(long apprenticeshipId, bool expectedValid)
{
var request = new SelectEmployerRequest { ApprenticeshipId = apprenticeshipId };
AssertValidationResult(x => x.ApprenticeshipId, request, expectedValid);
}

private void AssertValidationResult<T>(Expression<Func<SelectEmployerRequest, T>> property, SelectEmployerRequest instance, bool expectedValid)
{
var validator = new SelectEmployerRequestValidator();

if (expectedValid)
{
validator.ShouldNotHaveValidationErrorFor(property, instance);
}
else
{
validator.ShouldHaveValidationErrorFor(property, instance);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using FluentValidation.TestHelper;
using NUnit.Framework;
using SFA.DAS.ProviderCommitments.Web.Requests;
using SFA.DAS.ProviderCommitments.Web.Validators;
using SFA.DAS.ProviderCommitments.Web.Requests.Cohort;
using SFA.DAS.ProviderCommitments.Web.Validators.Cohort;
using System;
using System.Linq.Expressions;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Validators
namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Validators.Cohort
{
[TestFixture]
public class ConfirmEmployerRequestValidatorTests
Expand Down
Loading