From 8b44f75a67b7061177c8e18256b1810f1504b8ad Mon Sep 17 00:00:00 2001 From: snowman Date: Sun, 20 Aug 2023 02:37:05 +0800 Subject: [PATCH] rename url and revise createRoom test --- .../spring/controllers/RoomController.java | 5 ++--- .../controllers/RoomControllerTest.java | 20 +++++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/RoomController.java b/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/RoomController.java index dba452d3..760eb20c 100644 --- a/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/RoomController.java +++ b/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/RoomController.java @@ -23,14 +23,14 @@ public class RoomController { private final CreateRoomUseCase createRoomUseCase; - @PostMapping("/game") + @PostMapping("/room") public ResponseEntity createGame(@RequestBody CreateRoomRequest request) { CreateRoomPresenter presenter = new CreateRoomPresenter(); createRoomUseCase.execute(request.toRequest(), presenter); return status(OK).body(presenter.getCreateRoomView()); } - class CreateRoomPresenter implements CreateRoomUseCase.Presenter { + static class CreateRoomPresenter implements CreateRoomUseCase.Presenter { private Room room; @Override @@ -57,5 +57,4 @@ public CreateRoomUseCase.Request toRequest() { return new CreateRoomUseCase.Request(roomName, userName, userImage); } } - } diff --git a/packages/backend/spring/src/test/java/tw/waterballsa/gaas/citadels/spring/controllers/RoomControllerTest.java b/packages/backend/spring/src/test/java/tw/waterballsa/gaas/citadels/spring/controllers/RoomControllerTest.java index 839a0887..19561c81 100644 --- a/packages/backend/spring/src/test/java/tw/waterballsa/gaas/citadels/spring/controllers/RoomControllerTest.java +++ b/packages/backend/spring/src/test/java/tw/waterballsa/gaas/citadels/spring/controllers/RoomControllerTest.java @@ -3,7 +3,6 @@ import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.springframework.test.web.servlet.ResultActions; -import tw.waterballsa.gaas.citadels.app.usecases.CreateRoomUseCase; import tw.waterballsa.gaas.citadels.spring.CitadelsSpringBootTest; import tw.waterballsa.gaas.citadels.spring.controllers.viewmodel.CreateRoomView; import tw.waterballsa.gaas.citadels.spring.controllers.viewmodel.RoomView; @@ -22,25 +21,24 @@ public class RoomControllerTest extends CitadelsSpringBootTest { private static final String API_PREFIX = "/api/citadels"; @Test - public void whenUserACreatRoom_ShouldCreateSuccessfully() { - RoomController.CreateRoomRequest createRoomRequest = new RoomController.CreateRoomRequest("RoomA", "userA","user.png"); - CreateRoomView createRoomView = getBody(createRoom(createRoomRequest.toRequest()), CreateRoomView.class); + public void whenUserACreateRoom_ShouldCreateSuccessfully() { + RoomController.CreateRoomRequest createRoomRequest = new RoomController.CreateRoomRequest("RoomA", "userA", "user.png"); + CreateRoomView createRoomView = getBody(createRoom(createRoomRequest), CreateRoomView.class); Optional roomData = RoomDAO.findById(createRoomView.getRoom().getRoomId()); assertTrue(roomData.isPresent()); RoomData room = roomData.get(); UserData userData = room.getUsers().get(0); RoomView roomView = createRoomView.getRoom(); - assertEquals(roomView.getRoomName(),room.getName()); - assertEquals(roomView.getHolderName(),userData.getName()); + assertEquals(roomView.getRoomName(), room.getName()); + assertEquals(roomView.getHolderName(), userData.getName()); } - @SneakyThrows - private ResultActions createRoom(CreateRoomUseCase.Request createRoomRequest) { - return mockMvc.perform(post(API_PREFIX + "/game") + private ResultActions createRoom(RoomController.CreateRoomRequest createRoomRequest) { + return mockMvc.perform(post(API_PREFIX + "/room") .contentType(APPLICATION_JSON) .content(toJson(createRoomRequest))) - .andExpect(status().isOk()); - } + .andExpect(status().isOk()); + } }