camper/test/add_campsite_type.sql

74 lines
4.4 KiB
PL/PgSQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Test add_campsite_type
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
set search_path to camper, public;
select plan(13);
select has_function('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean']);
select function_lang_is('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean'], 'sql');
select function_returns('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean'], 'uuid');
select isnt_definer('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean']);
select volatility_is('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean'], 'volatile');
select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean'], 'guest', array[]::text[]);
select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean'], 'employee', array[]::text[]);
select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean'], 'admin', array['EXECUTE']);
select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean'], 'authenticator', array[]::text[]);
set client_min_messages to warning;
truncate campsite_type_i18n cascade;
truncate campsite_type cascade;
truncate media cascade;
truncate media_content cascade;
truncate company cascade;
reset client_min_messages;
insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, rtc_number, tourist_tax, tourist_tax_max_days, country_code, currency_code, default_lang_tag)
values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 60, 7, 'ES', 'EUR', 'ca')
, (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', '', 60, 7, 'FR', 'USD', 'ca')
;
insert into media_content (media_type, bytes)
values ('image/x-xpixmap', 'static char *s[]={"1 1 1 1","a c #ffffff","a"};')
;
insert into media (media_id, company_id, original_filename, content_hash)
values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};'))
, (4, 2, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};'))
;
select lives_ok(
$$ select add_campsite_type(1, 3, 'Type A', '', '<p>Features</p>', '', '<!-- block --><h2>This is what, exactly?</h2><!-- /block --><p>Dunno</p>', '', 'After 4 p.m.', '12 a.m.', 5, '[1, 7]', false, true) $$,
'Should be able to add a campsite type to the first company'
);
select lives_ok(
$$ select add_campsite_type(2, 4, 'Type B', '<p>One</p><p>Two</p>', '', '<p>Pricing</p>', '', '<p>More</p>', 'After 9 p.m.', '9 a.m.', 2, '(1, 7)', true, false) $$,
'Should be able to add a campsite type to the second company'
);
select bag_eq(
$$ select company_id, media_id, name, spiel::text, info::text, facilities::text, description::text, additional_info::text, check_in, check_out, active, max_campers, bookable_nights, overflow_allowed, ask_zone_preferences from campsite_type $$,
$$ values (1, 3, 'Type A', '', '<p>Features</p>', '', '<!-- block --><h2>This is what, exactly?</h2><!-- /block --><p>Dunno</p>', '', 'After 4 p.m.', '12 a.m.', true, 5, int4range(1, 8), false, true)
, (2, 4, 'Type B', '<p>One</p><p>Two</p>', '', '<p>Pricing</p>', '', '<p>More</p>', 'After 9 p.m.', '9 a.m.', true, 2, int4range(2, 7), true, false)
$$,
'Should have added all two campsite type'
);
select is_empty(
$$ select * from campsite_type_i18n $$,
'Should not have added any translation for campsite types.'
);
select *
from finish();
rollback;