Repository navigation
fix: 시드 재실행이 리뷰 댓글 FK로 실패하던 문제 수정 #534
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { seedCategories } from '../../prisma/seed/categories'; | ||
| import { resetSeedScope } from '../../prisma/seed/idempotent'; | ||
| import { seedOrders } from '../../prisma/seed/orders'; | ||
| import { seedRegions } from '../../prisma/seed/regions'; | ||
| import { seedReviews } from '../../prisma/seed/reviews'; | ||
| import { seedStores } from '../../prisma/seed/stores'; | ||
| import { seedUsers, type SeededUser } from '../../prisma/seed/users'; | ||
|
|
||
| import type { PrismaClient } from '@/generated/prisma/client'; | ||
| import { disconnectTestPrismaClient } from '@/test/db/prisma-test-client'; | ||
| import { closeTruncateConnection, truncateAll } from '@/test/db/truncate'; | ||
| import { | ||
| createAccount, | ||
| createOrderItem, | ||
| createReview, | ||
| createReviewReport, | ||
| } from '@/test/factories'; | ||
| import { createTestingModuleWithRealDb } from '@/test/modules/testing-module.builder'; | ||
|
|
||
| // 로컬에서 시드 데이터에 붙여 둔 행이 있어도 재시드(정리 → 재삽입)가 FK에 막히면 안 된다 | ||
| describe('resetSeedScope (real DB)', () => { | ||
| let prisma: PrismaClient; | ||
|
|
||
| beforeAll(async () => { | ||
| ({ prisma } = await createTestingModuleWithRealDb({ providers: [] })); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await closeTruncateConnection(); | ||
| await disconnectTestPrismaClient(); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await truncateAll(); | ||
| }); | ||
|
|
||
| /** 시드 main과 같은 순서로 리뷰까지 채운다 */ | ||
| async function seedThroughReviews(): Promise<SeededUser[]> { | ||
| const users = await seedUsers(prisma); | ||
| await seedRegions(prisma); | ||
| const categories = await seedCategories(prisma); | ||
| const stores = await seedStores(prisma, { categories }); | ||
| const orders = await seedOrders(prisma, { users, stores }); | ||
| await seedReviews(prisma, { users, stores, orders }); | ||
| return users; | ||
| } | ||
|
|
||
| function writeComment(reviewId: bigint, accountId: bigint) { | ||
| return prisma.reviewComment.create({ | ||
| data: { review_id: reviewId, account_id: accountId, content: '댓글' }, | ||
| }); | ||
| } | ||
|
|
||
| it('시드 리뷰에 다른 계정이 단 댓글이 있어도 정리하고 다시 시드한다', async () => { | ||
| const users = await seedThroughReviews(); | ||
| const seedReview = await prisma.review.findFirstOrThrow({ | ||
| where: { account_id: { in: users.map((u) => u.id) } }, | ||
| }); | ||
| const outsider = await createAccount(prisma, { account_type: 'USER' }); | ||
| const comment = await writeComment(seedReview.id, outsider.id); | ||
|
|
||
| await resetSeedScope(prisma); | ||
| await seedThroughReviews(); | ||
|
|
||
| expect( | ||
| await prisma.reviewComment.findUnique({ where: { id: comment.id } }), | ||
| ).toBeNull(); | ||
| expect( | ||
| await prisma.account.findUnique({ where: { id: outsider.id } }), | ||
| ).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('시드 리뷰에 달린 외부 댓글의 외부 신고도 지워 대상 없는 신고가 남지 않는다', async () => { | ||
| const users = await seedThroughReviews(); | ||
| const seedReview = await prisma.review.findFirstOrThrow({ | ||
| where: { account_id: { in: users.map((u) => u.id) } }, | ||
| }); | ||
| const outsider = await createAccount(prisma, { account_type: 'USER' }); | ||
| const comment = await writeComment(seedReview.id, outsider.id); | ||
| const report = await createReviewReport(prisma, { | ||
| review_comment_id: comment.id, | ||
| }); | ||
|
|
||
| await resetSeedScope(prisma); | ||
|
|
||
| expect( | ||
| await prisma.reviewReport.findUnique({ where: { id: report.id } }), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it('시드 사용자가 시드 밖 리뷰에 단 댓글은 지우고 그 리뷰는 남긴다', async () => { | ||
| const [seedUser] = await seedThroughReviews(); | ||
| const outsideReview = await createReview(prisma); | ||
| const comment = await writeComment(outsideReview.id, seedUser.id); | ||
|
|
||
| await resetSeedScope(prisma); | ||
|
|
||
| expect( | ||
| await prisma.reviewComment.findUnique({ where: { id: comment.id } }), | ||
| ).toBeNull(); | ||
| expect( | ||
| await prisma.review.findUnique({ where: { id: outsideReview.id } }), | ||
| ).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('시드 주문 밖에 있는 시드 사용자 리뷰의 댓글도 지운다', async () => { | ||
| const [seedUser] = await seedThroughReviews(); | ||
| const outsideItem = await createOrderItem(prisma); | ||
| const review = await createReview(prisma, { | ||
| order_item_id: outsideItem.id, | ||
| account_id: seedUser.id, | ||
| }); | ||
| const outsider = await createAccount(prisma, { account_type: 'USER' }); | ||
| const comment = await writeComment(review.id, outsider.id); | ||
|
|
||
| await resetSeedScope(prisma); | ||
|
|
||
| expect( | ||
| await prisma.review.findUnique({ where: { id: review.id } }), | ||
| ).toBeNull(); | ||
| expect( | ||
| await prisma.reviewComment.findUnique({ where: { id: comment.id } }), | ||
| ).toBeNull(); | ||
| }); | ||
| }); |
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.
When an external user reports an external user's comment on a seeded review, the earlier
reviewReport.deleteManydoes not match it because comment reports have noreview_idand the comment author is not seeded. This hard delete therefore only applies the FK'sON DELETE SET NULL, leaving aPENDINGreport with both target IDs null and itsopen_keyintact;ReviewAdminRepository.targetedReportWherethen excludes it from listing, detail, and resolution forever. Delete or resolve reports selected throughreview_comment.reviewbefore deleting these comments; the second newly added comment-deletion path has the same issue.Useful? React with 👍 / 👎.
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.
반영: 0) 신고 정리 단계에 "시드 리뷰(시드 사용자 작성·시드 매장)에 달린 댓글을 대상으로 한 신고" 조건 추가 — 댓글 삭제 전에 지워 대상 없는 PENDING이 남지 않음. 대시보드 대기 신고 수(countPendingReviewReports)가 대상 없는 PENDING까지 세므로 실제 불일치. 시드 사용자가 남의 리뷰에 단 댓글의 신고는 기존 review_comment.account_id 조건이 이미 덮음. 회귀 테스트 1건 추가.