알림문제 수정

This commit is contained in:
Macbook
2026-05-28 01:45:53 +09:00
parent aace2282d5
commit 01218b99c9
6 changed files with 180 additions and 31 deletions
@@ -159,6 +159,42 @@ class StrategyConditionTimeframeServiceTest {
assertFalse(service.usesTimeframe(5L, "1m"));
}
@Test
void collectForStrategy_stale1m5mArrayUses5mOnlyWhenConditionsSay5m() {
GcStrategy strategy = new GcStrategy();
strategy.setId(6L);
strategy.setName("알트레이어 매수 알림");
strategy.setBuyConditionJson("""
{
"type": "TIMEFRAME",
"candleType": "1m",
"candleTypes": ["1m", "5m"],
"children": [{
"type": "CONDITION",
"condition": {
"indicatorType": "CCI",
"leftCandleType": "5m",
"rightCandleType": "5m"
}
}]
}
""");
strategy.setSellConditionJson(null);
when(strategyRepo.findById(6L)).thenReturn(Optional.of(strategy));
when(dslNormalizer.alignSellStartTimeframeToBuy(org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any()))
.thenAnswer(inv -> inv.getArgument(1));
when(dslNormalizer.normalizeJson(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any()))
.thenAnswer(inv -> {
String json = inv.getArgument(0);
String name = inv.getArgument(1);
return new StrategyDslTimeframeNormalizer(objectMapper).normalizeJson(json, name);
});
Set<String> tfs = service.collectForStrategy(6L);
assertEquals(Set.of("5m"), tfs);
assertFalse(service.usesTimeframe(6L, "1m"));
}
@Test
void collectForStrategy_legacyTreeDefaultsTo1m() {
GcStrategy legacy = new GcStrategy();
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.*;
class StrategyDslTimeframeNormalizerTest {
@@ -49,6 +51,50 @@ class StrategyDslTimeframeNormalizerTest {
assertEquals("3m", root.path("candleType").asText());
}
@Test
void normalize_dropsStale1mWhenConditionsUse5mOnly() throws Exception {
String json = """
{
"type": "TIMEFRAME",
"candleType": "1m",
"candleTypes": ["1m", "5m"],
"children": [{
"type": "CONDITION",
"condition": {
"indicatorType": "CCI",
"leftCandleType": "5m",
"rightCandleType": "5m"
}
}]
}
""";
String normalized = normalizer.normalizeJson(json, "알트레이어 매수 알림");
JsonNode root = objectMapper.readTree(normalized);
assertEquals(1, root.path("candleTypes").size());
assertEquals("5m", root.path("candleTypes").get(0).asText());
assertEquals("5m", root.path("candleType").asText());
}
@Test
void resolveStartCandleTypes_dropsStale1mPair() throws Exception {
String json = """
{
"type": "TIMEFRAME",
"candleType": "1m",
"candleTypes": ["1m", "5m"],
"children": [{
"type": "CONDITION",
"condition": {
"indicatorType": "CCI",
"leftCandleType": "5m"
}
}]
}
""";
JsonNode root = objectMapper.readTree(json);
assertEquals(Set.of("5m"), StrategyDslTimeframeNormalizer.resolveStartCandleTypes(root));
}
@Test
void normalize_preservesMultiCandleTypesOnSave() throws Exception {
String json = """