-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpromptpay_test.go
77 lines (64 loc) · 1.64 KB
/
promptpay_test.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
package promptpay
import (
"testing"
)
func TestPromptPay(t *testing.T) {
paycheck := PromptPay{}
promptPayStr, err := paycheck.Gen()
if err == nil {
t.Error("Expect error: invalid PromptPayID")
}
paycheck.PromptPayID = "0105540087061"
paycheck.Amount = 100.75
expect := "00020101021129370016A000000677010111021301055400870615802TH53037645406100.756304C86C"
// Use ID
promptPayStr, err = paycheck.Gen()
if err != nil {
t.Fatal(err.Error())
}
if promptPayStr != expect {
t.Errorf("PromptPay doesn't match.\nGet\t%s\nExpect\t%s\n", promptPayStr, expect)
}
t.Log(promptPayStr)
for i := 0; i < 128; i++ {
paycheck.Amount = float64(i)
promptPayStr, err = paycheck.Gen()
if err != nil {
t.Fatal(err.Error())
}
t.Log(promptPayStr)
}
// check for invalid id
paycheck.PromptPayID = "012345678912"
promptPayStr, err = paycheck.Gen()
if err == nil {
t.Error("Expect error: invalid ID")
}
expect = "00020101021129370016A000000677010111011300668111111115802TH53037645406100.25630415A6"
// Use phone
paycheck.PromptPayID = "0811111111"
paycheck.Amount = 100.25
promptPayStr, err = paycheck.Gen()
if err != nil {
t.Fatal(err.Error())
}
t.Log(promptPayStr)
if promptPayStr != expect {
t.Errorf("PromptPay doesn't match\nGet\t%s\nExpect\t%s\n", promptPayStr, expect)
}
t.Log(promptPayStr)
for i := 0; i < 128; i++ {
paycheck.Amount = float64(i)
promptPayStr, err = paycheck.Gen()
if err != nil {
t.Fatal(err.Error())
}
t.Log(promptPayStr)
}
// check for invalid phone
paycheck.PromptPayID = "668123456745"
promptPayStr, err = paycheck.Gen()
if err == nil {
t.Error("Expect error: invalid phone")
}
}