Skip to content

Commit

Permalink
Merge pull request #13 from alongotv/feature/CommandTypeResolverTestC…
Browse files Browse the repository at this point in the history
…overage

Feature/command type resolver test coverage
  • Loading branch information
alongotv authored May 1, 2024
2 parents b6be80e + 453608f commit 49f7c29
Showing 1 changed file with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.alongo.discordbot.utils.CommandStorageFactory
import org.junit.jupiter.api.Test
import kotlin.test.BeforeTest
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

internal class CommandTypeResolverTest {
private val commandTypeResolver = CommandTypeResolver
Expand All @@ -19,15 +20,14 @@ internal class CommandTypeResolverTest {

@Test
fun testKekCommandsQuery() {
val kekQueries = listOf(
val validQueries = listOf(
"Я сходил в турецкий супермаркет и купил себе кек к чаю",
"Рецепт кекса очень прост: возьмите...",
"I saw a pukeko on my recent trip to the New Zealand!",
"A Key Encryption Key or KEK is simply a key that is solely used to encrypt keys."
)
for (query in kekQueries) {
assertEquals(commandTypeResolver.resolve(query), Command.KEK)
}

executeTest(validQueries, emptyList(), commandUnderTest = Command.KEK)
}

@Test
Expand All @@ -40,14 +40,59 @@ internal class CommandTypeResolverTest {
val failingQueries = listOf(
"Alexa, play despacito",
"Press ${validCommandMarker}play to win",
"play music"
"play music",
"${validCommandMarker}playarandomtrack"
)

executeTest(validQueries, failingQueries, Command.AUDIO.PLAY)
}

@Test
fun testPauseAudioCommandsQuery() {
val validQueries =
listOf(
"${validCommandMarker}pause",
"${validCommandMarker}pause https://example.com",
)

val failingQueries = listOf("pause", "${validCommandMarker}pause2")
executeTest(validQueries, failingQueries, Command.AUDIO.PAUSE)
}

@Test
fun testResumeAudioCommandsQuery() {
val validQueries =
listOf(
"${validCommandMarker}resume",
"${validCommandMarker}resume https://example.com",
)

val failingQueries = listOf("resume", "${validCommandMarker}resume2")
executeTest(validQueries, failingQueries, Command.AUDIO.RESUME)
}

@Test
fun testStopAudioCommandsQuery() {
val validQueries =
listOf(
"${validCommandMarker}stop",
"${validCommandMarker}stop https://example.com",
)

val failingQueries = listOf("stop", "${validCommandMarker}stop2")
executeTest(validQueries, failingQueries, Command.AUDIO.STOP)
}

private fun executeTest(
validQueries: List<String>,
failingQueries: List<String>,
commandUnderTest: Command
) {
for (query in validQueries) {
assertEquals(commandTypeResolver.resolve(query), Command.AUDIO.PLAY)
assertEquals(commandTypeResolver.resolve(query), commandUnderTest)
}

for (query in failingQueries) {
assertEquals(commandTypeResolver.resolve(query), null)
assertNotEquals(commandTypeResolver.resolve(query), commandUnderTest)
}
}

Expand Down

0 comments on commit 49f7c29

Please sign in to comment.