chore: update

This commit is contained in:
TakahashiNg
2026-05-12 01:37:50 +00:00
parent 104b66c07e
commit a36ead2085
2 changed files with 56 additions and 10 deletions
@@ -29,8 +29,15 @@ public class ShiftService {
@Query("allShifts")
@Description("Lấy danh sách tất cả các loại ca trực")
@RolesAllowed({ Role.Staff, Role.Manager })
public List<ShiftEntity> getAllShifts() {
return ShiftEntity.listAll();
public List<ShiftEntity> getAllShifts() throws GraphQLException {
String ownerId = request.getHeader(InternalValue.managerId);
if (ownerId == null || ownerId.isEmpty()) {
ownerId = request.getHeader(InternalValue.userId);
}
EateryEntity eatery = EateryEntity.findByOwnerId(ownerId);
return ShiftEntity.list("eatery", eatery);
}
@Query("myRegistrations")
@@ -31,9 +31,14 @@ public class ShiftServiceTest {
@Test
void testGetAllShifts() {
createMockShift("Ca Sáng", "08:00:00", "12:00:00");
UUID ownerId = createMockOwner();
EateryEntity eatery = createMockEatery(ownerId);
createMockShift("Ca Sáng", "08:00:00", "12:00:00", eatery);
given()
.header(InternalValue.role, Role.Manager)
.header(InternalValue.userId, ownerId)
.contentType("application/json")
.body("{ \"query\": \"{ allShifts { name startTime } }\" }")
.when()
@@ -74,12 +79,20 @@ public class ShiftServiceTest {
.post("/graphql")
.then()
.statusCode(200)
.body("data.createShift.name", is("Ca Chiều"));
.body("data.createShift.name", is("Ca Sáng"));
}
@Test
void testRegisterShift_Success() {
ShiftEntity shift = createMockShift("Ca Tối", "18:00:00", "22:00:00");
UUID ownerId = createMockOwner();
EateryEntity eatery = createMockEatery(ownerId);
ShiftEntity shift = createMockShift(
"Ca Tối",
"18:00:00",
"22:00:00",
eatery
);
UUID staffId = UUID.randomUUID();
String mutation = String.format(
@@ -100,11 +113,23 @@ public class ShiftServiceTest {
@Test
void testRegisterShift_Overlap_Fail() {
UUID ownerId = createMockOwner();
EateryEntity eatery = createMockEatery(ownerId);
UUID staffId = UUID.randomUUID();
// Tạo 2 ca bị trùng giờ nhau
ShiftEntity shift1 = createMockShift("Ca 1", "08:00:00", "12:00:00");
ShiftEntity shift2 = createMockShift("Ca 2", "10:00:00", "14:00:00");
ShiftEntity shift1 = createMockShift(
"Ca 1",
"08:00:00",
"12:00:00",
eatery
);
ShiftEntity shift2 = createMockShift(
"Ca 2",
"10:00:00",
"14:00:00",
eatery
);
// Đăng ký ca 1 trước
registerStaffToShift(staffId, shift1);
@@ -129,8 +154,16 @@ public class ShiftServiceTest {
@Test
void testDeleteShift_WithRegistrations_Fail() {
ShiftEntity shift = createMockShift("Ca Xóa", "08:00:00", "12:00:00");
registerStaffToShift(UUID.randomUUID(), shift);
UUID ownerId = createMockOwner();
EateryEntity eatery = createMockEatery(ownerId);
ShiftEntity shift = createMockShift(
"Ca Xóa",
"08:00:00",
"12:00:00",
eatery
);
UUID staffId = UUID.randomUUID();
registerStaffToShift(staffId, shift);
String mutation = String.format(
"mutation { deleteShift(id: \\\"%s\\\") }",
@@ -150,8 +183,14 @@ public class ShiftServiceTest {
// --- HELPER METHODS ---
@Transactional
ShiftEntity createMockShift(String name, String start, String end) {
ShiftEntity createMockShift(
String name,
String start,
String end,
EateryEntity eatery
) {
ShiftEntity shift = new ShiftEntity();
shift.eatery = eatery;
shift.name = name;
shift.startTime = LocalTime.parse(start);
shift.endTime = LocalTime.parse(end);