forked from vonmutinda/chapa
-
Notifications
You must be signed in to change notification settings - Fork 2
/
chapa_example_service_test.go
52 lines (41 loc) · 1.19 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
package chapa
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChapaExampleService(t *testing.T) {
InitConfig()
ctx := context.Background()
exampleService := NewExamplePaymentService(
New(),
)
t.Run("can list payment transactions", func(t *testing.T) {
transactionList, err := exampleService.ListTransactions(ctx)
assert.NoError(t, err)
assert.Equal(t, 2, len(transactionList.Transactions))
})
t.Run("can successfully checkout", func(t *testing.T) {
form := &CheckoutForm{
Amount: 12.30,
Currency: "ETB",
}
paymentTxn, err := exampleService.Checkout(ctx, 1032, form)
assert.NoError(t, err)
assert.Equal(t, form.Amount, paymentTxn.Amount)
assert.Equal(t, form.Currency, paymentTxn.Currency)
assert.Equal(t, PendingTransactionStatus, paymentTxn.Status)
assert.Zero(t, paymentTxn.Charge)
assert.NotZero(t, paymentTxn.TransID)
assert.Equal(t, 3, len(transactions))
})
t.Run("cannot checkout if user is unavailable", func(t *testing.T) {
form := &CheckoutForm{
Amount: 12.30,
Currency: "ETB",
}
_, err := exampleService.Checkout(ctx, 0, form)
assert.Error(t, err)
assert.Contains(t, err.Error(), "user not found")
})
}