Skip to content

Commit

Permalink
feat(productcatalog): remove plan phase-level internal APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
tothandras committed Dec 29, 2024
1 parent 991d3be commit 42e14d8
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 902 deletions.
2 changes: 1 addition & 1 deletion openmeter/productcatalog/plan/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c Config) Validate() error {
return nil
}

func New(config Config) (plan.Repository, error) {
func New(config Config) (*adapter, error) {
if err := config.Validate(); err != nil {
return nil, err
}
Expand Down
20 changes: 10 additions & 10 deletions openmeter/productcatalog/plan/adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func TestPostgresAdapter(t *testing.T) {
var phase *plan.Phase

t.Run("Create", func(t *testing.T) {
phaseInput := plan.CreatePhaseInput{
phaseInput := createPhaseInput{
NamespacedModel: models.NamespacedModel{
Namespace: namespace,
},
Expand Down Expand Up @@ -419,17 +419,17 @@ func TestPostgresAdapter(t *testing.T) {
},
}

phase, err = repo.CreatePhase(ctx, phaseInput)
phase, err = repo.createPhase(ctx, phaseInput)
assert.NoErrorf(t, err, "creating phase must not fail")

require.NotNilf(t, phase, "plan phase must not be nil")

plan.AssertPhaseCreateInputEqual(t, phaseInput, *phase)
assertPhaseCreateInputEqual(t, phaseInput, *phase)
})

t.Run("Get", func(t *testing.T) {
t.Run("ById", func(t *testing.T) {
getPhase, err := repo.GetPhase(ctx, plan.GetPhaseInput{
getPhase, err := repo.getPhase(ctx, getPhaseInput{
NamespacedID: models.NamespacedID{
Namespace: namespace,
ID: phase.ID,
Expand All @@ -443,7 +443,7 @@ func TestPostgresAdapter(t *testing.T) {
})

t.Run("ByKey", func(t *testing.T) {
getPhase, err := repo.GetPhase(ctx, plan.GetPhaseInput{
getPhase, err := repo.getPhase(ctx, getPhaseInput{
NamespacedID: models.NamespacedID{
Namespace: namespace,
},
Expand All @@ -459,7 +459,7 @@ func TestPostgresAdapter(t *testing.T) {
})

t.Run("Update", func(t *testing.T) {
phaseUpdate := plan.UpdatePhaseInput{
phaseUpdate := updatePhaseInput{
NamespacedID: models.NamespacedID{
Namespace: namespace,
ID: phase.ID,
Expand All @@ -469,16 +469,16 @@ func TestPostgresAdapter(t *testing.T) {
StartAfter: lo.ToPtr(ThreeMonthPeriod),
}

updatePhase, err := repo.UpdatePhase(ctx, phaseUpdate)
updatePhase, err := repo.updatePhase(ctx, phaseUpdate)
require.NoErrorf(t, err, "updating phase must not fail")

require.NotNilf(t, updatePhase, "phase must not be nil")

plan.AssertPhaseUpdateInputEqual(t, phaseUpdate, *updatePhase)
assertPhaseUpdateInputEqual(t, phaseUpdate, *updatePhase)
})

t.Run("Delete", func(t *testing.T) {
err = repo.DeletePhase(ctx, plan.DeletePhaseInput{
err = repo.deletePhase(ctx, deletePhaseInput{
NamespacedID: models.NamespacedID{
Namespace: namespace,
ID: phase.ID,
Expand All @@ -488,7 +488,7 @@ func TestPostgresAdapter(t *testing.T) {
})
require.NoErrorf(t, err, "deleting Phase must not fail")

getPhase, err := repo.GetPhase(ctx, plan.GetPhaseInput{
getPhase, err := repo.getPhase(ctx, getPhaseInput{
NamespacedID: models.NamespacedID{
Namespace: namespace,
ID: phase.ID,
Expand Down
53 changes: 53 additions & 0 deletions openmeter/productcatalog/plan/adapter/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package adapter

import (
"testing"

"github.com/samber/lo"
"github.com/stretchr/testify/assert"

"github.com/openmeterio/openmeter/openmeter/productcatalog/plan"
)

func assertPhaseCreateInputEqual(t *testing.T, i createPhaseInput, p plan.Phase) {
t.Helper()

assert.Equalf(t, i.Namespace, p.Namespace, "create input: namespace mismatch")
assert.Equalf(t, i.Key, p.Key, "create input: key mismatch")
assert.Equalf(t, i.Name, p.Name, "create input: name mismatch")
assert.Equalf(t, i.Description, p.Description, "create input: description mismatch")
assert.Equalf(t, i.Metadata, p.Metadata, "create input: metadata mismatch")
assert.Equalf(t, i.StartAfter.ISOString(), p.StartAfter.ISOString(), "create input: startAfter mismatch")

plan.AssertPlanRateCardsEqual(t, i.RateCards, p.RateCards)
}

func assertPhaseUpdateInputEqual(t *testing.T, i updatePhaseInput, p plan.Phase) {
t.Helper()

assert.Equalf(t, i.Namespace, p.Namespace, "update input: namespace mismatch")

assert.Equalf(t, i.Key, p.Key, "update input: key mismatch")

if i.Name != nil {
assert.Equalf(t, *i.Name, p.Name, "update input: name mismatch")
}

if i.Description != nil {
assert.Equalf(t, lo.FromPtrOr(i.Description, ""), lo.FromPtrOr(p.Description, ""), "update input: description mismatch")
}

if i.Metadata != nil {
assert.Equalf(t, *i.Metadata, p.Metadata, "update input: metadata mismatch")
}

if i.StartAfter != nil {
assert.Equalf(t, *i.StartAfter, p.StartAfter, "update input: startAfter mismatch")
}

assert.Equalf(t, i.PlanID, p.PlanID, "update input: planID mismatch")

if i.RateCards != nil {
plan.AssertPlanRateCardsEqual(t, *i.RateCards, p.RateCards)
}
}
Loading

0 comments on commit 42e14d8

Please sign in to comment.