Refactor 'the response should contain list'
This commit is contained in:
@@ -38,7 +38,7 @@ class `Article routes` : BaseTest() {
|
||||
`And the response should contain pattern`("$.result[1].createdBy.name.firstName", "firstName.+")
|
||||
`And the response should contain pattern`("$.result[2].createdBy.name.firstName", "firstName.+")
|
||||
`And the response should not contain`("$.result[3]")
|
||||
`And the response should contain list`("$.result", 3, 3)
|
||||
`And the response should contain list`("$.result", 3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class `Comment constitutions routes` : BaseTest() {
|
||||
`And the response should contain`("$.limit", 50)
|
||||
`And the response should contain`("$.result[0].createdBy.id", "46e0bda9-ca6a-4c65-a58b-7e7267a0bbc5")
|
||||
`And the response should contain`("$.result[0].target.id", "34ddd50a-da00-4a90-a869-08baa2a121be")
|
||||
`And the response should contain list`("$.result[*]", 1, 1)
|
||||
`And the response should contain list`("$.result[*]", 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ class `Opinion routes` : BaseTest() {
|
||||
`authenticated as`("Albert", "Einstein")
|
||||
} `Then the response should be` OK and {
|
||||
`And the response should contain`("$.result[0].name", "Opinion9")
|
||||
`And the response should contain list`("$.result[*]", 1, 1)
|
||||
`And the response should contain list`("$.result[*]", 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class `Workgroup routes` : BaseTest() {
|
||||
`And the response should contain`("$.description", "Une petite souris")
|
||||
|
||||
`And have property`("$.members")
|
||||
`And the response should contain list`("$.members", 3, 3)
|
||||
`And the response should contain list`("$.members", 3)
|
||||
`And the response should contain`("$.members.[1]citizen.id", "94f92424-c257-4582-907c-98564a8c4ac9")
|
||||
`And the response should contain`("$.members.[2]citizen.id", "87909ba3-2069-431c-9924-219fd8411cf2")
|
||||
}
|
||||
@@ -215,7 +215,7 @@ class `Workgroup routes` : BaseTest() {
|
||||
]
|
||||
"""
|
||||
} `Then the response should be` OK and {
|
||||
`And the response should contain list`("$", 2, 2)
|
||||
`And the response should contain list`("$", 2)
|
||||
`And the response should contain`("$.[0]citizen.id", "94f92424-c257-4582-907c-98564a8c4ac9")
|
||||
`And the response should contain`("$.[1]citizen.id", "1baf48bb-02bc-4d8f-ac86-33335354f5e7")
|
||||
}
|
||||
@@ -252,7 +252,7 @@ class `Workgroup routes` : BaseTest() {
|
||||
"""
|
||||
)
|
||||
} `Then the response should be` OK and {
|
||||
`And the response should contain list`("$", 2, 2)
|
||||
`And the response should contain list`("$", 2)
|
||||
`And the response should contain`("$.[0]citizen.id", "be3b0926-8628-4426-804a-75188a6eb315")
|
||||
`And the response should contain`("$.[1]citizen.id", "b49e20c1-8393-45d6-a6a0-3fa5c71cbdc1")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package integration.steps.then
|
||||
|
||||
import assert.assertGreaterThan
|
||||
import assert.assertLessThan
|
||||
import assert.assertContain
|
||||
import com.jayway.jsonpath.JsonPath
|
||||
import com.jayway.jsonpath.PathNotFoundException
|
||||
import io.ktor.http.HttpStatusCode
|
||||
@@ -85,15 +84,13 @@ fun TestApplicationResponse.`And the response should contain pattern`(path: Stri
|
||||
}
|
||||
}
|
||||
|
||||
fun TestApplicationResponse.`And the response should contain list`(path: String, min: Int? = null, max: Int? = null) {
|
||||
fun TestApplicationResponse.`And the response should contain list`(path: String, exactCount: Int) =
|
||||
`And the response should contain list`(path, IntRange(exactCount, exactCount))
|
||||
|
||||
fun TestApplicationResponse.`And the response should contain list`(path: String, range: IntRange) {
|
||||
JsonPath.read<JSONArray?>(content, path).also {
|
||||
assertNotNull(it)
|
||||
if (min != null) {
|
||||
it.size assertGreaterThan min
|
||||
}
|
||||
if (max != null) {
|
||||
it.size assertLessThan max
|
||||
}
|
||||
range assertContain it.size
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user