29 lines
1.0 KiB
JavaScript
29 lines
1.0 KiB
JavaScript
const mockCreateTransaction = jest.fn();
|
|
jest.mock('../../app/core/midtrans.service', () => ({
|
|
getCoreApi: jest.fn(),
|
|
getSnap: jest.fn().mockReturnValue({
|
|
createTransaction: mockCreateTransaction
|
|
})
|
|
}));
|
|
|
|
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 snapService = require('../../app/modules/snap/services/snap.service');
|
|
|
|
describe('SnapService', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should create a snap transaction successfully', async () => {
|
|
const payload = { order_id: 'u-snap', external_id: 'INV-S-001', amount: 100000 };
|
|
mockCreateTransaction.mockResolvedValue({ token: 't-123', redirect_url: 'http://m.com' });
|
|
const result = await snapService.createTransaction(payload);
|
|
expect(mockCreateTransaction).toHaveBeenCalled();
|
|
expect(result.token).toBe('t-123');
|
|
});
|
|
});
|