@@ -3,20 +3,24 @@ package by.jprof.telegram.bot.votes.voting_processor
33import by.jprof.telegram.bot.votes.dao.VotesDAO
44import by.jprof.telegram.bot.votes.model.Votes
55import by.jprof.telegram.bot.votes.tgbotapi_extensions.toInlineKeyboardMarkup
6+ import com.soywiz.klock.DateTime
67import dev.inmo.tgbotapi.bot.RequestsExecutor
78import dev.inmo.tgbotapi.extensions.api.answers.answerCallbackQuery
89import dev.inmo.tgbotapi.extensions.api.edit.ReplyMarkup.editMessageReplyMarkup
10+ import dev.inmo.tgbotapi.types.CallbackQuery.InlineMessageIdDataCallbackQuery
911import dev.inmo.tgbotapi.types.CallbackQuery.MessageDataCallbackQuery
1012import dev.inmo.tgbotapi.types.CallbackQuery.MessageGameShortNameCallbackQuery
1113import dev.inmo.tgbotapi.types.ChatId
12- import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
14+ import dev.inmo.tgbotapi.types.CommonUser
15+ import dev.inmo.tgbotapi.types.UserId
16+ import dev.inmo.tgbotapi.types.chat.GroupChatImpl
17+ import dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl
1318import dev.inmo.tgbotapi.types.message.content.TextContent
1419import io.mockk.*
1520import io.mockk.impl.annotations.MockK
1621import io.mockk.junit5.MockKExtension
1722import kotlinx.coroutines.runBlocking
1823import org.junit.jupiter.api.BeforeEach
19- import org.junit.jupiter.api.Disabled
2024import org.junit.jupiter.api.Test
2125import org.junit.jupiter.api.extension.ExtendWith
2226
@@ -44,50 +48,123 @@ internal class VotingProcessorTest {
4448 }
4549
4650 @Test
47- @Disabled
48- fun processCallbackQuery () = runBlocking {
49- val callbackQuery = mockk<MessageDataCallbackQuery > {
50- every { id } returns " "
51- every { user } returns mockk {
52- every { id } returns ChatId (42L )
53- }
54- every { chatInstance } returns " "
55- every { message.hint(ContentMessage ::class ) } returns mockk<ContentMessage <* >> {
56- every { messageId } returns 1L
57- every { content.hint(TextContent ::class ) } returns TextContent (" " )
58- every { chat } returns mockk {
59- every { id } returns ChatId (1L )
60- }
61- }
62- every { data } returns " TEST-42:+"
63- }
51+ fun processMessageDataCallbackQuery () = runBlocking {
52+ val message = CommonGroupContentMessageImpl (
53+ chat = GroupChatImpl (
54+ id = ChatId (1L ),
55+ title = " Test"
56+ ),
57+ messageId = 1L ,
58+ user = CommonUser (UserId (2L ), " Test 2" ),
59+ date = DateTime .now(),
60+ forwardInfo = null ,
61+ editDate = null ,
62+ replyTo = null ,
63+ replyMarkup = null ,
64+ content = TextContent (" " ),
65+ senderBot = null ,
66+ )
67+ val callbackQuery = MessageDataCallbackQuery (
68+ id = " " ,
69+ user = CommonUser (UserId (1L ), " Test 1" ),
70+ chatInstance = " " ,
71+ message = message,
72+ data = " TEST-42:+"
73+ )
6474
6575 coEvery { votesDAO.get(" TEST-42" ) } returns Votes (" TEST-42" , listOf (" +" , " -" ))
6676 coEvery { votesDAO.save(any()) } just runs
6777 coEvery { bot.answerCallbackQuery(callbackQuery) } returns true
6878
6979 sut.processCallbackQuery(callbackQuery)
7080
71- coVerify(exactly = 1 ) { votesDAO.save(Votes (" TEST-42" , listOf (" +" , " -" ), mapOf (" 42 " to " +" ))) }
81+ coVerify(exactly = 1 ) { votesDAO.save(Votes (" TEST-42" , listOf (" +" , " -" ), mapOf (" 1 " to " +" ))) }
7282 coVerify(exactly = 1 ) { bot.answerCallbackQuery(callbackQuery) }
7383 coVerify(exactly = 1 ) {
7484 bot.editMessageReplyMarkup(
75- message = callbackQuery. message,
76- replyMarkup = Votes (" TEST-42" , listOf (" +" , " -" ), mapOf (" 42 " to " +" )).toInlineKeyboardMarkup()
85+ message = message,
86+ replyMarkup = Votes (" TEST-42" , listOf (" +" , " -" ), mapOf (" 1 " to " +" )).toInlineKeyboardMarkup(),
7787 )
7888 }
7989
8090 clearAllMocks()
8191 }
8292
8393 @Test
84- @Disabled
85- fun processCallbackQueryForNewVotes () {
86- TODO ()
94+ fun processCallbackQueryForNewVotes () = runBlocking {
95+ val message = CommonGroupContentMessageImpl (
96+ chat = GroupChatImpl (
97+ id = ChatId (1L ),
98+ title = " Test"
99+ ),
100+ messageId = 1L ,
101+ user = CommonUser (UserId (2L ), " Test 2" ),
102+ date = DateTime .now(),
103+ forwardInfo = null ,
104+ editDate = null ,
105+ replyTo = null ,
106+ replyMarkup = null ,
107+ content = TextContent (" " ),
108+ senderBot = null ,
109+ )
110+ val callbackQuery = MessageDataCallbackQuery (
111+ id = " " ,
112+ user = CommonUser (UserId (1L ), " Test 1" ),
113+ chatInstance = " " ,
114+ message = message,
115+ data = " TEST-42:+"
116+ )
117+
118+ coEvery { votesDAO.get(" TEST-42" ) } returns null
119+ every { votesConstructor.invoke(" TEST-42" ) } returns Votes (" TEST-42" , listOf (" +" , " -" , " =" ))
120+ coEvery { votesDAO.save(any()) } just runs
121+ coEvery { bot.answerCallbackQuery(callbackQuery) } returns true
122+
123+ sut.processCallbackQuery(callbackQuery)
124+
125+ coVerify(exactly = 1 ) { votesDAO.save(Votes (" TEST-42" , listOf (" +" , " -" , " =" ), mapOf (" 1" to " +" ))) }
126+ coVerify(exactly = 1 ) { bot.answerCallbackQuery(callbackQuery) }
127+ coVerify(exactly = 1 ) {
128+ bot.editMessageReplyMarkup(
129+ message = message,
130+ replyMarkup = Votes (" TEST-42" , listOf (" +" , " -" , " =" ), mapOf (" 1" to " +" )).toInlineKeyboardMarkup(),
131+ )
132+ }
133+
134+ clearAllMocks()
135+ }
136+
137+ @Test
138+ fun processInlineMessageIdDataCallbackQuery () = runBlocking {
139+ val callbackQuery = InlineMessageIdDataCallbackQuery (
140+ id = " " ,
141+ user = CommonUser (UserId (1L ), " Test 1" ),
142+ chatInstance = " " ,
143+ inlineMessageId = " 300" ,
144+ data = " TEST-42:+"
145+ )
146+
147+ coEvery { votesDAO.get(" TEST-42" ) } returns null
148+ every { votesConstructor.invoke(" TEST-42" ) } returns Votes (" TEST-42" , listOf (" +" , " -" ))
149+ coEvery { votesDAO.save(any()) } just runs
150+ coEvery { bot.answerCallbackQuery(callbackQuery) } returns true
151+
152+ sut.processCallbackQuery(callbackQuery)
153+
154+ coVerify(exactly = 1 ) { votesDAO.save(Votes (" TEST-42" , listOf (" +" , " -" ), mapOf (" 1" to " +" ))) }
155+ coVerify(exactly = 1 ) { bot.answerCallbackQuery(callbackQuery) }
156+ coVerify(exactly = 1 ) {
157+ bot.editMessageReplyMarkup(
158+ inlineMessageId = " 300" ,
159+ replyMarkup = Votes (" TEST-42" , listOf (" +" , " -" ), mapOf (" 1" to " +" )).toInlineKeyboardMarkup(),
160+ )
161+ }
162+
163+ clearAllMocks()
87164 }
88165
89166 @Test
90- fun processNonMessageDataCallbackQuery () = runBlocking {
167+ fun processUnknownCallbackQuery () = runBlocking {
91168 sut.processCallbackQuery(
92169 MessageGameShortNameCallbackQuery (
93170 id = " test" ,
0 commit comments