-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/java/umc/kkijuk/server/member/dto/MemberPhoneNumberDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 0 additions & 146 deletions
146
src/test/java/umc/kkijuk/server/member/service/MemberInfoTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
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; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
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("[email protected]", "홍길동", | ||
"01012345678", LocalDate.parse("1999-03-31"), | ||
"testpassword", MarketingAgree.BOTH, State.ACTIVATE); | ||
member.changeFieldInfo(List.of("game", "computer")); | ||
memberJpaRepository.save(member); | ||
} | ||
|
||
private String testMemberEmail = "[email protected]"; | ||
@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<MemberInfoResponse> response = restTemplate.getForEntity("/member/myPage/info", MemberInfoResponse.class); | ||
|
||
// Then | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
|
||
MemberInfoResponse body = response.getBody(); | ||
assertNotNull(body); | ||
assertEquals("[email protected]", 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<MemberInfoChangeDto> requestEntity = new HttpEntity<>(changeDto); | ||
|
||
// When | ||
ResponseEntity<Boolean> 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<MemberFieldResponse> 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<MemberFieldDto> request = new HttpEntity<>(memberFieldDto); | ||
//when | ||
ResponseEntity<Boolean> 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()); | ||
} | ||
} |