diff --git a/.gitignore b/.gitignore index 0a765de9..4208daf5 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,4 @@ out/ src/main/resources/app.key src/main/resources/app.pub -!**/src/main/generated \ No newline at end of file +/src/main/generated/ \ No newline at end of file diff --git a/src/main/java/org/store/clothstar/member/service/MemberServiceImpl.java b/src/main/java/org/store/clothstar/member/service/MemberServiceImpl.java index df36d0d0..3618a5d7 100644 --- a/src/main/java/org/store/clothstar/member/service/MemberServiceImpl.java +++ b/src/main/java/org/store/clothstar/member/service/MemberServiceImpl.java @@ -99,7 +99,7 @@ public Long signUp(CreateMemberRequest createMemberDTO) { MemberEntity memberEntity = createMemberDTO.toMemberEntity(encodedPassword); //인증코드 확인 - boolean certifyStatus = verifyEmailCode(memberEntity.getEmail(), createMemberDTO.getCertifyNum()); + boolean certifyStatus = verifyEmailCertifyNum(memberEntity.getEmail(), createMemberDTO.getCertifyNum()); if (certifyStatus) { memberEntity = memberRepository.save(memberEntity); } else { @@ -129,12 +129,12 @@ private String sendEmailAuthentication(String toEmail) { return certifyNum; } - public Boolean verifyEmailCode(String email, String certifyNum) { - String codeFoundByEmail = redisUtil.getData(email); - if (codeFoundByEmail == null) { + public Boolean verifyEmailCertifyNum(String email, String certifyNum) { + String certifyNumFoundByRedis = redisUtil.getData(email); + if (certifyNumFoundByRedis == null) { return false; } - return codeFoundByEmail.equals(certifyNum); + return certifyNumFoundByRedis.equals(certifyNum); } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 406af5ca..c3629899 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -27,7 +27,7 @@ spring: # Redis data: redis: - host: localhost + host: ENC(GUuFDW7HjE98e7N28Vkb/xoIEgLeOCb5) port: 6379 duration: 600 diff --git a/src/test/java/org/store/clothstar/common/config/JasyptConfigTest.java b/src/test/java/org/store/clothstar/common/config/JasyptConfigTest.java index 5371bf4b..39727bba 100644 --- a/src/test/java/org/store/clothstar/common/config/JasyptConfigTest.java +++ b/src/test/java/org/store/clothstar/common/config/JasyptConfigTest.java @@ -10,8 +10,8 @@ class JasyptConfigTest { @Test void jasypt() { String url = ""; - String username = "nexthope22@gmail.com"; - String password = "pcde pppv pnxa dfmg"; + String username = ""; + String password = ""; System.out.println(jasyptEncoding(url)); System.out.println(jasyptEncoding(username)); diff --git a/src/test/java/org/store/clothstar/common/mail/MailServiceTest.java b/src/test/java/org/store/clothstar/common/mail/MailServiceTest.java index ded32e15..c9e143f2 100644 --- a/src/test/java/org/store/clothstar/common/mail/MailServiceTest.java +++ b/src/test/java/org/store/clothstar/common/mail/MailServiceTest.java @@ -1,7 +1,6 @@ package org.store.clothstar.common.mail; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -10,7 +9,6 @@ @SpringBootTest @ActiveProfiles("test") -@Disabled class MailServiceTest { @Autowired MailService mailService; diff --git a/src/test/java/org/store/clothstar/common/redis/RedisUtilTest.java b/src/test/java/org/store/clothstar/common/redis/RedisUtilTest.java index 3a2a24c8..ecea53b7 100644 --- a/src/test/java/org/store/clothstar/common/redis/RedisUtilTest.java +++ b/src/test/java/org/store/clothstar/common/redis/RedisUtilTest.java @@ -1,29 +1,39 @@ package org.store.clothstar.common.redis; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest +@ActiveProfiles("test") class RedisUtilTest { @Autowired private RedisUtil redisUtil; - + @DisplayName("redis 데이터가 생성되고 삭제되는지 확인한다.") @Test - public void redisTest() throws Exception { + public void redisCreateAndDeleteTest() throws Exception { + //redis 데이터가 생성됐는지 확인한다. //given - String email = "test@test.com"; - String code = "aaa111"; + String key = "test@test.com"; + String value = "aaa111"; + + //when + redisUtil.setDataExpire(key, value); + + //then + Assertions.assertTrue(redisUtil.existData(key)); + Assertions.assertEquals(redisUtil.getData(key), value); + //redis 데이터가 삭제 됐는지 확인한다. //when - redisUtil.setDataExpire(email, code); + redisUtil.deleteData(key); //then - Assertions.assertTrue(redisUtil.existData("test@test.com")); - Assertions.assertFalse(redisUtil.existData("test1@test.com")); - Assertions.assertEquals(redisUtil.getData(email), "aaa111"); + Assertions.assertFalse(redisUtil.existData(key)); } } \ No newline at end of file diff --git a/src/test/java/org/store/clothstar/member/controller/MemberAndSellerSignUpIntegrationTest.java b/src/test/java/org/store/clothstar/member/controller/MemberAndSellerSignUpIntegrationTest.java index 4dff33e1..cef59b15 100644 --- a/src/test/java/org/store/clothstar/member/controller/MemberAndSellerSignUpIntegrationTest.java +++ b/src/test/java/org/store/clothstar/member/controller/MemberAndSellerSignUpIntegrationTest.java @@ -1,8 +1,6 @@ package org.store.clothstar.member.controller; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -14,11 +12,9 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; import org.springframework.transaction.annotation.Transactional; -import org.store.clothstar.common.config.jwt.JwtUtil; +import org.store.clothstar.common.redis.RedisUtil; import org.store.clothstar.member.domain.MemberRole; -import org.store.clothstar.member.dto.request.CreateSellerRequest; -import org.store.clothstar.member.dto.request.ModifyMemberRequest; -import org.store.clothstar.member.dto.request.ModifyPasswordRequest; +import org.store.clothstar.member.dto.request.*; import org.store.clothstar.member.entity.MemberEntity; import org.store.clothstar.member.repository.MemberRepository; import org.store.clothstar.member.util.CreateObject; @@ -41,23 +37,27 @@ class MemberAndSellerSignUpIntegrationTest { private ObjectMapper objectMapper; @Autowired - private JwtUtil jwtUtil; + private MemberRepository memberRepository; @Autowired - private MemberRepository memberRepository; + private RedisUtil redisUtil; private static final String MEMBER_URL = "/v1/members"; private static final String SELLER_URL = "/v1/sellers"; private MemberEntity memberEntity; - @DisplayName("회원가입을 완료한 후 memberId와 accessToken을 받아서 판매자 가입을 신청한 테스트이다.") + @DisplayName("회원가입 통합테스트") @WithMockUser - @Disabled @Test - void signUpAndSellerTest() throws Exception { + void signUpIntegrationTest() throws Exception { //회원가입 통합 테스트 //given - final String requestBody = objectMapper.writeValueAsString(CreateObject.getCreateMemberRequest()); + String email = "test@naver.com"; + String certifyNum = redisUtil.createdCertifyNum(); + redisUtil.createRedisData(email, certifyNum); + + CreateMemberRequest createMemberRequest = CreateObject.getCreateMemberRequest(email, certifyNum); + final String requestBody = objectMapper.writeValueAsString(createMemberRequest); //when ResultActions actions = mockMvc.perform(post(MEMBER_URL) @@ -66,22 +66,39 @@ void signUpAndSellerTest() throws Exception { //then actions.andExpect(status().isCreated()); + } - String responseBody = actions.andReturn().getResponse().getContentAsString(); - JsonNode jsonNode = objectMapper.readTree(responseBody); - Long memberId = jsonNode.get("id").asLong(); - MemberEntity memberEntity = memberRepository.findById(memberId).get(); - String accessToken = jwtUtil.createAccessToken(memberEntity); + @DisplayName("회원가입시 인증번호 전송 통합테스트") + @WithMockUser + @Test + void certifyNumEmailSendTest() throws Exception { + //given + CertifyNumRequest certifyNumRequest = new CertifyNumRequest("test@naver.com"); + final String url = "/v1/members/auth"; + final String requestBody = objectMapper.writeValueAsString(certifyNumRequest); + + //when + ResultActions actions = mockMvc.perform(post(url) + .contentType(MediaType.APPLICATION_JSON) + .content(requestBody)); - //회원가입해서 받은 memberId로 판매자 신청 테스트 + //then + actions.andExpect(status().isOk()).andDo(print()); + } + + @DisplayName("판매자(Seller) 가입 통합테스트") + @WithMockUser(roles = "SELLER") + @Test + void sellerSignUpIntegrationTest() throws Exception { //given + memberEntity = memberRepository.save(CreateObject.getMemberEntityByCreateMemberRequestDTO()); + Long memberId = memberEntity.getMemberId(); final String sellerUrl = SELLER_URL + "/" + memberId; CreateSellerRequest createSellerRequest = getCreateSellerRequest(memberId); final String sellerRequestBody = objectMapper.writeValueAsString(createSellerRequest); //when ResultActions sellerActions = mockMvc.perform(post(sellerUrl) - .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON) .content(sellerRequestBody)); diff --git a/src/test/java/org/store/clothstar/member/controller/MemberControllerValidationTest.java b/src/test/java/org/store/clothstar/member/controller/MemberControllerValidationTest.java index c67894ea..0f8ed093 100644 --- a/src/test/java/org/store/clothstar/member/controller/MemberControllerValidationTest.java +++ b/src/test/java/org/store/clothstar/member/controller/MemberControllerValidationTest.java @@ -13,10 +13,14 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; import org.springframework.transaction.annotation.Transactional; +import org.store.clothstar.common.error.exception.SignupCertifyNumAuthFailedException; import org.store.clothstar.member.dto.request.CreateMemberRequest; import org.store.clothstar.member.dto.request.ModifyPasswordRequest; import org.store.clothstar.member.repository.MemberRepository; +import org.store.clothstar.member.service.MemberService; +import org.store.clothstar.member.util.CreateObject; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -36,9 +40,24 @@ public class MemberControllerValidationTest { @Autowired MemberRepository memberRepository; + @Autowired + MemberService memberService; + private static final String MEMBER_SIGN_UP_URL = "/v1/members"; - @DisplayName("회원가입시 이메일 양식을 지켜야 한다..") + @DisplayName("회원가입시 인증번호가 틀리면 회원가입이 안돼야 한다.") + @Test + void signUpCertifyNumFailTest() { + //given + CreateMemberRequest createMemberRequest = CreateObject.getCreateMemberRequest(); + + //when & then + Throwable exception = assertThrows(SignupCertifyNumAuthFailedException.class, () -> { + memberService.signUp(createMemberRequest); + }); + } + + @DisplayName("회원가입시 이메일 양식을 지켜야 한다.") @Test void signUp_emailValidationTest() throws Exception { //given diff --git a/src/test/java/org/store/clothstar/member/util/CreateObject.java b/src/test/java/org/store/clothstar/member/util/CreateObject.java index 685e2a38..e723188b 100644 --- a/src/test/java/org/store/clothstar/member/util/CreateObject.java +++ b/src/test/java/org/store/clothstar/member/util/CreateObject.java @@ -31,6 +31,17 @@ public static CreateMemberRequest getCreateMemberRequest(String email) { return createMemberRequest; } + public static CreateMemberRequest getCreateMemberRequest(String email, String certifyNum) { + String password = "testl122"; + String name = "현수"; + String telNo = "010-1234-1245"; + + CreateMemberRequest createMemberRequest = new CreateMemberRequest( + email, password, name, telNo, certifyNum + ); + + return createMemberRequest; + } public static MemberEntity getMemberEntityByCreateMemberRequestDTO() { return getCreateMemberRequest().toMemberEntity(); diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 0c076a70..8882060f 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -20,6 +20,12 @@ spring: auth: true starttls: enable: true + # Redis + data: + redis: + host: ENC(GUuFDW7HjE98e7N28Vkb/xoIEgLeOCb5) + port: 6379 + duration: 600 jpa: hibernate: