#29 Implement Workgroup (route, voter, repo, entity)

Create tests for workgroup routes
add CitizenWithUserI
This commit is contained in:
2020-03-13 21:05:09 +01:00
parent dc034f7c51
commit 27232c5ca9
9 changed files with 399 additions and 9 deletions

View File

@@ -0,0 +1,53 @@
package feature
import fr.dcproject.entity.*
import io.cucumber.datatable.DataTable
import io.cucumber.java8.En
import org.joda.time.DateTime
import org.koin.test.KoinTest
import org.koin.test.get
import java.util.*
import fr.dcproject.repository.Citizen as CitizenRepository
import fr.dcproject.repository.Workgroup as WorkgroupRepository
class WorkgroupSteps : En, KoinTest {
init {
When("I have workgroup:") { body: DataTable ->
val data = body.asMap<String, String>(String::class.java, String::class.java)
val creator = if (data["created_by"] != null) {
CitizenRef(UUID.fromString(data["created_by"]))
} else {
val username = "paul-langevin".toLowerCase() + UUID.randomUUID()
val user = User(
username = username,
plainPassword = "azerty"
)
Citizen(
name = CitizenI.Name("Paul", "Langevin"),
email = "$username@dc-project.fr",
birthday = DateTime.now(),
user = user
).also {
get<CitizenRepository>().insertWithUser(it)
}
}
val owner = if (data["owner"] != null) {
CitizenRef(UUID.fromString(data["owner"]))
} else {
creator
}
val workgroup = WorkgroupSimple(
id = UUID.fromString(data["id"] ?: UUID.randomUUID().toString()),
name = data["name"] ?: "Les Incoruptible",
description = data["description"] ?: "La vie est notre jeux",
createdBy = creator,
owner = owner,
anonymous = (data["anonymous"] ?: false) == true
)
get<WorkgroupRepository>().upsert(workgroup)
}
}
}

View File

@@ -0,0 +1,44 @@
@workgroup
Feature: Workgroup
Scenario: Can get one workgroup
Given I have citizen Stephen Hawking
And I am authenticated as Stephen Hawking
And I have workgroup:
| id | ab469134-bf14-4856-b093-ae1aa990f977 |
| name | Les Mousquets |
When I send a GET request to "/workgroups/ab469134-bf14-4856-b093-ae1aa990f977"
Then the response status code should be 200
And the JSON should contain:
| id | ab469134-bf14-4856-b093-ae1aa990f977 |
| name | Les Mousquets |
Scenario: Can create a workgroup
Given I have citizen Werner Heisenberg
And I am authenticated as Werner Heisenberg
When I send a POST request to "/workgroups" with body:
"""
{
"id":"f496d86d-6654-4068-91ff-90e1dbcc5f38",
"name":"Les Bouffons",
"description":"La vie est belle",
"anonymous":false
}
"""
Then the response status code should be 201
And the JSON should contain:
| id | f496d86d-6654-4068-91ff-90e1dbcc5f38 |
| name | Les Bouffons |
| description | La vie est belle |
| anonymous | false |
Scenario: Can get workgroups list
Given I have citizen Max Planck
And I am authenticated as Max Planck
And I have workgroup:
| id | 3fd8edb6-c4b4-4c94-bc75-ddd9b290d32c |
| name | Les Pissenlits |
When I send a GET request to "/workgroups"
Then the response status code should be 200
And the response should contain object:
| $.result[0]id | 3fd8edb6-c4b4-4c94-bc75-ddd9b290d32c |