-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e68e12a
test: 문제집 삭제 비즈니스 로직에 대한 단위테스트 구현
JangAJang 1d6aca6
feat: 비즈니스 로직 구현
JangAJang 5af8ca5
test: 문제집 삭제에 대한 통합테스트 구현
JangAJang 51872f6
test: 컨트롤러 테스트 추가
JangAJang 7ec980b
feat: 컨트롤러 로직 구현
JangAJang fe8d370
test: 재사용 메서드 beforeEach로 분리 및 오타 수정
JangAJang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ import { | |
memberFixturesOAuthRequest, | ||
mockReqWithMemberFixture, | ||
oauthRequestFixture, | ||
otherMemberFixture, | ||
} from '../../member/fixture/member.fixture'; | ||
import { WorkbookIdResponse } from '../dto/workbookIdResponse'; | ||
import { Request, Response } from 'express'; | ||
import { INestApplication, ValidationPipe } from '@nestjs/common'; | ||
import { CategoryRepository } from '../../category/repository/category.repository'; | ||
import { MemberRepository } from '../../member/repository/member.repository'; | ||
|
@@ -36,12 +38,16 @@ import { | |
} from '../../category/fixture/category.fixture'; | ||
import * as request from 'supertest'; | ||
import { CreateWorkbookRequest } from '../dto/createWorkbookRequest'; | ||
import { WorkbookNotFoundException } from '../exception/workbook.exception'; | ||
import { | ||
WorkbookForbiddenException, | ||
WorkbookNotFoundException, | ||
} from '../exception/workbook.exception'; | ||
import { WorkbookResponse } from '../dto/workbookResponse'; | ||
import { WorkbookTitleResponse } from '../dto/workbookTitleResponse'; | ||
import { CategoryNotFoundException } from '../../category/exception/category.exception'; | ||
import { WorkbookRepository } from '../repository/workbook.repository'; | ||
import { UpdateWorkbookRequest } from '../dto/updateWorkbookRequest'; | ||
import { ManipulatedTokenNotFiltered } from '../../token/exception/token.exception'; | ||
|
||
describe('WorkbookController 단위테스트', () => { | ||
let controller: WorkbookController; | ||
|
@@ -51,6 +57,7 @@ describe('WorkbookController 단위테스트', () => { | |
findWorkbookTitles: jest.fn(), | ||
findSingleWorkbook: jest.fn(), | ||
updateWorkbook: jest.fn(), | ||
deleteWorkbookById: jest.fn(), | ||
}; | ||
const mockTokenService = {}; | ||
|
||
|
@@ -209,6 +216,75 @@ describe('WorkbookController 단위테스트', () => { | |
expect(result.content).toBe(workbookFixtureWithId.content); | ||
}); | ||
}); | ||
|
||
describe('문제집을 삭제한다', () => { | ||
const response = { | ||
status: jest.fn().mockReturnThis(), | ||
send: jest.fn(), | ||
} as unknown as Response; | ||
|
||
it('member와 id를 주면 문제집을 삭제한다', async () => { | ||
//given | ||
|
||
//when | ||
mockWorkbookService.deleteWorkbookById.mockResolvedValue(undefined); | ||
|
||
//then | ||
await expect( | ||
controller.deleteAnswer(mockReqWithMemberFixture, 1, response), | ||
).resolves.toBeUndefined(); | ||
}); | ||
|
||
it('member가 null이면 ManipulatedToken예외처리한다', async () => { | ||
//given | ||
|
||
//when | ||
mockWorkbookService.deleteWorkbookById.mockRejectedValue( | ||
new ManipulatedTokenNotFiltered(), | ||
); | ||
|
||
//then | ||
await expect( | ||
controller.deleteAnswer( | ||
{ user: null } as unknown as Request, | ||
1, | ||
response, | ||
), | ||
).rejects.toThrow(new ManipulatedTokenNotFiltered()); | ||
}); | ||
|
||
it('다른 회원이 삭제요청하면 WorkbookForbiddenException처리한다', async () => { | ||
//given | ||
|
||
//when | ||
mockWorkbookService.deleteWorkbookById.mockRejectedValue( | ||
new WorkbookForbiddenException(), | ||
); | ||
|
||
//then | ||
await expect( | ||
controller.deleteAnswer( | ||
{ user: otherMemberFixture } as unknown as Request, | ||
1, | ||
response, | ||
), | ||
).rejects.toThrow(new WorkbookForbiddenException()); | ||
}); | ||
|
||
it('없는 문제집을 삭제요청하ㅑ면 WorkbookNotFoundException처리한다', async () => { | ||
//given | ||
|
||
//when | ||
mockWorkbookService.deleteWorkbookById.mockRejectedValue( | ||
new WorkbookNotFoundException(), | ||
); | ||
|
||
//then | ||
await expect( | ||
controller.deleteAnswer(mockReqWithMemberFixture, 11412, response), | ||
).rejects.toThrow(new WorkbookNotFoundException()); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('WorkbookController 통합테스트', () => { | ||
|
@@ -696,6 +772,63 @@ describe('WorkbookController 통합테스트', () => { | |
}); | ||
}); | ||
|
||
describe('문제집을 삭제한다', () => { | ||
it('문제집을 성공적으로 삭제한다', async () => { | ||
//given | ||
await memberRepository.save(memberFixture); | ||
await categoryRepository.save(categoryFixtureWithId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 통합 테스트 시 member와 category를 save하는 것은 공통 로직인거 같은데 beforeEach로 하나의 함수로 리팩터링 하는건 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const workbook = await workbookRepository.save(workbookFixtureWithId); | ||
|
||
//when & then | ||
const token = await authService.login(memberFixturesOAuthRequest); | ||
const agent = request.agent(app.getHttpServer()); | ||
await agent | ||
.delete(`/api/workbook/${workbook.id}`) | ||
.set('Cookie', [`accessToken=${token}`]) | ||
.expect(204); | ||
}); | ||
|
||
it('쿠키가 없으면 401에러를 반환한다', async () => { | ||
//given | ||
await memberRepository.save(memberFixture); | ||
await categoryRepository.save(categoryFixtureWithId); | ||
const workbook = await workbookRepository.save(workbookFixtureWithId); | ||
|
||
//when & then | ||
const agent = request.agent(app.getHttpServer()); | ||
await agent.delete(`/api/workbook/${workbook.id}`).expect(401); | ||
}); | ||
|
||
it('다른 사람의 문제집 삭제 요청을 하면 403에러를 반환한다', async () => { | ||
//given | ||
await memberRepository.save(memberFixture); | ||
await categoryRepository.save(categoryFixtureWithId); | ||
const workbook = await workbookRepository.save(workbookFixtureWithId); | ||
|
||
//when & then | ||
const token = await authService.login(oauthRequestFixture); | ||
const agent = request.agent(app.getHttpServer()); | ||
await agent | ||
.delete(`/api/workbook/${workbook.id}`) | ||
.set('Cookie', [`accessToken=${token}`]) | ||
.expect(403); | ||
}); | ||
|
||
it('존재하지 않는 문제집을 삭제하려하면 404에러를 반환한다', async () => { | ||
//given | ||
await memberRepository.save(memberFixture); | ||
await categoryRepository.save(categoryFixtureWithId); | ||
|
||
//when & then | ||
const token = await authService.login(memberFixturesOAuthRequest); | ||
const agent = request.agent(app.getHttpServer()); | ||
await agent | ||
.delete(`/api/workbook/124123`) | ||
.set('Cookie', [`accessToken=${token}`]) | ||
.expect(404); | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await workbookRepository.query('delete from Workbook'); | ||
await workbookRepository.query('delete from Member'); | ||
|
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오타 발견했습니다!! 수정 부탁드려요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fe8d370