chore: update book enabled status wiring
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user