fix(02-04): set invoice status to SENT on generation
Invoices were created with default DRAFT status, but PaymentService queries for SENT/PARTIAL/OVERDUE. This broke the generate → pay flow. Now invoices are immediately SENT with issuedAt timestamp on generation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -365,7 +365,7 @@ describe("Invoice generation — POSTPAID", () => {
|
||||
const invoice = result!.invoice as Record<string, unknown>;
|
||||
expect(Number(invoice.totalAmount)).toBeCloseTo(49.99);
|
||||
expect(Number(invoice.subtotal)).toBeCloseTo(49.99);
|
||||
expect(invoice.status).toBe(InvoiceStatus.DRAFT);
|
||||
expect(invoice.status).toBe(InvoiceStatus.SENT);
|
||||
expect(invoice.subscriberId).toBe(subscriberId);
|
||||
});
|
||||
|
||||
@@ -615,7 +615,7 @@ describe("Credit auto-application on invoice generation", () => {
|
||||
expect(result!.creditApplied).toBe(false);
|
||||
|
||||
const invoice = result!.invoice as Record<string, unknown>;
|
||||
expect(invoice.status).toBe(InvoiceStatus.DRAFT);
|
||||
expect(invoice.status).toBe(InvoiceStatus.SENT);
|
||||
expect(Number(invoice.amountPaid)).toBe(0);
|
||||
});
|
||||
|
||||
@@ -1000,11 +1000,11 @@ describe("getInvoice and listInvoices", () => {
|
||||
});
|
||||
|
||||
it("listInvoices filters by status", async () => {
|
||||
const result = await listInvoices(tA(), { status: InvoiceStatus.DRAFT });
|
||||
const allDraft = (result.invoices as Array<Record<string, unknown>>).every(
|
||||
(inv) => inv.status === InvoiceStatus.DRAFT || inv.status === InvoiceStatus.PARTIAL || inv.status === InvoiceStatus.OVERDUE
|
||||
const result = await listInvoices(tA(), { status: InvoiceStatus.SENT });
|
||||
const allSent = (result.invoices as Array<Record<string, unknown>>).every(
|
||||
(inv) => inv.status === InvoiceStatus.SENT || inv.status === InvoiceStatus.PARTIAL || inv.status === InvoiceStatus.OVERDUE
|
||||
);
|
||||
// All returned should be DRAFT (some might have been changed to OVERDUE by other tests)
|
||||
// All returned should be SENT (some might have been changed to OVERDUE or PARTIAL by other tests)
|
||||
expect(result.invoices).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -210,6 +210,8 @@ export async function generateInvoiceForSubscriber(
|
||||
subtotal: monthlyPrice,
|
||||
totalAmount: monthlyPrice,
|
||||
amountPaid: new Prisma.Decimal(0),
|
||||
status: 'SENT',
|
||||
issuedAt: new Date(),
|
||||
lines: {
|
||||
create: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user