fix(signals): send the entry form when publishing a signal

Without entryType the API reads an exact entry, so every range signal from
the composer was refused with 422.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amiram_se 2026-11-05 19:01:42 +04:00
parent 5b8b8f4cd4
commit 5daff15196
5 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,42 @@
import { describe, expect, it } from 'vitest';
import { toCreatePostDto } from './mappers';
const prediction = {
symbol: 'btc-usdt',
market: 'crypto',
direction: 'long' as const,
targetPrices: [75000],
stopLoss: 65000,
horizon: '1w',
};
describe('toCreatePostDto', () => {
it('sends a range with its entry form, or the API reads an exact entry', () => {
const dto = toCreatePostDto({
type: 'prediction',
prediction: {
...prediction,
entryType: 'range',
entryLow: 69000,
entryHigh: 70000,
},
});
expect(dto.prediction).toMatchObject({
entryType: 'range',
entryLow: 69000,
entryHigh: 70000,
});
});
it('sends an exact entry with its entry form', () => {
const dto = toCreatePostDto({
type: 'prediction',
prediction: { ...prediction, entryType: 'exact', entryPrice: 69500 },
});
expect(dto.prediction).toMatchObject({
entryType: 'exact',
entryPrice: 69500,
});
});
});

View File

@ -113,6 +113,7 @@ function toPredictionDto(args: PredictionArgs): PredictionDto {
market: args.market.trim(),
direction: args.direction,
entryPrice: args.entryPrice ?? undefined,
entryType: args.entryType,
entryLow: args.entryLow ?? undefined,
entryHigh: args.entryHigh ?? undefined,
targetPrices: args.targetPrices,

View File

@ -154,6 +154,8 @@ export type PredictionArgs = {
symbol: string;
market: string;
direction: PredictionDirection;
/** Which entry form the API reads; it takes `exact` when this is left out. */
entryType?: 'exact' | 'range';
/** Exactly one form to publish: this, or `entryLow` with `entryHigh`. */
entryPrice?: number;
entryLow?: number;
@ -203,6 +205,7 @@ export type PredictionDto = {
symbol: string;
market: string;
direction: PredictionDirection;
entryType?: 'exact' | 'range';
entryPrice?: number;
entryLow?: number;
entryHigh?: number;

View File

@ -205,6 +205,7 @@ describe('usePredictionComposerPage publishing', () => {
await act(async () => result.current.publish());
const [args] = vi.mocked(publishPrediction).mock.calls[0];
expect(args.prediction).toMatchObject({
entryType: 'exact',
entryPrice: 100,
stopLoss: 90,
targetPrices: [120],
@ -231,7 +232,11 @@ describe('usePredictionComposerPage publishing', () => {
await act(async () => result.current.publish());
const [args] = vi.mocked(publishPrediction).mock.calls[0];
expect(args.prediction).toMatchObject({ entryLow: 98, entryHigh: 102 });
expect(args.prediction).toMatchObject({
entryType: 'range',
entryLow: 98,
entryHigh: 102,
});
expect(args.prediction.entryPrice).toBeUndefined();
});

View File

@ -431,6 +431,7 @@ export function usePredictionComposerPage({
symbol: sent.symbol,
market: sent.market,
direction: sent.direction,
entryType: sent.entryMode,
...(sent.entryMode === 'range'
? {
entryLow: sent.entryLow ?? undefined,