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.
34 lines
907 B
Go
34 lines
907 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, model.BuffRush, 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,
|
|
BuffCharges: map[string]model.BuffChargeState{
|
|
string(model.BuffRush): {Remaining: 0, PeriodEnd: &end},
|
|
},
|
|
}
|
|
if err := consumeFreeBuffCharge(h, model.BuffRush, time.Now()); err == nil {
|
|
t.Fatal("expected error when exhausted")
|
|
}
|
|
}
|