package paymentkit

import "testing"

func TestNormalizeStatusCoversCanonicalPaymentStates(t *testing.T) {
	for _, test := range []struct {
		input, want string
	}{
		{input: "fulfilled", want: "success"},
		{input: "client_pending", want: "pending"},
		{input: "trade_closed", want: "failed"},
	} {
		if got := NormalizeStatus(test.input, "unknown"); got != test.want {
			t.Fatalf("NormalizeStatus(%q) = %q, want %q", test.input, got, test.want)
		}
	}
}

func TestNormalizeStatusSeparatesRefundStates(t *testing.T) {
	if got := NormalizeStatus("REFUND_SUCCESS", "unknown"); got != "success" {
		t.Fatalf("payment status for completed payment = %q, want success", got)
	}
	if got := NormalizeRefundStatus("REFUND_SUCCESS", "unknown"); got != "success" {
		t.Fatalf("refund status = %q, want success", got)
	}
}

func TestNormalizeStatusDoesNotTreatRefundAsPaymentFailure(t *testing.T) {
	if got := NormalizeStatus("REFUND", "unknown"); got != "unknown" {
		t.Fatalf("NormalizeStatus(REFUND) = %q, want fallback", got)
	}
}

func TestNormalizeRefundStatusAcceptsTradeSuccess(t *testing.T) {
	if got := NormalizeRefundStatus("TRADE_SUCCESS", "unknown"); got != "success" {
		t.Fatalf("NormalizeRefundStatus(TRADE_SUCCESS) = %q, want success", got)
	}
}
