Skip to content

Commit 847649b

Browse files
committed
Test only guild commands can use @Test
1 parent 8313630 commit 847649b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

BotCommands-core/src/test/kotlin/io/github/freya022/botcommands/commands/application/autobuilder/SlashCommandAutoBuilderTest.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,31 @@ class SlashCommandAutoBuilderTest {
375375
}
376376
}
377377

378-
// TODO test that Test only works on guild commands (throw otherwise)
378+
@Nested
379+
inner class TestCommands {
380+
381+
@JDASlashCommand(name = "test_command")
382+
@io.github.freya022.botcommands.api.commands.application.annotations.Test
383+
fun globalTopLevel(event: GlobalSlashEvent) { consume(event) }
384+
385+
@Test
386+
fun `Can only use on guild commands`() {
387+
every { functionAnnotationsMap.getWithClassAnnotation(Command::class, JDASlashCommand::class) } answers {
388+
listOf(
389+
ClassPathFunction(this@TestCommands, TestCommands::globalTopLevel),
390+
)
391+
}
392+
393+
val autoBuilder = spyk(SlashCommandAutoBuilder(serviceContainer, applicationConfig, resolverContainer, functionAnnotationsMap))
394+
val manager = mockk<GlobalApplicationCommandManager> {
395+
every { context } returns mockk()
396+
}
397+
val exception = assertThrows<RuntimeException> {
398+
autoBuilder.declareGlobalApplicationCommands(manager)
399+
}
400+
assertTrue(exception.cause!!.cause!!.message!!.startsWith("Test commands must have their scope set to GUILD"))
401+
}
402+
}
379403

380404
@Suppress("NOTHING_TO_INLINE", "unused")
381405
private inline fun consume(e: Any) {}

0 commit comments

Comments
 (0)