diff --git a/src/main/java/umc/kkijuk/server/member/dto/MemberInfoChangeDto.java b/src/main/java/umc/kkijuk/server/member/dto/MemberInfoChangeDto.java index b4df23ea..df5eca8b 100644 --- a/src/main/java/umc/kkijuk/server/member/dto/MemberInfoChangeDto.java +++ b/src/main/java/umc/kkijuk/server/member/dto/MemberInfoChangeDto.java @@ -1,6 +1,7 @@ package umc.kkijuk.server.member.dto; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @@ -11,9 +12,11 @@ @Data @NoArgsConstructor public class MemberInfoChangeDto { - private Long id; //jwt토큰으로 받을땐 제거 + @NotNull private String phoneNumber; + @NotNull private LocalDate birthDate; + @NotNull private MarketingAgree marketingAgree; @Builder diff --git a/src/main/java/umc/kkijuk/server/member/dto/MemberJoinDto.java b/src/main/java/umc/kkijuk/server/member/dto/MemberJoinDto.java index 85bd9421..8a319faa 100644 --- a/src/main/java/umc/kkijuk/server/member/dto/MemberJoinDto.java +++ b/src/main/java/umc/kkijuk/server/member/dto/MemberJoinDto.java @@ -1,5 +1,6 @@ package umc.kkijuk.server.member.dto; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @@ -13,13 +14,21 @@ @NoArgsConstructor public class MemberJoinDto { + @NotNull private String email; + @NotNull private String name; + @NotNull private String phoneNumber; + @NotNull private LocalDate birthDate; + @NotNull private String password; + @NotNull private String passwordConfirm; + @NotNull private MarketingAgree marketingAgree; + @NotNull private State userState; // @Builder diff --git a/src/main/java/umc/kkijuk/server/member/dto/MemberPhoneNumberDto.java b/src/main/java/umc/kkijuk/server/member/dto/MemberPhoneNumberDto.java index 968a6e5c..62ded14a 100644 --- a/src/main/java/umc/kkijuk/server/member/dto/MemberPhoneNumberDto.java +++ b/src/main/java/umc/kkijuk/server/member/dto/MemberPhoneNumberDto.java @@ -1,5 +1,6 @@ package umc.kkijuk.server.member.dto; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @@ -7,6 +8,7 @@ @Data @NoArgsConstructor public class MemberPhoneNumberDto { + @NotNull private String phoneNumber; @Builder diff --git a/src/test/java/umc/kkijuk/server/member/service/MemberInfoTest.java b/src/test/java/umc/kkijuk/server/member/service/MemberInfoTest.java deleted file mode 100644 index 0159aca0..00000000 --- a/src/test/java/umc/kkijuk/server/member/service/MemberInfoTest.java +++ /dev/null @@ -1,146 +0,0 @@ -package umc.kkijuk.server.member.service; - -import org.junit.jupiter.api.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.transaction.annotation.Transactional; -import umc.kkijuk.server.member.controller.response.MemberFieldResponse; -import umc.kkijuk.server.member.controller.response.MemberInfoResponse; -import umc.kkijuk.server.member.controller.response.ResultResponse; -import umc.kkijuk.server.member.domain.MarketingAgree; -import umc.kkijuk.server.member.domain.Member; -import umc.kkijuk.server.member.domain.State; -import umc.kkijuk.server.member.dto.MemberFieldDto; -import umc.kkijuk.server.member.dto.MemberInfoChangeDto; -import umc.kkijuk.server.member.repository.MemberJpaRepository; - -import java.time.LocalDate; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class MemberInfoTest { - - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private MemberJpaRepository memberJpaRepository; - - @BeforeEach - public void setup() { - memberJpaRepository.deleteAll(); - } - - - - @Test - @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) - public void 내정보_조회() { - // Given - Member member1 = new Member("asd@naver.com", "홍길동", "010-1234-5678", - LocalDate.parse("1999-03-31"), "passwordTest", MarketingAgree.BOTH, State.ACTIVATE); - Member savedMember = memberJpaRepository.save(member1); - - // When - ResponseEntity response = restTemplate.getForEntity("/member/myPage/info", MemberInfoResponse.class); - - // Then - assertEquals(HttpStatus.OK, response.getStatusCode()); - - MemberInfoResponse body = response.getBody(); - assertNotNull(body); - assertEquals("asd@naver.com", body.getEmail()); - assertEquals("홍길동", body.getName()); - assertEquals("010-1234-5678", body.getPhoneNumber()); - assertEquals(LocalDate.parse("1999-03-31"), body.getBirthDate()); - } - - @Test - @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) - public void 내정보_수정() { - // Given - Member member1 = new Member("asd@naver.com", "홍길동", "010-1234-5678", - LocalDate.parse("1999-03-31"), "passwordTest", MarketingAgree.BOTH, State.ACTIVATE); - memberJpaRepository.save(member1); - - - MemberInfoChangeDto changeDto = MemberInfoChangeDto.builder() - .phoneNumber("010-5678-1234") - .birthDate(LocalDate.parse("2000-01-01")) - .marketingAgree(MarketingAgree.EMAIL) - .build(); - - HttpEntity requestEntity = new HttpEntity<>(changeDto); - - // When - ResponseEntity response = restTemplate.exchange("/member/myPage/info", HttpMethod.PUT, requestEntity, ResultResponse.class); - - // Then - assertEquals(HttpStatus.OK, response.getStatusCode()); - ResultResponse body = response.getBody(); - assertNotNull(body); - assertEquals("information update success", body.getMessage()); - - // Verify changes - Member updatedMember = memberJpaRepository.findById(member1.getId()).orElse(null); - assertNotNull(updatedMember); - assertEquals("010-5678-1234", updatedMember.getPhoneNumber()); - assertEquals(LocalDate.parse("2000-01-01"), updatedMember.getBirthDate()); - assertEquals(MarketingAgree.EMAIL, updatedMember.getMarketingAgree()); - } - - @Test - @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) - public void 관심분야_조회(){ - // 회원추가 - Member member1 = new Member("asd@naver.com", "홍길동", "010-1234-5678", - LocalDate.parse("1999-03-31"), "passwordTest", MarketingAgree.BOTH, State.ACTIVATE); - member1.changeFieldInfo(List.of("game", "computer")); - memberJpaRepository.save(member1); - - ResponseEntity response = restTemplate.getForEntity("/member/myPage/field", MemberFieldResponse.class); - - assertEquals(HttpStatus.OK, response.getStatusCode()); - MemberFieldResponse body = response.getBody(); - assertNotNull(body); - assertEquals(List.of("game", "computer"), body.getField()); - } - - - @Test - @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) - public void 관심분야_수정(){ - //given - //회원추가 - Member member1 = new Member("asd@naver.com", "홍길동", "010-1234-5678", - LocalDate.parse("1999-03-31"), "passwordTest", MarketingAgree.BOTH, State.ACTIVATE); - member1.changeFieldInfo(List.of("game", "computer")); - memberJpaRepository.save(member1); - - - MemberFieldDto memberFieldDto = MemberFieldDto.builder().field(List.of("book", "movie")).build(); - HttpEntity request = new HttpEntity<>(memberFieldDto); - //when - ResponseEntity response = restTemplate.postForEntity("/member/myPage/field", request, MemberFieldResponse.class); - //then - assertEquals(HttpStatus.OK, response.getStatusCode()); - MemberFieldResponse body = response.getBody(); - assertNotNull(body); - assertEquals(List.of("book", "movie"), body.getField()); - - Member updatedMember = memberJpaRepository.findById(1L).orElse(null); - assertNotNull(updatedMember); - assertEquals(List.of("book", "movie"), updatedMember.getField()); - } - -} diff --git a/src/test/java/umc/kkijuk/server/member/service/MemberServiceTest.java b/src/test/java/umc/kkijuk/server/member/service/MemberServiceTest.java index b2d621b3..ea0f9459 100644 --- a/src/test/java/umc/kkijuk/server/member/service/MemberServiceTest.java +++ b/src/test/java/umc/kkijuk/server/member/service/MemberServiceTest.java @@ -1,22 +1,30 @@ package umc.kkijuk.server.member.service; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.transaction.annotation.Transactional; +import umc.kkijuk.server.member.controller.response.MemberFieldResponse; +import umc.kkijuk.server.member.controller.response.MemberInfoResponse; +import umc.kkijuk.server.member.controller.response.ResultResponse; import umc.kkijuk.server.member.domain.exception.ConfirmPasswordMismatchException; import umc.kkijuk.server.member.domain.MarketingAgree; import umc.kkijuk.server.member.domain.Member; import umc.kkijuk.server.member.domain.State; +import umc.kkijuk.server.member.dto.MemberFieldDto; +import umc.kkijuk.server.member.dto.MemberInfoChangeDto; import umc.kkijuk.server.member.dto.MemberJoinDto; import umc.kkijuk.server.member.repository.MemberJpaRepository; import java.time.LocalDate; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -24,7 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@Transactional public class MemberServiceTest { @Autowired @@ -36,6 +43,15 @@ public class MemberServiceTest { @Autowired private TestRestTemplate restTemplate; + @BeforeEach + public void setUp() { + Member member = new Member("test@naver.com", "홍길동", + "01012345678", LocalDate.parse("1999-03-31"), + "testpassword", MarketingAgree.BOTH, State.ACTIVATE); + member.changeFieldInfo(List.of("game", "computer")); + memberJpaRepository.save(member); + } + private String testMemberEmail = "asd@naver.com"; @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) @@ -115,4 +131,87 @@ public void joinExceptionWIthPasswordIncorrect() { assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); assertThat(response.getBody()).contains("Passwords do not match"); } + + @Test + @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) + public void 내정보_조회_성공() { + // Given + + // When + ResponseEntity response = restTemplate.getForEntity("/member/myPage/info", MemberInfoResponse.class); + + // Then + assertEquals(HttpStatus.OK, response.getStatusCode()); + + MemberInfoResponse body = response.getBody(); + assertNotNull(body); + assertEquals("test@naver.com", body.getEmail()); + assertEquals("홍길동", body.getName()); + assertEquals("01012345678", body.getPhoneNumber()); + assertEquals(LocalDate.parse("1999-03-31"), body.getBirthDate()); + } + + @Test + @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) + public void 내정보_수정() { + // Given + + MemberInfoChangeDto changeDto = MemberInfoChangeDto.builder() + .phoneNumber("010-5678-1234") + .birthDate(LocalDate.parse("2000-01-01")) + .marketingAgree(MarketingAgree.EMAIL) + .build(); + + HttpEntity requestEntity = new HttpEntity<>(changeDto); + + // When + ResponseEntity response = restTemplate.exchange("/member/myPage/info", HttpMethod.PUT, requestEntity, Boolean.class); + + // Then + assertEquals(HttpStatus.OK, response.getStatusCode()); + Boolean body = response.getBody(); + assertNotNull(body); + assertEquals(true, body); + + // Verify changes + Member updatedMember = memberJpaRepository.findById(1L).orElse(null); + assertNotNull(updatedMember); + assertEquals("010-5678-1234", updatedMember.getPhoneNumber()); + assertEquals(LocalDate.parse("2000-01-01"), updatedMember.getBirthDate()); + assertEquals(MarketingAgree.EMAIL, updatedMember.getMarketingAgree()); + } + + @Test + @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) + public void 관심분야_조회(){ + // 회원추가 + + ResponseEntity response = restTemplate.getForEntity("/member/myPage/field", MemberFieldResponse.class); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + MemberFieldResponse body = response.getBody(); + assertNotNull(body); + assertEquals(List.of("game", "computer"), body.getField()); + } + + + @Test + @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) + public void 관심분야_수정(){ + //given + + MemberFieldDto memberFieldDto = MemberFieldDto.builder().field(List.of("book", "movie")).build(); + HttpEntity request = new HttpEntity<>(memberFieldDto); + //when + ResponseEntity response = restTemplate.postForEntity("/member/myPage/field", request, Boolean.class); + //then + assertEquals(HttpStatus.OK, response.getStatusCode()); + Boolean body = response.getBody(); + assertNotNull(body); + assertEquals(true, body); + + Member updatedMember = memberJpaRepository.findById(1L).orElse(null); + assertNotNull(updatedMember); + assertEquals(List.of("book", "movie"), updatedMember.getField()); + } }