feature #14: Add routes for get follows of one citizen

This commit is contained in:
2019-08-21 13:37:16 +02:00
parent 9b2b5e681f
commit 4e9f737e00
11 changed files with 179 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
package feature
import com.google.gson.Gson
import com.google.gson.JsonParser
import cucumber.api.java8.En
import fr.dcproject.entity.Citizen
import fr.dcproject.entity.User
@@ -21,6 +22,7 @@ import org.koin.test.inject
import org.opentest4j.AssertionFailedError
import java.util.*
import kotlin.random.Random
import kotlin.test.assertTrue
import kotlin.test.asserter
import feature.Context.Companion.current as currentContext
@@ -103,14 +105,11 @@ class Request: En, KoinTest {
And("the response should contain object:") { expected: DataTable ->
val call: TestApplicationCall = currentContext.call ?: throw AssertionFailedError("No call")
val p = call.response
val response = Gson().fromJson<Map<String, String>>(p.content, Map::class.java)
val response = JsonParser().parse(p.content).getAsJsonObject()
expected.asMap<String, String>(String::class.java, String::class.java).forEach { (key, value) ->
if (response.containsKey(key)) {
assertEquals(value, response[key])
return@And
}
asserter.fail("The response not contain $key field")
expected.asMap<String, String>(String::class.java, String::class.java).forEach { (key, valueExpected) ->
assertTrue(response.has(key))
assertEquals(valueExpected, response.get(key).asString)
}
}
}

View File

@@ -9,6 +9,17 @@ Feature: follow Article and Constitution
When I send a "POST" request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/follow"
Then the response status code should be 201
Scenario: The route for get follows of articles must response a 200 and return objects
Given I have citizen:
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
| firstName | Jaque |
| lastName | Dupuis |
When I send a "GET" request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/follows/articles"
Then the response status code should be 200
And the response should contain object:
| current_page | 1 |
| limit | 50 |
Scenario: The route for unfollow article must response a 204
Given I have citizen:
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
@@ -26,6 +37,17 @@ Feature: follow Article and Constitution
When I send a "POST" request to "/constitutions/72aa1ee1-4963-eb44-c9e0-5ce6e0f18f00/follow"
Then the response status code should be 201
Scenario: The route for get follows of constitutions must response a 200 and return objects
Given I have citizen:
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
| firstName | Jaque |
| lastName | Dupuis |
When I send a "GET" request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/follows/constitutions"
Then the response status code should be 200
And the response should contain object:
| current_page | 1 |
| limit | 50 |
Scenario: The route for unfollow constitution must response a 204
Given I have citizen:
| id | 64b7b379-2298-43ec-b428-ba134930cabd |