first commit
This commit is contained in:
46
tests/unit/paylater.service.test.js
Normal file
46
tests/unit/paylater.service.test.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const mockCharge = jest.fn();
|
||||
jest.mock('../../app/core/midtrans.service', () => ({
|
||||
getCoreApi: jest.fn().mockReturnValue({
|
||||
charge: mockCharge,
|
||||
transaction: { status: jest.fn(), refund: jest.fn(), cancel: jest.fn() }
|
||||
}),
|
||||
getSnap: jest.fn().mockReturnValue({ createTransaction: jest.fn() })
|
||||
}));
|
||||
|
||||
const mockOrderFindByPk = jest.fn();
|
||||
jest.mock('../../models/migration', () => ({
|
||||
Order: { findByPk: mockOrderFindByPk, findOne: jest.fn(), update: jest.fn() },
|
||||
Payment: { findOne: jest.fn(), create: jest.fn(), update: jest.fn() }
|
||||
}));
|
||||
|
||||
const paylaterService = require('../../app/modules/paylater/services/paylater.service');
|
||||
|
||||
describe('PayLaterService', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should create an akulaku transaction successfully', async () => {
|
||||
const payload = { order_id: 'u-123', external_id: 'INV-AK-001', amount: 1000000 };
|
||||
mockCharge.mockResolvedValue({ status_code: '201' });
|
||||
await paylaterService.createTransaction(payload, 'akulaku');
|
||||
expect(mockCharge).toHaveBeenCalledWith(expect.objectContaining({
|
||||
payment_type: 'akulaku'
|
||||
}));
|
||||
});
|
||||
|
||||
it('should fallback to order total if amount is missing', async () => {
|
||||
const payload = { order_id: 'u-123', external_id: 'INV-AK-001' };
|
||||
mockOrderFindByPk.mockResolvedValue({ total: 1000000 });
|
||||
mockCharge.mockResolvedValue({ status_code: '201' });
|
||||
|
||||
await paylaterService.createTransaction(payload, 'kredivo');
|
||||
|
||||
expect(mockOrderFindByPk).toHaveBeenCalledWith('u-123');
|
||||
expect(mockCharge).toHaveBeenCalledWith(expect.objectContaining({
|
||||
transaction_details: expect.objectContaining({
|
||||
gross_amount: 1000000
|
||||
})
|
||||
}));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user