Improve BitMaskI

This commit is contained in:
2021-03-20 00:54:01 +01:00
parent c9879be72c
commit d03b585372
4 changed files with 12 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ interface BitMaskI {
infix operator fun contains(which: BitMaskI): Boolean = bit and which.bit == which.bit infix operator fun contains(which: BitMaskI): Boolean = bit and which.bit == which.bit
infix operator fun plus(mask: BitMaskI): BitMaskI = BitMask(mask.bit and this.bit) infix operator fun plus(mask: BitMaskI): BitMaskI = BitMask(mask.bit and this.bit)
infix operator fun minus(mask: BitMaskI): BitMaskI = BitMask(this.bit - mask.bit)
} }
class BitMask(override val bit: Long) : BitMaskI class BitMask(override val bit: Long) : BitMaskI

View File

@@ -80,7 +80,7 @@ class `Citizen routes` : BaseTest() {
fun `I cannot change my password if request is bad formatted`() { fun `I cannot change my password if request is bad formatted`() {
withIntegrationApplication { withIntegrationApplication {
`Given I have citizen`("Louis", "Breguet", id = "6cf2a19d-d15d-4ee5-b2a9-907afd26b525") `Given I have citizen`("Louis", "Breguet", id = "6cf2a19d-d15d-4ee5-b2a9-907afd26b525")
`When I send a PUT request`("/citizens/6cf2a19d-d15d-4ee5-b2a9-907afd26b525/password/change", Validate.RESPONSE_BODY) { `When I send a PUT request`("/citizens/6cf2a19d-d15d-4ee5-b2a9-907afd26b525/password/change", Validate.ALL - Validate.RESPONSE_BODY) {
`authenticated as`("Louis", "Breguet") `authenticated as`("Louis", "Breguet")
`with body`(""" `with body`("""
{ {

View File

@@ -43,7 +43,7 @@ class `Register routes` : BaseTest() {
@Test @Test
fun `I cannot register if no username was sent`() { fun `I cannot register if no username was sent`() {
withIntegrationApplication { withIntegrationApplication {
`When I send a POST request`("/register", Validate.RESPONSE_BODY) { `When I send a POST request`("/register", Validate.ALL - Validate.RESPONSE_BODY) {
`with body`(""" `with body`("""
{ {
"name": {"firstName":"George2", "lastName":"MICHEL2"}, "name": {"firstName":"George2", "lastName":"MICHEL2"},

View File

@@ -16,12 +16,15 @@ import io.ktor.server.testing.setBody
enum class Validate(override val bit: Long) : BitMaskI { enum class Validate(override val bit: Long) : BitMaskI {
REQUEST_BODY(1), REQUEST_BODY(1),
REQUEST_PARAM(2), REQUEST_PARAM(2),
REQUEST(3), REQUEST_HEADER(4),
RESPONSE_BODY(4), REQUEST(1 + 2 + 4),
ALL(7); RESPONSE_BODY(8),
RESPONSE_HEADER(16),
RESPONSE(8 + 16),
ALL((1 + 2 + 4) + (8 + 16));
} }
fun TestApplicationCall.valid(validate: Validate): TestApplicationCall { fun TestApplicationCall.valid(validate: BitMaskI): TestApplicationCall {
if (Validate.RESPONSE_BODY in validate) { if (Validate.RESPONSE_BODY in validate) {
response.`And the schema response body must be valid`() response.`And the schema response body must be valid`()
} }
@@ -48,7 +51,7 @@ fun TestApplicationEngine.`When I send a GET request`(uri: String? = null, valid
}.valid(validate) }.valid(validate)
} }
fun TestApplicationEngine.`When I send a POST request`(uri: String? = null, validate: Validate = Validate.ALL, setup: (TestApplicationRequest.() -> Unit)? = null): TestApplicationCall { fun TestApplicationEngine.`When I send a POST request`(uri: String? = null, validate: BitMaskI = Validate.ALL, setup: (TestApplicationRequest.() -> Unit)? = null): TestApplicationCall {
return handleRequest(true) { return handleRequest(true) {
method = HttpMethod.Post method = HttpMethod.Post
if (uri != null) { if (uri != null) {
@@ -60,7 +63,7 @@ fun TestApplicationEngine.`When I send a POST request`(uri: String? = null, vali
}.valid(validate) }.valid(validate)
} }
fun TestApplicationEngine.`When I send a PUT request`(uri: String? = null, validate: Validate = Validate.ALL, setup: (TestApplicationRequest.() -> Unit)? = null): TestApplicationCall { fun TestApplicationEngine.`When I send a PUT request`(uri: String? = null, validate: BitMaskI = Validate.ALL, setup: (TestApplicationRequest.() -> Unit)? = null): TestApplicationCall {
return handleRequest(true) { return handleRequest(true) {
method = HttpMethod.Put method = HttpMethod.Put
if (uri != null) { if (uri != null) {