forked from dundee/qrpay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment_test.go
63 lines (45 loc) · 1.21 KB
/
payment_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
package qrpay_test
import (
"os"
"testing"
"github.com/dundee/qrpay"
"github.com/stretchr/testify/assert"
)
func TestGetQRCodeImage(t *testing.T) {
p := qrpay.NewSpaydPayment()
p.SetIBAN("CZ5855000000001265098001")
b, _ := qrpay.GetQRCodeImage(p)
// check start of PNG image
assert.True(t, len(b) > 10)
assert.Equal(t, uint8(0x89), b[0])
assert.Equal(t, uint8(0x50), b[1])
}
func TestGetQRCodeImageWithErr(t *testing.T) {
p := qrpay.NewSpaydPayment()
b, err := qrpay.GetQRCodeImage(p)
assert.Nil(t, b)
assert.Equal(t, "IBAN is mandatory", err.Error())
}
func TestSaveQRCode(t *testing.T) {
path := "qr.jpeg"
defer os.Remove(path)
p := qrpay.NewSpaydPayment()
p.SetIBAN("CZ5855000000001265098001")
qrpay.SaveQRCodeImageToFile(p, path)
assert.FileExists(t, path)
}
func TestSaveEpcQRCode(t *testing.T) {
path := "qr.jpeg"
defer os.Remove(path)
p := qrpay.NewEpcPayment()
p.SetRecipientName("Red Cross")
p.SetIBAN("CZ5855000000001265098001")
qrpay.SaveQRCodeImageToFile(p, path)
assert.FileExists(t, path)
}
func TestSaveQRCodeWithErr(t *testing.T) {
path := "qr.jpeg"
p := qrpay.NewSpaydPayment()
err := qrpay.SaveQRCodeImageToFile(p, path)
assert.Equal(t, "IBAN is mandatory", err.Error())
}