-- Test edit_payment_account_other set client_min_messages to warning; create extension if not exists pgtap; reset client_min_messages; begin; select plan(13); set search_path to numerus, public; select has_function('numerus', 'edit_payment_account_other', array['uuid', 'text']); select function_lang_is('numerus', 'edit_payment_account_other', array['uuid', 'text'], 'sql'); select function_returns('numerus', 'edit_payment_account_other', array['uuid', 'text'], 'uuid'); select isnt_definer('numerus', 'edit_payment_account_other', array['uuid', 'text']); select volatility_is('numerus', 'edit_payment_account_other', array['uuid', 'text'], 'volatile'); select function_privs_are('numerus', 'edit_payment_account_other', array['uuid', 'text'], 'guest', array []::text[]); select function_privs_are('numerus', 'edit_payment_account_other', array['uuid', 'text'], 'invoicer', array ['EXECUTE']); select function_privs_are('numerus', 'edit_payment_account_other', array['uuid', 'text'], 'admin', array ['EXECUTE']); select function_privs_are('numerus', 'edit_payment_account_other', array['uuid', 'text'], 'authenticator', array []::text[]); set client_min_messages to warning; truncate payment_account cascade; truncate payment_method cascade; truncate company cascade; reset client_min_messages; set constraints "company_default_payment_method_id_fkey" deferred; insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111) ; insert into payment_method (payment_method_id, company_id, name, instructions) values (111, 1, 'cash', 'cash') ; set constraints "company_default_payment_method_id_fkey" immediate; insert into payment_account (payment_account_id, company_id, slug, payment_account_type, name) values (11, 1, '81c478ab-395c-44aa-a5b4-3489e5349a0b', 'other', 'Other 1') , (12, 1, '84e84788-54f1-4796-b93d-dfa2c9adc072', 'other', 'Other 2') , (13, 1, 'afb774a5-0c38-480c-bef2-fe03465071cd', 'cash', 'Cash') ; select lives_ok( $$ select edit_payment_account_other('81c478ab-395c-44aa-a5b4-3489e5349a0b', 'Something') $$, 'Should be able to edit the first other payment account' ); select lives_ok ( $$ select edit_payment_account_other('84e84788-54f1-4796-b93d-dfa2c9adc072', 'And something else') $$, 'Should be able to edit the second other payment account' ); select results_eq ( $$ select edit_payment_account_other('afb774a5-0c38-480c-bef2-fe03465071cd', 'Huh?')::text $$, $$ values (null::text) $$, 'Should do nothing to an account that is not of type other' ); select bag_eq( $$ select payment_account_id, payment_account_type::text, name from payment_account $$, $$ values (11, 'other', 'Something') , (12, 'other', 'And something else') , (13, 'cash', 'Cash') $$, 'Should have update all other payment accounts' ); select * from finish(); rollback;