Skip to content

Commit 4f30468

Browse files
committed
Fix JEPs
1 parent 6589b2d commit 4f30468

File tree

3 files changed

+71
-38
lines changed

3 files changed

+71
-38
lines changed

jep/src/main/kotlin/by/jprof/telegram/bot/jep/JEPUpdateProcessor.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class JEPUpdateProcessor(
3636
), UpdateProcessor {
3737
companion object {
3838
private val logger = LogManager.getLogger(JEPUpdateProcessor::class.java)!!
39-
private val linkRegex = "https?://openjdk\\.java\\.net/jeps/(\\d+)/?".toRegex()
39+
private val linkRegex = "https?://((openjdk\\.java\\.net)|(openjdk\\.org))/jeps/(?<jep>\\d+)/?".toRegex()
4040
}
4141

4242
override suspend fun process(update: Update) {
@@ -69,9 +69,8 @@ class JEPUpdateProcessor(
6969
(it as? URLTextSource)?.source ?: (it as? TextLinkTextSource)?.url
7070
}
7171
.mapNotNull {
72-
linkRegex.matchEntire(it)?.destructured
72+
linkRegex.matchEntire(it)?.groups?.get("jep")?.value
7373
}
74-
.map { (jep) -> jep }
7574
}
7675
}
7776

jep/src/main/kotlin/by/jprof/telegram/bot/jep/JsoupJEPSummary.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class JsoupJEPSummary : JEPSummary {
99
try {
1010
withContext(Dispatchers.IO) {
1111
Jsoup
12-
.connect("https://openjdk.java.net/jeps/${jep}")
12+
.connect("https://openjdk.org/jeps/${jep}")
1313
.get()
1414
.select("#Summary + p")
1515
.first()

jep/src/test/kotlin/by/jprof/telegram/bot/jep/JEPUpdateProcessorTest.kt

+68-34
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import by.jprof.telegram.bot.votes.model.Votes
55
import by.jprof.telegram.bot.votes.tgbotapi_extensions.toInlineKeyboardMarkup
66
import dev.inmo.tgbotapi.bot.RequestsExecutor
77
import dev.inmo.tgbotapi.extensions.api.answers.answerCallbackQuery
8+
import dev.inmo.tgbotapi.requests.edit.reply_markup.EditChatMessageReplyMarkup
89
import dev.inmo.tgbotapi.requests.send.SendTextMessage
910
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
1015
import dev.inmo.tgbotapi.types.message.MarkdownV2
1116
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
1217
import dev.inmo.tgbotapi.types.message.content.MessageContent
@@ -34,13 +39,11 @@ import io.mockk.verify
3439
import kotlinx.coroutines.runBlocking
3540
import kotlinx.serialization.json.JsonNull
3641
import org.junit.jupiter.api.BeforeEach
37-
import org.junit.jupiter.api.Disabled
3842
import org.junit.jupiter.api.Test
3943
import org.junit.jupiter.api.extension.ExtendWith
4044

4145
@RiskFeature
4246
@ExtendWith(MockKExtension::class)
43-
@Disabled
4447
internal 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\nCast 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\nCast 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

Comments
 (0)