Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
//go:build test && dev
|
|
|
|
package payments
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
// TestSquareRefundStatusToLocal_Table covers the full Square refund status
|
|
// space: COMPLETED/APPROVED → 'completed' terminal, FAILED/REJECTED → 'failed'
|
|
// terminal, and all other statuses (PENDING, CANCELED, unknown, empty,
|
|
// lowercase) → non-terminal with empty local status.
|
|
func TestSquareRefundStatusToLocal_Table(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
input string
|
|
wantStatus string
|
|
wantTerminal bool
|
|
}{
|
|
{"COMPLETED", "completed", true},
|
|
{"APPROVED", "completed", true},
|
|
{"FAILED", "failed", true},
|
|
{"REJECTED", "failed", true},
|
|
{"PENDING", "", false},
|
|
{"CANCELED", "", false},
|
|
{"", "", false},
|
|
{"UNKNOWN", "", false},
|
|
{"completed", "", false},
|
|
{"failed", "", false},
|
|
{"approved", "", false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.input, func(t *testing.T) {
|
|
status, terminal := SquareRefundStatusToLocal(tt.input)
|
|
if status != tt.wantStatus {
|
|
t.Errorf("SquareRefundStatusToLocal(%q) status = %q, want %q", tt.input, status, tt.wantStatus)
|
|
}
|
|
if terminal != tt.wantTerminal {
|
|
t.Errorf("SquareRefundStatusToLocal(%q) terminal = %v, want %v", tt.input, terminal, tt.wantTerminal)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestRoundingEpsilon_AtBoundary verifies roundingEpsilon is within the
|
|
// expected range (0.004 ± 0.001) so the money-safety zero threshold is stable.
|
|
func TestRoundingEpsilon_AtBoundary(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if roundingEpsilon < 0.003 || roundingEpsilon > 0.005 {
|
|
t.Errorf("roundingEpsilon = %.6f, expected ~0.004", roundingEpsilon)
|
|
}
|
|
}
|
|
|
|
// TestIsVerificationRequiredError_NilError safely handles nil input.
|
|
func TestIsVerificationRequiredError_NilError(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if isVerificationRequiredError(nil) {
|
|
t.Error("nil error must not be verification required")
|
|
}
|
|
}
|
|
|
|
// TestIsVerificationRequiredError_PlainError safely handles a non-structured
|
|
// error with no Square error code.
|
|
func TestIsVerificationRequiredError_PlainError(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if isVerificationRequiredError(errors.New("network timeout")) {
|
|
t.Error("a plain network error must not be verification required")
|
|
}
|
|
} |