From 1afc53748aad6cd7cf744caa82821a5514d84128 Mon Sep 17 00:00:00 2001 From: Tiago Lupepic Date: Tue, 2 Jun 2026 15:38:33 +0200 Subject: [PATCH] feat(presentation_group_keys): Support presentation group keys feature - Update usages to include presentation breakdowns - Update invoice fee to include presentation breakdowns - Add filter_by_presentation in current_usage --- tests/customer.test.ts | 224 ++++++++++++++++++++++++++++++++++++++++- tests/invoice.test.ts | 8 ++ tests/plan.test.ts | 22 +++- 3 files changed, 249 insertions(+), 5 deletions(-) diff --git a/tests/customer.test.ts b/tests/customer.test.ts index c969823..41856b7 100644 --- a/tests/customer.test.ts +++ b/tests/customer.test.ts @@ -1,4 +1,9 @@ -import type { Customer, CustomerInput, CustomerUsage } from "../mod.ts"; +import type { + Customer, + CustomerInput, + CustomerProjectedUsage, + CustomerUsage, +} from "../mod.ts"; import { lagoTest, notFoundErrorResponse, @@ -103,11 +108,205 @@ const customerUsage = { "amount_cents": 1200, }, ], + "filters": [ + { + "units": "1.0", + "amount_cents": 600, + "events_count": 3, + "values": { + "region": ["europe"], + }, + "presentation_breakdowns": [ + { + "presentation_by": { + "team": "engineering", + }, + "units": "1.0", + }, + ], + }, + ], + "grouped_usage": [ + { + "units": "2.0", + "amount_cents": 800, + "events_count": 4, + "grouped_by": { + "region": "europe", + }, + "filters": [ + { + "units": "1.0", + "amount_cents": 400, + "events_count": 2, + "values": { + "cloud": ["aws"], + }, + "presentation_breakdowns": [ + { + "presentation_by": { + "team": "operations", + }, + "units": "1.0", + }, + ], + }, + ], + "presentation_breakdowns": [ + { + "presentation_by": { + "team": "engineering", + }, + "units": "2.0", + }, + ], + }, + ], + "presentation_breakdowns": [ + { + "presentation_by": { + "region": "europe", + }, + "units": "2.0", + }, + ], }, ], }, } satisfies CustomerUsage; +const customerProjectedUsage = { + "customer_projected_usage": { + "from_datetime": "2022-09-14T00:00:00Z", + "to_datetime": "2022-09-14T00:00:00Z", + "issuing_date": "2022-09-15T00:00:00Z", + "amount_cents": 1200, + "projected_amount_cents": 2400, + "taxes_amount_cents": 200, + "total_amount_cents": 2600, + "charges_usage": [ + { + "units": "3.0", + "projected_units": "6.0", + "events_count": 5, + "amount_cents": 1200, + "projected_amount_cents": 2400, + "amount_currency": "EUR", + "charge": { + "lago_id": "278da83c-c007-4fbb-afcd-b00c07c41utg", + "charge_model": "standard", + }, + "billable_metric": { + "lago_id": "278da83c-c007-4fbb-afcd-b00c07c41utg", + "name": "Example name", + "code": "code", + "aggregation_type": "count_agg", + }, + "filters": [ + { + "units": "1.0", + "projected_units": "2.0", + "amount_cents": 600, + "projected_amount_cents": 1200, + "events_count": 3, + "values": { + "region": ["europe"], + }, + "presentation_breakdowns": [ + { + "presentation_by": { + "team": "engineering", + }, + "units": "1.0", + }, + ], + "projected_presentation_breakdowns": [ + { + "presentation_by": { + "team": "engineering", + }, + "units": "2.0", + }, + ], + }, + ], + "grouped_usage": [ + { + "units": "2.0", + "projected_units": "4.0", + "amount_cents": 800, + "projected_amount_cents": 1600, + "events_count": 4, + "grouped_by": { + "region": "europe", + }, + "filters": [ + { + "units": "1.0", + "projected_units": "2.0", + "amount_cents": 400, + "projected_amount_cents": 800, + "events_count": 2, + "values": { + "cloud": ["aws"], + }, + "presentation_breakdowns": [ + { + "presentation_by": { + "team": "operations", + }, + "units": "1.0", + }, + ], + "projected_presentation_breakdowns": [ + { + "presentation_by": { + "team": "operations", + }, + "units": "2.0", + }, + ], + }, + ], + "presentation_breakdowns": [ + { + "presentation_by": { + "team": "engineering", + }, + "units": "2.0", + }, + ], + "projected_presentation_breakdowns": [ + { + "presentation_by": { + "team": "engineering", + }, + "units": "4.0", + }, + ], + }, + ], + "presentation_breakdowns": [ + { + "presentation_by": { + "region": "europe", + }, + "units": "3.0", + }, + ], + "projected_presentation_breakdowns": [ + { + "presentation_by": { + "region": "europe", + }, + "units": "6.0", + }, + ], + }, + ], + }, +} satisfies CustomerProjectedUsage; + Deno.test("Successfully sent customer responds with 2xx", async (t) => { await lagoTest({ t, @@ -138,10 +337,16 @@ Deno.test("Current usage responds with a 2xx", async (t) => { testType: "200", route: "GET@/api/v1/customers/external_customer_id/current_usage", clientPath: ["customers", "findCustomerCurrentUsage"], - inputParams: ["external_customer_id", { external_subscription_id: "123" }], + inputParams: ["external_customer_id", { + external_subscription_id: "123", + filter_by_presentation: '["europe"]', + }], responseObject: customerUsage, status: 200, - urlParams: { external_subscription_id: "123" }, + urlParams: { + external_subscription_id: "123", + filter_by_presentation: '["europe"]', + }, }); }); @@ -157,3 +362,16 @@ Deno.test("Current usage responds with other than 2xx", async (t) => { urlParams: { external_subscription_id: "123" }, }); }); + +Deno.test("Projected usage responds with a 2xx", async (t) => { + await lagoTest({ + t, + testType: "200", + route: "GET@/api/v1/customers/external_customer_id/projected_usage", + clientPath: ["customers", "findCustomerProjectedUsage"], + inputParams: ["external_customer_id", { external_subscription_id: "123" }], + responseObject: customerProjectedUsage, + status: 200, + urlParams: { external_subscription_id: "123" }, + }); +}); diff --git a/tests/invoice.test.ts b/tests/invoice.test.ts index 236c5dd..eb68d06 100644 --- a/tests/invoice.test.ts +++ b/tests/invoice.test.ts @@ -86,6 +86,14 @@ const invoiceResponse = { "code": "code", "name": "name", }, + "presentation_breakdowns": [ + { + "presentation_by": { + "region": "europe", + }, + "units": "2.0", + }, + ], }, ], "credits": [ diff --git a/tests/plan.test.ts b/tests/plan.test.ts index 87cdd2f..5af688c 100644 --- a/tests/plan.test.ts +++ b/tests/plan.test.ts @@ -17,7 +17,16 @@ const planInput = { "id": "183da83c-c007-4fbb-afcd-b00c07c41ffe", "billable_metric_id": "278da83c-c007-4fbb-afcd-b00c07c41utg", "charge_model": "standard", - "properties": {}, + "properties": { + "presentation_group_keys": [ + { + "value": "region", + "options": { + "display_in_invoice": true, + }, + }, + ], + }, "group_properties": [ { "group_id": "123456", @@ -48,7 +57,16 @@ const planResponse = { "lago_billable_metric_id": "278da83c-c007-4fbb-afcd-b00c07c41utg", "created_at": "2022-09-14T16:35:31Z", "charge_model": "standard", - "properties": {}, + "properties": { + "presentation_group_keys": [ + { + "value": "region", + "options": { + "display_in_invoice": true, + }, + }, + ], + }, "group_properties": [ { "group_id": "123456",