36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
package creditcall
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.futuresens.co.uk/futuresens/hardlink/internal/types"
|
|
)
|
|
|
|
func TestPreauthLegacyDecision(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, result, kind string
|
|
approved, save bool
|
|
}{
|
|
{"sale", "APPROVED", "SALE", true, true},
|
|
{"verification", "APPROVED", "ACCOUNT VERIFICATION", true, false},
|
|
{"mixed case", "Approved", "Account Verification", true, false},
|
|
{"request spelling is not result spelling", "APPROVED", "AccountVerification", false, false},
|
|
{"missing type", "APPROVED", "", false, false},
|
|
{"declined sale", "DECLINED", "SALE", false, false},
|
|
{"declined verification", "DECLINED", "ACCOUNT VERIFICATION", false, false},
|
|
{"missing result", "", "SALE", false, false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
fields := map[string]string{types.TransactionResult: tc.result, types.TransactionType: tc.kind, types.Errors: "provider detail"}
|
|
redirect, save := BuildPreauthRedirectURL(fields)
|
|
if strings.HasPrefix(redirect, "/successful?") != tc.approved || save != tc.save {
|
|
t.Errorf("BuildPreauthRedirectURL(%v) = %q,%t, want approved=%t save=%t", fields, redirect, save, tc.approved, tc.save)
|
|
}
|
|
if _, ok := fields[types.TotalAmount]; ok {
|
|
t.Error("BuildPreauthRedirectURL fabricated TOTAL_AMOUNT")
|
|
}
|
|
})
|
|
}
|
|
}
|