Skip to content

Commit

Permalink
Merge pull request #922 from SkillsFundingAgency/CON-1187-remove-lega…
Browse files Browse the repository at this point in the history
…lentityid

CON-1187-Remove LegalEntityId
  • Loading branch information
Najamuddin-Muhammad authored Sep 1, 2020
2 parents 348a2b9 + 06893a9 commit 6d6a591
Show file tree
Hide file tree
Showing 38 changed files with 106 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class CloneVacancyOrchestratorTestBase
internal Vacancy SourceVacancy => new Vacancy
{
Id = SourceVacancyId,
LegalEntityId = 1,
AccountLegalEntityPublicHashedId = "1",
EmployerAccountId = EmployerAccountId,
Status = VacancyStatus.Live,
StartDate = SourceStartDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ namespace Esfa.Recruit.Employer.UnitTests.Employer.Web.Services
public class LegalEntityAgreementServiceTests
{
const string EmployerAccountId = "ABCDEF";
const long LegalEntityId = 1234;
const string AccountLegalEntityPublicHashedId = "ABCDEF";

private Mock<IEmployerVacancyClient> _clientMock;

[Fact]
public void HasLegalEntityAgreementAsync_ShouldReturnFalseIfNoMatchingLegalEntity()
{
var sut = GetLegalEntityAgreementService(EmployerAccountId, 5678, true, 5678, true, "5678");
var sut = GetLegalEntityAgreementService(EmployerAccountId, true, "5678",true, "5678");

var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result;

Expand All @@ -32,7 +31,7 @@ public void HasLegalEntityAgreementAsync_ShouldReturnFalseIfNoMatchingLegalEntit
[Fact]
public void HasLegalEntityAgreementAsync_ShouldNotCheckEmployerServiceWhenHasAgreement()
{
var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, true, LegalEntityId, true, AccountLegalEntityPublicHashedId);
var sut = GetLegalEntityAgreementService(EmployerAccountId, true, AccountLegalEntityPublicHashedId,true, AccountLegalEntityPublicHashedId);

var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result;

Expand All @@ -43,7 +42,7 @@ public void HasLegalEntityAgreementAsync_ShouldNotCheckEmployerServiceWhenHasAgr
[Fact]
public void HasLegalEntityAgreementAsync_ShouldCheckEmployerServiceWhenHasNoAgreement()
{
var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, true, AccountLegalEntityPublicHashedId);
var sut = GetLegalEntityAgreementService(EmployerAccountId, false, AccountLegalEntityPublicHashedId,true, AccountLegalEntityPublicHashedId);

var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result;

Expand All @@ -55,7 +54,7 @@ public void HasLegalEntityAgreementAsync_ShouldCheckEmployerServiceWhenHasNoAgre
[Fact]
public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceLegalEntityHasNoAgreement()
{
var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, false, AccountLegalEntityPublicHashedId);
var sut = GetLegalEntityAgreementService(EmployerAccountId, false, AccountLegalEntityPublicHashedId,false, AccountLegalEntityPublicHashedId);

var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result;

Expand All @@ -67,7 +66,7 @@ public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceLeg
[Fact]
public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceCantLocateLegalEntity()
{
var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, 5678, true, AccountLegalEntityPublicHashedId);
var sut = GetLegalEntityAgreementService(EmployerAccountId, false, "5678", true, AccountLegalEntityPublicHashedId);

var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result;

Expand All @@ -76,8 +75,8 @@ public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceCan
_clientMock.Verify(c => c.SetupEmployerAsync(EmployerAccountId), Times.Never);
}

private LegalEntityAgreementService GetLegalEntityAgreementService(string employerAccountId, long legalEntityId,
bool hasLegalEntityAgreement, long employerServiceLegalEntityId,
private LegalEntityAgreementService GetLegalEntityAgreementService(string employerAccountId,
bool hasLegalEntityAgreement, string employerServiceAccountLegalEntityPublicHashedId,
bool employerServiceHasLegalEntityAgreement, string accountLegalEntityPublicHashedId)
{
_clientMock = new Mock<IEmployerVacancyClient>();
Expand All @@ -87,7 +86,6 @@ private LegalEntityAgreementService GetLegalEntityAgreementService(string employ
LegalEntities = new List<LegalEntity>
{
new LegalEntity{
LegalEntityId = legalEntityId,
HasLegalEntityAgreement = hasLegalEntityAgreement,
AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId
}
Expand All @@ -99,8 +97,8 @@ private LegalEntityAgreementService GetLegalEntityAgreementService(string employ
{
new LegalEntity
{
LegalEntityId = employerServiceLegalEntityId,
HasLegalEntityAgreement = employerServiceHasLegalEntityAgreement
HasLegalEntityAgreement = employerServiceHasLegalEntityAgreement,
AccountLegalEntityPublicHashedId = employerServiceAccountLegalEntityPublicHashedId
}
}
.AsEnumerable()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void ThenReturnsCorrectlyPolulatedLegalEntity()
var actual = LegalEntityMapper.MapFromAccountApiLegalEntity(expected);

// Assert
actual.LegalEntityId.Should().Be(expected.LegalEntityId);
actual.AccountLegalEntityPublicHashedId.Should().Be(expected.AccountLegalEntityPublicHashedId);
actual.Name.Should().Be(expected.Name);
actual.HasLegalEntityAgreement.Should().BeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
using Esfa.Recruit.Vacancies.Client.Domain.Events;
using Esfa.Recruit.Vacancies.Client.Domain.Models;
using Esfa.Recruit.Vacancies.Client.Infrastructure.QueryStore.Projections.EditVacancyInfo;
using Esfa.Recruit.Vacancies.Jobs.UnitTests.DomainEvents.Handlers.Provider.ProviderBlockedDomainEventHandlerTests;
using Moq;
using Newtonsoft.Json;
using Xunit;

namespace Esfa.Recruit.Vacancies.Jobs.UnitTests.DomainEvents.Handlers.Provider.ProviderBlockedDomainEventHandlerTests
namespace Recruit.Vacancies.Jobs.UnitTests.DomainEvents.Handlers.Provider.ProviderBlockedDomainEventHandlerTests
{
public class HandleAsyncTests : ProviderBlockedDomainEventHandlerTestBase
{
Expand Down Expand Up @@ -157,8 +158,8 @@ protected ProviderEditVacancyInfo GetProviderProfile()
EmployerAccountId = _employerAccount1,
LegalEntities = new List<LegalEntity>()
{
new LegalEntity() { LegalEntityId = 1, AccountLegalEntityPublicHashedId = _legalEntity1 },
new LegalEntity() { LegalEntityId = 2, AccountLegalEntityPublicHashedId = _legalEntity2 }
new LegalEntity() { AccountLegalEntityPublicHashedId = _legalEntity1 },
new LegalEntity() { AccountLegalEntityPublicHashedId = _legalEntity2 }
}
},
new EmployerInfo { EmployerAccountId = _employerAccount3 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Esfa.Recruit.Vacancies.Client.Application.Queues;
using Esfa.Recruit.Vacancies.Client.Application.Queues.Messages;
using Esfa.Recruit.Vacancies.Client.Domain.Messaging;
using Esfa.Recruit.Vacancies.Client.Domain.Repositories;
using Esfa.Recruit.Vacancies.Client.Infrastructure.QueryStore;
using Esfa.Recruit.Vacancies.Client.Infrastructure.Services.EmployerAccount;
using Esfa.Recruit.Vacancies.Jobs.Configuration;
using Esfa.Recruit.Vacancies.Jobs.ExternalSystemEventHandlers;
Expand All @@ -21,7 +19,7 @@
using SFA.DAS.ProviderRelationships.Types.Models;
using Xunit;

namespace Esfa.Recruit.Vacancies.Jobs.UnitTests.ExternalSystemEventHandlers
namespace Recruit.Vacancies.Jobs.UnitTests.ExternalSystemEventHandlers
{
public class UpdatedPermissionsExternalSystemEventHandlerTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Moq;
using Xunit;

namespace Esfa.Recruit.Vacancies.Jobs.UnitTests.Jobs
namespace Recruit.Vacancies.Jobs.UnitTests.Jobs
{
public class TransferVacanciesFromProviderJobTests
{
Expand All @@ -35,28 +35,34 @@ public TransferVacanciesFromProviderJobTests()
public async Task GivenRequest_WhenNoMatchingVacanciesToTransfer_AndProviderHasManyLegalEntityPermissions_ThenShouldNotQueueAnyTransfers()
{
const long Ukprn = 1;
const long LegalEntityId = 2;
const string AccountLegalEntityPublicHashedId = "2";
const string EmployerAccountId = "employer-account-id";

_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForLegalEntityAsync(Ukprn, LegalEntityId))
_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForLegalEntityAsync(Ukprn, AccountLegalEntityPublicHashedId))
.ReturnsAsync(Enumerable.Empty<Vacancy>());

var employerInfo = new EmployerInfo
{
LegalEntities = new List<LegalEntity>
{
new LegalEntity{LegalEntityId = LegalEntityId},
new LegalEntity{LegalEntityId = 12345}
new LegalEntity
{
AccountLegalEntityPublicHashedId = "2"
},
new LegalEntity
{
AccountLegalEntityPublicHashedId = "12345"
}
}
};

_mockQueryStoreReader.Setup(q => q.GetProviderEmployerVacancyDataAsync(Ukprn, EmployerAccountId))
.ReturnsAsync(employerInfo);

await _sut.Run(Ukprn, EmployerAccountId, LegalEntityId, Guid.NewGuid(), string.Empty, string.Empty, TransferReason.EmployerRevokedPermission);
await _sut.Run(Ukprn, EmployerAccountId, AccountLegalEntityPublicHashedId, Guid.NewGuid(), string.Empty, string.Empty, TransferReason.EmployerRevokedPermission);

_mockRecruitQueueService.Verify(x => x.AddMessageAsync(It.IsAny<TransferVacancyToLegalEntityQueueMessage>()), Times.Never);
_mockVacancyQuery.Verify(x => x.GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(It.IsAny<long>(), It.IsAny<string>()), Times.Never);
_mockVacancyQuery.Verify(x => x.GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(It.IsAny<long>(), It.IsAny<string>()), Times.Never);
}

[Fact]
Expand All @@ -68,27 +74,30 @@ public async Task GivenRequest_WhenMatchingVacanciesToTransfer_AndProviderHasSin
const string UserEmail = "[email protected]";
const string UserName = "John Smith";
const long Ukprn = 1;
const long LegalEntityId = 2;
const string AccountLegalEntityPublicHashedId = "2";
const string EmployerAccountId = "employer-account-id";

_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForLegalEntityAsync(Ukprn, LegalEntityId))
_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForLegalEntityAsync(Ukprn, AccountLegalEntityPublicHashedId))
.ReturnsAsync(new Fixture().CreateMany<Vacancy>(NoOfMatchingVacancies));

var employerInfo = new EmployerInfo
{
LegalEntities = new List<LegalEntity>
{
new LegalEntity{LegalEntityId = LegalEntityId}
new LegalEntity
{
AccountLegalEntityPublicHashedId = AccountLegalEntityPublicHashedId
}
}
};

_mockQueryStoreReader.Setup(q => q.GetProviderEmployerVacancyDataAsync(Ukprn, EmployerAccountId))
.ReturnsAsync(employerInfo);

_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(Ukprn, EmployerAccountId))
_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(Ukprn, EmployerAccountId))
.ReturnsAsync(new Fixture().CreateMany<Vacancy>(NoOfVacanciesWithoutLegalEntity));

await _sut.Run(Ukprn, EmployerAccountId, LegalEntityId, userRef, UserEmail, UserName, TransferReason.EmployerRevokedPermission);
await _sut.Run(Ukprn, EmployerAccountId, AccountLegalEntityPublicHashedId, userRef, UserEmail, UserName, TransferReason.EmployerRevokedPermission);

var expectedCallCount = NoOfMatchingVacancies + NoOfVacanciesWithoutLegalEntity;
_mockRecruitQueueService.Verify(x => x.AddMessageAsync(It.IsAny<TransferVacancyToLegalEntityQueueMessage>()), Times.Exactly(expectedCallCount));
Expand All @@ -102,27 +111,33 @@ public async Task GivenRequest_WhenMatchingVacanciesToTransfer_AndProviderHasMan
const string UserEmail = "[email protected]";
const string UserName = "John Smith";
const long Ukprn = 1;
const long LegalEntityId = 2;
const string AccountLegalEntityPublicHashedId = "2";
const string EmployerAccountId = "employer-account-id";

_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForLegalEntityAsync(Ukprn, LegalEntityId))
_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForLegalEntityAsync(Ukprn, AccountLegalEntityPublicHashedId))
.ReturnsAsync(new Fixture().CreateMany<Vacancy>(NoOfMatchingVacancies));

var employerInfo = new EmployerInfo
{
LegalEntities = new List<LegalEntity>
{
new LegalEntity{LegalEntityId = LegalEntityId},
new LegalEntity{LegalEntityId = 1234}
new LegalEntity
{
AccountLegalEntityPublicHashedId = AccountLegalEntityPublicHashedId
},
new LegalEntity
{
AccountLegalEntityPublicHashedId = "1234"
}
}
};

_mockQueryStoreReader.Setup(q => q.GetProviderEmployerVacancyDataAsync(Ukprn, EmployerAccountId))
.ReturnsAsync(employerInfo);

await _sut.Run(Ukprn, EmployerAccountId, LegalEntityId, userRef, UserEmail, UserName, TransferReason.EmployerRevokedPermission);
await _sut.Run(Ukprn, EmployerAccountId, AccountLegalEntityPublicHashedId, userRef, UserEmail, UserName, TransferReason.EmployerRevokedPermission);

_mockVacancyQuery.Verify(x => x.GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(It.IsAny<long>(), It.IsAny<string>()), Times.Never);
_mockVacancyQuery.Verify(x => x.GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(It.IsAny<long>(), It.IsAny<string>()), Times.Never);
_mockRecruitQueueService.Verify(x => x.AddMessageAsync(It.IsAny<TransferVacancyToLegalEntityQueueMessage>()), Times.Exactly(NoOfMatchingVacancies));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ private List<Task> RaiseEventsToRevokePermission(IEnumerable<EmployerInfo> emplo

foreach (var legalEntity in employer.LegalEntities)
{
_logger.LogInformation($"Queuing to revoke provider {ukprn} permission on account {employer.EmployerAccountId} for legal entity {legalEntity.LegalEntityId}.");
_logger.LogInformation($"Queuing to revoke provider {ukprn} permission on account {employer.EmployerAccountId} " +
$"for AccountLegalEntityPublicHashedId {legalEntity.AccountLegalEntityPublicHashedId}.");
var providerBlockedOnLegalEntityEvent = new ProviderBlockedOnLegalEntityEvent()
{
Ukprn = ukprn,
EmployerAccountId = employer.EmployerAccountId,
LegalEntityId = legalEntity.LegalEntityId,
AccountLegalEntityPublicHashedId = legalEntity.AccountLegalEntityPublicHashedId
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
using System.Linq;
using System.Threading.Tasks;
using Esfa.Recruit.Vacancies.Client.Domain.Events;
using Esfa.Recruit.Vacancies.Client.Infrastructure.Services.EmployerAccount;
using Esfa.Recruit.Vacancies.Client.Infrastructure.Services.ProviderRelationship;
using Microsoft.Extensions.Logging;

namespace Esfa.Recruit.Vacancies.Jobs.DomainEvents.Handlers.Provider
{
public class ProviderBlockedOnLegalEntityDomainEventHandler : DomainEventHandler, IDomainEventHandler<ProviderBlockedOnLegalEntityEvent>
{
private readonly IEmployerAccountProvider _employerAccountProvider;
private readonly IProviderRelationshipsService _providerRelationshipsService;
private readonly ILogger<ProviderBlockedOnLegalEntityDomainEventHandler> _logger;
public ProviderBlockedOnLegalEntityDomainEventHandler(
IEmployerAccountProvider employerAccountProvider,
IProviderRelationshipsService providerRelationshipsService,
public ProviderBlockedOnLegalEntityDomainEventHandler(IProviderRelationshipsService providerRelationshipsService,
ILogger<ProviderBlockedOnLegalEntityDomainEventHandler> logger) : base(logger)
{
_logger = logger;
_employerAccountProvider = employerAccountProvider;
_providerRelationshipsService = providerRelationshipsService;
}

public async Task HandleAsync(string eventPayload)
{
var eventData = DeserializeEvent<ProviderBlockedOnLegalEntityEvent>(eventPayload);

_logger.LogInformation($"Attempting to revoke provider {eventData.Ukprn} permission on account {eventData.EmployerAccountId} with public hash {eventData.AccountLegalEntityPublicHashedId} for legal entity {eventData.LegalEntityId}.");
_logger.LogInformation($"Attempting to revoke provider {eventData.Ukprn} permission on account {eventData.EmployerAccountId} with public hash {eventData.AccountLegalEntityPublicHashedId} for legal entity {eventData.AccountLegalEntityPublicHashedId}.");

await _providerRelationshipsService.RevokeProviderPermissionToRecruitAsync(eventData.Ukprn, eventData.AccountLegalEntityPublicHashedId);

_logger.LogInformation($"Successfully revoked provider {eventData.Ukprn} permission on account {eventData.EmployerAccountId} for legal entity {eventData.LegalEntityId}.");
_logger.LogInformation($"Successfully revoked provider {eventData.Ukprn} permission on account {eventData.EmployerAccountId} for legal entity {eventData.AccountLegalEntityPublicHashedId}.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ await _recruitQueueService.AddMessageAsync(new TransferVacanciesFromProviderQueu
{
Ukprn = message.Ukprn,
EmployerAccountId = employerAccountId,
LegalEntityId = legalEntity.LegalEntityId,
UserRef = message.UserRef.Value,
UserEmailAddress = message.UserEmailAddress,
UserName = $"{message.UserFirstName} {message.UserLastName}",
Expand Down
Loading

0 comments on commit 6d6a591

Please sign in to comment.