Skip to content

Commit

Permalink
[FEATURE] E4-S3 회원가입 API - 회원가입 service 테스트코드 작성 #25
Browse files Browse the repository at this point in the history
  • Loading branch information
choisungwook committed Oct 7, 2021
1 parent 8ac7b14 commit d8fb9b5
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.infp.ciat.user.service;

import com.infp.ciat.user.controller.dto.request.SignupRequestDTO;
import static org.junit.jupiter.api.Assertions.*;

import com.infp.ciat.user.entity.Account;
import com.infp.ciat.user.repository.AccountRepository;
import org.junit.jupiter.api.AfterEach;
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.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.transaction.annotation.Transactional;


//@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = "spring.config.location=classpath:application-test.yml")
@Transactional
class AccountServiceTest {

@Autowired
AccountService accountService;

@Autowired
AccountRepository accountRepository;

@AfterEach
public void aftereach() {
try {
accountRepository.deleteAllInBatch();
} catch (Exception e){
// hibernate error 무시
}
}

@Test
@DisplayName("한명 회원가입 테스트")
public void signin_one(){
SignupRequestDTO signup_requestdto = create_signup_requestdto("[email protected]", "test1", "password");
accountService.SignUp(signup_requestdto);

}

@Test
@DisplayName("두명 회원가입 테스트")
public void signin_two(){
SignupRequestDTO signup_requestdto1 = create_signup_requestdto("[email protected]", "test1", "password");
accountService.SignUp(signup_requestdto1);

SignupRequestDTO signup_requestdto2 = create_signup_requestdto("[email protected]", "test2", "password");
// assertThrows(DataIntegrityViolationException.class, () -> accountService.SignUp(signup_requestdto2));
accountService.SignUp(signup_requestdto2);
}

@Test
@DisplayName("중복 회원가입")
public void signin_duplicate(){
SignupRequestDTO signup_requestdto1 = create_signup_requestdto("[email protected]", "test1", "password");
accountService.SignUp(signup_requestdto1);

SignupRequestDTO signup_requestdto2 = create_signup_requestdto("[email protected]", "test1", "password");
assertThrows(DataIntegrityViolationException.class, () -> accountService.SignUp(signup_requestdto2));
}

/***
* 회원가입 요청 DTO 생성
* @param email
* @param nickname
* @param password
* @return
*/
private SignupRequestDTO create_signup_requestdto(String email, String nickname, String password) {
SignupRequestDTO signupRequestDTO = new SignupRequestDTO();
signupRequestDTO.setEmail(email);
signupRequestDTO.setNickname(nickname);
signupRequestDTO.setPassword(password);

return signupRequestDTO;
}

}

0 comments on commit d8fb9b5

Please sign in to comment.