smobilpay.TestWithCollectSyncVerifyInterval   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
package smobilpay
2
3
import (
4
	"net/http"
5
	"testing"
6
	"time"
7
8
	"github.com/stretchr/testify/assert"
9
)
10
11
func TestWithHTTPClient(t *testing.T) {
12
	t.Run("httpClient is not set when the httpClient is nil", func(t *testing.T) {
13
		// Setup
14
		t.Parallel()
15
16
		// Arrange
17
		config := defaultClientConfig()
18
19
		// Act
20
		WithHTTPClient(nil).apply(config)
21
22
		// Assert
23
		assert.NotNil(t, config.httpClient)
24
	})
25
26
	t.Run("httpClient is set when the httpClient is not nil", func(t *testing.T) {
27
		// Setup
28
		t.Parallel()
29
30
		// Arrange
31
		config := defaultClientConfig()
32
		newClient := &http.Client{Timeout: 300}
33
34
		// Act
35
		WithHTTPClient(newClient).apply(config)
36
37
		// Assert
38
		assert.NotNil(t, config.httpClient)
39
		assert.Equal(t, newClient.Timeout, config.httpClient.Timeout)
40
	})
41
}
42
43
func TestWithBaseURL(t *testing.T) {
44
	t.Run("baseURL is set successfully", func(t *testing.T) {
45
		// Setup
46
		t.Parallel()
47
48
		// Arrange
49
		baseURL := "https://example.com"
50
		config := defaultClientConfig()
51
52
		// Act
53
		WithBaseURL(baseURL).apply(config)
54
55
		// Assert
56
		assert.Equal(t, config.baseURL, config.baseURL)
57
	})
58
59
	t.Run("tailing / is trimmed from baseURL", func(t *testing.T) {
60
		// Setup
61
		t.Parallel()
62
63
		// Arrange
64
		baseURL := "https://example.com/"
65
		config := defaultClientConfig()
66
67
		// Act
68
		WithBaseURL(baseURL).apply(config)
69
70
		// Assert
71
		assert.Equal(t, "https://example.com", config.baseURL)
72
	})
73
}
74
75
func TestWithAccessToken(t *testing.T) {
76
	// Setup
77
	t.Parallel()
78
79
	// Arrange
80
	config := defaultClientConfig()
81
	accessToken := "access-token"
82
83
	// Act
84
	WithAccessToken(accessToken).apply(config)
85
86
	// Assert
87
	assert.Equal(t, accessToken, config.accessToken)
88
}
89
90
func TestWithAccessSecret(t *testing.T) {
91
	// Setup
92
	t.Parallel()
93
94
	// Arrange
95
	config := defaultClientConfig()
96
	accessSecret := "access-secret"
97
98
	// Act
99
	WithAccessSecret(accessSecret).apply(config)
100
101
	// Assert
102
	assert.Equal(t, accessSecret, config.accessSecret)
103
}
104
105
func TestWithCollectSyncVerifyInterval(t *testing.T) {
106
	// Setup
107
	t.Parallel()
108
109
	// Arrange
110
	config := defaultClientConfig()
111
	interval := time.Second * 2
112
113
	// Act
114
	WithCollectSyncVerifyInterval(interval).apply(config)
115
116
	// Assert
117
	assert.Equal(t, interval, config.collectSyncVerifyInterval)
118
}
119
120
func TestWithCollectSyncVerifyRetryCount(t *testing.T) {
121
	// Setup
122
	t.Parallel()
123
124
	// Arrange
125
	config := defaultClientConfig()
126
	retryCount := uint(1000)
127
128
	// Act
129
	WithCollectSyncVerifyRetryCount(retryCount).apply(config)
130
131
	// Assert
132
	assert.Equal(t, retryCount, config.collectSyncVerifyRetryCount)
133
}
134