Add validation on route PutVoteOnComment

This commit is contained in:
2021-04-15 02:33:46 +02:00
parent 0588f88f9a
commit 367f59ee18
3 changed files with 63 additions and 5 deletions

View File

@@ -181,4 +181,39 @@ class `Vote routes` : BaseTest() {
}
}
}
@TestFactory
@Tag("BadRequest")
fun `I cannot vote comment with wrong request`(): List<DynamicTest> {
withIntegrationApplication {
`Given I have citizen`("Antoine", "Lavoisier")
`Given I have article`(id = "835c5101-ca39-4038-a4e6-da6ee62ca6d5")
`Given I have comment on article`(
createdBy = Name("Antoine", "Lavoisier"),
article = "835c5101-ca39-4038-a4e6-da6ee62ca6d5",
id = "e793eccc-456b-4450-a292-46d592229b74",
)
}
return listOf(-10, -2, +2, +10).map { note ->
DynamicTest.dynamicTest("""I can vote comment with note "$note"""") {
withIntegrationApplication {
`When I send a PUT request`("/comments/e793eccc-456b-4450-a292-46d592229b74/vote", ALL - REQUEST_BODY) {
`authenticated as`("Antoine", "Lavoisier")
`with body`(
"""
{
"note": $note
}
"""
)
} `Then the response should be` BadRequest and {
`And the response should not be null`()
`And the response should contain`("$.invalidParams[0].name", ".note")
`And the response should contain`("$.invalidParams[0].reason", if (note > 0) "must be at most '1'" else "must be at least '-1'")
}
}
}
}
}
}