From e6c8b52164a6e7dc9e9450e1f4eab083192a5978 Mon Sep 17 00:00:00 2001 From: QiuSW <105186638@qq.com> Date: Wed, 19 Aug 2026 14:49:10 +0800 Subject: [PATCH] fix(#41): add missing json tags to ReparseOutcome Co-Authored-By: Claude Opus 5 --- server/app/goauto/sybimport/reparse.go | 8 +++--- server/app/goauto/sybimport/reparse_test.go | 28 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/server/app/goauto/sybimport/reparse.go b/server/app/goauto/sybimport/reparse.go index a440848..4ade256 100644 --- a/server/app/goauto/sybimport/reparse.go +++ b/server/app/goauto/sybimport/reparse.go @@ -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 ( diff --git a/server/app/goauto/sybimport/reparse_test.go b/server/app/goauto/sybimport/reparse_test.go index 0d2a663..8f9c712 100644 --- a/server/app/goauto/sybimport/reparse_test.go +++ b/server/app/goauto/sybimport/reparse_test.go @@ -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) + } + } +}