-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixing typo. RuleTemplateMessageRunner > RuleMessageTemplateRunner * Added unit tests
- Loading branch information
1 parent
39ee012
commit 25a8ce8
Showing
7 changed files
with
240 additions
and
3 deletions.
There are no files selected for viewing
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
88 changes: 88 additions & 0 deletions
88
src/Employer/UnitTests/Employer.Web/Mappings/ReviewFieldIndicatorMapperTests.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,88 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Esfa.Recruit.Employer.Web.Mappings; | ||
using Esfa.Recruit.Shared.Web.RuleTemplates; | ||
using Esfa.Recruit.Vacancies.Client.Application.Rules; | ||
using Esfa.Recruit.Vacancies.Client.Domain.Entities; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Esfa.Recruit.Employer.UnitTests.Employer.Web.Mappings | ||
{ | ||
public class ReviewFieldIndicatorMapperTests | ||
{ | ||
[Fact] | ||
public void ShouldMap() | ||
{ | ||
var shortDescriptionProfanityCheckRuleOutcome = | ||
new RuleOutcome( | ||
RuleId.ProfanityChecks, | ||
100, | ||
"Profanity 'drat' found in 'ShortDescription'", | ||
"ShortDescription", | ||
new List<RuleOutcome>(), "{\"Profanity\" : \"drat\",\"Occurrences\" : 1}"); | ||
|
||
var titleProfanityCheckRuleOutcome = new RuleOutcome( | ||
RuleId.ProfanityChecks, | ||
0, | ||
"No profanities found in 'Title'", | ||
"Title"); | ||
|
||
var profanityChecksRuleOutcome = new RuleOutcome( | ||
RuleId.ProfanityChecks, | ||
100, | ||
"No profanities found in 'Title', Profanity 'drat' found in 'ShortDescription', etc", | ||
"", | ||
new List<RuleOutcome> | ||
{ | ||
shortDescriptionProfanityCheckRuleOutcome, | ||
titleProfanityCheckRuleOutcome | ||
} | ||
); | ||
|
||
var sut = new ReviewFieldIndicatorMapper(new RuleMessageTemplateRunner()); | ||
|
||
var review = new VacancyReview | ||
{ | ||
ManualQaFieldIndicators = new List<ManualQaFieldIndicator> | ||
{ | ||
new ManualQaFieldIndicator | ||
{ | ||
IsChangeRequested = false, | ||
FieldIdentifier = VacancyReview.FieldIdentifiers.Title | ||
}, | ||
new ManualQaFieldIndicator | ||
{ | ||
IsChangeRequested = true, | ||
FieldIdentifier = VacancyReview.FieldIdentifiers.ShortDescription | ||
} | ||
}, | ||
AutomatedQaOutcomeIndicators = new List<RuleOutcomeIndicator> | ||
{ | ||
new RuleOutcomeIndicator | ||
{ | ||
IsReferred = false, | ||
RuleOutcomeId = titleProfanityCheckRuleOutcome.Id | ||
}, | ||
new RuleOutcomeIndicator | ||
{ | ||
IsReferred = true, | ||
RuleOutcomeId = shortDescriptionProfanityCheckRuleOutcome.Id | ||
} | ||
}, | ||
AutomatedQaOutcome = new RuleSetOutcome {RuleOutcomes = new List<RuleOutcome> {profanityChecksRuleOutcome}} | ||
}; | ||
|
||
var vm = sut.MapFromFieldIndicators(ReviewFieldMappingLookups.GetPreviewReviewFieldIndicators(), review).ToList(); | ||
|
||
vm.Count.Should().Be(1); | ||
|
||
var shortDescription = vm.Single(v => v.ReviewFieldIdentifier == VacancyReview.FieldIdentifiers.ShortDescription); | ||
|
||
shortDescription.ManualQaText.Should().NotBeNullOrEmpty(); | ||
|
||
shortDescription.AutoQaTexts.Count.Should().Be(1); | ||
shortDescription.AutoQaTexts[0].Should().Be("Brief overview contains the phrase 'drat'"); | ||
} | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/Employer/UnitTests/Employer.Web/Services/LegalEntityAgreementServiceTests.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,102 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Esfa.Recruit.Employer.Web.Services; | ||
using Esfa.Recruit.Vacancies.Client.Infrastructure.Client; | ||
using Esfa.Recruit.Vacancies.Client.Infrastructure.QueryStore.Projections.EditVacancyInfo; | ||
using FluentAssertions; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Esfa.Recruit.Employer.UnitTests.Employer.Web.Services | ||
{ | ||
public class LegalEntityAgreementServiceTests | ||
{ | ||
const string EmployerAccountId = "ABCDEF"; | ||
const long LegalEntityId = 1234; | ||
|
||
private Mock<IEmployerVacancyClient> _clientMock; | ||
|
||
[Fact] | ||
public void HasLegalEntityAgreementAsync_ShouldReturnFalseIfNoMatchingLegalEntity() | ||
{ | ||
var sut = GetLegalEntityAgreementService(EmployerAccountId, 5678, true, 5678, true); | ||
|
||
var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; | ||
|
||
result.Should().BeFalse(); | ||
_clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Never); | ||
} | ||
|
||
[Fact] | ||
public void HasLegalEntityAgreementAsync_ShouldNotCheckEmployerServiceWhenHasAgreement() | ||
{ | ||
var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, true, LegalEntityId, true); | ||
|
||
var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; | ||
|
||
result.Should().BeTrue(); | ||
_clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Never); | ||
} | ||
|
||
[Fact] public void HasLegalEntityAgreementAsync_ShouldCheckEmployerServiceWhenHasNoAgreement() | ||
{ | ||
var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, true); | ||
|
||
var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; | ||
|
||
result.Should().BeTrue(); | ||
_clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); | ||
_clientMock.Verify(c => c.SetupEmployerAsync(EmployerAccountId), Times.Once); | ||
} | ||
|
||
[Fact] public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceLegalEntityHasNoAgreement() | ||
{ | ||
var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, false); | ||
|
||
var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; | ||
|
||
result.Should().BeFalse(); | ||
_clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); | ||
_clientMock.Verify(c => c.SetupEmployerAsync(EmployerAccountId), Times.Never); | ||
} | ||
|
||
[Fact] | ||
public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceCantLocateLegalEntity() | ||
{ | ||
var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, 5678, true); | ||
|
||
var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; | ||
|
||
result.Should().BeFalse(); | ||
_clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); | ||
_clientMock.Verify(c => c.SetupEmployerAsync(EmployerAccountId), Times.Never); | ||
} | ||
|
||
private LegalEntityAgreementService GetLegalEntityAgreementService(string employerAccountId, long legalEntityId, bool hasLegalEntityAgreement, long employerServiceLegalEntityId, bool employerServiceHasLegalEntityAgreement) | ||
{ | ||
_clientMock = new Mock<IEmployerVacancyClient>(); | ||
_clientMock.Setup(c => c.GetEditVacancyInfoAsync(employerAccountId)).Returns(Task.FromResult( | ||
new EditVacancyInfo | ||
{ | ||
LegalEntities = new List<LegalEntity> | ||
{ | ||
new LegalEntity{LegalEntityId = legalEntityId, HasLegalEntityAgreement = hasLegalEntityAgreement} | ||
} | ||
})); | ||
|
||
_clientMock.Setup(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId)).Returns(Task.FromResult( | ||
new List<LegalEntity> | ||
{ | ||
new LegalEntity | ||
{ | ||
LegalEntityId = employerServiceLegalEntityId, | ||
HasLegalEntityAgreement = employerServiceHasLegalEntityAgreement | ||
} | ||
} | ||
.AsEnumerable())); | ||
|
||
return new LegalEntityAgreementService(_clientMock.Object); | ||
} | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/Shared/UnitTests/Shared.Web/RuleTemplates/RuleMessageTemplateRunnerTests.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,45 @@ | ||
using Esfa.Recruit.Shared.Web.RuleTemplates; | ||
using Esfa.Recruit.Vacancies.Client.Application.Rules; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Esfa.Recruit.Vacancies.Client.UnitTests.Shared.Web.RuleTemplates | ||
{ | ||
public class RuleMessageTemplateRunnerTests | ||
{ | ||
[Fact] | ||
public void ShouldCreateProfanityCheckMessage() | ||
{ | ||
var sut = new RuleMessageTemplateRunner(); | ||
|
||
var actual = sut.ToText(RuleId.ProfanityChecks, "{\"Profanity\":\"drat\",\"Occurrences\":1}", "Profanity field"); | ||
actual.Should().Be("Profanity field contains the phrase 'drat'"); | ||
|
||
actual = sut.ToText(RuleId.ProfanityChecks, "{\"Profanity\":\"drat\",\"Occurrences\":3}", "Profanity field"); | ||
actual.Should().Be("Profanity field contains the phrase 'drat' 3 times"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldCreateBannedPhraseCheckMessage() | ||
{ | ||
var sut = new RuleMessageTemplateRunner(); | ||
|
||
var actual = sut.ToText(RuleId.BannedPhraseChecks, "{\"BannedPhrase\":\"driving licence\",\"Occurrences\":1}", "Banned phrase field"); | ||
actual.Should().Be("Banned phrase field contains the phrase 'driving licence'"); | ||
|
||
actual = sut.ToText(RuleId.BannedPhraseChecks, "{\"BannedPhrase\":\"driving licence\",\"Occurrences\":3}", "Banned phrase field"); | ||
|
||
actual.Should().Be("Banned phrase field contains the phrase 'driving licence' 3 times"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldCreateTitlePopularityCheckMessage() | ||
{ | ||
var sut = new RuleMessageTemplateRunner(); | ||
|
||
var actual = sut.ToText(RuleId.TitlePopularity, "{\"TrainingCode\":\"CODE\",\"TrainingTitle\":\"TITLE\",\"TrainingType\":\"TYPE\"}", "Title field"); | ||
|
||
actual.Should().Be("The title field is not common for apprenticeships with the training TYPE CODE - TITLE."); | ||
} | ||
} | ||
} |