Files
midtrans-gateway/tests/unit/cstore.service.test.js
2026-02-18 16:03:43 +07:00

36 lines
1.4 KiB
JavaScript

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() })
}));
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 cstoreService = require('../../app/modules/cstore/services/cstore.service');
describe('CStoreService', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should create an indomaret transaction successfully', async () => {
const payload = { order_id: 'u-123', external_id: 'INV-I-001', amount: 50000 };
mockCharge.mockResolvedValue({ status_code: '201' });
const result = await cstoreService.createTransaction(payload, 'indomaret');
expect(mockCharge).toHaveBeenCalled();
});
it('should create an alfamart transaction successfully', async () => {
const payload = { order_id: 'u-123', external_id: 'INV-A-001', amount: 30000 };
mockCharge.mockResolvedValue({ status_code: '201' });
const result = await cstoreService.createTransaction(payload, 'alfamart');
expect(mockCharge).toHaveBeenCalled();
});
});