Complete shared domain contract verification
This commit is contained in:
@@ -32,6 +32,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Validator, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := itemregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare item registry: %w", err)
|
||||
@@ -93,9 +96,6 @@ func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
@@ -12,6 +13,15 @@ import (
|
||||
itemregistry "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/items/registry"
|
||||
)
|
||||
|
||||
func TestConstructionRejectsCollectionSelectionOnRegistry(t *testing.T) {
|
||||
refs := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
itemregistry.ReferenceSlot: {Items: []contracts.ReferenceItem{{Collections: []string{}}}},
|
||||
}}
|
||||
if _, err := New(Options{}, refs); err == nil || !strings.Contains(err.Error(), itemregistry.ReferenceSlot) {
|
||||
t.Fatalf("expected registry selection error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorRejectsUnknownAndMismatchedItemPairs(t *testing.T) {
|
||||
id := itemidentity.DeriveID("Torch")
|
||||
content, err := itemcodec.New().Encode(dnd.ItemRegistry{Items: []dnd.Item{{ID: id, Name: "Torch", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}})
|
||||
|
||||
Reference in New Issue
Block a user