71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package store
|
|
|
|
import (
|
|
"aeternalis/server/content"
|
|
"aeternalis/server/internal/game"
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestVisualLibraryPublicationReplayAndResourceCompatibility(t *testing.T) {
|
|
ctx := context.Background()
|
|
dsn := "file:" + filepath.ToSlash(filepath.Join(t.TempDir(), "visual.db"))
|
|
db, err := Open(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer func() { db.Close() }()
|
|
c, err := db.Catalog(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
a := content.Appearance{Version: 1, Family: "tree", Variant: 3, Seed: 42, Height: 1, Width: 1, Detail: .5, Primary: "#80a77a", Secondary: "#785443", Accent: "#d8ae85"}
|
|
change := CatalogChange{ID: game.ID(), ExpectedVersion: c.Version, Op: "create-visual", Reason: "Create blossom design", Visual: &content.VisualPreset{Name: "Blossom", Appearance: a}}
|
|
preview, err := db.PreviewCatalog(ctx, change)
|
|
if err != nil || preview.Resolved.HasDefinitionID() {
|
|
t.Fatal("preview reserved identity", err)
|
|
}
|
|
result, err := db.PublishCatalog(ctx, "artist", change)
|
|
if err != nil || result.ID == "" {
|
|
t.Fatal(err)
|
|
}
|
|
retry, err := db.PublishCatalog(ctx, "artist", change)
|
|
if err != nil || retry != result {
|
|
t.Fatal("replay changed design identity", err)
|
|
}
|
|
if change.Visual.ID != "" {
|
|
t.Fatal("publication mutated submitted design")
|
|
}
|
|
if err = db.Close(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
db, err = Open(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c, err = db.Catalog(ctx)
|
|
if err != nil || len(c.Visuals) != 1 || c.Visuals[0].Appearance != a {
|
|
t.Fatal("visual not durable", err)
|
|
}
|
|
r := c.Gathering.Resources[0]
|
|
r.ID = ""
|
|
r.Name = "Blossom tree"
|
|
r.Model = "tree"
|
|
r.Appearance = &a
|
|
publication := CatalogChange{ID: game.ID(), ExpectedVersion: c.Version, Op: "create-resource", Reason: "Use reusable blossom design", Resource: &r}
|
|
if _, err = db.PublishCatalog(ctx, "artist", publication); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c, err = db.Catalog(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r.Model = "ore"
|
|
publication.ID = game.ID()
|
|
publication.ExpectedVersion = c.Version
|
|
if _, err = db.PublishCatalog(ctx, "artist", publication); err == nil {
|
|
t.Fatal("tree appearance assigned to ore")
|
|
}
|
|
}
|