import { PartnerReportStore } from '../src/b2b/partner-report.store'; import type { DatabaseService } from '../src/database/database.service'; import type { Principal } from '../src/identity/identity.types'; describe('Partner report presentation', () => { const actor = { organizationId: 'organization' } as Principal; it('preserves exact large totals and reports an empty account without fabricated currency', async () => { const tx = { businessAccount: { findFirst: jest.fn().mockResolvedValue({ id: 'account' }), }, $queryRaw: jest.fn().mockResolvedValue([ { currency: 'INR', orderCount: 2, activeOrderCount: 2, cancelledOrderCount: 0, unpaidOrderCount: 1, partiallyPaidOrderCount: 1, paidOrderCount: 0, merchandiseTotal: '999999999999999999999.99', paidTotal: '0.01', outstandingTotal: '999999999999999999999.98', }, ]), }; const db = { $transaction: jest.fn(async (work) => work(tx)) }; const store = new PartnerReportStore(db as unknown as DatabaseService); expect((await store.report(actor, 'account')).currencies[0]).toMatchObject({ merchandiseTotal: '999999999999999999999.99', paidTotal: '0.01', outstandingTotal: '999999999999999999999.98', }); expect(db.$transaction).toHaveBeenCalledWith(expect.any(Function), { isolationLevel: 'RepeatableRead', }); tx.$queryRaw.mockResolvedValue([]); expect(await store.report(actor, 'account')).toEqual({ accountId: 'account', currencies: [], }); }); it('rejects missing accounts before querying financial records', async () => { const tx = { businessAccount: { findFirst: jest.fn().mockResolvedValue(null) }, $queryRaw: jest.fn(), }; const db = { $transaction: async (work: (value: typeof tx) => unknown) => work(tx), }; await expect( new PartnerReportStore(db as unknown as DatabaseService).report( actor, 'missing', ), ).rejects.toMatchObject({ code: 'BUSINESS_ACCOUNT_NOT_FOUND' }); expect(tx.$queryRaw).not.toHaveBeenCalled(); }); });