numerus/test/attach_to_payment.sql

81 lines
3.5 KiB
MySQL
Raw Normal View History

2024-08-11 22:08:18 +00:00
-- Test attach_to_payment
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(12);
set search_path to numerus, public;
select has_function('numerus', 'attach_to_payment', array['uuid', 'text', 'text', 'bytea']);
select function_lang_is('numerus', 'attach_to_payment', array['uuid', 'text', 'text', 'bytea'], 'sql');
select function_returns('numerus', 'attach_to_payment', array['uuid', 'text', 'text', 'bytea'], 'void');
select isnt_definer('numerus', 'attach_to_payment', array['uuid', 'text', 'text', 'bytea']);
select volatility_is('numerus', 'attach_to_payment', array['uuid', 'text', 'text', 'bytea'], 'volatile');
select function_privs_are('numerus', 'attach_to_payment', array ['uuid', 'text', 'text', 'bytea'], 'guest', array []::text[]);
select function_privs_are('numerus', 'attach_to_payment', array ['uuid', 'text', 'text', 'bytea'], 'invoicer', array ['EXECUTE']);
select function_privs_are('numerus', 'attach_to_payment', array ['uuid', 'text', 'text', 'bytea'], 'admin', array ['EXECUTE']);
select function_privs_are('numerus', 'attach_to_payment', array ['uuid', 'text', 'text', 'bytea'], 'authenticator', array []::text[]);
set client_min_messages to warning;
truncate payment_attachment cascade;
truncate payment cascade;
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, payment_account_type, name)
values (11, 1, 'cash', 'Cash 1')
, (12, 1, 'cash', 'Cash 2')
, (13, 1, 'other', 'Other')
;
insert into payment (payment_id, company_id, slug, description, payment_date, payment_account_id, amount, currency_code, payment_status)
values (16, 1, '7ac3ae0e-b0c1-4206-a19b-0be20835edd4', 'Payment 1', '2023-05-04', 12, 111, 'EUR', 'complete')
, (17, 1, 'b57b980b-247b-4be4-a0b7-03a7819c53ae', 'Payment 2', '2023-05-05', 13, 100, 'EUR', 'partial')
;
insert into payment_attachment (payment_id, original_filename, mime_type, content)
values (17, 'something.txt', 'text/plain', convert_to('Once upon a time…', 'UTF-8'))
;
select lives_ok(
$$ select attach_to_payment('7ac3ae0e-b0c1-4206-a19b-0be20835edd4', 'payment.txt', 'text/plain', convert_to('To pay 42 ', 'UTF-8')) $$,
'Should be able to attach a document to the first payment'
);
select lives_ok(
$$ select attach_to_payment('b57b980b-247b-4be4-a0b7-03a7819c53ae', 'payment.html', 'text/html', convert_to('<html><p>To pay 42 €</p></html>', 'UTF-8')) $$,
'Should be able to replate the second payments attachment with a new document'
);
select bag_eq(
$$ select payment_id, original_filename, mime_type, convert_from(content, 'UTF-8') from payment_attachment $$,
$$ values (16, 'payment.txt', 'text/plain', 'To pay 42 ')
, (17, 'payment.html', 'text/html', '<html><p>To pay 42 €</p></html>')
$$,
'Should have attached all documents'
);
select *
from finish();
rollback;