first commit
This commit is contained in:
28
tests/unit/snap.service.test.js
Normal file
28
tests/unit/snap.service.test.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user