chore(test):update test user model
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user