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
9 changes: 9 additions & 0 deletions backend/src/__tests__/loanEndpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ describe('GET /api/loans/:loanId', () => {
expect(response.body.success).toBe(true);
expect(response.body.loanId).toBe('123');
expect(response.body.summary.principal).toBe(1000);
expect(response.body.summary.accruedInterest).toBeGreaterThan(0);
expect(response.body.summary.totalOwed).toBe(
response.body.summary.principal +
response.body.summary.accruedInterest -
response.body.summary.totalRepaid,
);
});

it('should return 403 when the loan belongs to another borrower', async () => {
Expand Down Expand Up @@ -385,6 +391,9 @@ describe('GET /api/loans/:loanId/amortization-schedule', () => {
totalInterest: 120,
totalDue: 1120,
});
expect(response.body.amortization.totalDue).toBe(
response.body.amortization.principal + response.body.amortization.totalInterest,
);
expect(Array.isArray(response.body.amortization.schedule)).toBe(true);
expect(response.body.amortization.schedule.length).toBeGreaterThan(0);
});
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/loanController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
try {
const { loanId } = req.params;

const borrower = (req as any).user?.publicKey as string;

Check warning on line 55 in backend/src/controllers/loanController.ts

View workflow job for this annotation

GitHub Actions / backend

Unexpected any. Specify a different type

const result = await query('SELECT * FROM loans WHERE id = $1', [loanId]);
const loan = result.rows[0] as Record<string, unknown> | undefined;
Expand Down Expand Up @@ -560,7 +560,7 @@
const accruedInterest = isPending
? 0
: (principal * rateBps * elapsedLedgers) / (10000 * termLedgers);
const totalOwed = principal - accruedInterest - totalRepaid;
const totalOwed = principal + accruedInterest - totalRepaid;

res.json({
success: true,
Expand Down
Loading