Split up some methods, added some spongemock testing
This commit is contained in:
parent
bff3537253
commit
67864966a5
10 changed files with 125 additions and 109 deletions
|
@ -19,6 +19,8 @@ dependencies {
|
|||
implementation(Libs.javalin)
|
||||
implementation(Libs.slf4j_simple)
|
||||
implementation(Libs.jackson_databind)
|
||||
|
||||
testImplementation(Libs.junit_jupiter)
|
||||
}
|
||||
|
||||
application {
|
||||
|
@ -28,3 +30,10 @@ application {
|
|||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
|
@ -38,6 +38,10 @@ object Libs {
|
|||
const val kotlin_stdlib_jdk8: String = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:" +
|
||||
Versions.org_jetbrains_kotlin
|
||||
|
||||
/**
|
||||
* https://junit.org/junit5/ */
|
||||
const val junit_jupiter: String = "org.junit.jupiter:junit-jupiter:" + Versions.junit_jupiter
|
||||
|
||||
/**
|
||||
* http://www.slf4j.org */
|
||||
const val slf4j_simple: String = "org.slf4j:slf4j-simple:" + Versions.slf4j_simple
|
||||
|
|
|
@ -13,12 +13,14 @@ object Versions {
|
|||
|
||||
const val de_fayard_buildsrcversions_gradle_plugin: String = "0.3.2"
|
||||
|
||||
const val javalin: String = "2.8.0"
|
||||
const val javalin: String = "2.8.0" // available: "3.0.0"
|
||||
|
||||
const val org_jetbrains_kotlin_jvm_gradle_plugin: String = "1.3.31"
|
||||
|
||||
const val org_jetbrains_kotlin: String = "1.3.31"
|
||||
|
||||
const val junit_jupiter: String = "5.4.2"
|
||||
|
||||
const val slf4j_simple: String = "1.7.26"
|
||||
|
||||
/**
|
||||
|
@ -31,8 +33,8 @@ object Versions {
|
|||
|
||||
const val currentVersion: String = "5.4.1"
|
||||
|
||||
const val nightlyVersion: String = "5.6-20190607000159+0000"
|
||||
const val nightlyVersion: String = "5.6-20190615000035+0000"
|
||||
|
||||
const val releaseCandidate: String = "5.5-rc-2"
|
||||
const val releaseCandidate: String = "5.5-rc-3"
|
||||
}
|
||||
}
|
||||
|
|
78
src/main/kotlin/.gitignore
vendored
78
src/main/kotlin/.gitignore
vendored
|
@ -1,78 +0,0 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### Kotlin template
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# CMake
|
||||
cmake-build-debug/
|
||||
cmake-build-release/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
|
@ -1,13 +0,0 @@
|
|||
data class RespObj(
|
||||
val command: Commands,
|
||||
val text: String,
|
||||
val response_url: String,
|
||||
val team_id: String,
|
||||
val channel_id: String
|
||||
)
|
||||
|
||||
enum class Commands {
|
||||
Spongebob,
|
||||
Uppercase,
|
||||
Error
|
||||
}
|
|
@ -1,3 +1,8 @@
|
|||
package com.anthonycicchetti.slackbot
|
||||
|
||||
import com.anthonycicchetti.slackbot.utility.Commands
|
||||
import com.anthonycicchetti.slackbot.utility.RespObj
|
||||
import com.anthonycicchetti.slackbot.utility.TextResponse
|
||||
import io.javalin.Context
|
||||
import io.javalin.Javalin
|
||||
import org.slf4j.LoggerFactory
|
||||
|
@ -22,9 +27,8 @@ fun main() {
|
|||
}
|
||||
|
||||
fun handleSlackEvent(ctx: Context) {
|
||||
|
||||
// Short circuit for ssl check
|
||||
if ((ctx.formParam("ssl_check") ?: 0) == "1") {
|
||||
if ((ctx.formParam("ssl_check") ?: "0") == "1") {
|
||||
ctx.status(200)
|
||||
return
|
||||
}
|
||||
|
@ -65,16 +69,4 @@ fun sendResponse(ctx: Context, respObj: RespObj) {
|
|||
|
||||
}
|
||||
ctx.json(returnMap)
|
||||
}
|
||||
|
||||
data class TextResponse(val status: Int, val response: String)
|
||||
|
||||
private fun String.toSpongemock(): String {
|
||||
return this.mapIndexed { index, c ->
|
||||
if (!index.isOdd()) {
|
||||
c.toUpperCase()
|
||||
} else c
|
||||
}.joinToString(separator = "")
|
||||
}
|
||||
|
||||
private fun Int.isOdd(): Boolean = this.rem(2) == 0
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.anthonycicchetti.slackbot
|
||||
|
||||
fun String.toSpongemock(): String {
|
||||
return this
|
||||
.split(' ')
|
||||
.map { word ->
|
||||
word.mapIndexed { index, char ->
|
||||
if (!index.isOdd()) {
|
||||
char.toUpperCase()
|
||||
} else {
|
||||
char.toLowerCase()
|
||||
}
|
||||
}.joinToString("")
|
||||
}.joinToString(" ")
|
||||
}
|
||||
|
||||
private fun Int.isOdd(): Boolean = this.rem(2) == 0
|
|
@ -0,0 +1,15 @@
|
|||
package com.anthonycicchetti.slackbot.utility
|
||||
|
||||
data class RespObj(
|
||||
val command: Commands,
|
||||
val text: String,
|
||||
val response_url: String,
|
||||
val team_id: String,
|
||||
val channel_id: String
|
||||
)
|
||||
|
||||
sealed class Commands {
|
||||
object Spongebob : Commands()
|
||||
object Uppercase : Commands()
|
||||
object Error : Commands()
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package com.anthonycicchetti.slackbot.utility
|
||||
|
||||
data class TextResponse(val status: Int, val response: String)
|
|
@ -0,0 +1,65 @@
|
|||
package com.anthonycicchetti.slackbot
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
internal class TransformationsTest {
|
||||
|
||||
@Test
|
||||
fun `One lowercase word gets properly converted`() {
|
||||
val actual = "testing"
|
||||
val expected = "tEsTiNg"
|
||||
|
||||
assertEquals(expected, actual.toSpongemock())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `An ALL-CAPS word gets properly converted`() {
|
||||
val actual = "MAGMORTAR"
|
||||
val expected = "mAgMoRtAr"
|
||||
|
||||
assertEquals(expected, actual.toSpongemock())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `A title-cased word gets properly converted`() {
|
||||
val actual = "Electivire"
|
||||
val expected = "eLeCtIvIrE"
|
||||
|
||||
assertEquals(expected, actual.toSpongemock())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Multiple lowercase words get properly converted`() {
|
||||
val actual = "raichu and charmeleon"
|
||||
val expected = "rAiChU aNd cHaRmElEoN"
|
||||
|
||||
assertEquals(expected, actual.toSpongemock())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Multiple lowercase words with numbers interspersed get properly converted`() {
|
||||
val actual = "6 fearow cannot possibly defeat 2 dragonite"
|
||||
val expected = "6 fEaRoW cAnNoT pOsSiBlY dEfEaT 2 dRaGoNiTe"
|
||||
|
||||
assertEquals(expected, actual.toSpongemock())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Multiple Title-Case words get properly converted`() {
|
||||
val actual = "Harry Potter And The Prisoner Of Azkaban"
|
||||
val expected = "hArRy pOtTeR aNd tHe pRiSoNeR oF aZkAbAn"
|
||||
|
||||
assertEquals(expected, actual.toSpongemock())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Multiple ALL-CAPS words get properly converted`() {
|
||||
val actual = "I WISH YOU WEREN'T MY DAD"
|
||||
// TODO: Probably a compelling argument that I should not be interacting with punctuation...
|
||||
val expected = "i wIsH yOu wErEn't mY dAd"
|
||||
|
||||
assertEquals(expected, actual.toSpongemock())
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue