Skip to content

Commit

Permalink
Added email filtering check
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Howes committed May 21, 2021
1 parent 8a27ec5 commit 83bcc1d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public async Task<CommunicationUserPreference> GetUserPreferenceAsync(string req
case CommunicationConstants.RequestType.VacancyRejected:
SetPreferencesForVacancyRejectedNotification(userPref, userPreference);
return userPref;
case CommunicationConstants.RequestType.VacancyRejectedByEmployer:
SetPreferencesForVacancyRejectedByEmployerNotification(userPref, userPreference);
return userPref;
case CommunicationConstants.RequestType.ApplicationSubmitted:
SetPreferencesForApplicationSubmittedNotification(userPref, userPreference);
return userPref;
Expand All @@ -56,6 +59,17 @@ private void SetPreferencesForVacancyRejectedNotification(CommunicationUserPrefe
}
}

private void SetPreferencesForVacancyRejectedByEmployerNotification(CommunicationUserPreference userPref, UserNotificationPreferences userPreference)
{
if (userPreference == null) return;
if (userPreference.NotificationTypes.HasFlag(NotificationTypes.VacancyRejectedByEmployer))
{
userPref.Channels = DeliveryChannelPreferences.EmailOnly;
userPref.Frequency = DeliveryFrequency.Immediate;
userPref.Scope = userPreference.NotificationScope.GetValueOrDefault().ConvertToCommunicationScope();
}
}

private void SetPreferencesForApplicationSubmittedNotification(CommunicationUserPreference userPref, UserNotificationPreferences userPreference)
{
if (userPreference == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class UserPreferencesProviderPluginTests

[Theory]
[InlineData(CommunicationConstants.RequestType.VacancyRejected, DeliveryChannelPreferences.None, DeliveryFrequency.Default)]
[InlineData(CommunicationConstants.RequestType.VacancyRejectedByEmployer, DeliveryChannelPreferences.None, DeliveryFrequency.Default)]
[InlineData(CommunicationConstants.RequestType.ApplicationSubmitted, DeliveryChannelPreferences.None, DeliveryFrequency.Default)]
[InlineData(CommunicationConstants.RequestType.VacancyWithdrawnByQa, DeliveryChannelPreferences.EmailOnly, DeliveryFrequency.Immediate)]
[InlineData(CommunicationConstants.RequestType.ProviderBlockedProviderNotification, DeliveryChannelPreferences.EmailOnly, DeliveryFrequency.Immediate)]
Expand Down Expand Up @@ -77,6 +78,30 @@ public async Task WhenRequestTypeIsVacancyRejected_ShouldReturnRespectivePrefere
pref.Scope.Should().Be(Communication.Types.NotificationScope.Organisation);
}

[Fact]
public async Task WhenRequestTypeIsVacancyRejectedByEmployer_ShouldReturnRespectivePreferences()
{
var userPref = _fixture
.Build<UserNotificationPreferences>()
.With(p => p.NotificationTypes, NotificationTypes.VacancyRejectedByEmployer)
.With(p => p.NotificationScope, Esfa.Recruit.Vacancies.Client.Domain.Entities.NotificationScope.OrganisationVacancies)
.Create();

_repositoryMock
.Setup(u => u.GetAsync(It.IsAny<string>()))
.ReturnsAsync(userPref);

var sut = GetSut();

var user = _fixture.Create<CommunicationUser>();

var pref = await sut.GetUserPreferenceAsync(RequestType.VacancyRejectedByEmployer, user);

pref.Channels.Should().Be(DeliveryChannelPreferences.EmailOnly);
pref.Frequency.Should().Be(DeliveryFrequency.Immediate);
pref.Scope.Should().Be(Communication.Types.NotificationScope.Organisation);
}

[Fact]
public async Task WhenRequestTypeIsApplicationSubmitted_ShouldReturnRespectivePreferences()
{
Expand Down

0 comments on commit 83bcc1d

Please sign in to comment.