refactor(deposits): remove refund approval remnants

This commit is contained in:
2026-07-13 14:19:58 +08:00
parent 7b08560aef
commit 1f32d1285b
7 changed files with 186 additions and 40 deletions

View File

@@ -0,0 +1,38 @@
import { DepositsService } from './deposits.service';
import { Deposit } from '../entities/deposit.entity';
describe('DepositsService — direct refund', () => {
it('stores the refund result on the main status and renamed audit fields', async () => {
const deposit = {
id: 1,
amount: 500,
status: 'paid',
} as Deposit;
const repo = {
findOne: jest.fn().mockResolvedValue(deposit),
save: jest.fn().mockImplementation(async (value: Deposit) => value),
};
const service = new DepositsService(repo as never, {} as never, {} as never);
const result = await service.refund(
1,
{
refundDate: '2026-07-13',
deductionAmount: 100,
deductionReason: '物品损坏',
},
42,
);
expect(result).toMatchObject({
refundDate: '2026-07-13',
refundAmount: 400,
deductionAmount: 100,
deductionReason: '物品损坏',
status: 'partial_refund',
refundedBy: 42,
});
expect(result.refundedAt).toBeInstanceOf(Date);
expect(repo.save).toHaveBeenCalledWith(deposit);
});
});

View File

@@ -103,9 +103,8 @@ export class DepositsService {
deposit.status =
deduction > 0 ? (refundAmount > 0 ? 'partial_refund' : 'deducted') : 'refunded';
if (dto.notes) deposit.notes = dto.notes;
deposit.refundStatus = 'refunded';
deposit.refundApprovedBy = userId ?? null as unknown as number;
deposit.refundApprovedAt = new Date();
deposit.refundedBy = userId ?? null;
deposit.refundedAt = new Date();
return this.repo.save(deposit);
}