chore(test):update test user model
Java CI with Maven / build-and-test (push) Successful in 3m41s
Release package / release (push) Failing after 7m46s

This commit is contained in:
TranHuuDanh
2026-03-25 06:26:46 +00:00
parent 7db7e6de1e
commit b7a0a9f24c
@@ -2,12 +2,17 @@ package com.drinkool.models;
import static org.junit.jupiter.api.Assertions.*;
import io.quarkus.test.TestTransaction;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.persistence.*;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.BadRequestException;
import java.util.*;
import org.junit.jupiter.api.Test;
import com.drinkool.entities.CustomerEntity;
@Entity
@Table
class TestUserEntity extends UserModel {}
@@ -28,7 +33,7 @@ public class UserModelTest {
assertNotNull(user.id, "ID not null after persist");
assertEquals("Tran Huu Danh", user.name);
assertEquals(phone, user.phone);
assertNotNull(user.hashedPassword, "password phai hash");
// assertNotNull(user.hashedPassword, "password phai hash");
TestUserEntity savedUser = TestUserEntity.find(
"phone",
@@ -37,5 +42,33 @@ public class UserModelTest {
assertNotNull(savedUser);
}
// 2. Test case: Đăng ký thất bại do số điện thoại đã tồn tại
@Test
@Transactional
public void testSignupFailExistedUser(){
TestUserEntity existUser = new TestUserEntity();
String phone =
"+8477" + String.format("%07d", (new Random()).nextInt(10000000));
String password = "tungtungtungshahua";
existUser.signup("Nguyen Thanh Quy", phone, password);
CustomerEntity newCustomer = new CustomerEntity();
BadRequestException exception = assertThrows(BadRequestException.class, () -> {
newCustomer.signup("Nguyen Viet Anh",phone,"02092006Anh");
});
assertEquals("ExistedUser", exception.getMessage());
}
// 3. Test case: Đăng ký thất bại do số điện thoại sai định dạng
@Test
@TestTransaction
public void testSignupFailInvalidPhoneNumber() {
TestUserEntity customer = new TestUserEntity();
String invalidPhone = "12345";
BadRequestException exception = assertThrows(BadRequestException.class, () -> {
customer.signup("Lam Vi Hoang", invalidPhone, "Pass123");
});
assertEquals("InvalidPhoneNumber", exception.getMessage());
}
}