Add test for bad request
This commit is contained in:
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature
|
|||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature
|
import com.fasterxml.jackson.databind.SerializationFeature
|
||||||
import com.fasterxml.jackson.datatype.joda.JodaModule
|
import com.fasterxml.jackson.datatype.joda.JodaModule
|
||||||
|
import com.github.jasync.sql.db.postgresql.exceptions.GenericDatabaseException
|
||||||
import fr.dcproject.entity.Article
|
import fr.dcproject.entity.Article
|
||||||
import fr.dcproject.entity.Citizen
|
import fr.dcproject.entity.Citizen
|
||||||
import fr.dcproject.entity.Constitution
|
import fr.dcproject.entity.Constitution
|
||||||
@@ -16,17 +17,17 @@ import fr.dcproject.security.voter.AuthorizationVoter
|
|||||||
import fr.dcproject.security.voter.CitizenVoter
|
import fr.dcproject.security.voter.CitizenVoter
|
||||||
import fr.postgresjson.migration.Migrations
|
import fr.postgresjson.migration.Migrations
|
||||||
import io.ktor.application.Application
|
import io.ktor.application.Application
|
||||||
|
import io.ktor.application.call
|
||||||
import io.ktor.application.install
|
import io.ktor.application.install
|
||||||
import io.ktor.auth.Authentication
|
import io.ktor.auth.Authentication
|
||||||
import io.ktor.auth.authenticate
|
import io.ktor.auth.authenticate
|
||||||
import io.ktor.auth.jwt.jwt
|
import io.ktor.auth.jwt.jwt
|
||||||
import io.ktor.features.AutoHeadResponse
|
import io.ktor.features.*
|
||||||
import io.ktor.features.CallLogging
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.features.ContentNegotiation
|
|
||||||
import io.ktor.features.DataConversion
|
|
||||||
import io.ktor.jackson.jackson
|
import io.ktor.jackson.jackson
|
||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Locations
|
import io.ktor.locations.Locations
|
||||||
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Routing
|
import io.ktor.routing.Routing
|
||||||
import io.ktor.util.KtorExperimentalAPI
|
import io.ktor.util.KtorExperimentalAPI
|
||||||
import org.eclipse.jetty.util.log.Slf4jLog
|
import org.eclipse.jetty.util.log.Slf4jLog
|
||||||
@@ -34,6 +35,7 @@ import org.koin.ktor.ext.Koin
|
|||||||
import org.koin.ktor.ext.get
|
import org.koin.ktor.ext.get
|
||||||
import org.slf4j.event.Level
|
import org.slf4j.event.Level
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.CompletionException
|
||||||
import fr.dcproject.repository.Article as RepositoryArticle
|
import fr.dcproject.repository.Article as RepositoryArticle
|
||||||
import fr.dcproject.repository.Citizen as RepositoryCitizen
|
import fr.dcproject.repository.Citizen as RepositoryCitizen
|
||||||
import fr.dcproject.repository.Constitution as RepositoryConstitution
|
import fr.dcproject.repository.Constitution as RepositoryConstitution
|
||||||
@@ -153,6 +155,18 @@ fun Application.module() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install(StatusPages) {
|
||||||
|
// TODO move to postgresJson lib
|
||||||
|
exception<CompletionException> { e ->
|
||||||
|
val parent = e.cause?.cause
|
||||||
|
if (parent is GenericDatabaseException) {
|
||||||
|
call.respond(HttpStatusCode.BadRequest, parent.errorMessage.message!!)
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO move to postgresJson lib
|
// TODO move to postgresJson lib
|
||||||
get<Migrations>().run()
|
get<Migrations>().run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,20 @@ Feature: Auth routes
|
|||||||
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.
|
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Scenario: The route for create citizen must response a 200 and return object
|
||||||
|
When I send a POST request to "/register" with body:
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"name": {"first_name":"George2", "last_name":"MICHEL2"},
|
||||||
|
"birthday": "2001-01-01",
|
||||||
|
"user":{
|
||||||
|
"username": "",
|
||||||
|
"plain_password": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Then the response status code should be 400
|
||||||
|
|
||||||
Scenario: The route for create citizen must response a 200 and return object
|
Scenario: The route for create citizen must response a 200 and return object
|
||||||
When I send a POST request to "/login" with body:
|
When I send a POST request to "/login" with body:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user