Add Integration test for comment

This commit is contained in:
2021-02-17 23:02:38 +01:00
parent 55aa512aa5
commit 0ecf0c205f
17 changed files with 426 additions and 18 deletions

View File

@@ -1,14 +1,19 @@
package integration.steps
import assert.assertGreaterThan
import assert.assertLessThan
import com.jayway.jsonpath.JsonPath
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.TestApplicationCall
import io.ktor.server.testing.TestApplicationResponse
import net.minidev.json.JSONArray
import org.amshove.kluent.`should be equal to`
import org.amshove.kluent.`should be null`
import org.amshove.kluent.`should be`
import org.amshove.kluent.`should not be null`
import org.amshove.kluent.shouldContain
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
fun TestApplicationCall.`Then the response should be`(status: HttpStatusCode? = null, block: TestApplicationResponse.() -> Unit): TestApplicationCall = this.apply {
if (status != null) {
@@ -43,11 +48,26 @@ infix fun Pair<JsonPath, Any>.`whish contains`(expected: Any): Pair<JsonPath, An
second `should be equal to` expected
}
fun TestApplicationResponse.`And the response should contain`(path: String, valueExpected: String) {
assertEquals(valueExpected, JsonPath.read<Any>(content, path)?.toString() ?: throw AssertionError("\"$path -> ${valueExpected}\" element not found on json response"))
fun <T> TestApplicationResponse.`And the response should contain`(path: String, valueExpected: T?): T {
return JsonPath.read<T?>(content, path).also {
assertEquals<T?>(valueExpected, it ?: throw AssertionError("\"$path -> ${valueExpected}\" element not found on json response"))
}
}
fun TestApplicationResponse.`And the response should contain list`(path: String, min: Int? = null, max: Int? = null) {
JsonPath.read<JSONArray?>(content, path).also {
assertNotNull(it)
if (min != null) {
it.size assertGreaterThan min
}
if (max != null) {
it.size assertLessThan max
}
}
}
val TestApplicationResponse.`And the response should not be null` get() = content.`should not be null`()
fun TestApplicationResponse.`And the response should be null`() = content.`should be null`()
infix fun String.`and should contains`(expected: String) = this
.`should not be null`()
.shouldContain(expected)