camper/test/order_services.sql

61 lines
2.0 KiB
PL/PgSQL

-- Test order_services
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(11);
set search_path to camper, public;
select has_function('camper', 'order_services', array['integer[]']);
select function_lang_is('camper', 'order_services', array['integer[]'], 'sql');
select function_returns('camper', 'order_services', array['integer[]'], 'void');
select isnt_definer('camper', 'order_services', array['integer[]']);
select volatility_is('camper', 'order_services', array['integer[]'], 'volatile');
select function_privs_are('camper', 'order_services', array ['integer[]'], 'guest', array[]::text[]);
select function_privs_are('camper', 'order_services', array ['integer[]'], 'employee', array[]::text[]);
select function_privs_are('camper', 'order_services', array ['integer[]'], 'admin', array['EXECUTE']);
select function_privs_are('camper', 'order_services', array ['integer[]'], 'authenticator', array[]::text[]);
set client_min_messages to warning;
truncate service 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, country_code, currency_code, default_lang_tag)
values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 'ES', 'EUR', 'ca')
;
insert into service (service_id, company_id, icon_name, name, description)
values (4, 1, 'baby', '1', '<p>a</p>')
, (5, 1, 'nopet', '2', '<p>b</p>')
, (6, 1, 'castle', '3', '<p>c</p>')
, (7, 1, 'area', '4', '<p>d</p>')
, (8, 1, 'campfire', '5', '<p>e</p>')
;
select lives_ok(
$$ select order_services('{6,8,7,4,5}') $$,
'Should be able to sort services using their ID'
);
select bag_eq(
$$ select service_id, position from service $$,
$$ values (6, 1)
, (8, 2)
, (7, 3)
, (4, 4)
, (5, 5)
$$,
'Should have sorted all services.'
);
select *
from finish();
rollback;