Files

38 lines
1.4 KiB
Go
Raw Permalink Normal View History

2026-10-16 13:48:51 +02:00
package billing
import "testing"
func TestContentDebitUnits(t *testing.T) {
rates := map[string]int64{"title": 1000, "description": 2500, "seo_meta": 1000}
cases := []struct {
selected []string
processingType string
want int64
}{
2026-10-20 17:50:32 +02:00
{[]string{"title"}, "title", 10000},
{[]string{"title", "description"}, "enhance", 10000},
{[]string{"title", "description", "seo_meta"}, "enhance", 10000},
{[]string{"seo_meta"}, "seo_meta", 10000},
{[]string{"title", "title"}, "title", 10000},
{nil, "description", 10000},
2026-10-16 13:48:51 +02:00
}
for _, tt := range cases {
got, err := ContentDebitUnits(tt.selected, tt.processingType, rates)
if err != nil || got != tt.want {
t.Errorf("%v/%s => %d, %v; expected %d", tt.selected, tt.processingType, got, err, tt.want)
}
}
if _, err := ContentDebitUnits([]string{"campaign_copy"}, "full", rates); err == nil {
t.Fatal("unknown type accepted")
}
for _, outputs := range [][]string{nil, {"title"}, {"title", "description", "seo_meta"}} {
got, err := ContentDebitUnits(outputs, "enhance", map[string]int64{"title": 1000, "description": 2500, "seo_meta": 1000, "product": 3750})
2026-10-20 17:50:32 +02:00
if err != nil || got != 10000 {
2026-10-16 13:48:51 +02:00
t.Errorf("per-product price outputs=%v got=%d err=%v", outputs, got, err)
}
}
zero, err := ContentDebitUnits([]string{"title"}, "title", map[string]int64{"title": 0})
2026-10-20 17:50:32 +02:00
if err != nil || zero != 10000 {
2026-10-16 13:48:51 +02:00
t.Fatalf("zero cost %v %v", zero, err)
}
}