-
Notifications
You must be signed in to change notification settings - Fork 3
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
hkf-tech
wants to merge
46
commits into
CV-587_InformPage
Choose a base branch
from
CV-588-Change-Employer
base: CV-587_InformPage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
a271771
CV-588 Change Of Employer
6f1fb67
CV-588 Added more test.
67b3319
CV-588 Code Refactoring.
5d1298d
Merge branch 'master' into CV-588-Change-Employer
948449a
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
57517ff
CV-588 Code refactoring.
1ef7abf
Cv-588 Cohort Refactoring
e83af2f
CV-588 Code Refactoring.
1230c77
cv-588
5d20081
CV-588 Code review changes.
46216c7
Confirm employer WIP
chrisfoster76 6b94477
Merge branch 'CV-588-Change-Employer' into CV-589-Confirm-Employer
fc7b512
Merge branch 'master' into CV-588-Change-Employer
217dd73
Merge branch 'CV-856_ChangeEmployerLink' into CV-588-Change-Employer
f218315
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
80450bc
CV-589 Adding views
abb6a87
CV-589 Added tests and validator
ba10cfa
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
Pauljgraham 3076ccf
CV-589 Fix url
6ed9855
Merge branch 'CV-587_InformPage' into CV-588-Change-Employer
Pauljgraham 0b850bc
CV-589 More tests.
37e3ee7
removed extra title after merge
Pauljgraham 294fe71
CV-589 Removed commented code
c79cb70
CV-589 Renamed folder
2509810
CV-589 Refactoring
14085de
CV-589
a713cb9
Merge branch 'master' into CV-589-Confirm-Employer
95f9170
Merge branch 'master' into CV-589-Reactoring-Changes
00e010a
Merge branch 'CV-588-Change-Employer' into CV-589-Confirm-Employer
5011e70
Merge branch 'CV-588-Change-Employer' into CV-589-Reactoring-Changes
66e1076
Merge branch 'CV-589-Confirm-Employer' into CV-589-Reactoring-Changes
db5b2c4
Test Review: added id's to apprentice details v2
AkshayBanifatsyevichChugh 6869ebc
CV-589 Tech review changes.
a1d1bd3
CV-589 Test fix
323caaa
Merge pull request #127 from SkillsFundingAgency/CV-589-Reactoring-Ch…
hkf-tech 36ba3fd
CV-589 Test file name changed.
d15a35c
CV-589 Tech review changes.
829c4a5
Merge pull request #128 from SkillsFundingAgency/CV-583-DataLock-Tria…
Najamuddin-Muhammad 04dabc7
Merge branch 'master' into CV-589-Confirm-Employer
af5535f
CV-635 Footer Changes.
ab27751
CV-635 Updated the shared UI package.
f2ff117
Merge pull request #130 from SkillsFundingAgency/CV-635-Footer
hkf-tech c63c2ed
CV-586 Bug Fix
7d85785
CV-589
c251197
Merge pull request #126 from SkillsFundingAgency/CV-589-Confirm-Employer
Najamuddin-Muhammad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...itments.Web.UnitTests/Controllers/ApprenticesControllerTests/WhenGettingSelectEmployer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
...lectApprenticeEmployerRequestToViewModelTests/WhenIMapSelectEmployerRequestToViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
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()); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...derCommitments.Web.UnitTests/Validators/Apprentice/SelectEmployerRequestValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...s/ConfirmEmployerRequestValidatorTests.cs → ...t/ConfirmEmployerRequestValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra lines not needed