Skip to content

Commit

Permalink
The user's email to be sent should be confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlcf88 committed Mar 19, 2023
1 parent 4ed9cb1 commit 5cd51fa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ public class FakeExternalUserLookupServiceProvider : IExternalUserLookupServiceP
return new UserData(
NotificationServiceProviderMailingTestConsts.FakeUser1Id,
"fake1",
"user1@easyabp.io");
"user1@easyabp.io",
emailConfirmed: true);
}

if (id == NotificationServiceProviderMailingTestConsts.FakeUser2Id)
{
return new UserData(
NotificationServiceProviderMailingTestConsts.FakeUser2Id,
"fake2",
"user2@easyabp.io");
"user2@easyabp.io",
emailConfirmed: false);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ await EmailNotificationSendingJob.ExecuteAsync(
notification.FailureReason.ShouldBeNull();
}

[Fact]
public async Task Should_Set_Notification_Result_To_Failure_If_Email_Is_Not_Confirmed()
{
var userIds = new List<Guid>
{
NotificationServiceProviderMailingTestConsts.FakeUser2Id
};

await CreateEmailNotificationAsync(userIds, Subject, Body);

var notification = (await NotificationRepository.GetListAsync()).First();

await EmailNotificationSendingJob.ExecuteAsync(
new EmailNotificationSendingJobArgs(notification.TenantId, notification.Id));

notification = await NotificationRepository.GetAsync(notification.Id);

notification.Success.ShouldBe(false);
notification.CompletionTime.ShouldNotBeNull();
notification.FailureReason.ShouldBe(NotificationConsts.FailureReasons.ReceiverInfoNotFound);
}

[Fact]
public async Task Should_Set_Notification_Result_To_Failure_If_User_Not_Found()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ public IdentityUserEmailAddressProvider(
{
_userLookupServiceProvider = userLookupServiceProvider;
}

public virtual async Task<string> GetAsync(Guid userId)
{
var userData = await _userLookupServiceProvider.FindByIdAsync(userId);

return userData?.Email;
if (userData is null || !userData.EmailConfirmed || userData.Email.IsNullOrWhiteSpace())
{
return null;
}

return userData.Email;
}
}
}

0 comments on commit 5cd51fa

Please sign in to comment.