Passed
Push — main ( 254060...55305f )
by Acho
02:24
created

afrikpay.TestBillPayResponse_IsSuccessful   A

Complexity

Conditions 4

Size

Total Lines 38
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 19
dl 0
loc 38
rs 9.45
c 0
b 0
f 0
nop 1
1
package afrikpay
2
3
import (
4
	"encoding/json"
5
	"testing"
6
	"time"
7
8
	"github.com/NdoleStudio/afrikpay-go/internal/stubs"
9
	"github.com/stretchr/testify/assert"
10
)
11
12
func TestBillPayResponse_IsPending(t *testing.T) {
13
	t.Run("pending transaction is true", func(t *testing.T) {
14
		// Arrange
15
		response := new(BillPayResponse)
16
		err := json.Unmarshal(stubs.BillPayPending(), response)
17
		assert.Nil(t, err)
18
19
		// Act
20
		isPending := response.IsPending()
21
22
		// Assert
23
		assert.True(t, isPending)
24
	})
25
26
	t.Run("failed transaction is false", func(t *testing.T) {
27
		// Arrange
28
		response := new(BillPayResponse)
29
		err := json.Unmarshal(stubs.BillPayWithError(), response)
30
		assert.Nil(t, err)
31
32
		// Act
33
		isPending := response.IsPending()
34
35
		// Assert
36
		assert.False(t, isPending)
37
	})
38
39
	t.Run("successfull transaction is false", func(t *testing.T) {
40
		// Arrange
41
		response := new(BillPayResponse)
42
		err := json.Unmarshal(stubs.BillPay(), response)
43
		assert.Nil(t, err)
44
45
		// Act
46
		isPending := response.IsPending()
47
48
		// Assert
49
		assert.False(t, isPending)
50
	})
51
}
52
53
func TestBillPayResponse_IsSuccessful(t *testing.T) {
54
	t.Run("pending transaction is false", func(t *testing.T) {
55
		// Arrange
56
		response := new(BillPayResponse)
57
		err := json.Unmarshal(stubs.BillPayPending(), response)
58
		assert.Nil(t, err)
59
60
		// Act
61
		isSuccessful := response.IsSuccessful()
62
63
		// Assert
64
		assert.False(t, isSuccessful)
65
	})
66
67
	t.Run("failed transaction is false", func(t *testing.T) {
68
		// Arrange
69
		response := new(BillPayResponse)
70
		err := json.Unmarshal(stubs.BillPayWithError(), response)
71
		assert.Nil(t, err)
72
73
		// Act
74
		isSuccessful := response.IsSuccessful()
75
76
		// Assert
77
		assert.False(t, isSuccessful)
78
	})
79
80
	t.Run("successfull transaction is true", func(t *testing.T) {
81
		// Arrange
82
		response := new(BillPayResponse)
83
		err := json.Unmarshal(stubs.BillPay(), response)
84
		assert.Nil(t, err)
85
86
		// Act
87
		isSuccessful := response.IsSuccessful()
88
89
		// Assert
90
		assert.True(t, isSuccessful)
91
	})
92
}
93
94
func TestBillTransaction_GetDate(t *testing.T) {
95
	t.Run("pending transaction returns correct date", func(t *testing.T) {
96
		// Arrange
97
		response := new(BillPayResponse)
98
		err := json.Unmarshal(stubs.BillPayPending(), response)
99
		expected := time.Date(2022, 6, 11, 13, 37, 31, 0, time.UTC)
100
		assert.Nil(t, err)
101
102
		// Act
103
		date, err := response.Result.GetDate()
104
105
		// Assert
106
		assert.Nil(t, err)
107
		assert.Equal(t, expected.Unix(), date.Unix())
108
	})
109
110
	t.Run("failed transaction returns error", func(t *testing.T) {
111
		// Arrange
112
		response := new(BillPayResponse)
113
		err := json.Unmarshal(stubs.BillPayWithError(), response)
114
		assert.Nil(t, err)
115
116
		// Act
117
		_, err = response.Result.GetDate()
118
119
		// Assert
120
		assert.NotNil(t, err)
121
	})
122
123
	t.Run("successfull transaction returns correct date", func(t *testing.T) {
124
		// Arrange
125
		response := new(BillPayResponse)
126
		err := json.Unmarshal(stubs.BillPay(), response)
127
		expected := time.Date(2022, 4, 19, 17, 0, 6, 0, time.UTC)
128
		assert.Nil(t, err)
129
130
		// Act
131
		date, err := response.Result.GetDate()
132
133
		// Assert
134
		assert.Nil(t, err)
135
		assert.Equal(t, expected.Unix(), date.Unix())
136
	})
137
}
138