Big refactoring #77
13
src/main/kotlin/fr/dcproject/common/dto/CreatedBy.kt
Normal file
13
src/main/kotlin/fr/dcproject/common/dto/CreatedBy.kt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package fr.dcproject.common.dto
|
||||||
|
|
||||||
|
import fr.dcproject.component.citizen.database.CitizenI
|
||||||
|
import java.util.UUID
|
||||||
|
import fr.dcproject.common.entity.CreatedBy as EntityCreatedBy
|
||||||
|
|
||||||
|
interface CreatedBy {
|
||||||
|
val createdBy: UUID
|
||||||
|
|
||||||
|
class Imp(parent: EntityCreatedBy<CitizenI>) : CreatedBy {
|
||||||
|
override val createdBy: UUID = parent.createdBy.id
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/main/kotlin/fr/dcproject/common/dto/Paginated.kt
Normal file
16
src/main/kotlin/fr/dcproject/common/dto/Paginated.kt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package fr.dcproject.common.dto
|
||||||
|
|
||||||
|
import fr.dcproject.common.entity.EntityI
|
||||||
|
import fr.postgresjson.connexion.Paginated
|
||||||
|
|
||||||
|
fun <E : EntityI> Paginated<E>.toOutput(setup: (E) -> Any): Any {
|
||||||
|
return object {
|
||||||
|
val count = this@toOutput.count
|
||||||
|
val currentPage = this@toOutput.count
|
||||||
|
val limit = this@toOutput.limit
|
||||||
|
val offset = this@toOutput.offset
|
||||||
|
val total = this@toOutput.total
|
||||||
|
val totalPages = this@toOutput.totalPages
|
||||||
|
val result = this@toOutput.result.map { setup(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,8 +8,8 @@ import fr.dcproject.common.entity.TargetI
|
|||||||
import fr.dcproject.common.entity.TargetRef
|
import fr.dcproject.common.entity.TargetRef
|
||||||
import fr.dcproject.common.entity.Versionable
|
import fr.dcproject.common.entity.Versionable
|
||||||
import fr.dcproject.common.entity.VersionableId
|
import fr.dcproject.common.entity.VersionableId
|
||||||
import fr.dcproject.component.citizen.database.CitizenCart
|
|
||||||
import fr.dcproject.component.citizen.database.CitizenCartI
|
import fr.dcproject.component.citizen.database.CitizenCartI
|
||||||
|
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||||
import fr.dcproject.component.citizen.database.CitizenI
|
import fr.dcproject.component.citizen.database.CitizenI
|
||||||
import fr.dcproject.component.citizen.database.CitizenRef
|
import fr.dcproject.component.citizen.database.CitizenRef
|
||||||
import fr.dcproject.component.opinion.entity.Opinionable
|
import fr.dcproject.component.opinion.entity.Opinionable
|
||||||
@@ -78,7 +78,7 @@ class ArticleForUpdate(
|
|||||||
class ArticleForListing(
|
class ArticleForListing(
|
||||||
id: UUID? = null,
|
id: UUID? = null,
|
||||||
override val title: String,
|
override val title: String,
|
||||||
override val createdBy: CitizenCart,
|
override val createdBy: CitizenCreator,
|
||||||
override val workgroup: WorkgroupCart?,
|
override val workgroup: WorkgroupCart?,
|
||||||
override val deletedAt: DateTime?,
|
override val deletedAt: DateTime?,
|
||||||
override val draft: Boolean
|
override val draft: Boolean
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package fr.dcproject.component.article.routes
|
package fr.dcproject.component.article.routes
|
||||||
|
|
||||||
|
import fr.dcproject.common.dto.toOutput
|
||||||
import fr.dcproject.common.security.assert
|
import fr.dcproject.common.security.assert
|
||||||
import fr.dcproject.component.article.ArticleAccessControl
|
import fr.dcproject.component.article.ArticleAccessControl
|
||||||
import fr.dcproject.component.article.database.ArticleForListing
|
import fr.dcproject.component.article.database.ArticleForListing
|
||||||
@@ -44,7 +45,33 @@ object FindArticles {
|
|||||||
get<ArticlesRequest> {
|
get<ArticlesRequest> {
|
||||||
repo.findArticles(it)
|
repo.findArticles(it)
|
||||||
.apply { ac.assert { canView(result, citizenOrNull) } }
|
.apply { ac.assert { canView(result, citizenOrNull) } }
|
||||||
.let { call.respond(it) }
|
.let {
|
||||||
|
call.respond(
|
||||||
|
it.toOutput {
|
||||||
|
object {
|
||||||
|
val id = it.id
|
||||||
|
val title = it.title
|
||||||
|
val createdBy = object {
|
||||||
|
val id = it.createdBy.id
|
||||||
|
val name = it.createdBy.name.let {
|
||||||
|
object {
|
||||||
|
val firstName = it.firstName
|
||||||
|
val lastName = it.lastName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val email = it.createdBy.email
|
||||||
|
}
|
||||||
|
val workgroup = it.workgroup?.let {
|
||||||
|
object {
|
||||||
|
val id = it.id
|
||||||
|
val name = it.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val draft = it.draft
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,7 +243,37 @@ paths:
|
|||||||
result:
|
result:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/ArticleResponse'
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
title:
|
||||||
|
type: string
|
||||||
|
created_by:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
name:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
first_name:
|
||||||
|
type: string
|
||||||
|
last_name:
|
||||||
|
type: string
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
workgroup:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
draft:
|
||||||
|
type: boolean
|
||||||
post:
|
post:
|
||||||
security:
|
security:
|
||||||
- JWTAuth: []
|
- JWTAuth: []
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import integration.steps.`And have property`
|
import integration.steps.then.`And have property`
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should contain pattern`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`And the response should not be null`
|
||||||
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import integration.steps.`whish contains`
|
import integration.steps.then.`whish contains`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have article created by workgroup`
|
import integration.steps.given.`Given I have article created by workgroup`
|
||||||
import integration.steps.given.`Given I have article`
|
import integration.steps.given.`Given I have article`
|
||||||
import integration.steps.given.`Given I have articles`
|
import integration.steps.given.`Given I have articles`
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`Given I have workgroup`
|
import integration.steps.given.`Given I have workgroup`
|
||||||
import integration.steps.given.`authenticated as`
|
import integration.steps.given.`authenticated as`
|
||||||
|
import integration.steps.then.`And the response should contain list`
|
||||||
|
import integration.steps.then.`And the response should not contain`
|
||||||
import io.ktor.http.HttpStatusCode.Companion.OK
|
import io.ktor.http.HttpStatusCode.Companion.OK
|
||||||
import org.junit.jupiter.api.Tag
|
import org.junit.jupiter.api.Tag
|
||||||
import org.junit.jupiter.api.Tags
|
import org.junit.jupiter.api.Tags
|
||||||
@@ -28,6 +31,11 @@ class `Article routes` : BaseTest() {
|
|||||||
`Given I have articles`(3)
|
`Given I have articles`(3)
|
||||||
`When I send a GET request`("/articles") `Then the response should be` OK and {
|
`When I send a GET request`("/articles") `Then the response should be` OK and {
|
||||||
`And the response should not be null`()
|
`And the response should not be null`()
|
||||||
|
`And the response should contain pattern`("$.result[0].created_by.name.first_name", "firstName.+")
|
||||||
|
`And the response should contain pattern`("$.result[1].created_by.name.first_name", "firstName.+")
|
||||||
|
`And the response should contain pattern`("$.result[2].created_by.name.first_name", "firstName.+")
|
||||||
|
`And the response should not contain`("$.result[3]")
|
||||||
|
`And the response should contain list`("$.result", 3, 3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import integration.steps.`And have property`
|
import integration.steps.then.`And have property`
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should not be null`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a PUT request`
|
import integration.steps.`when`.`When I send a PUT request`
|
||||||
import integration.steps.`whish contains`
|
import integration.steps.then.`whish contains`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`authenticated as`
|
import integration.steps.given.`authenticated as`
|
||||||
import io.ktor.http.HttpStatusCode.Companion.BadRequest
|
import io.ktor.http.HttpStatusCode.Companion.BadRequest
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import fr.dcproject.component.citizen.database.CitizenI.Name
|
import fr.dcproject.component.citizen.database.CitizenI.Name
|
||||||
import integration.steps.`And the response should contain`
|
import integration.steps.then.`And the response should contain`
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should not be null`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import integration.steps.`when`.`When I send a PUT request`
|
import integration.steps.`when`.`When I send a PUT request`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have article`
|
import integration.steps.given.`Given I have article`
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`Given I have comment on article`
|
import integration.steps.given.`Given I have comment on article`
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import fr.dcproject.component.citizen.database.CitizenI.Name
|
import fr.dcproject.component.citizen.database.CitizenI.Name
|
||||||
import integration.steps.`And the response should contain list`
|
import integration.steps.then.`And the response should contain list`
|
||||||
import integration.steps.`And the response should contain`
|
import integration.steps.then.`And the response should contain`
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should not be null`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`Given I have comment on constitution`
|
import integration.steps.given.`Given I have comment on constitution`
|
||||||
import integration.steps.given.`Given I have constitution`
|
import integration.steps.given.`Given I have constitution`
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should not be null`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have article`
|
import integration.steps.given.`Given I have article`
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`Given I have comment on article`
|
import integration.steps.given.`Given I have comment on article`
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import integration.steps.`And have property`
|
import integration.steps.then.`And have property`
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should not be null`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import integration.steps.`whish contains`
|
import integration.steps.then.`whish contains`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`Given I have constitution`
|
import integration.steps.given.`Given I have constitution`
|
||||||
import integration.steps.given.`Given I have constitutions`
|
import integration.steps.given.`Given I have constitutions`
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import integration.steps.`And the response should be null`
|
import integration.steps.then.`And the response should be null`
|
||||||
import integration.steps.`And the response should contain`
|
import integration.steps.then.`And the response should contain`
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should not be null`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a DELETE request`
|
import integration.steps.`when`.`When I send a DELETE request`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`And follow article`
|
import integration.steps.given.`And follow article`
|
||||||
import integration.steps.given.`Given I have article`
|
import integration.steps.given.`Given I have article`
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import integration.steps.`And the response should be null`
|
import integration.steps.then.`And the response should be null`
|
||||||
import integration.steps.`And the response should contain`
|
import integration.steps.then.`And the response should contain`
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should not be null`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a DELETE request`
|
import integration.steps.`when`.`When I send a DELETE request`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`And follow constitution`
|
import integration.steps.given.`And follow constitution`
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`Given I have constitution`
|
import integration.steps.given.`Given I have constitution`
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import integration.steps.`And the response should not be null`
|
import integration.steps.then.`And the response should not be null`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`and should contains`
|
import integration.steps.then.`and should contains`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`authenticated as`
|
import integration.steps.given.`authenticated as`
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import fr.dcproject.component.citizen.database.CitizenI.Name
|
import fr.dcproject.component.citizen.database.CitizenI.Name
|
||||||
import integration.steps.`And the response should contain list`
|
import integration.steps.then.`And the response should contain list`
|
||||||
import integration.steps.`And the response should contain`
|
import integration.steps.then.`And the response should contain`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a PUT request`
|
import integration.steps.`when`.`When I send a PUT request`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have an opinion choice`
|
import integration.steps.given.`Given I have an opinion choice`
|
||||||
import integration.steps.given.`Given I have article`
|
import integration.steps.given.`Given I have article`
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
import org.amshove.kluent.`should be null`
|
import org.amshove.kluent.`should be null`
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import fr.dcproject.component.citizen.database.CitizenI.Name
|
import fr.dcproject.component.citizen.database.CitizenI.Name
|
||||||
import integration.steps.`And the response should contain`
|
import integration.steps.then.`And the response should contain`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a PUT request`
|
import integration.steps.`when`.`When I send a PUT request`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have article`
|
import integration.steps.given.`Given I have article`
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`Given I have comment on article`
|
import integration.steps.given.`Given I have comment on article`
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import fr.dcproject.component.citizen.database.CitizenI.Name
|
import fr.dcproject.component.citizen.database.CitizenI.Name
|
||||||
import integration.steps.`And the response should be null`
|
import integration.steps.then.`And the response should be null`
|
||||||
import integration.steps.`And the response should contain list`
|
import integration.steps.then.`And the response should contain list`
|
||||||
import integration.steps.`And the response should contain`
|
import integration.steps.then.`And the response should contain`
|
||||||
import integration.steps.`Then the response should be`
|
import integration.steps.then.`Then the response should be`
|
||||||
import integration.steps.`when`.`When I send a DELETE request`
|
import integration.steps.`when`.`When I send a DELETE request`
|
||||||
import integration.steps.`when`.`When I send a GET request`
|
import integration.steps.`when`.`When I send a GET request`
|
||||||
import integration.steps.`when`.`When I send a POST request`
|
import integration.steps.`when`.`When I send a POST request`
|
||||||
import integration.steps.`when`.`When I send a PUT request`
|
import integration.steps.`when`.`When I send a PUT request`
|
||||||
import integration.steps.and
|
import integration.steps.then.and
|
||||||
import integration.steps.given.`Given I have citizen`
|
import integration.steps.given.`Given I have citizen`
|
||||||
import integration.steps.given.`Given I have workgroup`
|
import integration.steps.given.`Given I have workgroup`
|
||||||
import integration.steps.given.`With members`
|
import integration.steps.given.`With members`
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package integration.steps
|
package integration.steps.then
|
||||||
|
|
||||||
import assert.assertGreaterThan
|
import assert.assertGreaterThan
|
||||||
import assert.assertLessThan
|
import assert.assertLessThan
|
||||||
import com.jayway.jsonpath.JsonPath
|
import com.jayway.jsonpath.JsonPath
|
||||||
|
import com.jayway.jsonpath.PathNotFoundException
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.server.testing.TestApplicationCall
|
import io.ktor.server.testing.TestApplicationCall
|
||||||
import io.ktor.server.testing.TestApplicationResponse
|
import io.ktor.server.testing.TestApplicationResponse
|
||||||
@@ -12,8 +13,10 @@ import org.amshove.kluent.`should be null`
|
|||||||
import org.amshove.kluent.`should be`
|
import org.amshove.kluent.`should be`
|
||||||
import org.amshove.kluent.`should not be null`
|
import org.amshove.kluent.`should not be null`
|
||||||
import org.amshove.kluent.shouldContain
|
import org.amshove.kluent.shouldContain
|
||||||
|
import org.junit.jupiter.api.assertThrows
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
fun TestApplicationCall.`Then the response should be`(status: HttpStatusCode? = null, block: TestApplicationResponse.() -> Unit): TestApplicationCall = this.apply {
|
fun TestApplicationCall.`Then the response should be`(status: HttpStatusCode? = null, block: TestApplicationResponse.() -> Unit): TestApplicationCall = this.apply {
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
@@ -62,6 +65,26 @@ inline fun <reified T> TestApplicationResponse.`And the response should contain`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun TestApplicationResponse.`And the response should not contain`(path: String) {
|
||||||
|
assertThrows<PathNotFoundException> {
|
||||||
|
JsonPath.read(content, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun TestApplicationResponse.`And the response should contain pattern`(path: String, expectedRegex: String): Any {
|
||||||
|
return JsonPath.read<Any?>(content, path).also {
|
||||||
|
it.let {
|
||||||
|
if (it is JSONArray && it.count() == 1) {
|
||||||
|
it.first()
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}?.let {
|
||||||
|
assertTrue(expectedRegex.toRegex().containsMatchIn(it.toString()))
|
||||||
|
} ?: throw AssertionError("\"$path -> element not found on json response")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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, min: Int? = null, max: Int? = null) {
|
||||||
JsonPath.read<JSONArray?>(content, path).also {
|
JsonPath.read<JSONArray?>(content, path).also {
|
||||||
assertNotNull(it)
|
assertNotNull(it)
|
||||||
|
|||||||
Reference in New Issue
Block a user