chore: update
This commit is contained in:
@@ -22,7 +22,6 @@ bin/
|
|||||||
nb-configuration.xml
|
nb-configuration.xml
|
||||||
|
|
||||||
# Visual Studio Code
|
# Visual Studio Code
|
||||||
.vscode
|
|
||||||
.factorypath
|
.factorypath
|
||||||
*.rdb
|
*.rdb
|
||||||
|
|
||||||
|
|||||||
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Attach to Quarkus",
|
||||||
|
"request": "attach",
|
||||||
|
"hostName": "localhost",
|
||||||
|
"port": 5005
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -66,10 +66,14 @@ public class EateryService {
|
|||||||
@Mutation("updateMenuItem")
|
@Mutation("updateMenuItem")
|
||||||
@RolesAllowed(Role.Manager)
|
@RolesAllowed(Role.Manager)
|
||||||
@Transactional
|
@Transactional
|
||||||
public MenuItemEntity updateMenuItem(
|
public MenuItemEntity updateMenuItem(UpdateMenuItem menuItem) {
|
||||||
@Name("menuItem") UpdateMenuItem menuItem
|
UUID ownerId = UUID.fromString(request.getHeader(InternalValue.userId));
|
||||||
) {
|
|
||||||
MenuItemEntity item = MenuItemEntity.findById(menuItem.getId());
|
MenuItemEntity item = MenuItemEntity.find(
|
||||||
|
"id = ?1 and eatery.ownerId = ?2",
|
||||||
|
menuItem.getId(),
|
||||||
|
ownerId
|
||||||
|
).firstResult();
|
||||||
|
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ quarkus.native.remote-container-build=true
|
|||||||
quarkus.native.additional-build-args=--future-defaults=all
|
quarkus.native.additional-build-args=--future-defaults=all
|
||||||
|
|
||||||
# Kafka
|
# Kafka
|
||||||
mp.messaging.connector.smallrye-kafka.bootstrap.servers=${KAFKA_SERVICE_SERVICE_HOST:host.docker.internal}:9092
|
%prod.mp.messaging.connector.smallrye-kafka.bootstrap.servers=${KAFKA_SERVICE_SERVICE_HOST:host.docker.internal}:9092
|
||||||
|
mp.messaging.incoming.manager-in.connector=smallrye-in-memory
|
||||||
|
|
||||||
## Create restaurant topic
|
## Create restaurant topic
|
||||||
mp.messaging.incoming.manager-in.connector=smallrye-kafka
|
mp.messaging.incoming.manager-in.connector=smallrye-kafka
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import com.drinkool.dtos.AddMenuItem;
|
|||||||
import com.drinkool.entities.EateryEntity;
|
import com.drinkool.entities.EateryEntity;
|
||||||
import com.drinkool.entities.MenuItemEntity;
|
import com.drinkool.entities.MenuItemEntity;
|
||||||
import com.drinkool.lib.dtos.event.ManagerCreate;
|
import com.drinkool.lib.dtos.event.ManagerCreate;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import io.smallrye.reactive.messaging.memory.InMemoryConnector;
|
import io.smallrye.reactive.messaging.memory.InMemoryConnector;
|
||||||
@@ -61,9 +60,10 @@ public class EateryServiceTest {
|
|||||||
Assertions.assertEquals("Quan Bun Cha Test", eatery.name);
|
Assertions.assertEquals("Quan Bun Cha Test", eatery.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID lastSavedId;
|
private UUID savedEateryId;
|
||||||
private String lastSavedName;
|
private String savedEateryName;
|
||||||
private UUID lastOwnerId = UUID.randomUUID();
|
private UUID savedOwnerId = UUID.randomUUID();
|
||||||
|
private UUID savedMenuItemId;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -71,11 +71,11 @@ public class EateryServiceTest {
|
|||||||
MenuItemEntity.deleteAll();
|
MenuItemEntity.deleteAll();
|
||||||
EateryEntity.deleteAll();
|
EateryEntity.deleteAll();
|
||||||
|
|
||||||
lastSavedName = faker.restaurant().name();
|
savedEateryName = faker.restaurant().name();
|
||||||
|
|
||||||
EateryEntity eatery = new EateryEntity();
|
EateryEntity eatery = new EateryEntity();
|
||||||
eatery = eatery.create(lastOwnerId, lastSavedName);
|
eatery = eatery.create(savedOwnerId, savedEateryName);
|
||||||
lastSavedId = eatery.id;
|
savedEateryId = eatery.id;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
EateryEntity e = new EateryEntity();
|
EateryEntity e = new EateryEntity();
|
||||||
@@ -83,13 +83,13 @@ public class EateryServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
MenuItemEntity.create(
|
savedMenuItemId = MenuItemEntity.create(
|
||||||
eatery,
|
eatery,
|
||||||
new AddMenuItem(
|
new AddMenuItem(
|
||||||
faker.food().dish(),
|
faker.food().dish(),
|
||||||
faker.number().randomDouble(2, 10, 100)
|
faker.number().randomDouble(2, 10, 100)
|
||||||
)
|
)
|
||||||
);
|
).id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public class EateryServiceTest {
|
|||||||
.statusCode(200)
|
.statusCode(200)
|
||||||
// GraphQL trả về dữ liệu bọc trong object "data"
|
// GraphQL trả về dữ liệu bọc trong object "data"
|
||||||
.body("data.allEateries", notNullValue())
|
.body("data.allEateries", notNullValue())
|
||||||
.body("data.allEateries.name", hasItems(lastSavedName));
|
.body("data.allEateries.name", hasItems(savedEateryName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -116,7 +116,7 @@ public class EateryServiceTest {
|
|||||||
// Lưu ý: Trong GraphQL, String/UUID phải nằm trong dấu ngoặc kép
|
// Lưu ý: Trong GraphQL, String/UUID phải nằm trong dấu ngoặc kép
|
||||||
String query = String.format(
|
String query = String.format(
|
||||||
"{ \"query\": \"{ eateryById(id: \\\"%s\\\") { ownerId name } }\" }",
|
"{ \"query\": \"{ eateryById(id: \\\"%s\\\") { ownerId name } }\" }",
|
||||||
lastSavedId
|
savedEateryId
|
||||||
);
|
);
|
||||||
|
|
||||||
given()
|
given()
|
||||||
@@ -126,7 +126,7 @@ public class EateryServiceTest {
|
|||||||
.post("/graphql")
|
.post("/graphql")
|
||||||
.then()
|
.then()
|
||||||
.statusCode(200)
|
.statusCode(200)
|
||||||
.body("data.eateryById.name", is(lastSavedName));
|
.body("data.eateryById.name", is(savedEateryName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -154,7 +154,7 @@ public class EateryServiceTest {
|
|||||||
given()
|
given()
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
.header(InternalValue.role, Role.Manager)
|
.header(InternalValue.role, Role.Manager)
|
||||||
.header(InternalValue.userId, lastOwnerId) // Thay "x-user-id" bằng InternalValue.userId của bạn
|
.header(InternalValue.userId, savedOwnerId) // Thay "x-user-id" bằng InternalValue.userId của bạn
|
||||||
.body(requestBody)
|
.body(requestBody)
|
||||||
.when()
|
.when()
|
||||||
.post("/graphql")
|
.post("/graphql")
|
||||||
@@ -189,7 +189,7 @@ public class EateryServiceTest {
|
|||||||
given()
|
given()
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
.header(InternalValue.role, Role.Customer)
|
.header(InternalValue.role, Role.Customer)
|
||||||
.header(InternalValue.userId, lastOwnerId)
|
.header(InternalValue.userId, savedOwnerId)
|
||||||
.body(requestBody)
|
.body(requestBody)
|
||||||
.when()
|
.when()
|
||||||
.post("/graphql")
|
.post("/graphql")
|
||||||
@@ -229,7 +229,7 @@ public class EateryServiceTest {
|
|||||||
"}";
|
"}";
|
||||||
|
|
||||||
Map<String, Object> variables = new HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
variables.put("id", lastSavedId.toString());
|
variables.put("id", savedEateryId.toString());
|
||||||
|
|
||||||
Map<String, Object> requestBody = new HashMap<>();
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
requestBody.put("query", query);
|
requestBody.put("query", query);
|
||||||
@@ -276,19 +276,19 @@ public class EateryServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateMenuItem_Success() {
|
public void testUpdateMenuItem_Success() {
|
||||||
String mutation = """
|
String mutation = """
|
||||||
mutation updateMenuItem($menuItem: UpdateMenuItemInput!) {
|
mutation updateMenuItem($menuItem: UpdateMenuItemInput!) {
|
||||||
updateMenuItem(menuItem: $menuItem) {
|
updateMenuItem(menuItem: $menuItem) {
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
price
|
price
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
String newValue = "Phở Bò";
|
String newValue = "Phở Bò";
|
||||||
|
|
||||||
Map<String, Object> menuItemData = new HashMap<>();
|
Map<String, Object> menuItemData = new HashMap<>();
|
||||||
menuItemData.put("id", lastSavedName);
|
menuItemData.put("id", savedMenuItemId);
|
||||||
menuItemData.put("name", newValue);
|
menuItemData.put("name", newValue);
|
||||||
|
|
||||||
Map<String, Object> variables = new HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
@@ -300,14 +300,14 @@ public class EateryServiceTest {
|
|||||||
|
|
||||||
given()
|
given()
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
.header(InternalValue.role, Role.Customer)
|
.header(InternalValue.role, Role.Manager)
|
||||||
.header(InternalValue.userId, lastOwnerId)
|
.header(InternalValue.userId, savedOwnerId)
|
||||||
.body(requestBody)
|
.body(requestBody)
|
||||||
.when()
|
.when()
|
||||||
.post("/graphql")
|
.post("/graphql")
|
||||||
.then()
|
.then()
|
||||||
.body("data.updateMenuItem.name", is(newValue))
|
.body("data.updateMenuItem.name", is(newValue))
|
||||||
.body("data.updateMenuItem.id", is(lastSavedId))
|
.body("data.updateMenuItem.id", is(savedMenuItemId.toString()))
|
||||||
.statusCode(200);
|
.statusCode(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-1
@@ -1 +1,33 @@
|
|||||||
mvn clean package -Dquarkus.container-image.push=false -Dquarkus.container-image.build=false
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Khởi tạo giá trị mặc định
|
||||||
|
DEBUG_FLAG=""
|
||||||
|
TEST_FLAG=""
|
||||||
|
|
||||||
|
# Duyệt qua các tham số đầu vào
|
||||||
|
for arg in "$@"; do
|
||||||
|
case $arg in
|
||||||
|
--debug)
|
||||||
|
DEBUG_FLAG="-Dmaven.surefire.debug"
|
||||||
|
shift # Bỏ qua flag này
|
||||||
|
;;
|
||||||
|
--test=*)
|
||||||
|
# Lấy giá trị sau dấu =
|
||||||
|
TEST_NAME="${arg#*=}"
|
||||||
|
TEST_FLAG="-Dtest=$TEST_NAME"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Các tham số không xác định (nếu cần xử lý thêm)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Running: mvn clean package $DEBUG_FLAG $TEST_FLAG"
|
||||||
|
|
||||||
|
# Chạy lệnh Maven
|
||||||
|
mvn clean package \
|
||||||
|
-Dquarkus.container-image.push=false \
|
||||||
|
-Dquarkus.container-image.build=false \
|
||||||
|
$DEBUG_FLAG \
|
||||||
|
$TEST_FLAG
|
||||||
Reference in New Issue
Block a user