-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(templates): add tests for change phone number in Boilerplate #9027…
… (#9028)
- Loading branch information
1 parent
2501883
commit 9e23ee1
Showing
23 changed files
with
500 additions
and
133 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,8 @@ await server.Build(services => | |
|
||
await authenticationManager.SignIn(new() | ||
{ | ||
Email = "[email protected]", | ||
Password = "123456" | ||
Email = TestData.DefaultTestEmail, | ||
Password = TestData.DefaultTestPassword | ||
}, default); | ||
|
||
var userController = scope.ServiceProvider.GetRequiredService<IUserController>(); | ||
|
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 |
---|---|---|
|
@@ -28,9 +28,9 @@ public async Task SignIn_Should_WorkAsExpected() | |
|
||
await Expect(Page).ToHaveTitleAsync(AppStrings.SignInPageTitle); | ||
|
||
const string email = "[email protected]"; | ||
const string password = "123456"; | ||
const string userFullName = "Boilerplate test account"; | ||
const string email = TestData.DefaultTestEmail; | ||
const string password = TestData.DefaultTestPassword; | ||
const string userFullName = TestData.DefaultTestFullName; | ||
|
||
await Page.GetByPlaceholder(AppStrings.EmailPlaceholder).FillAsync(email); | ||
await Page.GetByPlaceholder(AppStrings.PasswordPlaceholder).FillAsync(password); | ||
|
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 |
---|---|---|
|
@@ -33,11 +33,11 @@ public async Task SignIn(string mode) | |
switch (mode) | ||
{ | ||
case "ValidCredentials": | ||
var identityHomePage = await signInPage.SignIn(); | ||
var identityHomePage = await signInPage.SignInWithEmail(); | ||
await identityHomePage.AssertSignInSuccess(); | ||
break; | ||
case "InvalidCredentials": | ||
await signInPage.SignIn(email: "[email protected]", password: "invalid"); | ||
await signInPage.SignInWithEmail(email: "[email protected]", password: "invalid"); | ||
await signInPage.AssertSignInFailed(); | ||
break; | ||
default: | ||
|
@@ -61,7 +61,7 @@ public async Task SignOut() | |
await signInPage.Open(); | ||
await signInPage.AssertOpen(); | ||
|
||
var identityHomePage = await signInPage.SignIn(email); | ||
var identityHomePage = await signInPage.SignInWithEmail(email); | ||
await identityHomePage.AssertSignInSuccess(email, userFullName: null); | ||
|
||
await dbContext.Entry(user).ReloadAsync(); | ||
|
@@ -118,20 +118,24 @@ public async Task SignUp(string mode) | |
[DataRow("Token")] | ||
[DataRow("InvalidToken")] | ||
[DataRow("MagicLink")] | ||
[DataRow("TooManyRequests")] | ||
[DataRow("NotExisted")] | ||
public async Task ForgotPassword(string mode) | ||
{ | ||
await using var scope = TestServer.WebApp.Services.CreateAsyncScope(); | ||
|
||
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); | ||
var userService = new UserService(dbContext); | ||
var email = $"{Guid.NewGuid()}@gmail.com"; | ||
await userService.AddUser(email); | ||
var email = await CreateNewUser(); | ||
|
||
var forgotPasswordPage = new ForgotPasswordPage(Page, WebAppServerAddress); | ||
|
||
await forgotPasswordPage.Open(); | ||
await forgotPasswordPage.AssertOpen(); | ||
|
||
if (mode is "NotExisted") | ||
{ | ||
await forgotPasswordPage.ForgotPassword("[email protected]"); | ||
await forgotPasswordPage.AssertUserNotFound(); | ||
return; | ||
} | ||
|
||
var resetPasswordPage = await forgotPasswordPage.ForgotPassword(email); | ||
await resetPasswordPage.AssertOpen(); | ||
|
||
|
@@ -145,14 +149,19 @@ public async Task ForgotPassword(string mode) | |
var token = await resetPasswordEmail.GetToken(); | ||
await resetPasswordPage.ContinueByToken(token); | ||
break; | ||
case "MagicLink": | ||
resetPasswordPage = await resetPasswordEmail.OpenMagicLink(); | ||
break; | ||
case "InvalidToken": | ||
await resetPasswordPage.ContinueByToken("111111"); | ||
await resetPasswordPage.SetPassword(newPassword); | ||
await resetPasswordPage.AssertInvalidToken(); | ||
return; | ||
case "MagicLink": | ||
resetPasswordPage = await resetPasswordEmail.OpenMagicLink(); | ||
break; | ||
case "TooManyRequests": | ||
await Page.GoBackAsync(); | ||
await forgotPasswordPage.ForgotPassword(email); | ||
await forgotPasswordPage.AssertTooManyRequests(); | ||
return; | ||
default: | ||
throw new NotSupportedException(); | ||
} | ||
|
@@ -166,72 +175,148 @@ public async Task ForgotPassword(string mode) | |
await signInPage.Open(); | ||
await signInPage.AssertOpen(); | ||
|
||
var identityHomePage = await signInPage.SignIn(email, newPassword); | ||
var identityHomePage = await signInPage.SignInWithEmail(email, newPassword); | ||
await identityHomePage.AssertSignInSuccess(email, userFullName: null); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("Token")] | ||
[DataRow("InvalidToken")] | ||
[DataRow("MagicLink")] | ||
[DataRow("TooManyRequests")] | ||
public async Task ChangeEmail(string mode) | ||
{ | ||
await using var scope = TestServer.WebApp.Services.CreateAsyncScope(); | ||
|
||
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); | ||
var userService = new UserService(dbContext); | ||
var email = $"{Guid.NewGuid()}@gmail.com"; | ||
await userService.AddUser(email); | ||
var email = await CreateNewUser(); | ||
|
||
var signInPage = new SignInPage(Page, WebAppServerAddress); | ||
|
||
await signInPage.Open(); | ||
await signInPage.AssertOpen(); | ||
|
||
var identityHomePage = await signInPage.SignIn(email); | ||
var identityHomePage = await signInPage.SignInWithEmail(email); | ||
await identityHomePage.AssertSignInSuccess(email, userFullName: null); | ||
|
||
var settinsPage = new SettingsPage(Page, WebAppServerAddress); | ||
var settingsPage = new SettingsPage(Page, WebAppServerAddress); | ||
|
||
await settinsPage.Open(); | ||
await settinsPage.AssertOpen(); | ||
await settingsPage.Open(); | ||
await settingsPage.AssertOpen(); | ||
|
||
await settinsPage.ExpandAccount(); | ||
await settinsPage.AssertExpandAccount(email); | ||
await settingsPage.ExpandAccount(); | ||
await settingsPage.AssertExpandAccount(email); | ||
|
||
var newEmail = $"{Guid.NewGuid()}@gmail.com"; | ||
await settinsPage.ChangeEmail(newEmail); | ||
await settinsPage.AssertChangeEmail(); | ||
await settingsPage.ChangeEmail(newEmail); | ||
await settingsPage.AssertChangeEmail(); | ||
|
||
var confirmationEmail = await settinsPage.OpenConfirmationEmail(); | ||
var confirmationEmail = await settingsPage.OpenConfirmationEmail(); | ||
await confirmationEmail.AssertContent(); | ||
|
||
switch (mode) | ||
{ | ||
case "Token": | ||
var token = await confirmationEmail.GetToken(); | ||
await settinsPage.ConfirmByToken(token); | ||
await settingsPage.ConfirmEmailByToken(token); | ||
break; | ||
case "InvalidToken": | ||
await settinsPage.ConfirmByToken("111111"); | ||
await settinsPage.AssertInvalidToken(); | ||
return; | ||
case "MagicLink": | ||
settinsPage = await confirmationEmail.OpenMagicLink(); | ||
settingsPage = await confirmationEmail.OpenMagicLink(); | ||
break; | ||
case "InvalidToken": | ||
await settingsPage.ConfirmEmailByToken("111111"); | ||
await settingsPage.AssertEmailInvalidToken(); | ||
return; | ||
case "TooManyRequests": | ||
await settingsPage.ClickOnPhoneTab(); | ||
await settingsPage.ClickOnEmailTab(); | ||
await settingsPage.ChangeEmail(newEmail); | ||
await settingsPage.AssertTooManyRequestsForChangeEmail(); | ||
return; | ||
default: | ||
throw new NotSupportedException(); | ||
} | ||
await settinsPage.AssertConfirmSuccess(); | ||
await settingsPage.AssertConfirmEmailSuccess(); | ||
|
||
signInPage = await settinsPage.SignOut(); | ||
signInPage = await settingsPage.SignOut(); | ||
await signInPage.AssertOpen(); | ||
await signInPage.AssertSignOut(); | ||
|
||
await signInPage.SignIn(email); | ||
await signInPage.SignInWithEmail(email); | ||
await signInPage.AssertSignInFailed(); | ||
|
||
settinsPage = await signInPage.SignIn<SettingsPage>(newEmail); | ||
await settinsPage.AssertSignInSuccess(newEmail, userFullName: null); | ||
settingsPage = await signInPage.SignInWithEmail<SettingsPage>(newEmail); | ||
await settingsPage.AssertSignInSuccess(newEmail, userFullName: null); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("Token")] | ||
[DataRow("InvalidToken")] | ||
[DataRow("TooManyRequests")] | ||
public async Task ChangePhone(string mode) | ||
{ | ||
var email = await CreateNewUser(); | ||
|
||
var signInPage = new SignInPage(Page, WebAppServerAddress); | ||
|
||
await signInPage.Open(); | ||
await signInPage.AssertOpen(); | ||
|
||
var identityHomePage = await signInPage.SignInWithEmail(email); | ||
await identityHomePage.AssertSignInSuccess(email, userFullName: null); | ||
|
||
var settingsPage = new SettingsPage(Page, WebAppServerAddress); | ||
|
||
await settingsPage.Open(); | ||
await settingsPage.AssertOpen(); | ||
|
||
await settingsPage.ExpandAccount(); | ||
await settingsPage.ClickOnPhoneTab(); | ||
await settingsPage.AssertPhoneTab(null); | ||
|
||
var phone = $"+1{Random.Shared.Next(1111111111, int.MaxValue)}"; | ||
await settingsPage.ChangePhone(phone); | ||
await settingsPage.AssertChangePhone(); | ||
|
||
switch (mode) | ||
{ | ||
case "Token": | ||
var token = settingsPage.GetPhoneToken(); | ||
await settingsPage.ConfirmPhoneByToken(token); | ||
|
||
await settingsPage.AssertConfirmPhoneSuccess(); | ||
|
||
signInPage = await settingsPage.SignOut(); | ||
await signInPage.AssertOpen(); | ||
await signInPage.AssertSignOut(); | ||
|
||
await signInPage.ClickOnPhoneTab(); | ||
await signInPage.AssertPhoneTab(); | ||
|
||
settingsPage = await signInPage.SignInWithPhone<SettingsPage>(phone); | ||
await settingsPage.AssertSignInSuccess(email, userFullName: null); | ||
return; | ||
case "InvalidToken": | ||
await settingsPage.ConfirmPhoneByToken("111111"); | ||
await settingsPage.AssertPhoneInvalidToken(); | ||
return; | ||
case "TooManyRequests": | ||
await settingsPage.ClickOnEmailTab(); | ||
await settingsPage.ClickOnPhoneTab(); | ||
await settingsPage.ChangePhone(phone); | ||
await settingsPage.AssertTooManyRequestsForChangePhone(); | ||
return; | ||
default: | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
|
||
private async Task<string> CreateNewUser() | ||
{ | ||
await using var scope = TestServer.WebApp.Services.CreateAsyncScope(); | ||
|
||
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); | ||
var userService = new UserService(dbContext); | ||
var email = $"{Guid.NewGuid()}@gmail.com"; | ||
await userService.AddUser(email); | ||
|
||
return email; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Boilerplate.Tests.PageTests.PageModels.Email; | ||
using System.Text.RegularExpressions; | ||
using Boilerplate.Tests.PageTests.PageModels.Email; | ||
using Boilerplate.Tests.PageTests.PageModels.Layout; | ||
|
||
namespace Boilerplate.Tests.PageTests.PageModels.Identity; | ||
|
@@ -24,7 +25,7 @@ public override async Task AssertOpen() | |
await Assertions.Expect(resetPasswordLink).ToHaveAttributeAsync("href", Urls.ResetPasswordPage); | ||
} | ||
|
||
public async Task<ResetPasswordPage> ForgotPassword(string email = "[email protected]") | ||
public async Task<ResetPasswordPage> ForgotPassword(string email = TestData.DefaultTestEmail) | ||
{ | ||
this.email = email; | ||
await Page.GetByPlaceholder(AppStrings.EmailPlaceholder).FillAsync(email); | ||
|
@@ -33,6 +34,17 @@ public async Task<ResetPasswordPage> ForgotPassword(string email = "test@bitplat | |
return new(Page, WebAppServerAddress) { EmailAddress = email }; | ||
} | ||
|
||
public async Task AssertUserNotFound() | ||
{ | ||
await Assertions.Expect(Page.GetByText(AppStrings.UserNotFound)).ToBeVisibleAsync(); | ||
} | ||
|
||
public async Task AssertTooManyRequests() | ||
{ | ||
var pattern = new Regex(AppStrings.WaitForResetPasswordTokenRequestResendDelay.Replace("{0}", ".*")); | ||
await Assertions.Expect(Page.GetByText(pattern)).ToBeVisibleAsync(); | ||
} | ||
|
||
public async Task<ResetPasswordEmail> OpenResetPasswordEmail() | ||
{ | ||
Assert.IsNotNull(email, $"Call {nameof(ForgotPassword)} method first."); | ||
|
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
Oops, something went wrong.