2023-09-14 23:23:51 +00:00
|
|
|
-- Test translate_campsite_type
|
|
|
|
set client_min_messages to warning;
|
|
|
|
create extension if not exists pgtap;
|
|
|
|
reset client_min_messages;
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
select plan(13);
|
|
|
|
|
|
|
|
set search_path to camper, public;
|
|
|
|
|
2024-01-22 19:19:19 +00:00
|
|
|
select has_function('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text']);
|
|
|
|
select function_lang_is('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'sql');
|
|
|
|
select function_returns('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'void');
|
|
|
|
select isnt_definer('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text']);
|
|
|
|
select volatility_is('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'volatile');
|
|
|
|
select function_privs_are('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'guest', array[]::text[]);
|
|
|
|
select function_privs_are('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'employee', array[]::text[]);
|
|
|
|
select function_privs_are('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'admin', array['EXECUTE']);
|
|
|
|
select function_privs_are('camper', 'translate_campsite_type', array['uuid', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'authenticator', array[]::text[]);
|
2023-09-14 23:23:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
set client_min_messages to warning;
|
|
|
|
truncate campsite_type cascade;
|
|
|
|
truncate media cascade;
|
Manage all media uploads in a single place
It made no sense to have a file upload in each form that needs a media,
because to reuse an existing media users would need to upload the exact
same file again; this is very unusual and unfriendly.
A better option is to have a “centralized” media section, where people
can upload files there, and then have a picker to select from there.
Ideally, there would be an upload option in the picker, but i did not
add it yet.
I’ve split the content from the media because i want users to have the
option to update a media, for instance when they need to upload a
reduced or cropped version of the same photo, without an edit they would
need to upload the file as a new media and then update all places where
the old version was used. And i did not want to trouble people that
uploads the same photo twice: without the separate relation, doing so
would throw a constraint error.
I do not believe there is any security problem to have all companies
link their media to the same file, as they were already readable by
everyone and could upload the data from a different company to their
own; in other words, it is not worse than it was now.
2023-09-20 23:56:44 +00:00
|
|
|
truncate media_content cascade;
|
2023-09-14 23:23:51 +00:00
|
|
|
truncate company cascade;
|
|
|
|
reset client_min_messages;
|
|
|
|
|
2024-02-27 18:45:47 +00:00
|
|
|
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')
|
2023-09-14 23:23:51 +00:00
|
|
|
;
|
|
|
|
|
Manage all media uploads in a single place
It made no sense to have a file upload in each form that needs a media,
because to reuse an existing media users would need to upload the exact
same file again; this is very unusual and unfriendly.
A better option is to have a “centralized” media section, where people
can upload files there, and then have a picker to select from there.
Ideally, there would be an upload option in the picker, but i did not
add it yet.
I’ve split the content from the media because i want users to have the
option to update a media, for instance when they need to upload a
reduced or cropped version of the same photo, without an edit they would
need to upload the file as a new media and then update all places where
the old version was used. And i did not want to trouble people that
uploads the same photo twice: without the separate relation, doing so
would throw a constraint error.
I do not believe there is any security problem to have all companies
link their media to the same file, as they were already readable by
everyone and could upload the data from a different company to their
own; in other words, it is not worse than it was now.
2023-09-20 23:56:44 +00:00
|
|
|
insert into media_content (media_type, bytes)
|
|
|
|
values ('image/x-xpixmap', 'static char *s[]={"1 1 1 1","a c #ffffff","a"};')
|
|
|
|
, ('image/x-xpixmap', 'static char *s[]={"1 1 1 1","a c #ff00ff","a"};')
|
|
|
|
, ('image/x-xpixmap', 'static char *s[]={"1 1 1 1","a c #ffff00","a"};')
|
|
|
|
;
|
|
|
|
|
|
|
|
insert into media (media_id, company_id, original_filename, content_hash)
|
|
|
|
values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};'))
|
|
|
|
, (3, 1, 'cover3.xpm', sha256('static char *s[]={"1 1 1 1","a c #ff00ff","a"};'))
|
|
|
|
, (4, 1, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffff00","a"};'))
|
2023-09-14 23:23:51 +00:00
|
|
|
;
|
|
|
|
|
Add campsite_type_pet_cost relation to hold price of dogs in campsites
It is a separate relation, instead of having a field in campsite_type,
because not all campsite types allow dogs. I could have added a new
field to campsite_type, but then its values it would be meaningless for
campsites that do not allow dogs, and a nullable field is not a valid
solution because NULL means “unknown”, but we **do** know the price —
none.
A separate relation encodes the same information without ambiguities nor
null values, and, in fact, removed the dogs_allowed field from
campsite_type to prevent erroneous status, such as a campsite type that
allows dogs without having a cost — even if the cost is zero, it has to
be added to the new relation.
2024-02-10 05:18:30 +00:00
|
|
|
insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, active, max_campers, bookable_nights)
|
|
|
|
values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '<h2>One</h2>', '<p>Features A</p>', '<p>Pricing A</p>', '<p>A</p>', '<p>Additional A</p>', '', '', true, 4, '[1, 7]')
|
|
|
|
, (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', '<h2>Two</h2>', '<p>Features B</p>', '<p>Pricing B</p>', '<p>B</p>', '<p>Additional B</p>', '', '', false, 5, '[2, 6]')
|
2023-09-14 23:23:51 +00:00
|
|
|
;
|
|
|
|
|
2024-01-22 19:19:19 +00:00
|
|
|
insert into campsite_type_i18n (campsite_type_id, lang_tag, name, spiel, info, facilities, description, additional_info, check_in, check_out)
|
|
|
|
select campsite_type_id, 'ca', 'tipusb', '<h2>dos</h2>', '<p>característiques b</p>', '<p>preus b</p>', '<p>B</p>', '<p>B addicional</p>', 'entrada', 'sortida' from campsite_type
|
2023-09-14 23:23:51 +00:00
|
|
|
where slug = '9b6370f7-f941-46f2-bc6e-de455675bd0a'
|
|
|
|
;
|
|
|
|
|
|
|
|
select lives_ok(
|
2024-01-22 19:19:19 +00:00
|
|
|
$$ select translate_campsite_type('87452b88-b48f-48d3-bb6c-0296de64164e', 'ca', 'Tipus A', null, '<p>Característiques A</p>', null, '<p>a</p>', null, 'CI1', null) $$,
|
2023-09-14 23:23:51 +00:00
|
|
|
'Should be able to translate the first type'
|
|
|
|
);
|
|
|
|
|
|
|
|
select lives_ok(
|
2024-01-22 19:19:19 +00:00
|
|
|
$$ select translate_campsite_type('9b6370f7-f941-46f2-bc6e-de455675bd0a', 'es', 'Tipo B', '<h2>Dos</h2>', null, '<p>Precios B</p>', null, '<p>B adicional</p>', null, 'CO2') $$,
|
2023-09-14 23:23:51 +00:00
|
|
|
'Should be able to translate the second type'
|
|
|
|
);
|
|
|
|
|
|
|
|
select lives_ok(
|
2024-01-22 19:19:19 +00:00
|
|
|
$$ select translate_campsite_type('9b6370f7-f941-46f2-bc6e-de455675bd0a', 'ca', 'Tipus B', '<h2>Dos</h2>', '<p>Característiques B</p>', '<p>Preus B</p>', '<p>2</p>', '<p>2 addicional</p>', 'E2', 'S2') $$,
|
2023-10-13 11:40:48 +00:00
|
|
|
'Should be able to overwrite the catalan translation of the second type'
|
2023-09-14 23:23:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
select bag_eq(
|
2024-01-22 19:19:19 +00:00
|
|
|
$$ select slug::text, lang_tag, i18n.name, i18n.spiel::text, i18n.info::text, i18n.facilities::text, i18n.description::text, i18n.additional_info::text, i18n.check_in, i18n.check_out from campsite_type_i18n as i18n join campsite_type using (campsite_type_id) $$,
|
|
|
|
$$ values ('87452b88-b48f-48d3-bb6c-0296de64164e', 'ca', 'Tipus A', '', '<p>Característiques A</p>', '', '<p>a</p>', '', 'CI1', '')
|
|
|
|
, ('9b6370f7-f941-46f2-bc6e-de455675bd0a', 'ca', 'Tipus B', '<h2>Dos</h2>', '<p>Característiques B</p>', '<p>Preus B</p>', '<p>2</p>', '<p>2 addicional</p>', 'E2', 'S2')
|
|
|
|
, ('9b6370f7-f941-46f2-bc6e-de455675bd0a', 'es', 'Tipo B', '<h2>Dos</h2>', '', '<p>Precios B</p>', '', '<p>B adicional</p>', '', 'CO2')
|
2023-09-14 23:23:51 +00:00
|
|
|
$$,
|
|
|
|
'Should have added and updated all translations.'
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
select *
|
|
|
|
from finish();
|
|
|
|
|
|
|
|
rollback;
|