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(); process.env.PROJECT_ID = 'CBT'; }); 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).toHaveBeenCalledWith(expect.objectContaining({ transaction_details: expect.objectContaining({ order_id: 'INV-I-001-CBT' }) })); }); 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(); }); });