mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-08-29 20:42:35 +00:00
fix(spec): unwrap SQL wrapper metadata types
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/bitechdev/ResolveSpec/pkg/common"
|
||||
"github.com/bitechdev/ResolveSpec/pkg/spectypes"
|
||||
)
|
||||
|
||||
// detailTestModel is a simple model with gorm column/type tags for detail format tests.
|
||||
@@ -207,3 +208,30 @@ func TestBuildDetailFields_SkipsRelations(t *testing.T) {
|
||||
t.Errorf("expected 2 scalar fields (id, name), got %d", len(fields))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildDetailFields_UnwrapsSQLTypes(t *testing.T) {
|
||||
type model struct {
|
||||
Name spectypes.SqlString `gorm:"column:name" json:"name"`
|
||||
CreatedAt spectypes.SqlTimeStamp `gorm:"column:created_at" json:"created_at"`
|
||||
Metadata spectypes.SqlJSONB `gorm:"column:metadata;type:jsonb" json:"metadata"`
|
||||
}
|
||||
|
||||
fields := (&Handler{}).buildDetailFields(model{})
|
||||
byName := make(map[string]string, len(fields))
|
||||
for _, field := range fields {
|
||||
byName[field.Name] = field.DataType
|
||||
if !field.Nullable {
|
||||
t.Errorf("%q: expected SQL wrapper to be nullable", field.Name)
|
||||
}
|
||||
}
|
||||
|
||||
for name, want := range map[string]string{
|
||||
"name": "string",
|
||||
"created_at": "unknown",
|
||||
"metadata": "unknown",
|
||||
} {
|
||||
if got := byName[name]; got != want {
|
||||
t.Errorf("%q: expected type %q, got %q", name, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user