The Go cutover omitted get_character_inventory; the React InventoryWindow
fetches GET /inventory/{name} and got 404 -> empty. Port the endpoint:
per-character items with placement (current_wielded_location/container_id/
items_capacity), mana (current_mana/max_mana from original_json IntValues),
icon overlays, and join-table combat/req/enh/rating stats; material-prefixed
name. Returns {character_name,item_count,items}.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestEnrichInventoryRow(t *testing.T) {
|
|
// NULL columns are dropped.
|
|
out := enrichInventoryRow(map[string]any{"name": "Helm", "armor_level": nil, "value": 100})
|
|
if _, ok := out["armor_level"]; ok {
|
|
t.Errorf("nil column armor_level should be dropped, got %v", out["armor_level"])
|
|
}
|
|
if out["value"] != 100 {
|
|
t.Errorf("value = %v, want 100", out["value"])
|
|
}
|
|
|
|
// Material prefix is applied and original_name preserved.
|
|
out = enrichInventoryRow(map[string]any{"name": "Chiran Helm", "material": "Pyreal"})
|
|
if out["name"] != "Pyreal Chiran Helm" {
|
|
t.Errorf("name = %v, want %q", out["name"], "Pyreal Chiran Helm")
|
|
}
|
|
if out["original_name"] != "Chiran Helm" {
|
|
t.Errorf("original_name = %v, want %q", out["original_name"], "Chiran Helm")
|
|
}
|
|
if out["material_name"] != "Pyreal" {
|
|
t.Errorf("material_name = %v, want Pyreal", out["material_name"])
|
|
}
|
|
|
|
// Already-prefixed name is not doubled.
|
|
out = enrichInventoryRow(map[string]any{"name": "Pyreal Helm", "material": "Pyreal"})
|
|
if out["name"] != "Pyreal Helm" {
|
|
t.Errorf("name = %v, want no double prefix", out["name"])
|
|
}
|
|
if _, ok := out["original_name"]; ok {
|
|
t.Errorf("original_name should be unset when no prefix applied")
|
|
}
|
|
}
|