Skip to content

Commit 1450d31

Browse files
committed
Code clean-up
In this PR we; - Add more test - KISS more (no human lips were affected or damaged in this process) - file restructure - Add more types - clean up useRef usage -
1 parent 28bc397 commit 1450d31

File tree

9 files changed

+360
-214
lines changed

9 files changed

+360
-214
lines changed

.DS_Store

-2 KB
Binary file not shown.

__tests__/utils.test.ts

+95-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import {
77
toNumber,
88
getAmountValueInKobo,
99
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';
1215

1316
describe('Utility functions work properly', () => {
1417
test('getChannels should return a stingified array with comma', () => {
@@ -62,4 +65,94 @@ describe('Utility functions work properly', () => {
6265
result = isNegative(200.0);
6366
expect(result).toBe(false);
6467
});
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+
});
65158
});

development/index.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { NativeModules } from 'react-native'
21
import Paystack from './paystack';
32
import * as paystackProps from './types'
43

54
export {
65
Paystack,
76
paystackProps
87
}
9-
10-
export default NativeModules.ReactNativePaystackWebviewModule
11-

0 commit comments

Comments
 (0)