feat: add tbank tokens

This commit is contained in:
2026-08-13 19:31:43 +03:00
parent 4cbfc2621c
commit 31cbba8654
25 changed files with 3592 additions and 24 deletions
@@ -0,0 +1,45 @@
import { BadRequestException } from '@nestjs/common';
jest.mock('../prisma/prisma.service', () => ({
PrismaService: class PrismaService {},
}));
import { TbankConnectionService } from './tbank-connection.service';
describe('TbankConnectionService', () => {
const prisma = {
tbankConnection: {
findUnique: jest.fn(),
upsert: jest.fn(),
deleteMany: jest.fn(),
},
};
const config = {
getOrThrow: jest.fn(() => 'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY='),
};
const tbank = { validateToken: jest.fn() };
const service = new TbankConnectionService(
prisma as never,
config as never,
tbank,
);
beforeEach(() => jest.clearAllMocks());
it('does not persist an invalid token', async () => {
tbank.validateToken.mockRejectedValue(new Error('INVALID_TBANK_TOKEN'));
await expect(service.put('user-1', ' token ')).rejects.toEqual(
expect.any(BadRequestException),
);
expect(prisma.tbankConnection.upsert).not.toHaveBeenCalled();
});
it('deletes a connection idempotently', async () => {
await service.delete('user-1');
expect(prisma.tbankConnection.deleteMany).toHaveBeenCalledWith({
where: { userId: 'user-1' },
});
});
});