@@ -5,8 +5,13 @@ import by.jprof.telegram.bot.votes.model.Votes
5
5
import by.jprof.telegram.bot.votes.tgbotapi_extensions.toInlineKeyboardMarkup
6
6
import dev.inmo.tgbotapi.bot.RequestsExecutor
7
7
import dev.inmo.tgbotapi.extensions.api.answers.answerCallbackQuery
8
+ import dev.inmo.tgbotapi.requests.edit.reply_markup.EditChatMessageReplyMarkup
8
9
import dev.inmo.tgbotapi.requests.send.SendTextMessage
9
10
import 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
10
15
import dev.inmo.tgbotapi.types.message.MarkdownV2
11
16
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
12
17
import dev.inmo.tgbotapi.types.message.content.MessageContent
@@ -34,13 +39,11 @@ import io.mockk.verify
34
39
import kotlinx.coroutines.runBlocking
35
40
import kotlinx.serialization.json.JsonNull
36
41
import org.junit.jupiter.api.BeforeEach
37
- import org.junit.jupiter.api.Disabled
38
42
import org.junit.jupiter.api.Test
39
43
import org.junit.jupiter.api.extension.ExtendWith
40
44
41
45
@RiskFeature
42
46
@ExtendWith(MockKExtension ::class )
43
- @Disabled
44
47
internal class JEPUpdateProcessorTest {
45
48
@MockK
46
49
private lateinit var jepSummary: JEPSummary
@@ -123,12 +126,10 @@ internal class JEPUpdateProcessorTest {
123
126
" Hello, world!" ,
124
127
listOf (
125
128
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" ),
127
130
)
128
131
)
129
- every { chat } returns mockk {
130
- every { id } returns ChatId (1L )
131
- }
132
+ every { chat } returns GroupChatImpl (ChatId (1L ), " Test Chat" )
132
133
}
133
134
134
135
coEvery { jepSummary.of(any()) } returns null
@@ -169,11 +170,11 @@ internal class JEPUpdateProcessorTest {
169
170
listOf (
170
171
URLTextSource (" https://openjdk.java.net/jeps/1" ),
171
172
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" ),
172
175
)
173
176
)
174
- every { chat } returns mockk {
175
- every { id } returns ChatId (1L )
176
- }
177
+ every { chat } returns GroupChatImpl (ChatId (1L ), " Test Chat" )
177
178
}
178
179
179
180
coEvery { jepSummary.of(any()) } answers { " JEP ${it.invocation.args[0 ]} !" }
@@ -200,6 +201,24 @@ internal class JEPUpdateProcessorTest {
200
201
replyMarkup = Votes (" JEP-2" , listOf (" \uD83D\uDC4D " , " \uD83D\uDC4E " )).toInlineKeyboardMarkup()
201
202
)
202
203
)
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
+ )
203
222
}
204
223
confirmVerified(bot)
205
224
clearAllMocks()
@@ -216,13 +235,14 @@ internal class JEPUpdateProcessorTest {
216
235
fun processNonJEPCallbackQuery () = runBlocking {
217
236
sut.process(
218
237
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
+ )
226
246
)
227
247
)
228
248
@@ -233,36 +253,36 @@ internal class JEPUpdateProcessorTest {
233
253
fun processBadCallbackQuery () = runBlocking {
234
254
sut.process(
235
255
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
+ )
243
264
)
244
265
)
245
266
246
267
verify { listOf (jepSummary, votesDAO, bot) wasNot called }
247
268
}
248
269
249
270
@Test
250
- @Disabled
251
271
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
+ }
252
277
val callbackQuery = MessageDataCallbackQuery (
253
278
id = " " ,
254
- from = mockk {
255
- every { id } returns ChatId (1L )
256
- },
279
+ from = CommonUser (
280
+ id = ChatId (1L ),
281
+ firstName = " " ,
282
+ ),
257
283
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
- },
265
284
data = " JEP-1:+" ,
285
+ message = message,
266
286
)
267
287
268
288
coEvery { votesDAO.get(" JEP-1" ) } returns Votes (" JEP-1" , listOf (" +" , " -" ), mapOf (" 2" to " -" ))
@@ -273,6 +293,20 @@ internal class JEPUpdateProcessorTest {
273
293
274
294
coVerify(exactly = 1 ) { votesDAO.save(Votes (" JEP-1" , listOf (" +" , " -" ), mapOf (" 1" to " +" , " 2" to " -" ))) }
275
295
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
+ }
276
310
277
311
confirmVerified(bot)
278
312
clearAllMocks()
0 commit comments