first (part 3: src directory)
Deploy Iddaai Backend / build-and-deploy (push) Successful in 33s

This commit is contained in:
2026-04-16 15:12:27 +03:00
parent 2f0b85a0c7
commit 182f4aae16
125 changed files with 22552 additions and 0 deletions
@@ -0,0 +1,81 @@
/* eslint-disable @typescript-eslint/unbound-method */
import axios from 'axios';
import { PredictionJobType } from './predictions.types';
import { PredictionsProcessor } from './predictions.processor';
jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
describe('PredictionsProcessor', () => {
let processor: PredictionsProcessor;
beforeEach(() => {
jest.clearAllMocks();
process.env.AI_ENGINE_URL = 'http://unit-ai:8000';
processor = new PredictionsProcessor();
});
afterEach(() => {
delete process.env.AI_ENGINE_URL;
});
it('posts to analyze endpoint for predict-match jobs', async () => {
mockedAxios.post.mockResolvedValueOnce({ data: { ok: true } } as any);
const job = {
id: 'j1',
name: PredictionJobType.PREDICT_MATCH,
data: { matchId: 'match-123' },
} as any;
const result = await processor.process(job);
expect(result).toEqual({ ok: true });
expect(mockedAxios.post).toHaveBeenCalledWith(
'http://unit-ai:8000/v20plus/analyze/match-123',
{},
{ timeout: 30000 },
);
});
it('posts mapped payload to coupon endpoint for smart-coupon jobs', async () => {
mockedAxios.post.mockResolvedValueOnce({ data: { bets: [] } } as any);
const job = {
id: 'j2',
name: PredictionJobType.SMART_COUPON,
data: {
matchIds: ['m1', 'm2'],
strategy: 'BALANCED',
options: { maxMatches: 4, minConfidence: 65 },
},
} as any;
const result = await processor.process(job);
expect(result).toEqual({ bets: [] });
expect(mockedAxios.post).toHaveBeenCalledWith(
'http://unit-ai:8000/v20plus/coupon',
{
match_ids: ['m1', 'm2'],
strategy: 'BALANCED',
max_matches: 4,
min_confidence: 65,
},
{ timeout: 60000 },
);
});
it('throws for unknown job type', async () => {
const job = {
id: 'j3',
name: 'unknown-job',
data: {},
} as any;
await expect(processor.process(job)).rejects.toThrow(
'Unknown job type: unknown-job',
);
});
});