fix(#41): add missing json tags to ReparseOutcome

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
QiuSW
2026-08-19 14:49:10 +08:00
co-authored by Claude Opus 5
parent f72c24b5da
commit e6c8b52164
2 changed files with 32 additions and 4 deletions
+4 -4
View File
@@ -27,10 +27,10 @@ type rawDetailSpec struct {
// ReparseOutcome reports what one row's reparse actually did, for the batch
// result page's per-line feedback.
type ReparseOutcome struct {
SYBProductID uint64
Outcome string // reparsed | skipped_manual | unchanged
OldStatus string
NewStatus string
SYBProductID uint64 `json:"sybProductId"`
Outcome string `json:"outcome"` // reparsed | skipped_manual | unchanged
OldStatus string `json:"oldStatus"`
NewStatus string `json:"newStatus"`
}
const (
@@ -2,6 +2,8 @@ package sybimport_test
import (
"context"
"encoding/json"
"strings"
"testing"
"go-admin/app/goauto/models"
@@ -148,3 +150,29 @@ func TestManualCorrectMergesIntoArchiveLikeASuccessfulParse(t *testing.T) {
t.Fatal("a manual correction should merge into the shopee archive same as a successful auto-parse")
}
}
// Regression test: ReparseOutcome originally had no json tags at all, so Go's
// default marshaling produced PascalCase keys ("SYBProductID", "OldStatus")
// instead of the camelCase the rest of this API and the admin frontend use.
// A frontend built against the intended camelCase names would have silently
// read undefined for every field.
func TestReparseOutcomeMarshalsToCamelCaseKeys(t *testing.T) {
db := openTestDB(t)
applied, err := sybimport.ApplyDetail(context.Background(), db, realOrder(), realDetailA())
if err != nil {
t.Fatalf("apply: %v", err)
}
outcome, err := sybimport.Reparse(context.Background(), db, applied.SYBProduct.ID, false)
if err != nil {
t.Fatalf("reparse: %v", err)
}
encoded, err := json.Marshal(outcome)
if err != nil {
t.Fatalf("marshal: %v", err)
}
for _, key := range []string{`"sybProductId"`, `"outcome"`, `"oldStatus"`, `"newStatus"`} {
if !strings.Contains(string(encoded), key) {
t.Fatalf("expected key %s in %s", key, encoded)
}
}
}