chore: update
This commit is contained in:
@@ -22,7 +22,6 @@ bin/
|
||||
nb-configuration.xml
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
.factorypath
|
||||
*.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")
|
||||
@RolesAllowed(Role.Manager)
|
||||
@Transactional
|
||||
public MenuItemEntity updateMenuItem(
|
||||
@Name("menuItem") UpdateMenuItem menuItem
|
||||
) {
|
||||
MenuItemEntity item = MenuItemEntity.findById(menuItem.getId());
|
||||
public MenuItemEntity updateMenuItem(UpdateMenuItem menuItem) {
|
||||
UUID ownerId = UUID.fromString(request.getHeader(InternalValue.userId));
|
||||
|
||||
MenuItemEntity item = MenuItemEntity.find(
|
||||
"id = ?1 and eatery.ownerId = ?2",
|
||||
menuItem.getId(),
|
||||
ownerId
|
||||
).firstResult();
|
||||
|
||||
if (item == null) return null;
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ quarkus.native.remote-container-build=true
|
||||
quarkus.native.additional-build-args=--future-defaults=all
|
||||
|
||||
# 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
|
||||
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.MenuItemEntity;
|
||||
import com.drinkool.lib.dtos.event.ManagerCreate;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.smallrye.reactive.messaging.memory.InMemoryConnector;
|
||||
@@ -61,9 +60,10 @@ public class EateryServiceTest {
|
||||
Assertions.assertEquals("Quan Bun Cha Test", eatery.name);
|
||||
}
|
||||
|
||||
private UUID lastSavedId;
|
||||
private String lastSavedName;
|
||||
private UUID lastOwnerId = UUID.randomUUID();
|
||||
private UUID savedEateryId;
|
||||
private String savedEateryName;
|
||||
private UUID savedOwnerId = UUID.randomUUID();
|
||||
private UUID savedMenuItemId;
|
||||
|
||||
@BeforeEach
|
||||
@Transactional
|
||||
@@ -71,11 +71,11 @@ public class EateryServiceTest {
|
||||
MenuItemEntity.deleteAll();
|
||||
EateryEntity.deleteAll();
|
||||
|
||||
lastSavedName = faker.restaurant().name();
|
||||
savedEateryName = faker.restaurant().name();
|
||||
|
||||
EateryEntity eatery = new EateryEntity();
|
||||
eatery = eatery.create(lastOwnerId, lastSavedName);
|
||||
lastSavedId = eatery.id;
|
||||
eatery = eatery.create(savedOwnerId, savedEateryName);
|
||||
savedEateryId = eatery.id;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
EateryEntity e = new EateryEntity();
|
||||
@@ -83,13 +83,13 @@ public class EateryServiceTest {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
MenuItemEntity.create(
|
||||
savedMenuItemId = MenuItemEntity.create(
|
||||
eatery,
|
||||
new AddMenuItem(
|
||||
faker.food().dish(),
|
||||
faker.number().randomDouble(2, 10, 100)
|
||||
)
|
||||
);
|
||||
).id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class EateryServiceTest {
|
||||
.statusCode(200)
|
||||
// GraphQL trả về dữ liệu bọc trong object "data"
|
||||
.body("data.allEateries", notNullValue())
|
||||
.body("data.allEateries.name", hasItems(lastSavedName));
|
||||
.body("data.allEateries.name", hasItems(savedEateryName));
|
||||
}
|
||||
|
||||
@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
|
||||
String query = String.format(
|
||||
"{ \"query\": \"{ eateryById(id: \\\"%s\\\") { ownerId name } }\" }",
|
||||
lastSavedId
|
||||
savedEateryId
|
||||
);
|
||||
|
||||
given()
|
||||
@@ -126,7 +126,7 @@ public class EateryServiceTest {
|
||||
.post("/graphql")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("data.eateryById.name", is(lastSavedName));
|
||||
.body("data.eateryById.name", is(savedEateryName));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,7 +154,7 @@ public class EateryServiceTest {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.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)
|
||||
.when()
|
||||
.post("/graphql")
|
||||
@@ -189,7 +189,7 @@ public class EateryServiceTest {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header(InternalValue.role, Role.Customer)
|
||||
.header(InternalValue.userId, lastOwnerId)
|
||||
.header(InternalValue.userId, savedOwnerId)
|
||||
.body(requestBody)
|
||||
.when()
|
||||
.post("/graphql")
|
||||
@@ -229,7 +229,7 @@ public class EateryServiceTest {
|
||||
"}";
|
||||
|
||||
Map<String, Object> variables = new HashMap<>();
|
||||
variables.put("id", lastSavedId.toString());
|
||||
variables.put("id", savedEateryId.toString());
|
||||
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("query", query);
|
||||
@@ -276,19 +276,19 @@ public class EateryServiceTest {
|
||||
@Test
|
||||
public void testUpdateMenuItem_Success() {
|
||||
String mutation = """
|
||||
mutation updateMenuItem($menuItem: UpdateMenuItemInput!) {
|
||||
updateMenuItem(menuItem: $menuItem) {
|
||||
id
|
||||
name
|
||||
price
|
||||
}
|
||||
}
|
||||
mutation updateMenuItem($menuItem: UpdateMenuItemInput!) {
|
||||
updateMenuItem(menuItem: $menuItem) {
|
||||
id
|
||||
name
|
||||
price
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String newValue = "Phở Bò";
|
||||
|
||||
Map<String, Object> menuItemData = new HashMap<>();
|
||||
menuItemData.put("id", lastSavedName);
|
||||
menuItemData.put("id", savedMenuItemId);
|
||||
menuItemData.put("name", newValue);
|
||||
|
||||
Map<String, Object> variables = new HashMap<>();
|
||||
@@ -300,14 +300,14 @@ public class EateryServiceTest {
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header(InternalValue.role, Role.Customer)
|
||||
.header(InternalValue.userId, lastOwnerId)
|
||||
.header(InternalValue.role, Role.Manager)
|
||||
.header(InternalValue.userId, savedOwnerId)
|
||||
.body(requestBody)
|
||||
.when()
|
||||
.post("/graphql")
|
||||
.then()
|
||||
.body("data.updateMenuItem.name", is(newValue))
|
||||
.body("data.updateMenuItem.id", is(lastSavedId))
|
||||
.body("data.updateMenuItem.id", is(savedMenuItemId.toString()))
|
||||
.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