camper/test/edit_season.sql

59 lines
2.5 KiB
MySQL
Raw Permalink Normal View History

-- Test edit_season
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(12);
select has_function('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean']);
select function_lang_is('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'sql');
select function_returns('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'uuid');
select isnt_definer('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean']);
select volatility_is('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'volatile');
select function_privs_are('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'guest', array[]::text[]);
select function_privs_are('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'employee', array[]::text[]);
select function_privs_are('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'admin', array['EXECUTE']);
select function_privs_are('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'authenticator', array[]::text[]);
set client_min_messages to warning;
truncate season 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')
;
insert into season (company_id, slug, name, color, active)
values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 'Low', to_integer('#232323'), true)
, (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 'High', to_integer('#323232'), false)
;
select lives_ok(
$$ select edit_season('87452b88-b48f-48d3-bb6c-0296de64164e', 'Very Low', '#1e1e1e', false) $$,
'Should be able to edit the first season'
);
select lives_ok(
$$ select edit_season('9b6370f7-f941-46f2-bc6e-de455675bd0a', 'Very High', '#9f9f9f', true) $$,
'Should be able to edit the second season'
);
select bag_eq(
$$ select slug::text, name, to_color(color)::text, active from season $$,
$$ values ('87452b88-b48f-48d3-bb6c-0296de64164e', 'Very Low', '#1e1e1e', false)
, ('9b6370f7-f941-46f2-bc6e-de455675bd0a', 'Very High', '#9f9f9f', true)
$$,
'Should have updated all seasons.'
);
select *
from finish();
rollback;