From d92bd72303f737d3eb8255f2c26cf75588255eaf Mon Sep 17 00:00:00 2001 From: TranHuuDanh Date: Mon, 30 Mar 2026 02:40:21 +0000 Subject: [PATCH] chore: update --- .../com/drinkool/models/UserModelTest.java | 44 +++++++++++++++++++ .../services/AuthenticationServiceTest.java | 38 ++++++++++++++++ .../services/InventoryItemEntity.java | 5 +++ .../services/InventoryServiceTest.java | 6 +++ 4 files changed, 93 insertions(+) create mode 100644 account-service/src/test/java/com/drinkool/services/AuthenticationServiceTest.java create mode 100644 account-service/src/test/java/com/drinkool/services/InventoryItemEntity.java diff --git a/account-service/src/test/java/com/drinkool/models/UserModelTest.java b/account-service/src/test/java/com/drinkool/models/UserModelTest.java index 2ff5633..6a6efff 100644 --- a/account-service/src/test/java/com/drinkool/models/UserModelTest.java +++ b/account-service/src/test/java/com/drinkool/models/UserModelTest.java @@ -9,10 +9,15 @@ import jakarta.transaction.Transactional; import jakarta.ws.rs.BadRequestException; import java.util.*; + +import javax.swing.text.StyledEditorKit.BoldAction; + import org.junit.jupiter.api.Test; import com.drinkool.entities.CustomerEntity; +import groovyjarjarantlr4.v4.parse.ANTLRParser.labeledAlt_return; + @Entity @Table class TestUserEntity extends UserModel {} @@ -71,4 +76,43 @@ public class UserModelTest { assertEquals("InvalidPhoneNumber", exception.getMessage()); } + @Test + @Transactional + public void testLoginSuccess() { + //dang nhap thanh cong + TestUserEntity user = new TestUserEntity(); + String phone = + "+8477" + String.format("%07d", (new Random()).nextInt(10000000)); + String password = "02092006Danh"; + user.signup("Tran Huu Danh", phone, password); + + Boolean loginResult = user.login(password); + + assertTrue(loginResult); + } + @Test + @Transactional + public void testLoginFailWrongPassword() { + //dang nhap that bai + TestUserEntity user = new TestUserEntity(); + String phone = + "+8477" + String.format("%07d", (new Random()).nextInt(10000000)); + String truePassword = "02092006Danh"; + String wrongPassword = "02092006danhh"; + + user.signup("Tran Huu Danh", phone, truePassword); + Boolean wrongTest = user.login(wrongPassword); + + assertFalse(wrongTest); + } + @Test + @Transactional + public void testLoginFailNullHashedPassword(){ + TestUserEntity user = new TestUserEntity(); + String phone = "+84372548260"; + user.hashedPassword = null; + + boolean loginResult = user.login("anhdomixi"); + assertFalse(loginResult); + } } diff --git a/account-service/src/test/java/com/drinkool/services/AuthenticationServiceTest.java b/account-service/src/test/java/com/drinkool/services/AuthenticationServiceTest.java new file mode 100644 index 0000000..b4b9447 --- /dev/null +++ b/account-service/src/test/java/com/drinkool/services/AuthenticationServiceTest.java @@ -0,0 +1,38 @@ +package com.drinkool.services; + +import static io.restassured.RestAssured.given; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; + +@QuarkusTest +public class AuthenticationServiceTest { + public void signupTestAPI(){ + Map newUser = new HashMap<>(); + newUser.put("name","Tran Huu Danh"); + newUser.put("phone","+8477" + String.format("%07d", (new Random()).nextInt(10000000))); + newUser.put("password","trandanh020906@"); + + given() + .contentType(ContentType.JSON) + .body(newUser) + .when() + .post("/api/signup") + .then() + .statusCode(201); + assertEquals(1, InventoryItemEntity.find("newUser", newUser).count()); + + } + @Test + public void loginTestAPI(){ + Map newUser = new HashMap<>(); + + } +} diff --git a/account-service/src/test/java/com/drinkool/services/InventoryItemEntity.java b/account-service/src/test/java/com/drinkool/services/InventoryItemEntity.java new file mode 100644 index 0000000..80a84ba --- /dev/null +++ b/account-service/src/test/java/com/drinkool/services/InventoryItemEntity.java @@ -0,0 +1,5 @@ +package com.drinkool.services; + +public interface InventoryItemEntity { + +} diff --git a/eatery-service/src/test/java/com/drinkool/services/InventoryServiceTest.java b/eatery-service/src/test/java/com/drinkool/services/InventoryServiceTest.java index 8e396cb..2069a93 100644 --- a/eatery-service/src/test/java/com/drinkool/services/InventoryServiceTest.java +++ b/eatery-service/src/test/java/com/drinkool/services/InventoryServiceTest.java @@ -1,12 +1,16 @@ package com.drinkool.services; import static io.restassured.RestAssured.given; +import static io.restassured.RestAssured.when; import static org.junit.jupiter.api.Assertions.assertEquals; import com.drinkool.dtos.AddInventory; import com.drinkool.entities.InventoryItemEntity; import io.quarkus.test.junit.QuarkusTest; import io.restassured.http.ContentType; + +import java.util.HashMap; +import java.util.Map; import java.util.Random; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -33,4 +37,6 @@ public class InventoryServiceTest { assertEquals(1, InventoryItemEntity.find("name", name).count()); } + + }