test: Add integration test for OpenRouterService with real API connection

This commit is contained in:
2025-02-15 19:07:50 +03:00
parent 1371af04ff
commit b19745a413
2 changed files with 49 additions and 3 deletions
@@ -0,0 +1,45 @@
package ru.cathub.telegabot.service;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import ru.cathub.telegabot.configuration.OpenRouterConfig;
import ru.cathub.telegabot.exception.OpenRouterException;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@SpringBootTest
@ActiveProfiles("test")
@Tag("integration")
class OpenRouterServiceLiveTest {
@Autowired
private OpenRouterService openRouterService;
@Autowired
private OpenRouterConfig openRouterConfig;
@Test
void shouldGetResponseFromRealApi() throws OpenRouterException {
// Пропускаем тест если нет API ключа
assumeTrue(openRouterConfig.getKey() != null && !openRouterConfig.getKey().isBlank(),
"OPENROUTER_API_KEY not set");
String response = openRouterService.getChatResponse("Hello in Russian");
assertNotNull(response);
assertFalse(response.isBlank());
System.out.println("API Response: " + response);
}
@Test
void shouldContainValidConfiguration() {
assertNotNull(openRouterConfig.getUrl());
assertNotNull(openRouterConfig.getModel());
assertTrue(openRouterConfig.getUrl().startsWith("https://"));
assertFalse(openRouterConfig.getModel().isBlank());
}
}
@@ -1,3 +1,4 @@
openrouter.api.url=https://test-url
openrouter.api.model=test-model
openrouter.api.key=test-key
openrouter.api.url=https://openrouter.ai/api/v1
openrouter.api.model=gryphe/mythomax-l2-13b
# Ключ должен быть установлен через переменную окружения OPENROUTER_API_KEY
openrouter.api.key=${OPENROUTER_API_KEY}