39 lines
1.4 KiB
Go
39 lines
1.4 KiB
Go
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
|
|
}{
|
|
{[]string{"title"}, "title", 1000},
|
|
{[]string{"title", "description"}, "enhance", 3500},
|
|
{[]string{"title", "description", "seo_meta"}, "enhance", 4500},
|
|
{[]string{"seo_meta"}, "seo_meta", 1000},
|
|
{[]string{"title", "title"}, "title", 1000},
|
|
{nil, "description", 2500},
|
|
}
|
|
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})
|
|
if err != nil || got != 3750 {
|
|
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})
|
|
if err != nil || zero != 0 {
|
|
t.Fatalf("zero cost %v %v", zero, err)
|
|
}
|
|
}
|