Skip to content

Commit e0d371a

Browse files
authored
Code clean-up (#198)
* 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 - * Update utils.test.ts * review fix
1 parent 28bc397 commit e0d371a

File tree

11 files changed

+303
-215
lines changed

11 files changed

+303
-215
lines changed

.DS_Store

-2 KB
Binary file not shown.

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ function Pay(){
150150
| | - **`card_brands`**: Supported card brands, e.g., `'verve'`, `'visa'`, `'mastercard'`. | | |
151151
| | - **`supported_mobile_money_providers`**: Supported mobile money providers, e.g., `'mtn'`, `'atl'`, `'vod'`. | | |
152152

153+
---
154+
#### Refs
155+
156+
| Name | use/description | extra |
157+
| :---------------- | :----------------------------------------------------------: | --------: |
158+
| `startTransaction`| Function triggered to start a transaction . Example usage: `paystackWebViewRef.current.startTransaction()` | default: `nill` |
159+
| `endTransaction` | Function triggered to ends a transaction . Example usage: `paystackWebViewRef.current.endTransaction()` | default: `nill` |
160+
153161
---
154162

155163
#### Dynamic Multi-Split Payment Object structure

__tests__/utils.test.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable prefer-const */
21
import {
32
toAmountInKobo,
43
isValidDecimalMonetaryValue,
@@ -7,8 +6,11 @@ import {
76
toNumber,
87
getAmountValueInKobo,
98
getChannels,
10-
} from '../development/helper';
11-
import { PaymentChannels } from '../development/types';
9+
buildKeyValueString,
10+
dynamicSplitObjectIsValid,
11+
paystackHtmlContent,
12+
} from '../development/utils/helper';
13+
import { DynamicMultiSplitProps, PaymentChannels } from '../development/types';
1214

1315
describe('Utility functions work properly', () => {
1416
test('getChannels should return a stingified array with comma', () => {
@@ -62,4 +64,32 @@ describe('Utility functions work properly', () => {
6264
result = isNegative(200.0);
6365
expect(result).toBe(false);
6466
});
67+
});
68+
69+
describe('Utility functions work properly', () => {
70+
test('buildKeyValueString should return correct string for key-value', () => {
71+
let result = buildKeyValueString('key1', 'value1');
72+
expect(result).toBe("key1: 'value1',");
73+
74+
result = buildKeyValueString('key2', undefined);
75+
expect(result).toBe('');
76+
});
77+
78+
test('dynamicSplitObjectIsValid should return true for valid split object', () => {
79+
const validSplit: DynamicMultiSplitProps = {
80+
type: 'percentage',
81+
bearer_type: 'all',
82+
subaccounts: [{ subaccount: 'sub1', share: '50' }]
83+
};
84+
85+
let result = dynamicSplitObjectIsValid(validSplit);
86+
expect(result).toBe(true);
87+
});
88+
89+
test('paystackHtmlContent should return HTML with correct params', () => {
90+
const params = "key1: 'value1', key2: 'value2'";
91+
const result = paystackHtmlContent(params);
92+
expect(result).toContain("key1: 'value1',");
93+
expect(result).toContain("key2: 'value2'");
94+
});
6595
});

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)