-
Notifications
You must be signed in to change notification settings - Fork 3
/
chapa_example_service_test.go
60 lines (43 loc) · 1.31 KB
/
chapa_example_service_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
package chapa
import (
"context"
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestChapaExampleService(t *testing.T) {
Convey("Chapa Example Service", t, func() {
ctx := context.Background()
exampleService := NewExamplePaymentService(
New(os.Getenv("CHAPA_API_KEY")),
)
Convey("can list payment transactions", func() {
transactionList, err := exampleService.ListPaymentTransactions(ctx)
So(err, ShouldBeNil)
So(len(transactionList.Transactions), ShouldEqual, 2)
})
Convey("can successfully checkout", func() {
form := &CheckoutForm{
Amount: 12.30,
Currency: "ETB",
}
paymentTxn, err := exampleService.Checkout(ctx, 1032, form)
So(err, ShouldBeNil)
So(paymentTxn.Amount, ShouldEqual, form.Amount)
So(paymentTxn.Currency, ShouldEqual, form.Currency)
So(paymentTxn.Status, ShouldEqual, PendingTransactionStatus)
So(paymentTxn.MerchantFee, ShouldBeZeroValue)
So(paymentTxn.TransactionID, ShouldNotBeZeroValue)
So(len(transactions), ShouldEqual, 3)
})
Convey("cannot checkout if user is unavailable", func() {
form := &CheckoutForm{
Amount: 12.30,
Currency: "ETB",
}
_, err := exampleService.Checkout(ctx, 0, form)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "user not found")
})
})
}