Skip to content

Commit

Permalink
Merge pull request #92 from Sprokof/add-ui-test-resetPassword
Browse files Browse the repository at this point in the history
update Jdbc class and add successResetPassword test
  • Loading branch information
devondragon authored Jun 2, 2024
2 parents d642028 + 3d8e533 commit 8d1c500
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/test/java/com/digitalsanctuary/spring/user/jdbc/Jdbc.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
*/
public class Jdbc {

private static final String DELETE_VERIFICATION_TOKEN_QUERY = "DELETE FROM verification_token WHERE user_id = (SELECT id FROM user_account WHERE first_name = ? AND email = ?)";
private static final String DELETE_VERIFICATION_TOKEN_QUERY = "DELETE FROM verification_token WHERE user_id = (SELECT id FROM user_account WHERE email = ?)";

private static final String DELETE_TEST_USER_ROLE = "DELETE FROM users_roles WHERE user_id = (SELECT id FROM user_account WHERE first_name = ? AND email = ?)";
private static final String DELETE_TEST_USER_ROLE = "DELETE FROM users_roles WHERE user_id = (SELECT id FROM user_account WHERE email = ?)";

private static final String DELETE_TEST_USER_QUERY = "DELETE FROM user_account WHERE first_name = ? AND email = ?";
private static final String DELETE_TEST_PASSWORD_RESET_TOKEN = "DELETE FROM password_reset_token WHERE user_id = (SELECT id FROM user_account WHERE email = ?)";

private static final String DELETE_TEST_USER_QUERY = "DELETE FROM user_account WHERE email = ?";

private static final String GET_LAST_USER_ID_QUERY = "SELECT max(id) FROM user_account";

Expand All @@ -26,9 +28,10 @@ public class Jdbc {

public static void deleteTestUser(UserDto userDto) {
try(Connection connection = ConnectionManager.open()) {
String[] params = new String[]{userDto.getFirstName(), userDto.getEmail()};
String[] params = new String[]{userDto.getEmail()};
execute(connection, DELETE_VERIFICATION_TOKEN_QUERY, params);
execute(connection, DELETE_TEST_USER_ROLE, params);
execute(connection, DELETE_TEST_PASSWORD_RESET_TOKEN, params);
execute(connection, DELETE_TEST_USER_QUERY, params);
} catch (SQLException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@


import com.digitalsanctuary.spring.user.dto.UserDto;
import com.digitalsanctuary.spring.user.ui.page.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.digitalsanctuary.spring.user.ui.data.UiTestData;
import com.digitalsanctuary.spring.user.jdbc.Jdbc;
import com.digitalsanctuary.spring.user.ui.page.LoginPage;
import com.digitalsanctuary.spring.user.ui.page.LoginSuccessPage;
import com.digitalsanctuary.spring.user.ui.page.RegisterPage;
import com.digitalsanctuary.spring.user.ui.page.SuccessRegisterPage;

import static com.digitalsanctuary.spring.user.ui.data.UiTestData.*;

Expand Down Expand Up @@ -61,4 +58,15 @@ public void successSignIn() {
Assertions.assertTrue(welcomeMessage.contains(firstName));
}

@Test
public void successResetPassword() {
Jdbc.saveTestUser(testUser);
ForgotPasswordPage forgotPasswordPage = new ForgotPasswordPage(URI + "user/forgot-password.html");
SuccessResetPasswordPage successResetPasswordPage = forgotPasswordPage
.fillEmail(testUser.getEmail())
.clickSubmitBtn();
String actualMessage = successResetPasswordPage.message();
Assertions.assertEquals(SUCCESS_RESET_PASSWORD_MESSAGE, actualMessage);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class UiTestData {

public static final String SUCCESS_SING_UP_MESSAGE = "Thank you for registering!";

public static final String SUCCESS_RESET_PASSWORD_MESSAGE = "You should receive a password reset email shortly";

public static final String TEST_USER_ENCODED_PASSWORD = "$2y$10$XIRn/npMMCGt21gpU6QAbeOAUSxj/C7A793YZe.a6AEvL0LhQwkqW";

public static UserDto getUserDto() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.digitalsanctuary.spring.user.ui.page;

import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
import com.digitalsanctuary.spring.user.ui.BaseUiTest;
import org.openqa.selenium.By;

import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$x;

public class ForgotPasswordPage extends BaseUiTest {
private final SelenideElement EMAIL_FIELD = $(By.id("email"));
private final SelenideElement SUBMIT_BTN = $x("//button");

public ForgotPasswordPage(String url) {
Selenide.open(url);
}

public ForgotPasswordPage fillEmail(String email) {
EMAIL_FIELD.setValue(email);
return this;
}

public SuccessResetPasswordPage clickSubmitBtn() {
SUBMIT_BTN.click();
return new SuccessResetPasswordPage();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.digitalsanctuary.spring.user.ui.page;

import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
import com.digitalsanctuary.spring.user.ui.BaseUiTest;

public class SuccessResetPasswordPage extends BaseUiTest {
private final SelenideElement SUCCESS_RESET_MESSAGE = Selenide.$x("//div[@class='container']//div[@class='container']//span");

public String message() {
return SUCCESS_RESET_MESSAGE.text();
}
}

0 comments on commit 8d1c500

Please sign in to comment.