Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename url and revise createRoom test #100

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要把 room 相關的 api 都放在 RoomController 嗎 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好呀

return mockMvc.perform(post(API_PREFIX + "/room")
.contentType(APPLICATION_JSON)
.content(toJson(createRoomRequest)))
.andExpect(status().isOk());
}
.andExpect(status().isOk());
}
}