feature #4: create procedure for user
This commit is contained in:
31
resources/tests/user.sql
Normal file
31
resources/tests/user.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
do
|
||||
$$
|
||||
declare
|
||||
created_user json := '{"username": "george", "plain_password": "azerty"}';
|
||||
selected_user json;
|
||||
exist_user json;
|
||||
begin
|
||||
call insert_user(created_user);
|
||||
assert created_user->>'username' = 'george', 'username must be george';
|
||||
assert created_user->>'password' is not null, 'password must be generated';
|
||||
|
||||
call find_user_by_id((created_user->>'id')::uuid, selected_user);
|
||||
assert selected_user->>'username' = 'george', 'username must be george';
|
||||
|
||||
call find_user_by_username(created_user->>'username', selected_user);
|
||||
assert selected_user->>'username' = 'george', 'username must be george';
|
||||
|
||||
select check_user('george', 'azerty') into exist_user;
|
||||
assert exist_user is not null, format('the function check_user must be return user object if username and password is correct, %s is return', exist_user::text);
|
||||
assert exist_user->>'username' = 'george', format('the function check_user must be return user object with username is "george", %s is return', exist_user::text);
|
||||
assert exist_user->>'password' is null, format('the function check_user must not be return the password, %s is return', exist_user::text);
|
||||
|
||||
delete from "user" where username = 'george';
|
||||
|
||||
select check_user('george', 'azerty') into exist_user;
|
||||
assert exist_user is null, format('the function check_user must be return null if user not exist, %s is return', exist_user::text);
|
||||
|
||||
raise notice 'user test pass';
|
||||
end;
|
||||
$$;
|
||||
|
||||
Reference in New Issue
Block a user