Skip to content

Conversation

@essaysir
Copy link
Contributor

@essaysir essaysir commented Apr 5, 2025

작업내용

  • 001. 회원가입시에, 연필 계좌가 생성되도록 엔티티 수정
  • 002. 한 줄 자기소개 변경 API 구현
  • 003. 연필 개수 요청 API 구현
  • 004. 연필 개수 요청에 대한 통합 테스트 코드 구현

추가로 설정할 내용

  • application.yml 에 밑의 내용 추가할 예정 ( 우선적으로 dev 에 추가 )
  • 테스트 시에, H2 데이터베이스를 통해, 테스트를 진행하기 위한 수정
spring:
  config:
    activate:
      on-profile: test
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:mem:testdb
    username: sa
    password:

  jpa:
    database: h2
    hibernate:
      ddl-auto: create
    properties:
      hibernate:
        dialect: org.hibernate.dialect.H2Dialect
        format_sql: true
    show-sql: true

  sql:
    init:
      mode: never

  h2:
    console:
      enabled: true
      path: /h2-console

상세설명_ & 캡쳐

  1. 회원가입시에, 연필 계좌가 생성되도록 엔티티 수정
    pencilAccount 에 Cascade.All 를 추가하여, 회원가입 시에, 연필 계좌도 자동적으로 생성하도록 수정
public static Member createKakaoMember(String email, Long targetId, String nickname, String agreeVersion) {
		Member member = Member.builder()
			.email(email)
			.provider(MemberProvider.KAKAO)
			.kakaoTargetId(targetId)
			.nickname(nickname)
			.refreshToken("")
			.refreshTokenExpiresAt(LocalDateTime.now())
			.agreeVersion(agreeVersion)
			.build();

		PencilAccount createAccount = PencilAccount.createPencilAccount(member);
		member.addPencilAccount(createAccount);

		return member;
	}

  1. 연필 개수에 요청에 대한 테스트 코드 구현

컨트롤러 테스트를 위해서, 메인어플리케이션에서 @EnableJpaAuditing 을 Configuration 클래스로 변경

package umc.th.juinjang.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@Configuration
public class JpaConfig {
}

컨트롤러 테스트

mockMvc.perform(
				MockMvcRequestBuilders.get("/api/v2/pencil-account/balance")
					.with(SecurityMockMvcRequestPostProcessors.authentication(authentication))
					.header("Authorization", mockToken)
					.contentType(MediaType.APPLICATION_JSON)
			)
			.andDo(MockMvcResultHandlers.print())
			.andExpect(MockMvcResultMatchers.status().isOk())
			.andExpect(MockMvcResultMatchers.jsonPath("$.result.totalBalance").value(100));

@essaysir essaysir added the ✨ feature 기능 추가 label Apr 5, 2025
@essaysir essaysir self-assigned this Apr 5, 2025
@PicturePark1101
Copy link
Contributor

테스트코드 잘 보았습니다 아직 테스트 코드 짜본 적 없는데 저도 API 구현 후 한번 시도해보고 싶어요!! 고생많으셨습니다!! 👍 👍

@PicturePark1101 PicturePark1101 requested review from hyeonahhh and removed request for yeon015 April 5, 2025 07:04
import umc.th.juinjang.api.pencilAccount.service.PencilAccountService;
import umc.th.juinjang.domain.member.model.Member;

@WebMvcTest(PencilAccountController.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컨트롤러 테스트는 실제로 처음 보는데 너무 대단하신 것 같아요..! 오늘도 한수 배웁니다.. 고생하셨습니다~!!

@hyeonahhh hyeonahhh merged commit c712d29 into dev Apr 6, 2025
1 check passed
@essaysir essaysir deleted the feat/#310 branch April 21, 2025 12:52
PicturePark1101 pushed a commit that referenced this pull request Jun 1, 2025
[feat/#310]  멤버에 한 줄 소개 및 연필 추가
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ feature 기능 추가

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants