Clean Citizen entities
Change plainPassword to just password Add request Input for /login
This commit is contained in:
@@ -4,7 +4,9 @@ import fr.dcproject.common.utils.toUUID
|
||||
import fr.dcproject.component.article.ArticleForUpdate
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.dcproject.component.article.ArticleRepository
|
||||
import fr.dcproject.component.auth.UserForCreate
|
||||
import fr.dcproject.component.citizen.Citizen
|
||||
import fr.dcproject.component.citizen.CitizenForCreate
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRepository
|
||||
import fr.dcproject.component.comment.article.CommentArticleRepository
|
||||
@@ -16,7 +18,6 @@ import org.joda.time.DateTime
|
||||
import org.koin.test.KoinTest
|
||||
import org.koin.test.get
|
||||
import java.util.UUID
|
||||
import fr.dcproject.component.auth.User as UserEntity
|
||||
|
||||
class ArticleSteps : En, KoinTest {
|
||||
init {
|
||||
@@ -57,16 +58,16 @@ class ArticleSteps : En, KoinTest {
|
||||
} else {
|
||||
val first = "firstName" + UUID.randomUUID().toString()
|
||||
val last = "lastName" + UUID.randomUUID().toString()
|
||||
Citizen(
|
||||
CitizenForCreate(
|
||||
birthday = DateTime.now(),
|
||||
name = CitizenI.Name(
|
||||
first,
|
||||
last
|
||||
),
|
||||
email = "$first@fakeemail.com",
|
||||
user = UserEntity(username = username, plainPassword = "azerty")
|
||||
).also {
|
||||
get<CitizenRepository>().insertWithUser(it)
|
||||
user = UserForCreate(username = username, password = "azerty")
|
||||
).let {
|
||||
get<CitizenRepository>().insertWithUser(it) ?: error("Unable to create User")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package steps
|
||||
|
||||
import fr.dcproject.component.auth.User
|
||||
import fr.dcproject.component.citizen.Citizen
|
||||
import fr.dcproject.component.auth.UserForCreate
|
||||
import fr.dcproject.component.citizen.CitizenForCreate
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRepository
|
||||
import io.cucumber.datatable.DataTable
|
||||
@@ -40,12 +40,12 @@ class CitizenSteps : En, KoinTest {
|
||||
val id: UUID = id ?: params?.get("id")?.let { UUID.fromString(it) } ?: UUID.randomUUID()
|
||||
val email = params?.get("email") ?: ("$firstName-$lastName".toLowerCase()) + "@dc-project.fr"
|
||||
|
||||
val user = User(
|
||||
val user = UserForCreate(
|
||||
id = id,
|
||||
username = "$firstName-$lastName".toLowerCase(),
|
||||
plainPassword = "azerty"
|
||||
password = "azerty",
|
||||
)
|
||||
val citizen = Citizen(
|
||||
val citizen = CitizenForCreate(
|
||||
id = id,
|
||||
name = CitizenI.Name(firstName, lastName),
|
||||
email = email,
|
||||
|
||||
@@ -2,7 +2,9 @@ package steps
|
||||
|
||||
import fr.dcproject.common.utils.toUUID
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
import fr.dcproject.component.auth.UserForCreate
|
||||
import fr.dcproject.component.citizen.Citizen
|
||||
import fr.dcproject.component.citizen.CitizenForCreate
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRepository
|
||||
import fr.dcproject.component.citizen.CitizenWithUserI
|
||||
@@ -18,7 +20,6 @@ import org.joda.time.DateTime
|
||||
import org.koin.test.KoinTest
|
||||
import org.koin.test.get
|
||||
import java.util.UUID
|
||||
import fr.dcproject.component.auth.User as UserEntity
|
||||
|
||||
class ConstitutionSteps : En, KoinTest {
|
||||
init {
|
||||
@@ -55,16 +56,16 @@ class ConstitutionSteps : En, KoinTest {
|
||||
} else {
|
||||
val first = "firstName" + UUID.randomUUID().toString()
|
||||
val last = "lastName" + UUID.randomUUID().toString()
|
||||
Citizen(
|
||||
CitizenForCreate(
|
||||
birthday = DateTime.now(),
|
||||
name = CitizenI.Name(
|
||||
first,
|
||||
last
|
||||
),
|
||||
email = "$first@fakeemail.com",
|
||||
user = UserEntity(username = username, plainPassword = "azerty")
|
||||
).also {
|
||||
get<CitizenRepository>().insertWithUser(it)
|
||||
user = UserForCreate(username = username, password = "azerty")
|
||||
).let {
|
||||
get<CitizenRepository>().insertWithUser(it) ?: error("Unable to create User")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package steps
|
||||
|
||||
import fr.dcproject.common.utils.toUUID
|
||||
import fr.dcproject.component.auth.User
|
||||
import fr.dcproject.component.citizen.Citizen
|
||||
import fr.dcproject.component.auth.UserForCreate
|
||||
import fr.dcproject.component.citizen.CitizenForCreate
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.component.citizen.CitizenRepository
|
||||
@@ -39,17 +39,17 @@ class WorkgroupSteps : En, KoinTest {
|
||||
get<CitizenRepository>().findByUsername(it.toLowerCase().replace(' ', '-'))
|
||||
} ?: run {
|
||||
val username = "paul-langevin".toLowerCase() + UUID.randomUUID()
|
||||
val user = User(
|
||||
val user = UserForCreate(
|
||||
username = username,
|
||||
plainPassword = "azerty"
|
||||
password = "azerty",
|
||||
)
|
||||
Citizen(
|
||||
CitizenForCreate(
|
||||
name = CitizenI.Name("Paul", "Langevin"),
|
||||
email = "$username@dc-project.fr",
|
||||
birthday = DateTime.now(),
|
||||
user = user
|
||||
).also {
|
||||
get<CitizenRepository>().insertWithUser(it)
|
||||
).let {
|
||||
get<CitizenRepository>().insertWithUser(it) ?: error("Unable to create User")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@auth
|
||||
Feature: Auth routes
|
||||
|
||||
Scenario: The route for create citizen must response a 200 and return object
|
||||
Scenario: I can resiter
|
||||
When I send a POST request to "/register" with body:
|
||||
"""
|
||||
{
|
||||
@@ -9,7 +9,7 @@ Feature: Auth routes
|
||||
"birthday": "2001-01-01",
|
||||
"user":{
|
||||
"username": "george-junior",
|
||||
"plain_password": "azerty"
|
||||
"password": "azerty"
|
||||
},
|
||||
"email": "george-junior@gmail.com"
|
||||
}
|
||||
@@ -20,7 +20,7 @@ Feature: Auth routes
|
||||
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.
|
||||
"""
|
||||
|
||||
Scenario: The route for create citizen must response a 400 and return object
|
||||
Scenario: I cannot create user if no username was sent
|
||||
When I send a POST request to "/register" with body:
|
||||
"""
|
||||
{
|
||||
@@ -28,18 +28,19 @@ Feature: Auth routes
|
||||
"birthday": "2001-01-01",
|
||||
"user":{
|
||||
"username": "",
|
||||
"plain_password": ""
|
||||
"password": ""
|
||||
}
|
||||
}
|
||||
"""
|
||||
Then the response status code should be 400
|
||||
|
||||
Scenario: The route for create citizen must response a 200 and return object
|
||||
Scenario: I can login with username and password
|
||||
The route for create citizen must response a 200 and return object
|
||||
Given I have citizen Niels Bohr
|
||||
When I send a POST request to "/login" with body:
|
||||
"""
|
||||
{
|
||||
"name": "niels-bohr",
|
||||
"username": "niels-bohr",
|
||||
"password": "azerty"
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
@citizen
|
||||
Feature: citizens routes
|
||||
|
||||
Scenario: The route for get citizens must response a 200
|
||||
Scenario: I can get Citizens informations
|
||||
Given I have citizen Jean Perrin with ID "5267a5c6-af42-4a02-aa2b-6b71d2e43973"
|
||||
And I am authenticated as Jean Perrin
|
||||
When I send a GET request to "/citizens"
|
||||
Then the response status code should be 200
|
||||
|
||||
Scenario: The route for get one citizen must response a 200 and return citizen
|
||||
Scenario: I can get specific Citizen informations
|
||||
Given I have citizen Linus Pauling with ID "47a05c0f-7329-46c3-a7d0-325db37e9114"
|
||||
Given I am authenticated as Linus Pauling
|
||||
When I send a GET request to "/citizens/47a05c0f-7329-46c3-a7d0-325db37e9114"
|
||||
@@ -15,7 +15,7 @@ Feature: citizens routes
|
||||
And the response should contain object:
|
||||
| id | 47a05c0f-7329-46c3-a7d0-325db37e9114 |
|
||||
|
||||
Scenario: Can get connected citizen
|
||||
Scenario: I can get my citizen informations when I was connected
|
||||
Given I have citizen Henri Becquerel with ID "47356809-c8ef-4649-8b99-1c5cb9886d38"
|
||||
And I am authenticated as Henri Becquerel
|
||||
When I send a GET request to "/citizens/current"
|
||||
@@ -24,7 +24,7 @@ Feature: citizens routes
|
||||
| id | 47356809-c8ef-4649-8b99-1c5cb9886d38 |
|
||||
|
||||
@online
|
||||
Scenario: Can be connect with Passwordless auth
|
||||
Scenario: I can be connect with Passwordless auth
|
||||
Given I have citizen
|
||||
| id | c606110c-ff0e-4d09-a79e-74632d7bf7bd |
|
||||
| email | fabrice.lecomte.be@gmail.com |
|
||||
|
||||
@@ -4,7 +4,7 @@ declare
|
||||
wrong_citizen json;
|
||||
_user_id uuid := fixture_user();
|
||||
created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel@gmail.com"}';
|
||||
created_citizen_with_user json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel2@gmail.com", "user":{"username": "george junior", "plain_password": "azerty", "roles": ["ROLE_USER"]}}';
|
||||
created_citizen_with_user json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel2@gmail.com", "user":{"username": "george junior", "password": "azerty", "roles": ["ROLE_USER"]}}';
|
||||
selected_citizen json;
|
||||
begin
|
||||
created_citizen := jsonb_set(created_citizen::jsonb, '{user}'::text[], jsonb_build_object('id', _user_id::text), true)::json;
|
||||
|
||||
@@ -5,11 +5,11 @@ declare
|
||||
created_user json;
|
||||
begin
|
||||
if (name = 'george') then
|
||||
created_user = '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
created_user = '{"username": "george", "password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
elseif (name = 'john') then
|
||||
created_user = '{"username": "john", "plain_password": "qwerty", "roles": ["ROLE_USER"]}';
|
||||
created_user = '{"username": "john", "password": "qwerty", "roles": ["ROLE_USER"]}';
|
||||
elseif (name = 'tesla') then
|
||||
created_user = '{"username": "tesla", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
created_user = '{"username": "tesla", "password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
end if;
|
||||
|
||||
select insert_user(created_user) into created_user;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
do
|
||||
$$
|
||||
declare
|
||||
created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
created_user2 json := '{"username": "george2", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
created_user json := '{"username": "george", "password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
created_user2 json := '{"username": "george2", "password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
_citizen_id uuid;
|
||||
_citizen_id2 uuid;
|
||||
created_citizen json := $json$
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
do
|
||||
$$
|
||||
declare
|
||||
created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
created_user json := '{"username": "george", "password": "azerty", "roles": ["ROLE_USER"]}';
|
||||
user_with_other_password json;
|
||||
selected_user json;
|
||||
exist_user json;
|
||||
@@ -26,7 +26,7 @@ begin
|
||||
assert exist_user->>'password' is null, format('the function check_user must not be return the password, %s is return', exist_user::text);
|
||||
|
||||
-- test change password
|
||||
user_with_other_password = jsonb_set(created_user::jsonb, '{plain_password}', '"qwerty"'::jsonb);
|
||||
user_with_other_password = jsonb_set(created_user::jsonb, '{password}', '"qwerty"'::jsonb);
|
||||
perform change_user_password(user_with_other_password);
|
||||
select check_user('george', 'qwerty') into exist_user;
|
||||
assert exist_user->>'username' = 'george', format('the function change_user_password must change password: %s', exist_user::text);
|
||||
|
||||
Reference in New Issue
Block a user