-
Notifications
You must be signed in to change notification settings - Fork 28
/
main_test.go
43 lines (35 loc) · 1.41 KB
/
main_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
package main
import (
"context"
"strings"
"testing"
"github.com/adyen/adyen-go-api-library/v16/src/adyen"
"github.com/adyen/adyen-go-api-library/v16/src/checkout"
"github.com/adyen/adyen-go-api-library/v16/src/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_main(t *testing.T) {
t.Run("Create a new APIClient", func(t *testing.T) {
client := adyen.NewClient(&common.Config{
Environment: "TEST",
})
require.NotNil(t, client)
checkoutClient := client.Checkout()
require.NotNil(t, checkoutClient)
require.NotNil(t, checkoutClient.PaymentsApi)
require.NotNil(t, checkoutClient.PaymentsApi.Client.Cfg)
require.Equal(t, common.TestEnv, checkoutClient.PaymentLinksApi.Client.Cfg.Environment)
assert.Equal(t, "https://checkout-test.adyen.com/checkout/"+adyen.CheckoutAPIVersion, checkoutClient.ModificationsApi.BasePath())
t.Run("Create a API request that should fail", func(t *testing.T) {
req := checkoutClient.PaymentsApi.PaymentMethodsInput().PaymentMethodsRequest(checkout.PaymentMethodsRequest{})
res, httpRes, err := checkoutClient.PaymentsApi.PaymentMethods(context.Background(), req)
require.NotNil(t, err)
assert.Equal(t, true, strings.Contains(err.Error(), "Unauthorized"))
require.NotNil(t, res)
assert.Equal(t, checkout.PaymentMethodsResponse{}, res)
require.NotNil(t, httpRes)
assert.Equal(t, 401, httpRes.StatusCode)
})
})
}