refactor: serve static frontend with Go APIs
This commit is contained in:
@@ -74,9 +74,26 @@ func TestBillingAdminRoutesRequireSuperAdminAndValidateWrites(t *testing.T) {
|
||||
if got := serveJSON(t, super, http.MethodPatch, "/api/admin/billing/account", map[string]any{"accountName": " Acme ", "bankName": " Bank ", "accountNumber": " 123 ", "contact": " Ops "}); got.Code != 200 || account.saved.AccountName != "Acme" {
|
||||
t.Fatalf("account status=%d saved=%+v body=%s", got.Code, account.saved, got.Body.String())
|
||||
}
|
||||
if got := serveJSON(t, super, http.MethodPost, "/api/admin/billing/adjustments", map[string]any{"organizationId": "org", "amountYuan": 1.235, "direction": "debit", "note": " correction "}); got.Code != 200 || service.adjustment.AmountFen != 124 || service.adjustment.DeltaFen != -124 || service.adjustment.OperatorID != "root" {
|
||||
got := serveJSON(t, super, http.MethodPost, "/api/admin/billing/adjustments", map[string]any{"organizationId": "org", "amountYuan": 1.235, "direction": "debit", "note": " correction "})
|
||||
if got.Code != 200 || service.adjustment.AmountFen != 124 || service.adjustment.DeltaFen != -124 || service.adjustment.OperatorID != "root" {
|
||||
t.Fatalf("adjustment status=%d got=%+v body=%s", got.Code, service.adjustment, got.Body.String())
|
||||
}
|
||||
var adjustmentResponse map[string]json.RawMessage
|
||||
if err := json.Unmarshal(got.Body.Bytes(), &adjustmentResponse); err != nil {
|
||||
t.Fatalf("decode adjustment response: %v", err)
|
||||
}
|
||||
if _, ok := adjustmentResponse["wallet"]; !ok {
|
||||
t.Fatalf("adjustment response missing lowercase wallet: %s", got.Body.String())
|
||||
}
|
||||
if _, ok := adjustmentResponse["entry"]; !ok {
|
||||
t.Fatalf("adjustment response missing lowercase entry: %s", got.Body.String())
|
||||
}
|
||||
if _, ok := adjustmentResponse["Wallet"]; ok {
|
||||
t.Fatalf("adjustment response contains uppercase Wallet: %s", got.Body.String())
|
||||
}
|
||||
if _, ok := adjustmentResponse["Entry"]; ok {
|
||||
t.Fatalf("adjustment response contains uppercase Entry: %s", got.Body.String())
|
||||
}
|
||||
if got := serveJSON(t, super, http.MethodPatch, "/api/admin/billing/prices/price-1", map[string]any{"standardUnitPriceFen": 1, "markupMultiplier": 2}); got.Code != 400 {
|
||||
t.Fatalf("whitelist status=%d", got.Code)
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ type routeMethodPattern struct {
|
||||
allow []string
|
||||
}
|
||||
|
||||
// WithRouteMethodCompatibility applies the method behavior that Next derives
|
||||
// from app route exports. It sits outside authentication so OPTIONS never
|
||||
// depends on runtime configuration and HEAD executes the corresponding GET
|
||||
// semantics while suppressing the response body.
|
||||
// WithRouteMethodCompatibility applies the legacy-compatible method matrix
|
||||
// for the checked-in public HTTP contract. It sits outside authentication so
|
||||
// OPTIONS never depends on runtime configuration and HEAD executes the
|
||||
// corresponding GET semantics while suppressing the response body.
|
||||
func WithRouteMethodCompatibility(next http.Handler) http.Handler {
|
||||
patterns := routeMethodPatterns(GoRouteSurface())
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
// RouteSurface describes one externally visible route explicitly owned by the
|
||||
// Go modular monolith. It is kept source-independent so contract tests can
|
||||
// compare it with the checked-in Next.js surface before any cutover.
|
||||
// compare it with the checked-in public HTTP contract.
|
||||
type RouteSurface struct {
|
||||
Method string `json:"method"`
|
||||
Path string `json:"path"`
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGoRouteSurfaceExactlyMatchesCheckedInNextManifest(t *testing.T) {
|
||||
func TestGoRouteSurfaceExactlyMatchesCheckedInPublicHTTPContract(t *testing.T) {
|
||||
_, source, _, _ := runtime.Caller(0)
|
||||
raw, err := os.ReadFile(filepath.Join(filepath.Dir(source), "../../../contracts/http/route-surface.v1.json"))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user