public async Task <CommunicationUserPreference> GetUserPreferenceAsync(string requestType, CommunicationUser user) { var userPref = new CommunicationUserPreference() { Channels = DeliveryChannelPreferences.None }; var userPreference = await _repository.GetAsync(user.UserId); switch (requestType) { case CommunicationConstants.RequestType.VacancyRejected: SetPreferencesForVacancyRejectedNotification(userPref, userPreference); return(userPref); case CommunicationConstants.RequestType.ApplicationSubmitted: SetPreferencesForApplicationSubmittedNotification(userPref, userPreference); return(userPref); case CommunicationConstants.RequestType.VacancyWithdrawnByQa: case CommunicationConstants.RequestType.ProviderBlockedProviderNotification: case CommunicationConstants.RequestType.ProviderBlockedEmployerNotificationForTransferredVacancies: case CommunicationConstants.RequestType.ProviderBlockedEmployerNotificationForLiveVacancies: case CommunicationConstants.RequestType.ProviderBlockedEmployerNotificationForPermissionOnly: SetPreferencesForMandatoryOrganisationEmailNotification(userPref); return(userPref); default: throw new NotImplementedException($"User preferences not implemented for request {requestType}"); } }
private void SetPreferencesForApplicationSubmittedNotification(CommunicationUserPreference userPref, UserNotificationPreferences userPreference) { if (userPreference == null) { return; } if (userPreference.NotificationTypes.HasFlag(NotificationTypes.ApplicationSubmitted)) { userPref.Channels = DeliveryChannelPreferences.EmailOnly; userPref.Frequency = userPreference.NotificationFrequency.GetDeliveryFrequencyPreferenceFromUserFrequencyPreference(); userPref.Scope = userPreference.NotificationScope.GetValueOrDefault().ConvertToCommunicationScope(); } }
private void SetPreferencesForVacancyRejectedNotification(CommunicationUserPreference userPref, UserNotificationPreferences userPreference) { if (userPreference == null) { return; } if (userPreference.NotificationTypes.HasFlag(NotificationTypes.VacancyRejected)) { userPref.Channels = DeliveryChannelPreferences.EmailOnly; userPref.Frequency = DeliveryFrequency.Immediate; userPref.Scope = userPreference.NotificationScope.GetValueOrDefault().ConvertToCommunicationScope(); } }
private void SetPreferencesForVacancySentForReviewNotification(CommunicationUserPreference userPref, UserNotificationPreferences userPreference) { if (userPreference == null) { return; } if (userPreference.NotificationTypes.HasFlag(NotificationTypes.VacancySentForReview)) { userPref.Channels = DeliveryChannelPreferences.EmailOnly; userPref.Frequency = DeliveryFrequency.Immediate; userPref.Scope = NotificationScope.Organisation; } }
public async Task GivenMatchingMessageIds_UserPreferenceIsNotDaily_ThenShouldReturnNullAggregateMessage(DeliveryFrequency userFrequencyPreference) { var commPref = new CommunicationUserPreference { Frequency = userFrequencyPreference, Channels = DeliveryChannelPreferences.EmailOnly, Scope = NotificationScope.Individual }; var from = DateTime.UtcNow.AddDays(-1); var to = DateTime.UtcNow; var acr = new AggregateCommunicationRequest(Guid.NewGuid(), TestRequestType, DeliveryFrequency.Daily, DateTime.UtcNow, from, to); var messages = Enumerable.Repeat <CommunicationMessage>(GetTestTemplateMessage(), 10); _mockUserPreferenceProvider.Setup(x => x.GetUserPreferenceAsync(TestRequestType, It.IsAny <CommunicationUser>())) .ReturnsAsync(commPref); var aggregateMessage = await _sut.CreateAggregateMessageAsync(acr, messages); aggregateMessage.Should().BeNull(); }
public async Task GivenMatchingMessageIds_AndOnlySubsetOfMessageAreValidParticipation_ShouldReturnAggregateMessage() { var commPref = new CommunicationUserPreference { Frequency = DeliveryFrequency.Daily, Channels = DeliveryChannelPreferences.EmailOnly, Scope = NotificationScope.Individual }; var from = DateTime.UtcNow.AddDays(-1); var to = DateTime.UtcNow; var acr = new AggregateCommunicationRequest(Guid.NewGuid(), TestRequestType, DeliveryFrequency.Daily, DateTime.UtcNow, from, to); var messages = Enumerable.Repeat <CommunicationMessage>(GetTestTemplateMessage(), 10); _mockUserPreferenceProvider.Setup(x => x.GetUserPreferenceAsync(TestRequestType, It.IsAny <CommunicationUser>())) .ReturnsAsync(commPref); _mockParticipantResolver.Setup(x => x.ValidateParticipantAsync(messages)) .ReturnsAsync(Enumerable.Repeat <CommunicationMessage>(messages.First(), 3)); var aggregateMessage = await _sut.CreateAggregateMessageAsync(acr, messages); aggregateMessage.Should().NotBeNull(); }
private void SetPreferencesForMandatoryOrganisationEmailNotification(CommunicationUserPreference userPref) { userPref.Channels = DeliveryChannelPreferences.EmailOnly; userPref.Frequency = DeliveryFrequency.Immediate; userPref.Scope = NotificationScope.Organisation; }