@@ -7,8 +7,11 @@ import {
7
7
toNumber ,
8
8
getAmountValueInKobo ,
9
9
getChannels ,
10
- } from '../development/helper' ;
11
- import { PaymentChannels } from '../development/types' ;
10
+ buildKeyValueString ,
11
+ dynamicSplitObjectIsValid ,
12
+ paystackHtmlContent ,
13
+ } from '../development//utils/helper' ;
14
+ import { DynamicMultiSplitProps , PaymentChannels } from '../development/types' ;
12
15
13
16
describe ( 'Utility functions work properly' , ( ) => {
14
17
test ( 'getChannels should return a stingified array with comma' , ( ) => {
@@ -62,4 +65,94 @@ describe('Utility functions work properly', () => {
62
65
result = isNegative ( 200.0 ) ;
63
66
expect ( result ) . toBe ( false ) ;
64
67
} ) ;
68
+ } ) ;
69
+
70
+ describe ( 'Utility functions work properly' , ( ) => {
71
+ test ( 'getChannels should return a stringified array with commas' , ( ) => {
72
+ let testChannels : PaymentChannels [ ] = [ 'card' , 'bank' ] ;
73
+ let expectedOutput = 'channels: ["card","bank"],' ;
74
+
75
+ const result = getChannels ( testChannels ) ;
76
+ expect ( result ) . toBe ( expectedOutput ) ;
77
+ } ) ;
78
+
79
+ test ( 'toAmountInKobo should return kobo value for amount' , ( ) => {
80
+ let result = toAmountInKobo ( '4600.00' ) ;
81
+ expect ( result ) . toBe ( 460000 ) ;
82
+
83
+ result = toAmountInKobo ( 1200.93 ) ;
84
+ expect ( result ) . toBe ( 120093 ) ;
85
+ } ) ;
86
+
87
+ test ( 'getAmountValueInKobo should return kobo value for valid amounts' , ( ) => {
88
+ let result = getAmountValueInKobo ( '4600.00' ) ;
89
+ expect ( result ) . toBe ( 460000 ) ;
90
+
91
+ result = getAmountValueInKobo ( 'not_correct_money_amount' ) ;
92
+ expect ( result ) . toBe ( 0 ) ;
93
+ } ) ;
94
+
95
+ test ( 'isValidDecimalMonetaryValue should return true for only valid amount' , ( ) => {
96
+ let result = isValidDecimalMonetaryValue ( '2500.00' ) ;
97
+ expect ( result ) . toBe ( true ) ;
98
+
99
+ result = isValidDecimalMonetaryValue ( '2500' ) ;
100
+ expect ( result ) . toBe ( true ) ;
101
+
102
+ result = isValidDecimalMonetaryValue ( 'invalid_amount' ) ;
103
+ expect ( result ) . toBe ( false ) ;
104
+ } ) ;
105
+
106
+ test ( 'isValidStringAmount should return true for valid amount strings' , ( ) => {
107
+ let result = isValidStringAmount ( '2500.00' ) ;
108
+ expect ( result ) . toBe ( true ) ;
109
+
110
+ result = isValidStringAmount ( 'not_money_amount' ) ;
111
+ expect ( result ) . toBe ( false ) ;
112
+
113
+ result = isValidStringAmount ( '2500.' ) ;
114
+ expect ( result ) . toBe ( false ) ;
115
+ } ) ;
116
+
117
+ test ( 'toNumber should convert string amount to number' , ( ) => {
118
+ const result = toNumber ( '2500.00' ) ;
119
+ expect ( result ) . toBe ( 2500 ) ;
120
+ } ) ;
121
+
122
+ test ( 'isNegative should return true if amount is negative' , ( ) => {
123
+ let result = isNegative ( '-200.00' ) ;
124
+ expect ( result ) . toBe ( true ) ;
125
+
126
+ result = isNegative ( - 200.0 ) ;
127
+ expect ( result ) . toBe ( true ) ;
128
+
129
+ result = isNegative ( 200.0 ) ;
130
+ expect ( result ) . toBe ( false ) ;
131
+ } ) ;
132
+
133
+ test ( 'buildKeyValueString should return correct string for key-value' , ( ) => {
134
+ let result = buildKeyValueString ( 'key1' , 'value1' ) ;
135
+ expect ( result ) . toBe ( "key1: 'value1'," ) ;
136
+
137
+ result = buildKeyValueString ( 'key2' , undefined ) ;
138
+ expect ( result ) . toBe ( '' ) ;
139
+ } ) ;
140
+
141
+ test ( 'dynamicSplitObjectIsValid should return true for valid split object' , ( ) => {
142
+ const validSplit : DynamicMultiSplitProps = {
143
+ type : 'percentage' ,
144
+ bearer_type : 'all' ,
145
+ subaccounts : [ { subaccount : 'sub1' , share : '50' } ]
146
+ } ;
147
+
148
+ let result = dynamicSplitObjectIsValid ( validSplit ) ;
149
+ expect ( result ) . toBe ( true ) ;
150
+ } ) ;
151
+
152
+ test ( 'paystackHtmlContent should return HTML with correct params' , ( ) => {
153
+ const params = "key1: 'value1', key2: 'value2'" ;
154
+ const result = paystackHtmlContent ( params ) ;
155
+ expect ( result ) . toContain ( "key1: 'value1'," ) ;
156
+ expect ( result ) . toContain ( "key2: 'value2'" ) ;
157
+ } ) ;
65
158
} ) ;
0 commit comments