Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/event-handlers/deposit-delete.saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class DepositDeleteSaga {
) {}

/**
* 후원이 μ •μƒμ μœΌλ‘œ μ²˜λ¦¬λ˜μ–΄ μ—°κ΄€λœ 후원을 λ¨Όμ € μ œκ±°ν•΄μ•Ό ν•©λ‹ˆλ‹€. 이 ν”„λ‘œμ„ΈμŠ€λŠ” 후원 μ‚­μ œ 성곡 여뢀에 따라 μ‹€νŒ¨ν•  수 μžˆλŠ” ν”„λ‘œμ„ΈμŠ€λ‘œ, μ˜ˆμ™Έ λ°œμƒμ‹œ μ μ ˆν•œ λ³΄μƒμ‘°μΉ˜λ₯Ό μˆ˜ν–‰ν•©λ‹ˆλ‹€.
* 후원이 μ •μƒμ μœΌλ‘œ μ²˜λ¦¬λ˜μ–΄ μ—°κ΄€λœ 후원을 λ¨Όμ € μ œκ±°ν•΄μ•Ό ν•©λ‹ˆλ‹€. 그리고 μ˜ˆλΉ„ν›„μ›μ˜ μƒνƒœλ₯Ό μ΄ˆκΈ°ν™”ν•œ λ’€ 이체내역을 μ‚­μ œν•©λ‹ˆλ‹€.
*
* 이 ν”„λ‘œμ„ΈμŠ€λŠ” 후원 μ‚­μ œ 성곡 여뢀에 따라 μ‹€νŒ¨ν•  수 μžˆλŠ” ν”„λ‘œμ„ΈμŠ€λ‘œ, μ˜ˆμ™Έ λ°œμƒμ‹œ μ μ ˆν•œ λ³΄μƒμ‘°μΉ˜λ₯Ό μˆ˜ν–‰ν•©λ‹ˆλ‹€.
*/
@OnEvent(MatchedDepositDeleteRequestedEvent.name, { async: true })
async handleMatchedDepositDeleteRequested(
Expand Down Expand Up @@ -70,6 +72,29 @@ export class DepositDeleteSaga {
throw error;
}
}

// μ˜ˆλΉ„ν›„μ› 맀치 μ·¨μ†Œ
try {
await this.cancelMatchProvDon.execute(
deposit.senderSig,
depositId,
adminId,
);
} catch (error) {
if (error instanceof InvalidStatus) {
// μ˜ˆλΉ„ν›„μ› 맀치 μ·¨μ†Œ μ‹€νŒ¨! 보상 절차λ₯Ό μ§„ν–‰ν•©λ‹ˆλ‹€
// send notification to admin
const notiDto = new CreateNotificationDto({
recvId: adminId,
sendId: undefined,
notiType: NotiType.ProvisionalDonationMatchCancelFailed,
subId: deposit.senderSig,
});
await this.notiService.createNoti(notiDto);
} else {
throw error;
}
}
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/features/deposit/deposit.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,19 +488,20 @@ describe('Deposit API E2E Test', () => {
expect(foundDeposit).toBeNull();
});

it('should delete donation and decrease fundSum if matched', async () => {
it('should delete donation and decrease fundSum and reset to pending on provdon if matched', async () => {
// Scenario: Create matched deposit, donation, and funding
const funding = await createMockFundingWithRelations(
{
userRepo,
fundingRepo,
depositRepo,
donationRepo,
provDonRepo,
},
{
fundUser: mockFundingOwner,
},
{ deposit: 1, donation: 1 },
{ deposit: 1, donation: 1, provDonation: 1 },
);

const donation = funding.donations[0];
Expand All @@ -524,6 +525,12 @@ describe('Deposit API E2E Test', () => {
where: { donId: donation.donId },
});
expect(foundDonation).toBeNull();

// Provisional Donation의 μƒνƒœκ°€ Pending이어야 ν•©λ‹ˆλ‹€.
const foundProvDon = await provDonRepo.findOne({
where: { senderSig: deposit.senderSig },
});
expect(foundProvDon.status).toBe(ProvisionalDonationStatus.Pending);
});
});

Expand Down
19 changes: 9 additions & 10 deletions src/tests/mock-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,21 @@ export const createMockFundingWithRelations = async (
mockFunding.donations = donations;
await delegate.fundingRepo.save(mockFunding);
}
}

// Handle optional provisional donations
if (delegate.provDonRepo) {
await Promise.all(
Array(amount?.provDonation ?? 1)
.fill(null)
.map(() =>
delegate.provDonRepo.save(
// Handle optional provisional donations
if (delegate.provDonRepo) {
await delegate.provDonRepo.save(
Array(amount?.provDonation ?? 1)
.fill(null)
.map((_, index) =>
createMockProvisionalDonation({
funding: mockFunding,
senderUser: mockUser,
senderSig: deposits[index].senderSig,
}),
),
),
);
);
}
}

return mockFunding;
Expand Down