back tests 80+

This commit is contained in:
iqubik
2026-03-29 03:52:43 +03:00
parent e7a63dfff0
commit 7f5aae32e7
28 changed files with 5024 additions and 9 deletions
@@ -0,0 +1,87 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { Test, TestingModule } from '@nestjs/testing';
import { RotationController } from 'src/rotation/rotation.controller';
import { RotationService } from 'src/rotation/rotation.service';
describe('RotationController', () => {
let controller: RotationController;
let rotationService: RotationService;
const mockRotationService = {
performRotation: jest.fn(),
rotateSingleSubscription: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [RotationController],
providers: [
{
provide: RotationService,
useValue: mockRotationService,
},
],
}).compile();
controller = module.get<RotationController>(RotationController);
rotationService = module.get<RotationService>(RotationService);
});
afterEach(() => {
jest.clearAllMocks();
});
describe('rotateAll', () => {
it('должен запустить плановую ротацию', async () => {
const mockResult = { success: true, message: 'Ротация выполнена' };
mockRotationService.performRotation.mockResolvedValue(mockResult);
const result = await controller.rotateAll();
expect(result).toEqual(mockResult);
expect(rotationService.performRotation).toHaveBeenCalledTimes(1);
});
it('должен вернуть ошибку ротации', async () => {
const mockError = { success: false, message: 'Нет подписок' };
mockRotationService.performRotation.mockResolvedValue(mockError);
const result = await controller.rotateAll();
expect(result).toEqual(mockError);
});
});
describe('rotateSingle', () => {
it('должен запустить ротацию одной подписки', async () => {
const mockResult = {
success: true,
message: 'Ротация подписки выполнена',
};
mockRotationService.rotateSingleSubscription.mockResolvedValue(
mockResult,
);
const result = await controller.rotateSingle('sub-123');
expect(result).toEqual(mockResult);
expect(rotationService.rotateSingleSubscription).toHaveBeenCalledWith(
'sub-123',
);
});
it('должен вернуть ошибку ротации одной подписки', async () => {
const mockError = { success: false, message: 'Подписка не найдена' };
mockRotationService.rotateSingleSubscription.mockResolvedValue(mockError);
const result = await controller.rotateSingle('non-existent');
expect(result).toEqual(mockError);
});
});
});