Skip to content

Commit 0457493

Browse files
committed
Disallow empty options list in /done
1 parent b83d817 commit 0457493

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

quizoji/src/main/kotlin/by/jprof/telegram/bot/quizoji/QuizojiDoneCommandUpdateProcessor.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ class QuizojiDoneCommandUpdateProcessor(
4747
return
4848
}
4949

50+
if (state.options.isEmpty()) {
51+
bot.sendMessage(
52+
chat = chat,
53+
text = "Please, provide some options for your quizoji!"
54+
)
55+
56+
return
57+
}
58+
5059
logger.debug("{} finished his Quizoji", chat.id.chatId)
5160

5261
val quizoji = Quizoji(

quizoji/src/test/kotlin/by/jprof/telegram/bot/quizoji/QuizojiDoneCommandUpdateProcessorTest.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,48 @@ internal class QuizojiDoneCommandUpdateProcessorTest {
203203
clearAllMocks()
204204
}
205205

206+
@Test
207+
fun processNoOptions() = runBlocking {
208+
val question = TextContent("Question", listOf(RegularTextSource("Question")))
209+
210+
coEvery { dialogStateDAO.get(1, 2) }.returns(WaitingForOptions(1, 2, question))
211+
coEvery { votesDAO.save(any()) } just runs
212+
coEvery { quizojiDAO.save(any()) } just runs
213+
coEvery { dialogStateDAO.delete(any(), any()) } just runs
214+
215+
val chat = PrivateChatImpl(ChatId(1))
216+
217+
sut.process(
218+
MessageUpdate(
219+
updateId = 1,
220+
data = PrivateContentMessageImpl(
221+
messageId = 1,
222+
user = CommonUser(ChatId(2), "Test"),
223+
chat = chat,
224+
content = TextContent("/done"),
225+
date = DateTime.now(),
226+
editDate = null,
227+
forwardInfo = null,
228+
replyTo = null,
229+
replyMarkup = null,
230+
senderBot = null,
231+
paymentInfo = null,
232+
)
233+
)
234+
)
235+
236+
coVerify(exactly = 1) { dialogStateDAO.get(1, 2) }
237+
coVerify(exactly = 1) {
238+
bot.sendMessage(
239+
chat = chat,
240+
text = "Please, provide some options for your quizoji!"
241+
)
242+
}
243+
verify { listOf(quizojiDAO, votesDAO) wasNot called }
244+
245+
clearAllMocks()
246+
}
247+
206248
@Test
207249
fun processTextQuestion() = runBlocking {
208250
val question = TextContent("Question", listOf(RegularTextSource("Question")))

0 commit comments

Comments
 (0)