Skip to content

Commit

Permalink
test/#359: UpdateWeight 통합 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
LJH098 committed Jul 12, 2024
1 parent 385db5f commit a4ff9e7
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.gaebaljip.exceed.member;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.ResultActions;

import com.gaebaljip.exceed.common.IntegrationTest;
import com.gaebaljip.exceed.common.WithMockUser;
import com.gaebaljip.exceed.dto.request.UpdateWeightRequest;
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberEntity;
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberRepository;

public class UpdateWeightIntegrationTest extends IntegrationTest {
@Autowired private MemberRepository memberRepository;

@Test
@DisplayName("몸무게 수정 성공")
@WithMockUser(memberId = 1L)
void when_updateWeight_expected_success() throws Exception {
// given
Long memberId = 1L;
UpdateWeightRequest updateWeightRequest =
UpdateWeightRequest.builder().weight(50.0).targetWeight(70.5).build();

// when
ResultActions resultActions =
mockMvc.perform(
patch("/v1/members/weight")
.content(om.writeValueAsString(updateWeightRequest))
.contentType(MediaType.APPLICATION_JSON));
MemberEntity member = memberRepository.findById(memberId).get();

// then
resultActions.andExpectAll(status().isOk());
assertAll(
() -> assertEquals(updateWeightRequest.weight(), member.getWeight()),
() -> assertEquals(updateWeightRequest.targetWeight(), member.getTargetWeight()));
}
}

0 comments on commit a4ff9e7

Please sign in to comment.