refactor: organize backend by business responsibility

This commit is contained in:
2026-09-13 13:52:57 +03:00
parent 7fde3ece6e
commit 8ba005346d
145 changed files with 3027 additions and 2346 deletions
@@ -0,0 +1,41 @@
import {
BadRequestException,
ServiceUnavailableException,
} from '@nestjs/common';
import { TbankTokenService } from './tbank-token.service';
describe('TbankTokenService', () => {
const config = {
getOrThrow: jest.fn(() => 'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY='),
};
let service: TbankTokenService;
beforeEach(() => {
jest.clearAllMocks();
service = new TbankTokenService(config as never);
});
it('encrypts and decrypts a token through the configured crypto', () => {
const encrypted = service.encrypt('secret-token');
expect(encrypted).not.toContain('secret-token');
expect(service.decrypt(encrypted)).toBe('secret-token');
expect(config.getOrThrow).toHaveBeenCalledWith('TOKEN_ENCRYPTION_KEY');
});
it('translates invalid T-Bank token errors and preserves unrelated failures', async () => {
await expect(
service.translateInvalidToken(() =>
Promise.reject(new Error('INVALID_TBANK_TOKEN')),
),
).rejects.toEqual(expect.any(BadRequestException));
const unavailable = new ServiceUnavailableException({
code: 'TBANK_UNAVAILABLE',
});
await expect(
service.translateInvalidToken(() => Promise.reject(unavailable)),
).rejects.toBe(unavailable);
});
});