You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
761 B
Go

package handler
import (
"testing"
"time"
"github.com/denisovdennis/autohero/internal/model"
)
func TestConsumeFreeBuffCharge_SubscriptionSkipsQuota(t *testing.T) {
h := &model.Hero{SubscriptionActive: true, BuffFreeChargesRemaining: 0}
now := time.Now()
if err := consumeFreeBuffCharge(h, now); err != nil {
t.Fatal(err)
}
if h.BuffFreeChargesRemaining != 0 {
t.Fatalf("expected no charge mutation for subscriber, got %d", h.BuffFreeChargesRemaining)
}
}
func TestConsumeFreeBuffCharge_Exhausted(t *testing.T) {
end := time.Now().Add(time.Hour)
h := &model.Hero{
BuffFreeChargesRemaining: 0,
BuffQuotaPeriodEnd: &end,
}
if err := consumeFreeBuffCharge(h, time.Now()); err == nil {
t.Fatal("expected error when exhausted")
}
}