This commit is contained in:
@@ -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',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user