discord-kagebot/src/test/kotlin/moe/kageru/kagebot/ConfigTest.kt

42 lines
1.3 KiB
Kotlin
Raw Normal View History

2019-06-08 21:14:57 +02:00
package moe.kageru.kagebot
import io.kotlintest.shouldBe
2019-06-08 21:52:47 +02:00
import io.kotlintest.shouldNotBe
2019-11-24 14:03:45 +01:00
import io.kotlintest.specs.StringSpec
import io.mockk.every
import io.mockk.mockk
2019-07-13 15:39:50 +02:00
import moe.kageru.kagebot.config.Config
import moe.kageru.kagebot.config.LocalizationSpec
import moe.kageru.kagebot.config.SystemSpec
import moe.kageru.kagebot.features.SetConfigFeature
import java.awt.Color
2019-06-08 21:52:47 +02:00
2019-07-17 23:42:12 +02:00
@ExperimentalStdlibApi
2019-11-24 14:03:45 +01:00
class ConfigTest : StringSpec() {
init {
"should properly parse test config" {
TestUtil.prepareTestEnvironment()
Config.system[SystemSpec.serverId] shouldNotBe null
SystemSpec.color shouldBe Color.decode("#1793d0")
Config.features.welcome!!.embed shouldNotBe null
Config.commands.size shouldBe 3
}
2019-11-24 14:03:45 +01:00
"should parse test config via command" {
val redir = "says"
val testConfig = """
2019-11-14 15:10:30 +01:00
[localization]
redirectedMessage = "$redir"
messageDeleted = "dongered"
timeout = "timeout"
""".trimIndent()
2019-11-24 14:03:45 +01:00
val message = TestUtil.mockMessage("anything")
every { message.messageAttachments } returns listOf(mockk {
every { url.openStream().readAllBytes() } returns testConfig.toByteArray()
})
SetConfigFeature().handle(message)
Config.localization[LocalizationSpec.redirectedMessage] shouldBe redir
}
2019-11-14 15:10:30 +01:00
}
2019-11-24 14:03:45 +01:00
}