forked from noebs/noebs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helpers.go
108 lines (91 loc) · 2.42 KB
/
test_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"encoding/json"
"math/rand"
"testing"
"time"
"github.com/adonese/noebs/ebs_fields"
)
func populatePurchaseFields(missing bool) ebs_fields.PurchaseFields {
//FIXME
// accept the required transaction as an interface and return a struct.
// this should be a generic function for all fields
// it should also respects each struct types
// lets test populating purchase fields
fields := ebs_fields.PurchaseFields{
WorkingKeyFields: populateWorkingKeyFields(), CardInfoFields: populateCardInfoFields(),
AmountFields: populateAmountFields(),
}
if missing {
fields.TerminalID = ""
return fields
}
return fields
}
func populateCardTransferFields() ebs_fields.CardTransferFields {
toCard := "1234567891234567"
f := ebs_fields.CardTransferFields{
CommonFields: populateCommmonFields(),
CardInfoFields: populateCardInfoFields(),
AmountFields: populateAmountFields(),
ToCard: toCard,
}
return f
}
func populateWorkingKeyFields() ebs_fields.WorkingKeyFields {
f := ebs_fields.WorkingKeyFields{
CommonFields: populateCommmonFields(),
}
return f
}
func populateCommmonFields() ebs_fields.CommonFields {
f := ebs_fields.CommonFields{
TerminalID: "12345678",
TranDateTime: time.Now().UTC().String(),
SystemTraceAuditNumber: rand.Int(),
ClientID: "noebs",
}
return f
}
func populateCardInfoFields() ebs_fields.CardInfoFields {
f := ebs_fields.CardInfoFields{
Pin: "1234",
Pan: "1234567891234567",
Expdate: "2209",
}
return f
}
func populateAmountFields() ebs_fields.AmountFields {
currencyCode := "SDG"
amount := 32.43
f := ebs_fields.AmountFields{
TranCurrencyCode: currencyCode,
TranAmount: float32(amount),
}
return f
}
func getSuccessfulPurchasePayload(service interface{}) []byte {
// get the purchase struct only, try to generalize it later
if _, ok := service.(ebs_fields.PurchaseFields); ok {
f := populatePurchaseFields(false)
jsonFields, err := json.Marshal(f)
if err != nil {
return nil
}
return jsonFields
} else {
return nil
}
}
// invalid transaction fields to `which`? For now, let us make it for purchase ONLY.
func getFailedPurchasePayload(t *testing.T, service interface{}) []byte {
t.Helper()
p := populatePurchaseFields(false)
p.TranAmount = -32.43
fields, err := json.Marshal(p)
if err != nil {
t.Fatalf("There is an error: %s", err.Error())
return nil
}
return fields
}