126 lines
4.3 KiB
Go
126 lines
4.3 KiB
Go
package paybridge
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.futuresens.co.uk/futuresens/hardlink/paymentstatus"
|
|
)
|
|
|
|
func TestMapPayBridgeFinalStatus(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
status string
|
|
success bool
|
|
want string
|
|
}{
|
|
{"approved success", "APPROVED", true, paymentstatus.Approved},
|
|
{"approved without success", "APPROVED", false, paymentstatus.Error},
|
|
{"declined", "DECLINED", false, paymentstatus.Declined},
|
|
{"cancelled", "CANCELLED", false, paymentstatus.Cancelled},
|
|
{"timeout", "TIMEOUT", false, paymentstatus.Timeout},
|
|
{"voided", "VOIDED", false, paymentstatus.Voided},
|
|
{"voided daily limit exceeded", "VOIDED_DAILY_LIMIT_EXCEEDED", false, paymentstatus.DailyLimitExceeded},
|
|
{"daily limit void failed", "DAILY_LIMIT_EXCEEDED_VOID_FAILED", false, paymentstatus.VoidFailed},
|
|
{"daily limit validation error", "DAILY_LIMIT_VALIDATION_ERROR", false, paymentstatus.LimitValidationError},
|
|
{"error", "ERROR", false, paymentstatus.Error},
|
|
{"failed", "FAILED", false, paymentstatus.Error},
|
|
{"unknown", "UNKNOWN", false, paymentstatus.Error},
|
|
{"approved case insensitive", "approved", true, paymentstatus.Approved},
|
|
{"declined case insensitive", "declined", false, paymentstatus.Declined},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
got := mapPayBridgeFinalStatus(test.status, test.success)
|
|
if got != test.want {
|
|
t.Fatalf("got %q, want %q", got, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapPayBridgeStatusMessages(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
status string
|
|
want string
|
|
}{
|
|
{"insert or swipe card", "insert or swipe card", paymentstatus.PresentCard},
|
|
{"insert swipe or present card", "insert, swipe or present card", paymentstatus.PresentCard},
|
|
{"insert card", "insert card", paymentstatus.InsertCard},
|
|
{"please wait", "please wait", paymentstatus.PleaseWait},
|
|
{"do not remove card", "please wait. do not remove card", paymentstatus.DoNotRemoveCard},
|
|
{"try another interface", "please try another interface", paymentstatus.TryAnotherInterface},
|
|
{"pin", "pin", paymentstatus.EnterPIN},
|
|
{"pin again", "pin again", paymentstatus.EnterPINAgain},
|
|
{"transaction cancelled", "transaction cancelled", paymentstatus.Cancelled},
|
|
{"processing", "processing", paymentstatus.Processing},
|
|
{"approved", "approved", paymentstatus.Authorized},
|
|
{"declined", "declined", paymentstatus.Declined},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
got, matched := mapPayBridgeStatus(test.status, "")
|
|
if !matched {
|
|
t.Fatal("expected status to match")
|
|
}
|
|
if got != test.want {
|
|
t.Fatalf("got %q, want %q", got, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapPayBridgeStatusCodes(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
code string
|
|
want string
|
|
}{
|
|
{"insert card", "101", paymentstatus.InsertCard},
|
|
{"enter pin", "106", paymentstatus.EnterPIN},
|
|
{"cancelled", "124", paymentstatus.Cancelled},
|
|
{"please wait", "1017", paymentstatus.PleaseWait},
|
|
{"present card", "1109", paymentstatus.PresentCard},
|
|
{"present card alternate", "1113", paymentstatus.PresentCard},
|
|
{"enter pin again", "1129", paymentstatus.EnterPINAgain},
|
|
{"try another interface", "1274", paymentstatus.TryAnotherInterface},
|
|
{"do not remove card", "1312", paymentstatus.DoNotRemoveCard},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
got, matched := mapPayBridgeStatus("", test.code)
|
|
if !matched {
|
|
t.Fatal("expected code to match")
|
|
}
|
|
if got != test.want {
|
|
t.Fatalf("got %q, want %q", got, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapPayBridgeStatusNormalization(t *testing.T) {
|
|
got, matched := mapPayBridgeStatus(" PiN AgAiN ", "")
|
|
if !matched || got != paymentstatus.EnterPINAgain {
|
|
t.Fatalf("normalized message got (%q, %t), want (%q, true)", got, matched, paymentstatus.EnterPINAgain)
|
|
}
|
|
|
|
got, matched = mapPayBridgeStatus("", " 101 ")
|
|
if !matched || got != paymentstatus.InsertCard {
|
|
t.Fatalf("trimmed code got (%q, %t), want (%q, true)", got, matched, paymentstatus.InsertCard)
|
|
}
|
|
}
|
|
|
|
func TestMapPayBridgeStatusUnknown(t *testing.T) {
|
|
got, matched := mapPayBridgeStatus("unknown message", "999")
|
|
if matched {
|
|
t.Fatal("unknown status and code must not match")
|
|
}
|
|
if got != paymentstatus.Processing {
|
|
t.Fatalf("got %q, want %q", got, paymentstatus.Processing)
|
|
}
|
|
}
|