55 lines
1.8 KiB
MySQL
55 lines
1.8 KiB
MySQL
|
-- Test ensure_role_exists
|
||
|
set client_min_messages to warning;
|
||
|
create extension if not exists pgtap;
|
||
|
reset client_min_messages;
|
||
|
|
||
|
begin;
|
||
|
|
||
|
select plan(14);
|
||
|
|
||
|
set search_path to auth, public;
|
||
|
|
||
|
select has_function('ensure_role_exists');
|
||
|
select function_lang_is('ensure_role_exists', array []::name[], 'plpgsql');
|
||
|
select function_returns('ensure_role_exists', array []::name[], 'trigger');
|
||
|
select isnt_definer('ensure_role_exists', array []::name[]);
|
||
|
select volatility_is('ensure_role_exists', array []::name[], 'volatile');
|
||
|
select function_privs_are('ensure_role_exists', array []::name[], 'guest', array []::text[]);
|
||
|
select function_privs_are('ensure_role_exists', array []::name[], 'invoicer', array []::text[]);
|
||
|
select function_privs_are('ensure_role_exists', array []::name[], 'admin', array []::text[]);
|
||
|
select function_privs_are('ensure_role_exists', array []::name[], 'authenticator', array []::text[]);
|
||
|
|
||
|
select trigger_is('user', 'ensure_role_exists', 'ensure_role_exists');
|
||
|
|
||
|
set client_min_messages to warning;
|
||
|
truncate "user" cascade;
|
||
|
reset client_min_messages;
|
||
|
|
||
|
select lives_ok(
|
||
|
$$ insert into "user" (email, name, password, role) values ('info@tandem.blog', 'Factura', 'test', 'guest') $$,
|
||
|
'Should be able to insert a user with a valid role'
|
||
|
);
|
||
|
|
||
|
select throws_ok(
|
||
|
$$ insert into "user" (email, name, password, role) values ('nope@tandem.blog', 'Factura', 'test', 'non-existing-role') $$,
|
||
|
'23503',
|
||
|
'role not found: non-existing-role',
|
||
|
'Should not allow insert users with invalid roles'
|
||
|
);
|
||
|
|
||
|
select lives_ok($$ update "user" set role = 'invoicer' where email = 'info@tandem.blog' $$,
|
||
|
'Should be able to change the role of a user to another valid role'
|
||
|
);
|
||
|
|
||
|
select throws_ok($$ update "user" set role = 'usurer' where email = 'info@tandem.blog' $$,
|
||
|
'23503',
|
||
|
'role not found: usurer',
|
||
|
'Should not allow update users to invalid roles'
|
||
|
);
|
||
|
|
||
|
|
||
|
select *
|
||
|
from finish();
|
||
|
|
||
|
rollback;
|