diff --git a/src/lib/__tests__/getPqpRates.test.ts b/src/lib/__tests__/getPqpRates.test.ts index e1c48a3..0041851 100644 --- a/src/lib/__tests__/getPqpRates.test.ts +++ b/src/lib/__tests__/getPqpRates.test.ts @@ -296,13 +296,13 @@ describe("getPqpRates", () => { it("should correctly calculate PQP rates for all vehicle categories", () => { expect(getPqpRates(mockCoeData)).toEqual({ - "2025-01": { + "2025-02": { "Category A": 94513, "Category B": 110537, "Category C": 68481, "Category D": 8457, }, - "2024-12": { + "2025-01": { "Category A": 97747, "Category B": 109164, "Category C": 70912, @@ -322,8 +322,8 @@ describe("getPqpRates", () => { ); const result = getPqpRates(singleCategoryData); expect(result).toEqual({ - "2025-01": { "Category A": 94513 }, - "2024-12": { "Category A": 97747 }, + "2025-02": { "Category A": 94513 }, + "2025-01": { "Category A": 97747 }, }); }); diff --git a/src/lib/getPqpRates.ts b/src/lib/getPqpRates.ts index 14d8289..7def2b1 100644 --- a/src/lib/getPqpRates.ts +++ b/src/lib/getPqpRates.ts @@ -52,10 +52,14 @@ const getPqpRates = (data: COE[]): Record> => { ); return pqpResults.reduce((acc, { month, vehicle_class, pqp }) => { - if (!acc[month]) { - acc[month] = {}; + const nextMonth = new Date(month); + nextMonth.setMonth(nextMonth.getMonth() + 1); + const nextMonthKey = nextMonth.toISOString().slice(0, 7); + + if (!acc[nextMonthKey]) { + acc[nextMonthKey] = {}; } - acc[month][vehicle_class] = pqp; + acc[nextMonthKey][vehicle_class] = pqp; return acc; }, {}); };