Skip to content

Commit a715e2d

Browse files
committed
test: #89 판매자 정보 조회 API test 코드 추가
1 parent bef870e commit a715e2d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.ajou.hertz.common.auth.JwtTokenProvider;
3232
import com.ajou.hertz.common.auth.UserPrincipal;
3333
import com.ajou.hertz.common.config.SecurityConfig;
34+
import com.ajou.hertz.domain.instrument.service.InstrumentQueryService;
3435
import com.ajou.hertz.domain.user.constant.Gender;
3536
import com.ajou.hertz.domain.user.constant.RoleType;
3637
import com.ajou.hertz.domain.user.controller.UserController;
@@ -61,6 +62,9 @@ class UserControllerTest {
6162
@MockBean
6263
private UserQueryService userQueryService;
6364

65+
@MockBean
66+
private InstrumentQueryService instrumentQueryService;
67+
6468
private final MockMvc mvc;
6569

6670
private final ObjectMapper objectMapper;
@@ -295,6 +299,31 @@ public void securitySetUp() throws Exception {
295299
verifyEveryMocksShouldHaveNoMoreInteractions();
296300
}
297301

302+
@Test
303+
void 주어진_id로_판매자의_판매자_정보를_조회한다() throws Exception {
304+
// given
305+
long userId = 1L;
306+
UserDetails testUser = createTestUser(userId);
307+
UserDto expectedResult = createUserDto(userId);
308+
int sellingCount = 2;
309+
int soldCount = 3;
310+
given(userQueryService.getDtoById(userId)).willReturn(expectedResult);
311+
given(instrumentQueryService.countSellingItemsBySellerId(userId)).willReturn(sellingCount);
312+
given(instrumentQueryService.countSoldItemsBySellerId(userId)).willReturn(soldCount);
313+
314+
// when & then
315+
mvc.perform(
316+
get("/api/users/{userId}/seller", userId)
317+
.header(API_VERSION_HEADER_NAME, 1)
318+
.with(user(testUser))
319+
)
320+
.andExpect(status().isOk());
321+
then(userQueryService).should().getDtoById(userId);
322+
then(instrumentQueryService).should().countSellingItemsBySellerId(userId);
323+
then(instrumentQueryService).should().countSoldItemsBySellerId(userId);
324+
verifyEveryMocksShouldHaveNoMoreInteractions();
325+
}
326+
298327
private void verifyEveryMocksShouldHaveNoMoreInteractions() {
299328
then(userCommandService).shouldHaveNoMoreInteractions();
300329
then(userQueryService).shouldHaveNoMoreInteractions();

0 commit comments

Comments
 (0)