Compare commits

..

2 commits

Author SHA1 Message Date
ea2d1a86ba
Add test for invalid CSE key 2025-05-09 12:51:21 -07:00
7ac74f73bd
Add default value for maxTokens 2025-05-09 12:40:33 -07:00
2 changed files with 19 additions and 5 deletions

View file

@ -47,11 +47,16 @@ class Gemini2Test : LocalProperties() {
@DisplayName("Chat Tests") @DisplayName("Chat Tests")
inner class ChatTests { inner class ChatTests {
private val apiKey = getProperty(Gemini2.GEMINI_API_KEY) private val apiKey = getProperty(Gemini2.GEMINI_API_KEY)
private val maxTokens = getProperty(Gemini2.MAX_TOKENS_PROP).toInt()
@Test @Test
@DisableOnCi @DisableOnCi
fun chatHttpRequestInJavascript() { fun chatHttpRequestInJavascript() {
val maxTokens = try {
getProperty(Gemini2.MAX_TOKENS_PROP).toInt()
} catch (_: NumberFormatException) {
1024
}
assertThat( assertThat(
Gemini2.chat( Gemini2.chat(
"javascript function to make a request with XMLHttpRequest, just code", "javascript function to make a request with XMLHttpRequest, just code",

View file

@ -113,21 +113,30 @@ class GoogleSearchTest : LocalProperties() {
@Test @Test
fun `API key should not be empty`() { fun `API key should not be empty`() {
assertFailure { sanitizedSearch("test", "", "apiKey") } assertFailure { sanitizedSearch("test", "", "apiKey") }
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java)
.hasMessage("${GoogleSearch.SERVICE_NAME} is disabled. The API keys are missing.")
} }
@Test @Test
fun `CSE key should not empty`() { fun `CSE key should not be empty`() {
assertFailure { sanitizedSearch("test", "apiKey", "") } assertFailure { sanitizedSearch("test", "apiKey", "") }
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java)
.hasMessage("${GoogleSearch.SERVICE_NAME} is disabled. The API keys are missing.")
} }
@Test @Test
fun `Invalid API key should throw exception`() { fun `Invalid API key should throw exception`() {
assertFailure { sanitizedSearch("test", "apiKey", "cssKey") } assertFailure { sanitizedSearch("test", "apiKey", "cseKey") }
.isInstanceOf(ModuleException::class.java) .isInstanceOf(ModuleException::class.java)
.hasMessage("API key not valid. Please pass a valid API key.") .hasMessage("API key not valid. Please pass a valid API key.")
} }
@Test
fun `Invalid CSE key should throw exception`() {
assertFailure { sanitizedSearch("test", apiKey, "cseKey") }
.isInstanceOf(ModuleException::class.java)
.hasMessage("Request contains an invalid argument.")
}
} }
@Nested @Nested