Files
Xor290andClaude Sonnet 5.5 f9bfdc9d3c
ci-api / test (push) Successful in 20m38s
ci-web / test (push) Successful in 11m20s
feat(checkout): let the admin choose the details asked at checkout
The admin enables or disables each option (phone, address, Snapchat,
Instagram, Telegram, SimpleX, WhatsApp, Signal, notes, preferred time)
from a new "Checkout fields" page; the customer's name is always asked.

Backend
- checkoutfields module: single-row settings (CHECK id = 1), public GET
  and admin GET/PUT.
- orders: answers stored as JSONB (contacts, info_sup); the customer
  phone moves from customer_phone to contacts.phone (migration 000034
  copies existing values before dropping the column).
- Orders are validated against the live settings: disabled options and
  unknown keys are dropped, enabled phone/address are required, and
  format, length and control characters are checked.
- The Telegram notification includes the answers.

Frontend
- Checkout form generated from the enabled options; admin settings page;
  answers shown in the order list and detail.
- API calls live in src/api (checkoutFields.ts, orders.ts); ApiError
  keeps the response body so the rejected field can be reported.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-04 16:16:22 +02:00

58 lines
1.6 KiB
Go

package orders_test
import (
"sync"
"testing"
"gorm.io/gorm/schema"
"backend/internal/modules/orders"
)
// Régression : un champ de type struct sans Valuer/Scanner faisait échouer
// l'analyse du modèle par GORM au premier accès à la base, alors que
// `go build` passait.
func TestOrderModelIsValidForGORM(t *testing.T) {
s, err := schema.Parse(&orders.Order{}, &sync.Map{}, schema.NamingStrategy{})
if err != nil {
t.Fatalf("schema.Parse(Order) error = %v", err)
}
f := s.LookUpField("contacts")
if f == nil {
t.Fatalf("colonne contacts absente (colonnes: %v)", s.DBNames)
}
}
func TestContacts_RoundTrip(t *testing.T) {
in := orders.Contacts{orders.ContactWhatsapp: "+33612345678", orders.ContactHour: "18:30"}
v, err := in.Value()
if err != nil {
t.Fatal(err)
}
var out orders.Contacts
if err := out.Scan(v); err != nil {
t.Fatal(err)
}
if len(out) != 2 || out[orders.ContactWhatsapp] != "+33612345678" || out[orders.ContactHour] != "18:30" {
t.Errorf("relu = %v, attendu %v", out, in)
}
}
func TestContacts_NilAndNullAreEmpty(t *testing.T) {
var nilMap orders.Contacts
v, err := nilMap.Value()
if err != nil || v != "{}" {
t.Errorf("Value(nil) = %v, %v ; attendu \"{}\"", v, err)
}
var out orders.Contacts
if err := out.Scan(nil); err != nil || out == nil || len(out) != 0 {
t.Errorf("Scan(nil) = %v, %v ; attendu une map vide non nil", out, err)
}
if err := out.Scan([]byte(`{`)); err == nil {
t.Error("Scan d'un JSON invalide : erreur attendue")
}
if err := out.Scan(42); err == nil {
t.Error("Scan d'un type inattendu : erreur attendue")
}
}