RezinaLMS-BackEnd/internal/domain/course_access_test.go

45 lines
1.6 KiB
Go

package domain
import (
"math"
"testing"
)
func TestCoursePriceValidation(t *testing.T) {
for _, tt := range []struct {
price float64
currency string
valid bool
}{
{0, "ETB", true}, {1500.99, "ETB", true}, {-1, "ETB", false}, {1.001, "ETB", false}, {1500, "etb", false}, {1500, "123", false}, {math.Inf(1), "ETB", false}, {math.NaN(), "ETB", false},
} {
if err := ValidateCoursePricing(tt.price, tt.currency); (err == nil) != tt.valid {
t.Errorf("%v %q: %v", tt.price, tt.currency, err)
}
}
}
func TestCourseAccessInheritanceAndOverrides(t *testing.T) {
tests := []struct {
name string
chain []ContentAccessTier
want ContentAccessTier
}{
{"paid defaults", []ContentAccessTier{ContentAccessPremium, ContentAccessInherit, ContentAccessInherit}, ContentAccessPremium},
{"free defaults", []ContentAccessTier{ContentAccessFree, ContentAccessInherit, ContentAccessInherit}, ContentAccessFree},
{"free chapter preview", []ContentAccessTier{ContentAccessPremium, ContentAccessFree, ContentAccessInherit}, ContentAccessFree},
{"free lesson in paid chapter", []ContentAccessTier{ContentAccessPremium, ContentAccessPremium, ContentAccessFree}, ContentAccessFree},
{"paid lesson in free chapter", []ContentAccessTier{ContentAccessFree, ContentAccessFree, ContentAccessPremium}, ContentAccessPremium},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ResolveContentAccessTier(tt.chain...); got != tt.want {
t.Fatalf("got %s want %s", got, tt.want)
}
})
}
if got := ChildContentAccessTierForCreate(nil); got != "INHERIT" {
t.Fatalf("new children should inherit, got %s", got)
}
}