Skip to content

Commit

Permalink
test: 내 동네 등록 Controller 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
Srltas committed Oct 27, 2024
1 parent 42dac61 commit 949cfe8
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.srltas.runtogether.adapter.in;

import static com.srltas.runtogether.adapter.in.web.common.SessionAttribute.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.BDDMockito.*;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import com.srltas.runtogether.adapter.in.web.dto.AddUserNeighborhoodRequest;
import com.srltas.runtogether.adapter.out.session.UserSessionDTO;
import com.srltas.runtogether.application.port.in.AddUserNeighborhood;
import com.srltas.runtogether.application.port.in.AddUserNeighborhoodCommand;

import jakarta.servlet.http.HttpSession;

@ExtendWith(MockitoExtension.class)
class UserNeighborhoodControllerTest {

@Mock
private AddUserNeighborhood addUserNeighborhood;

@Mock
HttpSession session;

@InjectMocks
private UserNeighborhoodController userNeighborhoodController;

@Test
@DisplayName("내 동네 등록 성공")
void testAddUserNeighborhoodSuccess() {
AddUserNeighborhoodRequest request = new AddUserNeighborhoodRequest(100);
UserSessionDTO userSessionDTO = new UserSessionDTO(1L, "user1");
given(session.getAttribute(USER_SESSION)).willReturn(userSessionDTO);

ResponseEntity<Void> response = userNeighborhoodController.addUserNeighborhood(request, session);

assertThat(response.getStatusCode(), is(HttpStatus.CREATED));
verify(addUserNeighborhood).addNeighborhood(
new AddUserNeighborhoodCommand(userSessionDTO.userId(), request.neighborhoodId()));
}
}

0 comments on commit 949cfe8

Please sign in to comment.