-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase coverage on v1 UserEmailService and UserSmsService for AB#16851
- Loading branch information
Showing
2 changed files
with
174 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,41 @@ public async Task ValidateEmailAlreadyValidated() | |
Assert.Equal(ResultType.Error, actual.ResultStatus); | ||
} | ||
|
||
/// <summary> | ||
/// ValidateEmailAsync returns error when updating user profile to the database. | ||
/// </summary> | ||
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> | ||
[Fact] | ||
public async Task ValidateEmailReturnsError() | ||
{ | ||
// Arrange | ||
DbResult<UserProfile> dbResult = new() { Status = DbStatusCode.Error }; // Should cause error to be returned. | ||
|
||
Guid inviteKey = Guid.NewGuid(); | ||
MessagingVerification verificationByInviteKey = new() | ||
{ | ||
UserProfileId = HdIdMock, | ||
VerificationAttempts = 0, | ||
InviteKey = inviteKey, | ||
ExpireDate = DateTime.Now.AddDays(1), | ||
Validated = false, | ||
Email = new Email | ||
{ | ||
To = "[email protected]", | ||
}, | ||
}; | ||
|
||
UserProfile userProfile = new(); | ||
IUserEmailService service = GetUserEmailService(userProfile, verificationByInviteKey, updateUserProfileResult: dbResult); | ||
|
||
// Act | ||
RequestResult<bool> actual = await service.ValidateEmailAsync(HdIdMock, inviteKey); | ||
|
||
// Assert | ||
Assert.Equal(ResultType.Error, actual.ResultStatus); | ||
Assert.Equal(ErrorMessages.CannotPerformAction, actual.ResultError?.ResultMessage); | ||
} | ||
|
||
/// <summary> | ||
/// ValidateEmailAsync - invalid invite. | ||
/// </summary> | ||
|
@@ -246,8 +281,10 @@ private static IUserEmailService GetUserEmailService( | |
Mock<IUserProfileDelegate>? userProfileDelegateMock = null, | ||
Mock<INotificationSettingsService>? notificationSettingsServiceMock = null, | ||
Mock<IMessageSender>? messageSenderMock = null, | ||
bool changeFeedEnabled = false) | ||
bool changeFeedEnabled = false, | ||
DbResult<UserProfile>? updateUserProfileResult = null) | ||
{ | ||
updateUserProfileResult ??= new DbResult<UserProfile> { Status = DbStatusCode.Updated }; | ||
messagingVerificationDelegateMock ??= new(); | ||
messagingVerificationDelegateMock.Setup(s => s.GetLastByInviteKeyAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(verificationByInviteKey); | ||
messagingVerificationDelegateMock.Setup(s => s.GetLastForUserAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>())) | ||
|
@@ -256,7 +293,7 @@ private static IUserEmailService GetUserEmailService( | |
userProfileDelegateMock ??= new(); | ||
userProfileDelegateMock.Setup(u => u.GetUserProfileAsync(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<CancellationToken>())).ReturnsAsync(userProfile); | ||
userProfileDelegateMock.Setup(s => s.UpdateAsync(It.IsAny<UserProfile>(), It.IsAny<bool>(), It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(new DbResult<UserProfile> { Status = DbStatusCode.Updated }); | ||
.ReturnsAsync(updateUserProfileResult); | ||
|
||
notificationSettingsServiceMock ??= new(); | ||
messageSenderMock ??= new(); | ||
|
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