35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
const mockStatus = jest.fn();
|
|
const mockRefund = jest.fn();
|
|
jest.mock('../../app/core/midtrans.service', () => ({
|
|
getCoreApi: jest.fn().mockReturnValue({
|
|
transaction: { status: mockStatus, refund: mockRefund, cancel: jest.fn() }
|
|
}),
|
|
getSnap: jest.fn()
|
|
}));
|
|
|
|
jest.mock('../../models/migration', () => ({
|
|
Order: { findByPk: jest.fn(), findOne: jest.fn(), update: jest.fn() },
|
|
Payment: { findOne: jest.fn(), create: jest.fn(), update: jest.fn() }
|
|
}));
|
|
|
|
const transactionService = require('../../app/modules/transaction/services/transaction.service');
|
|
|
|
describe('TransactionService', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should get transaction status successfully', async () => {
|
|
mockStatus.mockResolvedValue({ transaction_status: 'settlement' });
|
|
const result = await transactionService.getStatus('INV-123');
|
|
expect(mockStatus).toHaveBeenCalledWith('INV-123');
|
|
expect(result.transaction_status).toBe('settlement');
|
|
});
|
|
|
|
it('should process refund successfully', async () => {
|
|
mockRefund.mockResolvedValue({ status_code: '200' });
|
|
const result = await transactionService.refund({ order_id: 'INV-123', external_id: 'INV-123', amount: 5000 });
|
|
expect(mockRefund).toHaveBeenCalled();
|
|
});
|
|
});
|