@@ -5,8 +5,13 @@ import by.jprof.telegram.bot.votes.model.Votes
55import by.jprof.telegram.bot.votes.tgbotapi_extensions.toInlineKeyboardMarkup
66import dev.inmo.tgbotapi.bot.RequestsExecutor
77import dev.inmo.tgbotapi.extensions.api.answers.answerCallbackQuery
8+ import dev.inmo.tgbotapi.requests.edit.reply_markup.EditChatMessageReplyMarkup
89import dev.inmo.tgbotapi.requests.send.SendTextMessage
910import dev.inmo.tgbotapi.types.ChatId
11+ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
12+ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
13+ import dev.inmo.tgbotapi.types.chat.CommonUser
14+ import dev.inmo.tgbotapi.types.chat.GroupChatImpl
1015import dev.inmo.tgbotapi.types.message.MarkdownV2
1116import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
1217import dev.inmo.tgbotapi.types.message.content.MessageContent
@@ -34,13 +39,11 @@ import io.mockk.verify
3439import kotlinx.coroutines.runBlocking
3540import kotlinx.serialization.json.JsonNull
3641import org.junit.jupiter.api.BeforeEach
37- import org.junit.jupiter.api.Disabled
3842import org.junit.jupiter.api.Test
3943import org.junit.jupiter.api.extension.ExtendWith
4044
4145@RiskFeature
4246@ExtendWith(MockKExtension ::class )
43- @Disabled
4447internal class JEPUpdateProcessorTest {
4548 @MockK
4649 private lateinit var jepSummary: JEPSummary
@@ -123,12 +126,10 @@ internal class JEPUpdateProcessorTest {
123126 " Hello, world!" ,
124127 listOf (
125128 URLTextSource (" https://openjdk.java.net/jeps/1" ),
126- TextLinkTextSource (" JEP 2" , " https://openjdk.java.net /jeps/2" ),
129+ TextLinkTextSource (" JEP 2" , " https://openjdk.org /jeps/2" ),
127130 )
128131 )
129- every { chat } returns mockk {
130- every { id } returns ChatId (1L )
131- }
132+ every { chat } returns GroupChatImpl (ChatId (1L ), " Test Chat" )
132133 }
133134
134135 coEvery { jepSummary.of(any()) } returns null
@@ -169,11 +170,11 @@ internal class JEPUpdateProcessorTest {
169170 listOf (
170171 URLTextSource (" https://openjdk.java.net/jeps/1" ),
171172 TextLinkTextSource (" JEP 2" , " https://openjdk.java.net/jeps/2" ),
173+ URLTextSource (" https://openjdk.org/jeps/3" ),
174+ TextLinkTextSource (" JEP 4" , " https://openjdk.org/jeps/4" ),
172175 )
173176 )
174- every { chat } returns mockk {
175- every { id } returns ChatId (1L )
176- }
177+ every { chat } returns GroupChatImpl (ChatId (1L ), " Test Chat" )
177178 }
178179
179180 coEvery { jepSummary.of(any()) } answers { " JEP ${it.invocation.args[0 ]} !" }
@@ -200,6 +201,24 @@ internal class JEPUpdateProcessorTest {
200201 replyMarkup = Votes (" JEP-2" , listOf (" \uD83D\uDC4D " , " \uD83D\uDC4E " )).toInlineKeyboardMarkup()
201202 )
202203 )
204+ bot.execute(
205+ SendTextMessage (
206+ chatId = ChatId (1L ),
207+ text = " JEP 3\\ !\n\n Cast your vote for *JEP 3* now ⤵️" ,
208+ parseMode = MarkdownV2 ,
209+ replyToMessageId = 1 ,
210+ replyMarkup = Votes (" JEP-3" , listOf (" \uD83D\uDC4D " , " \uD83D\uDC4E " )).toInlineKeyboardMarkup()
211+ )
212+ )
213+ bot.execute(
214+ SendTextMessage (
215+ chatId = ChatId (1L ),
216+ text = " JEP 4\\ !\n\n Cast your vote for *JEP 4* now ⤵️" ,
217+ parseMode = MarkdownV2 ,
218+ replyToMessageId = 1 ,
219+ replyMarkup = Votes (" JEP-4" , listOf (" \uD83D\uDC4D " , " \uD83D\uDC4E " )).toInlineKeyboardMarkup()
220+ )
221+ )
203222 }
204223 confirmVerified(bot)
205224 clearAllMocks()
@@ -216,13 +235,14 @@ internal class JEPUpdateProcessorTest {
216235 fun processNonJEPCallbackQuery () = runBlocking {
217236 sut.process(
218237 CallbackQueryUpdate (
219- 1L , MessageDataCallbackQuery (
220- id = " " ,
221- from = mockk(),
222- chatInstance = " " ,
223- message = mockk(),
224- data = " YOUTUBE-1:+" ,
225- )
238+ 1L ,
239+ MessageDataCallbackQuery (
240+ id = " " ,
241+ from = mockk(),
242+ chatInstance = " " ,
243+ message = mockk(),
244+ data = " YOUTUBE-1:+" ,
245+ )
226246 )
227247 )
228248
@@ -233,36 +253,36 @@ internal class JEPUpdateProcessorTest {
233253 fun processBadCallbackQuery () = runBlocking {
234254 sut.process(
235255 CallbackQueryUpdate (
236- 1L , MessageDataCallbackQuery (
237- id = " " ,
238- from = mockk(),
239- chatInstance = " " ,
240- message = mockk(),
241- data = " JEP-1+" ,
242- )
256+ 1L ,
257+ MessageDataCallbackQuery (
258+ id = " " ,
259+ from = mockk(),
260+ chatInstance = " " ,
261+ message = mockk(),
262+ data = " JEP-1+" ,
263+ )
243264 )
244265 )
245266
246267 verify { listOf (jepSummary, votesDAO, bot) wasNot called }
247268 }
248269
249270 @Test
250- @Disabled
251271 fun processCallbackQuery () = runBlocking {
272+ val message = mockk<ContentMessage <MessageContent >> {
273+ every { messageId } returns 100500L
274+ every { chat } returns GroupChatImpl (ChatId (2L ), " Test Chat" )
275+ every { content } returns TextContent (" " )
276+ }
252277 val callbackQuery = MessageDataCallbackQuery (
253278 id = " " ,
254- from = mockk {
255- every { id } returns ChatId (1L )
256- },
279+ from = CommonUser (
280+ id = ChatId (1L ),
281+ firstName = " " ,
282+ ),
257283 chatInstance = " " ,
258- message = mockk<ContentMessage <MessageContent >> {
259- every { messageId } returns 100500L
260- every { chat } returns mockk {
261- every { id } returns ChatId (2L )
262- }
263- every { content } returns TextContent (" " )
264- },
265284 data = " JEP-1:+" ,
285+ message = message,
266286 )
267287
268288 coEvery { votesDAO.get(" JEP-1" ) } returns Votes (" JEP-1" , listOf (" +" , " -" ), mapOf (" 2" to " -" ))
@@ -273,6 +293,20 @@ internal class JEPUpdateProcessorTest {
273293
274294 coVerify(exactly = 1 ) { votesDAO.save(Votes (" JEP-1" , listOf (" +" , " -" ), mapOf (" 1" to " +" , " 2" to " -" ))) }
275295 coVerify(exactly = 1 ) { bot.answerCallbackQuery(callbackQuery) }
296+ coVerify(exactly = 1 ) {
297+ bot.execute(
298+ EditChatMessageReplyMarkup (
299+ ChatId (2L ),
300+ 100500 ,
301+ InlineKeyboardMarkup (keyboard = listOf (
302+ listOf (
303+ CallbackDataInlineKeyboardButton (" 1 +" , " JEP-1:+" ),
304+ CallbackDataInlineKeyboardButton (" 1 -" , " JEP-1:-" )
305+ )
306+ ))
307+ )
308+ )
309+ }
276310
277311 confirmVerified(bot)
278312 clearAllMocks()
0 commit comments