Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NDD-285]: 문제집 삭제 로직 구현 (1h / 1h) #128

Merged
merged 6 commits into from
Nov 30, 2023
Merged

Conversation

JangAJang
Copy link
Collaborator

@JangAJang JangAJang commented Nov 29, 2023

NDD-285 Powered by Pull Request Badge

Why

  • 문제집 삭제 로직을 구현한다.
  • 삭제시에 권한을 확인해야 한다
  • 문제집 존재 여부를 검증해야 한다
  • 내부의 문제는 onDelete: CASCADE로 자동삭제시킨다.

How

async deleteWorkbookById(workbookId: number, member: Member) {
    validateManipulatedToken(member);
    const workbook = await this.workbookRepository.findById(workbookId);
    validateWorkbook(workbook);
    validateWorkbookOwner(workbook, member);
    await this.workbookRepository.remove(workbook);
  }
  • 회원을 받아 조작된 토큰인지 검증하고, 문제집을 가져온다(이 때 문제집의 Member와 카테고리를 fetch해서 가져온다)
  • 문제집의 소유자와 현재 회원이 같은지 검증한다.
  • DB에서 문제집을 삭제한다

Result

스크린샷 2023-11-30 16 36 39

  • 비즈니스 로직 단위 테스트

스크린샷 2023-11-30 16 36 58

  • 비즈니스 로직 통합 테스트

스크린샷 2023-11-30 16 37 26

  • 컨트롤러 로직 단위 테스트

스크린샷 2023-11-30 16 37 43

  • 컨트롤러 로직 통합 테스트

@JangAJang JangAJang self-assigned this Nov 29, 2023
Copy link

cloudflare-workers-and-pages bot commented Nov 29, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: fe8d370
Status: ✅  Deploy successful!
Preview URL: https://ca93158f.gomterview.pages.dev
Branch Preview URL: https://feature-ndd-285.gomterview.pages.dev

View logs

@JangAJang JangAJang added BE 백엔드 코드 변경사항 feature 새로운 기능이 추가 된 경우 test 테스트코드가 변경된 경우 labels Nov 29, 2023
).rejects.toThrow(new WorkbookForbiddenException());
});

it('없는 문제집을 삭제요청하ㅑ면 WorkbookNotFoundException처리한다', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

오타 발견했습니다!! 수정 부탁드려요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it('문제집을 성공적으로 삭제한다', async () => {
//given
await memberRepository.save(memberFixture);
await categoryRepository.save(categoryFixtureWithId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

통합 테스트 시 member와 category를 save하는 것은 공통 로직인거 같은데 beforeEach로 하나의 함수로 리팩터링 하는건 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@quiet-honey quiet-honey left a comment

Choose a reason for hiding this comment

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

LGTM!

@JangAJang JangAJang merged commit bdb867e into dev Nov 30, 2023
2 checks passed
@delete-merged-branch delete-merged-branch bot deleted the feature/NDD-285 branch November 30, 2023 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드 코드 변경사항 feature 새로운 기능이 추가 된 경우 test 테스트코드가 변경된 경우
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants