Files
notarius/internal/modules/dnd/validate/spells/shape/validator_test.go

68 lines
2.2 KiB
Go
Raw Normal View History

2026-07-07 21:37:58 +00:00
package shape
import (
"context"
"testing"
2026-07-17 07:02:30 +00:00
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
2026-07-07 21:37:58 +00:00
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
2026-07-17 07:02:30 +00:00
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
2026-07-07 21:37:58 +00:00
)
func TestValidatorApprovesWellFormedSpellPayload(t *testing.T) {
2026-07-17 07:02:30 +00:00
result, err := New(Options{}).Validate(context.Background(), requestWithValue(validSpellList()))
2026-07-07 21:37:58 +00:00
if err != nil {
t.Fatalf("Validate() error = %v, want nil", err)
}
if !result.Approved {
t.Fatalf("Validate() = %#v, want approved", result)
}
}
2026-07-17 07:02:30 +00:00
func TestValidatorRejectsMissingSpellList(t *testing.T) {
result, err := New(Options{}).Validate(context.Background(), requestWithValue(dnd.SpellList{}))
2026-07-07 21:37:58 +00:00
if err != nil {
t.Fatalf("Validate() error = %v, want nil", err)
}
if result.Approved {
t.Fatalf("Approved = true, want false")
}
if result.ReasonCode != ReasonCode {
t.Fatalf("ReasonCode = %q, want %q", result.ReasonCode, ReasonCode)
}
}
func TestValidatorRejectsMissingRequiredSpellFields(t *testing.T) {
2026-07-17 07:02:30 +00:00
value := validSpellList()
value.SpellCasts[0].Spell = ""
result, err := New(Options{}).Validate(context.Background(), requestWithValue(value))
2026-07-07 21:37:58 +00:00
if err != nil {
t.Fatalf("Validate() error = %v, want nil", err)
}
if result.Approved {
t.Fatalf("Approved = true, want false")
}
if result.ReasonCode != ReasonCode {
t.Fatalf("ReasonCode = %q, want %q", result.ReasonCode, ReasonCode)
}
}
func TestSpecAndRegister(t *testing.T) {
registry := pipeline.NewValidatorRegistry()
if err := Register(registry); err != nil {
t.Fatalf("Register() error = %v, want nil", err)
}
2026-07-17 07:02:30 +00:00
if _, err := DecodeOptions(map[string]any{"unexpected": true}); err == nil {
t.Fatal("DecodeOptions() error = nil, want unknown option error")
2026-07-07 21:37:58 +00:00
}
}
2026-07-17 07:02:30 +00:00
func requestWithValue(value dnd.SpellList) contracts.TypedValidationRequest[dnd.SpellList] {
return contracts.TypedValidationRequest[dnd.SpellList]{Value: value}
}
func validSpellList() dnd.SpellList {
return dnd.SpellList{SpellCasts: []dnd.SpellCast{{Caster: "Aria", Spell: "Cure Wounds", Effect: "heals", NarrativeDescription: "Aria heals Borin.", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}}
2026-07-07 21:37:58 +00:00
}