chore: update book enabled status wiring

This commit is contained in:
2026-04-27 11:41:35 +08:00
parent 93bde0a6b6
commit 67c33d06be
25 changed files with 336 additions and 122 deletions

View File

@@ -1,11 +1,11 @@
package book
import (
"reflect"
"strings"
"testing"
"github.com/flipped-aurora/gin-vue-admin/server/model/book"
commonModel "github.com/flipped-aurora/gin-vue-admin/server/model/common"
)
func TestValidateBookRejectsOutOfRangeAggregates(t *testing.T) {
@@ -47,17 +47,21 @@ func TestValidateBookRejectsInvalidFixedDictionaryValues(t *testing.T) {
}
}
func TestValidateBookAuthorRejectsInvalidStatus(t *testing.T) {
err := validateBookAuthor(book.BookAuthor{AuthorStatus: "bad"})
assertValidationErrorContains(t, err, "authorStatus")
}
func TestValidateBookAuthorAcceptsCommonEnabledStatus(t *testing.T) {
if err := validateBookAuthor(book.BookAuthor{AuthorStatus: commonModel.CommonEnabledStatusEnabled}); err != nil {
t.Fatalf("validateBookAuthor enabled error = %v", err)
func TestBookAuthorUsesIsEnabledBooleanContract(t *testing.T) {
authorType := reflect.TypeOf(book.BookAuthor{})
legacyFieldName := "Author" + "Status"
if _, ok := authorType.FieldByName(legacyFieldName); ok {
t.Fatal("BookAuthor still exposes legacy status field, want IsEnabled boolean only")
}
if err := validateBookAuthor(book.BookAuthor{AuthorStatus: commonModel.CommonEnabledStatusDisabled}); err != nil {
t.Fatalf("validateBookAuthor disabled error = %v", err)
field, ok := authorType.FieldByName("IsEnabled")
if !ok {
t.Fatal("BookAuthor missing IsEnabled field")
}
if field.Type.Kind() != reflect.Bool {
t.Fatalf("BookAuthor.IsEnabled kind = %s, want bool", field.Type.Kind())
}
if got := field.Tag.Get("json"); got != "isEnabled" {
t.Fatalf("BookAuthor.IsEnabled json tag = %q, want isEnabled", got)
}
}