-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
add(marupay): edahab unit test and overall jest configuration
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$', | ||
testPathIgnorePatterns: ['/node_modules/'], | ||
moduleFileExtensions: ['ts', 'js', 'json'], | ||
collectCoverage: true, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import axios from 'axios'; | ||
import { EdahabHandler, createEdahabHandler } from './edahab'; // Import your EdahabHandler | ||
import { Currency } from '../../handlers/enums'; | ||
import { VendorErrorException } from '../../handlers/exeptions'; | ||
|
||
jest.mock('axios'); | ||
Check warning on line 6 in packages/marupay/src/handlers/edahab/edahab.spec.ts
|
||
|
||
const mockedAxios = axios as jest.Mocked<typeof axios>; | ||
Check warning on line 8 in packages/marupay/src/handlers/edahab/edahab.spec.ts
|
||
|
||
describe('Edahab Handler', () => { | ||
Check warning on line 10 in packages/marupay/src/handlers/edahab/edahab.spec.ts
|
||
let handler: EdahabHandler; | ||
let options: any; | ||
|
||
beforeAll(() => { | ||
Check warning on line 14 in packages/marupay/src/handlers/edahab/edahab.spec.ts
|
||
handler = createEdahabHandler({ | ||
apiKey: 'yourApiKey', | ||
secretKey: 'yourSecretKey', | ||
merchantId: 'yourMerchantId', | ||
}); | ||
options = { | ||
accountNumber: '+252611234569', | ||
amount: 500, | ||
currency: Currency.SLSH, | ||
description: 'Test purchase', | ||
} | ||
}); | ||
|
||
it('returns the success payment response for purchase', async () => { | ||
Check warning on line 28 in packages/marupay/src/handlers/edahab/edahab.spec.ts
|
||
const serverResponse = { | ||
InvoiceStatus: "Paid", | ||
TransactionId: "MP2234219.2220.A91111", | ||
InvoiceId: 10145, | ||
}; | ||
|
||
mockedAxios.post.mockResolvedValueOnce({ data: serverResponse }); | ||
|
||
const result = await handler.purchase(options); | ||
|
||
expect(result.paymentStatus).toBe('Paid'); | ||
Check warning on line 39 in packages/marupay/src/handlers/edahab/edahab.spec.ts
|
||
}); | ||
|
||
it('throws vendor errors for purchase accordingly', async () => { | ||
Check warning on line 42 in packages/marupay/src/handlers/edahab/edahab.spec.ts
|
||
const serverResponse = { | ||
InvoiceStatus: "Unpaid", | ||
TransactionId: "MP2234219.2220.A91111", | ||
InvoiceId: 10145, | ||
}; | ||
|
||
mockedAxios.post.mockResolvedValueOnce({ data: serverResponse }); | ||
|
||
await expect(handler.purchase(options)).rejects.toThrow(new VendorErrorException('1', 'Unpaid')); | ||
Check warning on line 51 in packages/marupay/src/handlers/edahab/edahab.spec.ts
|
||
}); | ||
|
||
it('returns the success payment response for credit', async () => { | ||
const serverResponse = { | ||
TransactionId: '5678', | ||
TransactionStatus: 'Approved', | ||
TransactionMesage: 'Credit successful', | ||
}; | ||
|
||
mockedAxios.post.mockResolvedValueOnce({ data: serverResponse }); | ||
|
||
const result = await handler.credit(options); | ||
|
||
expect(result.paymentStatus).toBe('Approved'); | ||
}); | ||
|
||
it('throws vendor errors for credit accordingly', async () => { | ||
const serverResponse = { | ||
TransactionId: '5678', | ||
TransactionStatus: 'Failed', | ||
}; | ||
|
||
mockedAxios.post.mockResolvedValueOnce({ data: serverResponse }); | ||
|
||
await expect(handler.credit(options)).rejects.toThrow(new VendorErrorException('Failed', 'EDAHAB-CREDIT-ERROR')); | ||
}); | ||
|
||
}); |