51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
jest.mock('../../../../prisma/prisma.service', () => ({
|
|
PrismaService: class {},
|
|
}));
|
|
jest.mock('../../../../../generated/prisma/client', () => ({ Prisma: {} }));
|
|
import { PrismaService } from '../../../../prisma/prisma.service';
|
|
import { BankCardsRepository } from '../infrastructure/bank-cards.repository';
|
|
import { GetBankSummaryUseCase } from './get-bank-summary.use-case';
|
|
|
|
describe('bank card summary categories', () => {
|
|
it('resolves category names and rejects an inconsistent category reference', async () => {
|
|
const categories = jest
|
|
.fn()
|
|
.mockResolvedValue([{ id: 'food', name: 'Продукты' }]);
|
|
const tx = {
|
|
bankCardOperation: {
|
|
findMany: jest.fn().mockResolvedValue([
|
|
{
|
|
kind: 'expense',
|
|
categoryId: 'food',
|
|
amountKopecks: 123n,
|
|
date: '2026-09-13',
|
|
originalExpense: null,
|
|
},
|
|
]),
|
|
},
|
|
expenseCategory: { findMany: categories },
|
|
};
|
|
const service = new GetBankSummaryUseCase(
|
|
new BankCardsRepository({
|
|
$transaction: (run: (client: typeof tx) => unknown) => run(tx),
|
|
} as unknown as PrismaService),
|
|
);
|
|
|
|
await expect(
|
|
service.execute('user', { month: '2026-09' }),
|
|
).resolves.toMatchObject({
|
|
categories: [
|
|
{
|
|
categoryId: 'food',
|
|
categoryName: 'Продукты',
|
|
net: { value: '1.23' },
|
|
},
|
|
],
|
|
});
|
|
categories.mockResolvedValue([]);
|
|
await expect(service.execute('user', { month: '2026-09' })).rejects.toThrow(
|
|
'Bank operation category is missing',
|
|
);
|
|
});
|
|
});
|