Skip to content

Commit

Permalink
rename url and revise createRoom test
Browse files Browse the repository at this point in the history
  • Loading branch information
snowmancc committed Aug 19, 2023
1 parent ca65afb commit 8b44f75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
public class RoomController {
private final CreateRoomUseCase createRoomUseCase;

@PostMapping("/game")
@PostMapping("/room")
public ResponseEntity<CreateRoomView> 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
Expand All @@ -57,5 +57,4 @@ public CreateRoomUseCase.Request toRequest() {
return new CreateRoomUseCase.Request(roomName, userName, userImage);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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> 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());
}
}

0 comments on commit 8b44f75

Please sign in to comment.