Конфигурация хранит feature_flags (JSON-массив, NULL = нет) — какие данные она использует. Флаги выводятся из содержимого при каждом сохранении (internal/configfeatures). Если у конфигурации есть флаг, неизвестный этой версии, клиент отказывается её изменять: все write-пути отдают 409 unsupported_config_features со списком флагов, конфигуратор показывает баннер «обновите приложение» и блокирует сохранение. Push на сервер тоже отказывается, если серверная версия несёт неизвестный флаг; такое изменение остаётся в очереди до обновления. Первый флаг: sale_row_markups. Серверная миграция 034 добавляет колонку; до её применения запись идёт без колонки (с warning). Формат имён и реестр флагов — bible-local/02-architecture.md, ADL 2026-09-24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"git.mchus.pro/mchus/quoteforge/internal/configfeatures"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestClientFacingErrorMessageKeepsDomain4xx(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got := clientFacingErrorMessage(400, "invalid request", &json.SyntaxError{Offset: 1})
|
|
if got != "invalid request" {
|
|
t.Fatalf("expected fallback for decode error, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestClientFacingErrorMessagePreservesBusinessMessage(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := errString("main project variant cannot be deleted")
|
|
got := clientFacingErrorMessage(400, "invalid request", err)
|
|
if got != err.Error() {
|
|
t.Fatalf("expected business message, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestClientFacingErrorMessageHidesTechnical4xx(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := errString("sql: no rows in result set")
|
|
got := clientFacingErrorMessage(404, "resource not found", err)
|
|
if got != "resource not found" {
|
|
t.Fatalf("expected fallback for technical error, got %q", got)
|
|
}
|
|
}
|
|
|
|
type errString string
|
|
|
|
func (e errString) Error() string {
|
|
return string(e)
|
|
}
|
|
|
|
func TestRespondErrorUnsupportedFeaturesIs409(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
w := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(w)
|
|
|
|
err := fmt.Errorf("wrapped: %w", configfeatures.Check([]string{"future_x"}))
|
|
RespondError(c, http.StatusInternalServerError, "internal server error", err)
|
|
|
|
if w.Code != http.StatusConflict {
|
|
t.Fatalf("status = %d, want 409", w.Code)
|
|
}
|
|
var body struct {
|
|
Code string `json:"code"`
|
|
Features []string `json:"unsupported_features"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
|
|
t.Fatalf("decode body: %v", err)
|
|
}
|
|
if body.Code != "unsupported_config_features" || len(body.Features) != 1 || body.Features[0] != "future_x" {
|
|
t.Fatalf("unexpected body %s", w.Body.String())
|
|
}
|
|
}
|