From ea2d1a86ba08a34314b375457a2a1ac07a6d7179 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 9 May 2025 12:51:21 -0700 Subject: [PATCH] Add test for invalid CSE key --- .../erik/mobibot/modules/GoogleSearchTest.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt index 0edbaa5..a5bce34 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt @@ -113,21 +113,30 @@ class GoogleSearchTest : LocalProperties() { @Test fun `API key should not be empty`() { 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 - fun `CSE key should not empty`() { + fun `CSE key should not be empty`() { 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 fun `Invalid API key should throw exception`() { - assertFailure { sanitizedSearch("test", "apiKey", "cssKey") } + assertFailure { sanitizedSearch("test", "apiKey", "cseKey") } .isInstanceOf(ModuleException::class.java) .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