const { getNextInvoiceNumber } = require("../index"); describe("getNextInvoiceNumber", () => { test("should return -0001 for the first invoice of the year", () => { const year = new Date().getFullYear(); const invoicesData = { invoices: [] }; expect(getNextInvoiceNumber(year, invoicesData)).toBe(`${year}-0001`); }); test("should correctly increment the invoice number for the same year", () => { const year = new Date().getFullYear(); const invoicesData = { invoices: [{ number: `${year}-0001` }, { number: `${year}-0002` }], }; expect(getNextInvoiceNumber(year, invoicesData)).toBe(`${year}-0003`); }); test("should reset number for a new year", () => { const lastYear = new Date().getFullYear() - 1; const year = new Date().getFullYear(); const invoicesData = { invoices: [ { number: `${lastYear}-0001` }, { number: `${lastYear}-0002` }, ], }; expect(getNextInvoiceNumber(year, invoicesData)).toBe(`${year}-0001`); }); test("should handle unordered invoice numbers correctly", () => { const year = new Date().getFullYear(); const invoicesData = { invoices: [ { number: `${year}-0005` }, { number: `${year}-0001` }, { number: `${year}-0003` }, ], }; expect(getNextInvoiceNumber(year, invoicesData)).toBe(`${year}-0006`); }); });