From aa3a15c34f2370665f1525d4a83bcfcf2afbacb3 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Fri, 9 Dec 2022 00:48:43 +0000 Subject: [PATCH] api/materialize: make aggregates roundtrip Fixes #197 --- api/materialize/views.go | 8 +++++--- api/materialize/views_test.go | 17 ++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/api/materialize/views.go b/api/materialize/views.go index 2a92ffe..6afdfab 100644 --- a/api/materialize/views.go +++ b/api/materialize/views.go @@ -100,9 +100,11 @@ func ToPricingJSON(fs []control.Feature) ([]byte, error) { } p.Features[f.FeaturePlan.Name()] = apitypes.Feature{ - Title: values.ZeroIf(f.Title, f.FeaturePlan.String()), - Base: f.Base, - Tiers: tiers, + Title: values.ZeroIf(f.Title, f.FeaturePlan.String()), + Base: f.Base, + Mode: values.ZeroIf(f.Mode, "graduated"), + Aggregate: values.ZeroIf(f.Aggregate, "sum"), + Tiers: tiers, } m.Plans[f.Plan()] = p } diff --git a/api/materialize/views_test.go b/api/materialize/views_test.go index 20e4806..e985892 100644 --- a/api/materialize/views_test.go +++ b/api/materialize/views_test.go @@ -19,8 +19,9 @@ func TestPricingHuJSON(t *testing.T) { "plan:example@1": { "title": "Just an example plan to show off features", "features": { - "feature:graduated": { - "mode": "graduated", + "feature:volume": { + "mode": "volume", + "aggregate": "perpetual", "tiers": [ { "upto": 10 }, { "upto": 20, "price": 100 }, @@ -61,12 +62,12 @@ func TestPricingHuJSON(t *testing.T) { }, { PlanTitle: "Just an example plan to show off features", - Title: "feature:graduated@plan:example@1", - FeaturePlan: refs.MustParseFeaturePlan("feature:graduated@plan:example@1"), + Title: "feature:volume@plan:example@1", + FeaturePlan: refs.MustParseFeaturePlan("feature:volume@plan:example@1"), Currency: "usd", Interval: "@monthly", - Mode: "graduated", - Aggregate: "sum", + Mode: "volume", + Aggregate: "perpetual", Tiers: []control.Tier{ {Upto: 10, Price: 0, Base: 0}, {Upto: 20, Price: 100, Base: 0}, @@ -87,7 +88,9 @@ func TestPricingHuJSON(t *testing.T) { "plan:example@1": { "title": "Just an example plan to show off features", "features": { - "feature:graduated": { + "feature:volume": { + "mode": "volume", + "aggregate": "perpetual", "tiers": [ { "upto": 10 }, { "upto": 20, "price": 100 },