package finance

import (
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"

	"github.com/jackc/pgx/v5/pgconn"
)

func TestRespondErrClosedShiftIsBusinessConflict(t *testing.T) {
	rec := httptest.NewRecorder()
	respondErr(rec, httptest.NewRequest(http.MethodPost, "/api/v1/invoices/1/pay", nil), &pgconn.PgError{Code: "23514", ConstraintName: "cashier_shift_open", Message: "private database detail"})
	if rec.Code != http.StatusConflict {
		t.Fatalf("status=%d, want409", rec.Code)
	}
	if strings.Contains(rec.Body.String(), "private database") || !strings.Contains(rec.Body.String(), "Cashier shift is closed") {
		t.Fatalf("unsafe/unclassified response: %s", rec.Body.String())
	}
}
