34 lines
1.2 KiB
JavaScript
34 lines
1.2 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();
|
|
process.env.PROJECT_ID = 'CBT';
|
|
});
|
|
|
|
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).toHaveBeenCalledWith(expect.objectContaining({
|
|
transaction_details: expect.objectContaining({
|
|
order_id: 'INV-S-001-CBT'
|
|
})
|
|
}));
|
|
expect(result.token).toBe('t-123');
|
|
});
|
|
});
|