Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
api/materialize: make aggregates roundtrip (#198)
Browse files Browse the repository at this point in the history
Fixes #197
  • Loading branch information
bmizerany committed Dec 9, 2022
1 parent c8f5624 commit 83726d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 5 additions & 3 deletions api/materialize/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 10 additions & 7 deletions api/materialize/views_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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},
Expand All @@ -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 },
Expand Down

0 comments on commit 83726d7

Please sign in to comment.