package db import ( "testing" "online-back/internal/payment/paymenthistory" ) func TestOrderByClause(t *testing.T) { cases := []struct { filter paymenthistory.ListFilter want string }{ {paymenthistory.ListFilter{Desc: true}, "p.id DESC"}, {paymenthistory.ListFilter{Sort: "id"}, "p.id ASC"}, {paymenthistory.ListFilter{Sort: "status", Desc: true}, "p.gateway_status DESC, p.id DESC"}, {paymenthistory.ListFilter{Sort: "amount"}, "p.amount_tmt ASC, p.id DESC"}, {paymenthistory.ListFilter{Sort: "p.id; DROP TABLE users", Desc: true}, "p.id DESC"}, } for _, tc := range cases { if got := orderByClause(tc.filter); got != tc.want { t.Errorf("orderByClause(%+v) = %q, want %q", tc.filter, got, tc.want) } } }