diff --git a/demo/demo.sql b/demo/demo.sql index d8ccf4f..bea7c69 100644 --- a/demo/demo.sql +++ b/demo/demo.sql @@ -127,11 +127,11 @@ select translate_services_carousel_slide(63, 'en', 'Safari Tents'); select translate_services_carousel_slide(63, 'es', 'Tiendas Safari'); alter table campsite_type alter column campsite_type_id restart with 72; -select add_campsite_type(52, 62, 'Parceŀles', '
Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Parcel·les amples amb serveis a prop d’on ets per fer allò que vols.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 6, '[1, 7]', true, true, true); -select add_campsite_type(52, 63, 'Safari Tents', 'Un luxe de tendes per viure aventures.
Dues tendes amb terra de fusta, llits, cuina i tot de comoditats per gaudir de les teves vacances.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '16 h a 21 h', '10 h', 6, '[2, 7]', false, false, false); -select add_campsite_type(52, 64, 'Bungalous', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false, false); -select add_campsite_type(52, 65, 'Bungalous prèmium', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false, false); -select add_campsite_type(52, 66, 'Cabanes de fusta', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false, false); +select add_campsite_type(52, 62, 'Parceŀles', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Parcel·les amples amb serveis a prop d’on ets per fer allò que vols.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 6, '[1, 7]', true, true); +select add_campsite_type(52, 63, 'Safari Tents', 'Un luxe de tendes per viure aventures.
Dues tendes amb terra de fusta, llits, cuina i tot de comoditats per gaudir de les teves vacances.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '16 h a 21 h', '10 h', 6, '[2, 7]', false, false); +select add_campsite_type(52, 64, 'Bungalous', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false); +select add_campsite_type(52, 65, 'Bungalous prèmium', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false); +select add_campsite_type(52, 66, 'Cabanes de fusta', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false); insert into campsite_type_i18n (campsite_type_id, lang_tag, name, spiel, info, facilities, description, additional_info, check_in, check_out) values (72, 'en', 'Plots', 'Located on the campground’s mountain-side and overlooking the nature that surrounds us.
Large plots with serivces close to where you are to do what you want.
', '* Towels: extra cost
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '3 p.m. to 9 p.m.', '12 a.m.') @@ -146,6 +146,8 @@ values (72, 'en', 'Plots', 'Located on t , (76, 'es', 'Cabañas de madera', '
Ubicadas al lado montaña del camping y con vista a la naturaleza que nos rodea.
Dos cabañas de madera maciza de dos plantas y con porche cubierto para disfutrar entre árboles.
', '* Toallas: precio extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h') ; +select set_campsite_type_pet_cost (slug, '3.50') from campsite_type where campsite_type_id = 72; + alter table campsite_type_feature alter column campsite_type_feature_id restart with 82; insert into campsite_type_feature (campsite_type_id, icon_name, name) values (72, 'person', 'Máx. 5 pers.') diff --git a/deploy/add_campsite_type.sql b/deploy/add_campsite_type.sql index b7bf62a..f745d9f 100644 --- a/deploy/add_campsite_type.sql +++ b/deploy/add_campsite_type.sql @@ -13,16 +13,16 @@ set search_path to camper, public; drop function if exists add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean); -create or replace function add_campsite_type(company integer, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, bookable_nights int4range, dogs_allowed boolean, overflow_allowed boolean, ask_zone_preferences boolean) returns uuid as +create or replace function add_campsite_type(company integer, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, bookable_nights int4range, overflow_allowed boolean, ask_zone_preferences boolean) returns uuid as $$ - insert into campsite_type (company_id, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences) - values (company, media_id, name, xmlparse(content spiel), xmlparse(content info), xmlparse(content facilities), xmlparse(content description), xmlparse(content additional_info), check_in, check_out, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences) + insert into campsite_type (company_id, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, bookable_nights, overflow_allowed, ask_zone_preferences) + values (company, media_id, name, xmlparse(content spiel), xmlparse(content info), xmlparse(content facilities), xmlparse(content description), xmlparse(content additional_info), check_in, check_out, max_campers, bookable_nights, overflow_allowed, ask_zone_preferences) returning slug; $$ language sql ; -revoke execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean) from public; -grant execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean) to admin; +revoke execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean) from public; +grant execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean) to admin; commit; diff --git a/deploy/campsite_type__-dogs_allowed.sql b/deploy/campsite_type__-dogs_allowed.sql new file mode 100644 index 0000000..8a82ad2 --- /dev/null +++ b/deploy/campsite_type__-dogs_allowed.sql @@ -0,0 +1,19 @@ +-- Deploy camper:campsite_type__-dogs_allowed to pg +-- requires: campsite_type +-- requires: campsite_type_pet_cost +-- requires: set_campsite_type_pet_cost + +begin; + +set search_path to camper, public; + +select set_campsite_type_pet_cost(slug, '3.50') +from campsite_type +where dogs_allowed +; + +alter table campsite_type +drop column if exists dogs_allowed +; + +commit; diff --git a/deploy/campsite_type_pet_cost.sql b/deploy/campsite_type_pet_cost.sql new file mode 100644 index 0000000..04e6a54 --- /dev/null +++ b/deploy/campsite_type_pet_cost.sql @@ -0,0 +1,52 @@ +-- Deploy camper:campsite_type_pet_cost to pg +-- requires: roles +-- requires: schema_camper +-- requires: campsite_type +-- requires: user_profile + +begin; + +set search_path to camper, public; + +create table campsite_type_pet_cost ( + campsite_type_id integer primary key references campsite_type, + cost_per_night integer not null constraint cost_not_negative check(cost_per_night >= 0) +); + +grant select on table campsite_type_pet_cost to guest; +grant select on table campsite_type_pet_cost to employee; +grant select, insert, update, delete on table campsite_type_pet_cost to admin; + +alter table campsite_type_pet_cost enable row level security; + +create policy guest_ok +on campsite_type_pet_cost +for select +using (true) +; + +create policy insert_to_company +on campsite_type_pet_cost +for insert +with check ( + exists (select 1 from campsite_type join user_profile using (company_id) where campsite_type.campsite_type_id = campsite_type_pet_cost.campsite_type_id) +) +; + +create policy update_company +on campsite_type_pet_cost +for update +using ( + exists (select 1 from campsite_type join user_profile using (company_id) where campsite_type.campsite_type_id = campsite_type_pet_cost.campsite_type_id) +) +; + +create policy delete_from_company +on campsite_type_pet_cost +for delete +using ( + exists (select 1 from campsite_type join user_profile using (company_id) where campsite_type.campsite_type_id = campsite_type_pet_cost.campsite_type_id) +) +; + +commit; diff --git a/deploy/edit_campsite_type.sql b/deploy/edit_campsite_type.sql index ceb28d7..13e0c8e 100644 --- a/deploy/edit_campsite_type.sql +++ b/deploy/edit_campsite_type.sql @@ -13,7 +13,7 @@ set search_path to camper, public; drop function if exists edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean); -create or replace function edit_campsite_type(slug uuid, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, bookable_nights int4range, dogs_allowed boolean, overflow_allowed boolean, ask_zone_preferences boolean, active boolean) returns uuid as +create or replace function edit_campsite_type(slug uuid, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, bookable_nights int4range, overflow_allowed boolean, ask_zone_preferences boolean, active boolean) returns uuid as $$ update campsite_type set name = edit_campsite_type.name @@ -27,7 +27,6 @@ $$ , media_id = coalesce(edit_campsite_type.media_id, campsite_type.media_id) , max_campers = edit_campsite_type.max_campers , bookable_nights = edit_campsite_type.bookable_nights - , dogs_allowed = edit_campsite_type.dogs_allowed , overflow_allowed = edit_campsite_type.overflow_allowed , ask_zone_preferences = edit_campsite_type.ask_zone_preferences , active = edit_campsite_type.active @@ -37,7 +36,7 @@ $$ language sql ; -revoke execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean, boolean) from public; -grant execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean, boolean) to admin; +revoke execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean) from public; +grant execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean) to admin; commit; diff --git a/deploy/set_campsite_type_pet_cost.sql b/deploy/set_campsite_type_pet_cost.sql new file mode 100644 index 0000000..a348075 --- /dev/null +++ b/deploy/set_campsite_type_pet_cost.sql @@ -0,0 +1,30 @@ +-- Deploy camper:set_campsite_type_pet_cost to pg +-- requires: roles +-- requires: schema_camper +-- requires: campsite_type +-- requires: campsite_type_pet_cost +-- requires: parse_price + +begin; + +set search_path to camper, public; + +create or replace function set_campsite_type_pet_cost(slug uuid, cost text) returns void as +$$ + insert into campsite_type_pet_cost (campsite_type_id, cost_per_night) + select campsite_type_id, parse_price(cost, decimal_digits) + from campsite_type + join company using (company_id) + join currency using (currency_code) + where campsite_type.slug = set_campsite_type_pet_cost.slug + on conflict (campsite_type_id) do update + set cost_per_night = excluded.cost_per_night + ; +$$ + language sql +; + +revoke execute on function set_campsite_type_pet_cost(uuid, text) from public; +grant execute on function set_campsite_type_pet_cost(uuid, text) to admin; + +commit; diff --git a/deploy/unset_campsite_type_pet_cost.sql b/deploy/unset_campsite_type_pet_cost.sql new file mode 100644 index 0000000..3d8486a --- /dev/null +++ b/deploy/unset_campsite_type_pet_cost.sql @@ -0,0 +1,26 @@ +-- Deploy camper:unset_campsite_type_pet_cost to pg +-- requires: roles +-- requires: schema_camper +-- requires: campsite_type +-- requires: campsite_type_pet_cost + +begin; + +set search_path to camper, public; + +create or replace function unset_campsite_type_pet_cost(slug uuid) returns void as +$$ + delete from campsite_type_pet_cost + where campsite_type_id in ( + select campsite_type_id + from campsite_type + where campsite_type.slug = unset_campsite_type_pet_cost.slug + ); +$$ + language sql +; + +revoke execute on function unset_campsite_type_pet_cost(uuid) from public; +grant execute on function unset_campsite_type_pet_cost(uuid) to admin; + +commit; diff --git a/pkg/booking/cart.go b/pkg/booking/cart.go index 9fb292f..b36e0b7 100644 --- a/pkg/booking/cart.go +++ b/pkg/booking/cart.go @@ -54,6 +54,13 @@ func newBookingCart(ctx context.Context, conn *database.Conn, f *bookingForm, ca if err != nil { return cart, nil } + numDogs := 0 + if f.Guests.NumberDogs != nil { + numDogs, err = strconv.Atoi(f.Guests.NumberDogs.Val) + if err != nil { + return cart, nil + } + } optionMap := make(map[int]*campsiteTypeOption) var typeOptions []*campsiteTypeOption @@ -75,17 +82,19 @@ func newBookingCart(ctx context.Context, conn *database.Conn, f *bookingForm, ca row := conn.QueryRow(ctx, ` with per_person as ( select count(*) as num_nights - , sum(cost_per_night * ceiling(($4::numeric + $5::numeric + $6::numeric) / max_campers::numeric)::integer)::integer as nights + , sum(cost.cost_per_night * ceiling(($4::numeric + $5::numeric + $6::numeric) / max_campers::numeric)::integer)::integer as nights , sum(cost_per_adult * $4)::integer as adults , sum(cost_per_teenager * $5)::integer as teenagers , sum(cost_per_child * $6)::integer as children + , sum(case when $7 > 0 then coalesce(pet.cost_per_night, 0) else 0 end)::integer as dogs , sum(tourist_tax * $4)::integer as tourist_tax , max(decimal_digits) as decimal_digits from generate_series($1, $2, interval '1 day') as date(day) left join season_calendar on season_range @> date.day::date left join season using (season_id) left join campsite_type using (company_id) - left join campsite_type_cost using (campsite_type_id, season_id) + left join campsite_type_pet_cost as pet using (campsite_type_id) + left join campsite_type_cost as cost using (campsite_type_id, season_id) left join company using (company_id) left join currency using (currency_code) where campsite_type.slug = $3 @@ -95,7 +104,7 @@ func newBookingCart(ctx context.Context, conn *database.Conn, f *bookingForm, ca from generate_series($1, $2, interval '1 day') as date(day) join season_calendar on season_range @> date.day::date join campsite_type_option_cost using (season_id) - join unnest($7::integer[], $8::integer[]) as option_units(campsite_type_option_id, units) using (campsite_type_option_id) + join unnest($8::integer[], $9::integer[]) as option_units(campsite_type_option_id, units) using (campsite_type_option_id) group by campsite_type_option_id union all select -1, 0 ) @@ -104,6 +113,7 @@ func newBookingCart(ctx context.Context, conn *database.Conn, f *bookingForm, ca , coalesce(to_price(adults, decimal_digits), '') , coalesce(to_price(teenagers, decimal_digits), '') , coalesce(to_price(children, decimal_digits), '') + , coalesce(to_price(dogs, decimal_digits), '') , coalesce(to_price(tourist_tax, decimal_digits), '') , coalesce(to_price(nights + adults + teenagers + children + tourist_tax + sum(option_cost)::integer, decimal_digits), '') , array_agg((campsite_type_option_id, to_price(option_cost, decimal_digits))) @@ -113,19 +123,21 @@ func newBookingCart(ctx context.Context, conn *database.Conn, f *bookingForm, ca , adults , teenagers , children + , dogs , tourist_tax , decimal_digits -`, pgx.QueryResultFormats{pgx.BinaryFormatCode}, arrivalDate, departureDate.AddDate(0, 0, -1), campsiteType, numAdults, numTeenagers, numChildren, optionIDs, optionUnits) +`, pgx.QueryResultFormats{pgx.BinaryFormatCode}, arrivalDate, departureDate.AddDate(0, 0, -1), campsiteType, numAdults, numTeenagers, numChildren, numDogs, optionIDs, optionUnits) var numNights int var nights string var adults string var teenagers string var children string + var dogs string var touristTax string var total string var optionPrices database.RecordArray - if err = row.Scan(&numNights, &nights, &adults, &teenagers, &children, &touristTax, &total, &optionPrices); err != nil { + if err = row.Scan(&numNights, &nights, &adults, &teenagers, &children, &dogs, &touristTax, &total, &optionPrices); err != nil { if database.ErrorIsNotFound(err) { return cart, nil } @@ -145,6 +157,7 @@ func newBookingCart(ctx context.Context, conn *database.Conn, f *bookingForm, ca maybeAddLine(numAdults, adults, locale.PgettextNoop("Adult", "cart")) maybeAddLine(numTeenagers, teenagers, locale.PgettextNoop("Teenager", "cart")) maybeAddLine(numChildren, children, locale.PgettextNoop("Child", "cart")) + maybeAddLine(numDogs, dogs, locale.PgettextNoop("Dog", "cart")) for _, el := range optionPrices.Elements { optionID := el.Fields[0].Get() diff --git a/pkg/booking/public.go b/pkg/booking/public.go index c883247..0a9e304 100644 --- a/pkg/booking/public.go +++ b/pkg/booking/public.go @@ -368,8 +368,9 @@ func newBookingGuestFields(ctx context.Context, conn *database.Conn, campsiteTyp row := conn.QueryRow(ctx, ` select max_campers , overflow_allowed - , dogs_allowed + , pet.cost_per_night is not null as dogs_allowed from campsite_type + left join campsite_type_pet_cost as pet using (campsite_type_id) where slug = $1 `, campsiteType) var dogsAllowed bool diff --git a/pkg/campsite/types/admin.go b/pkg/campsite/types/admin.go index 96eae08..b8ec7b4 100644 --- a/pkg/campsite/types/admin.go +++ b/pkg/campsite/types/admin.go @@ -167,13 +167,16 @@ func addType(w http.ResponseWriter, r *http.Request, user *auth.User, company *a } processTypeForm(w, r, user, company, conn, f, func(ctx context.Context, tx *database.Tx) error { var err error - f.Slug, err = tx.AddCampsiteType(ctx, company.ID, f.Media.Int(), f.Name[f.DefaultLang].Val, f.Spiel[f.DefaultLang].Val, f.Info[f.DefaultLang].Val, f.Facilities[f.DefaultLang].Val, f.Description[f.DefaultLang].Val, f.AdditionalInfo[f.DefaultLang].Val, f.CheckIn[f.DefaultLang].Val, f.CheckOut[f.DefaultLang].Val, f.MaxCampers.Int(), f.MinNights.Int(), f.MaxNights.Int(), f.DogsAllowed.Checked, f.OverflowAllowed.Checked, f.AskZonePreferences.Checked) + f.Slug, err = tx.AddCampsiteType(ctx, company.ID, f.Media.Int(), f.Name[f.DefaultLang].Val, f.Spiel[f.DefaultLang].Val, f.Info[f.DefaultLang].Val, f.Facilities[f.DefaultLang].Val, f.Description[f.DefaultLang].Val, f.AdditionalInfo[f.DefaultLang].Val, f.CheckIn[f.DefaultLang].Val, f.CheckOut[f.DefaultLang].Val, f.MaxCampers.Int(), f.MinNights.Int(), f.MaxNights.Int(), f.OverflowAllowed.Checked, f.AskZonePreferences.Checked) if err != nil { return err } if err := translateTypes(ctx, tx, company, f); err != nil { return err } + if err := setTypeDogsPrice(ctx, tx, f); err != nil { + return err + } return setTypePrices(ctx, tx, f.Slug, f.Prices) }) } @@ -191,6 +194,14 @@ func translateTypes(ctx context.Context, tx *database.Tx, company *auth.Company, return nil } +func setTypeDogsPrice(ctx context.Context, tx *database.Tx, f *typeForm) error { + if f.DogsAllowed.Checked { + return tx.SetCampsitePetTypeCost(ctx, f.Slug, f.DogsPrice.Val) + } else { + return tx.UnsetCampsitePetTypeCost(ctx, f.Slug) + } +} + func setTypePrices(ctx context.Context, tx *database.Tx, slug string, prices map[int]*typePriceForm) error { for seasonID, p := range prices { if err := tx.SetCampsiteTypeCost(ctx, slug, seasonID, p.PricePerNight.Val, p.PricePerAdult.Val, p.PricePerTeenager.Val, p.PricePerChild.Val); err != nil { @@ -202,12 +213,15 @@ func setTypePrices(ctx context.Context, tx *database.Tx, slug string, prices map func editType(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn, f *typeForm) { processTypeForm(w, r, user, company, conn, f, func(ctx context.Context, tx *database.Tx) error { - if _, err := tx.EditCampsiteType(ctx, f.Slug, f.Media.Int(), f.Name[f.DefaultLang].Val, f.Spiel[f.DefaultLang].Val, f.Info[f.DefaultLang].Val, f.Facilities[f.DefaultLang].Val, f.Description[f.DefaultLang].Val, f.AdditionalInfo[f.DefaultLang].Val, f.CheckIn[f.DefaultLang].Val, f.CheckOut[f.DefaultLang].Val, f.MaxCampers.Int(), f.MinNights.Int(), f.MaxNights.Int(), f.DogsAllowed.Checked, f.OverflowAllowed.Checked, f.AskZonePreferences.Checked, f.Active.Checked); err != nil { + if _, err := tx.EditCampsiteType(ctx, f.Slug, f.Media.Int(), f.Name[f.DefaultLang].Val, f.Spiel[f.DefaultLang].Val, f.Info[f.DefaultLang].Val, f.Facilities[f.DefaultLang].Val, f.Description[f.DefaultLang].Val, f.AdditionalInfo[f.DefaultLang].Val, f.CheckIn[f.DefaultLang].Val, f.CheckOut[f.DefaultLang].Val, f.MaxCampers.Int(), f.MinNights.Int(), f.MaxNights.Int(), f.OverflowAllowed.Checked, f.AskZonePreferences.Checked, f.Active.Checked); err != nil { return err } if err := translateTypes(ctx, tx, company, f); err != nil { return err } + if err := setTypeDogsPrice(ctx, tx, f); err != nil { + return err + } return setTypePrices(ctx, tx, f.Slug, f.Prices) }) } @@ -279,6 +293,7 @@ type typeForm struct { MinNights *form.Input MaxNights *form.Input DogsAllowed *form.Checkbox + DogsPrice *form.Input OverflowAllowed *form.Checkbox AskZonePreferences *form.Checkbox Spiel form.I18nInput @@ -328,6 +343,9 @@ func newTypeForm(ctx context.Context, company *auth.Company, conn *database.Conn DogsAllowed: &form.Checkbox{ Name: "dogs_allowed", }, + DogsPrice: &form.Input{ + Name: "dogs_price", + }, OverflowAllowed: &form.Checkbox{ Name: "overflow_allowed", }, @@ -403,7 +421,8 @@ func (f *typeForm) FillFromDatabase(ctx context.Context, conn *database.Conn, sl , max_campers::text , lower(bookable_nights)::text , (upper(bookable_nights) - 1)::text - , dogs_allowed + , pet.cost_per_night is not null as dogs_allowed + , to_price(coalesce(pet.cost_per_night, 0)) as pet_cost , overflow_allowed , ask_zone_preferences , active @@ -416,7 +435,8 @@ func (f *typeForm) FillFromDatabase(ctx context.Context, conn *database.Conn, sl , array_agg((lang_tag, i18n.check_in)) , array_agg((lang_tag, i18n.check_out)) from campsite_type - left join campsite_type_i18n as i18n using (campsite_type_id) + left join campsite_type_pet_cost as pet using (campsite_type_id) + left join campsite_type_i18n as i18n using (campsite_type_id) where slug = $1 group by campsite_type.name , campsite_type.spiel::text @@ -429,7 +449,7 @@ func (f *typeForm) FillFromDatabase(ctx context.Context, conn *database.Conn, sl , media_id::text , max_campers::text , bookable_nights - , dogs_allowed + , pet.cost_per_night , overflow_allowed , ask_zone_preferences , active @@ -448,6 +468,7 @@ func (f *typeForm) FillFromDatabase(ctx context.Context, conn *database.Conn, sl &f.MinNights.Val, &f.MaxNights.Val, &f.DogsAllowed.Checked, + &f.DogsPrice.Val, &f.OverflowAllowed.Checked, &f.AskZonePreferences.Checked, &f.Active.Checked, @@ -531,6 +552,7 @@ func (f *typeForm) Parse(r *http.Request) error { f.MinNights.FillValue(r) f.MaxNights.FillValue(r) f.DogsAllowed.FillValue(r) + f.DogsPrice.FillValue(r) f.OverflowAllowed.FillValue(r) f.AskZonePreferences.FillValue(r) f.Spiel.FillValue(r) @@ -577,6 +599,13 @@ func (f *typeForm) Valid(ctx context.Context, conn *database.Conn, l *locale.Loc v.CheckMinInteger(f.MaxNights, f.MinNights.Int(), l.GettextNoop("Maximum number of nights must be equal or greater than the minimum.")) } } + if f.DogsAllowed.Checked { + if v.CheckRequired(f.DogsPrice, l.GettextNoop("Dogs price can not be empty when dogs are allowed.")) { + if v.CheckValidDecimal(f.DogsPrice, l.GettextNoop("Dogs price must be a decimal number.")) { + v.CheckMinDecimal(f.DogsPrice, 0.0, l.GettextNoop("Dogs price must be zero or greater.")) + } + } + } for _, p := range f.Prices { if v.CheckRequired(p.PricePerNight, l.GettextNoop("Price per night can not be empty.")) { if v.CheckValidDecimal(p.PricePerNight, l.GettextNoop("Price per night must be a decimal number.")) { diff --git a/pkg/campsite/types/public.go b/pkg/campsite/types/public.go index 2674609..042a43c 100644 --- a/pkg/campsite/types/public.go +++ b/pkg/campsite/types/public.go @@ -139,9 +139,10 @@ func newPublicPage(ctx context.Context, company *auth.Company, conn *database.Co , coalesce(i18n.additional_info, campsite_type.additional_info)::text as l10n_description , coalesce(i18n.check_in, campsite_type.check_in)::text as l10n_check_in , coalesce(i18n.check_out, campsite_type.check_out)::text as l10n_check_out - , dogs_allowed - , '3.50' as dogs_prices + , pet.cost_per_night is not null as dogs_allowed + , to_price(coalesce(pet.cost_per_night, 0)) as dogs_prices from campsite_type + left join campsite_type_pet_cost as pet using (campsite_type_id) left join campsite_type_i18n as i18n on campsite_type.campsite_type_id = i18n.campsite_type_id and i18n.lang_tag = $1 where slug = $2 and active diff --git a/pkg/database/funcs.go b/pkg/database/funcs.go index 957afb6..49fb17f 100644 --- a/pkg/database/funcs.go +++ b/pkg/database/funcs.go @@ -130,12 +130,12 @@ func (c *Conn) RemoveCampsiteFeature(ctx context.Context, id int) error { return err } -func (tx *Tx) AddCampsiteType(ctx context.Context, companyID int, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, minNights int, maxNights int, dogsAllowed bool, overflowAllowed bool, askZonePreferences bool) (string, error) { - return tx.GetText(ctx, "select add_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, int4range($12, $13), $14, $15, $16)", companyID, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, minNights, maxNights+1, dogsAllowed, overflowAllowed, askZonePreferences) +func (tx *Tx) AddCampsiteType(ctx context.Context, companyID int, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, minNights int, maxNights int, overflowAllowed bool, askZonePreferences bool) (string, error) { + return tx.GetText(ctx, "select add_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, int4range($12, $13), $14, $15)", companyID, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, minNights, maxNights+1, overflowAllowed, askZonePreferences) } -func (tx *Tx) EditCampsiteType(ctx context.Context, slug string, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, minNights int, maxNights int, dogsAllowed bool, overflowAllowed bool, askZonePreferences bool, active bool) (string, error) { - return tx.GetText(ctx, "select edit_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, int4range($12, $13), $14, $15, $16, $17)", slug, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, minNights, maxNights+1, dogsAllowed, overflowAllowed, askZonePreferences, active) +func (tx *Tx) EditCampsiteType(ctx context.Context, slug string, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, minNights int, maxNights int, overflowAllowed bool, askZonePreferences bool, active bool) (string, error) { + return tx.GetText(ctx, "select edit_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, int4range($12, $13), $14, $15, $16)", slug, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, minNights, maxNights+1, overflowAllowed, askZonePreferences, active) } func (c *Conn) OrderCampsiteTypes(ctx context.Context, slugs []string) error { @@ -152,6 +152,16 @@ func (tx *Tx) SetCampsiteTypeCost(ctx context.Context, slug string, seasonID int return err } +func (tx *Tx) SetCampsitePetTypeCost(ctx context.Context, slug string, cost string) error { + _, err := tx.Exec(ctx, "select set_campsite_type_pet_cost($1, $2)", slug, cost) + return err +} + +func (tx *Tx) UnsetCampsitePetTypeCost(ctx context.Context, slug string) error { + _, err := tx.Exec(ctx, "select unset_campsite_type_pet_cost($1)", slug) + return err +} + func (tx *Tx) AddCampsiteTypeOption(ctx context.Context, typeSlug string, name string, min int, max int) (int, error) { return tx.GetInt(ctx, "select add_campsite_type_option($1, $2, $3, $4)", typeSlug, name, min, max) } diff --git a/po/ca.po b/po/ca.po index 1111d32..e9640f1 100644 --- a/po/ca.po +++ b/po/ca.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: camper\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2024-02-10 03:29+0100\n" +"POT-Creation-Date: 2024-02-10 06:05+0100\n" "PO-Revision-Date: 2024-02-06 10:04+0100\n" "Last-Translator: jordi fita masA
', 5, '[1, 7]', false, true) - , (11, 2, 4, 'Type A', 'A
', 5, '[2, 5]', false, true) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, 3, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 2, 4, 'Type A', 'A
', 5, '[2, 5]', true) ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/add_campsite_feature.sql b/test/add_campsite_feature.sql index 1d63ef0..103f57c 100644 --- a/test/add_campsite_feature.sql +++ b/test/add_campsite_feature.sql @@ -43,9 +43,9 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (4, 1, 3, 'Type A', 'A
', true, false, 4, '[1, 7]') - , (5, 1, 3, 'Type B', 'B
', true, false, 5, '[2, 5]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, max_campers, bookable_nights) +values (4, 1, 3, 'Type A', 'A
', true, 4, '[1, 7]') + , (5, 1, 3, 'Type B', 'B
', true, 5, '[2, 5]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/add_campsite_type.sql b/test/add_campsite_type.sql index 1304273..b392ae2 100644 --- a/test/add_campsite_type.sql +++ b/test/add_campsite_type.sql @@ -9,15 +9,15 @@ 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', 'boolean']); -select function_lang_is('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', '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', 'boolean'], 'uuid'); -select isnt_definer('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean']); -select volatility_is('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', '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', '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', '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', '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', 'boolean'], 'authenticator', array[]::text[]); +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; @@ -44,19 +44,19 @@ values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a ; select lives_ok( - $$ select add_campsite_type(1, 3, 'Type A', '', 'Features
', '', 'Dunno
', '', 'After 4 p.m.', '12 a.m.', 5, '[1, 7]', true, false, true) $$, + $$ select add_campsite_type(1, 3, 'Type A', '', 'Features
', '', 'Dunno
', '', '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', 'One
Two
', '', 'Pricing
', '', 'More
', 'After 9 p.m.', '9 a.m.', 2, '(1, 7)', false, true, false) $$, + $$ select add_campsite_type(2, 4, 'Type B', 'One
Two
', '', 'Pricing
', '', 'More
', '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, dogs_allowed, overflow_allowed, ask_zone_preferences from campsite_type $$, - $$ values (1, 3, 'Type A', '', 'Features
', '', 'Dunno
', '', 'After 4 p.m.', '12 a.m.', true, 5, int4range(1, 8), true, false, true) - , (2, 4, 'Type B', 'One
Two
', '', 'Pricing
', '', 'More
', 'After 9 p.m.', '9 a.m.', true, 2, int4range(2, 7), false, true, false) + $$ 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', '', 'Features
', '', 'Dunno
', '', 'After 4 p.m.', '12 a.m.', true, 5, int4range(1, 8), false, true) + , (2, 4, 'Type B', 'One
Two
', '', 'Pricing
', '', 'More
', 'After 9 p.m.', '9 a.m.', true, 2, int4range(2, 7), true, false) $$, 'Should have added all two campsite type' ); diff --git a/test/add_campsite_type_carousel_slide.sql b/test/add_campsite_type_carousel_slide.sql index 8cf3d94..afbc77d 100644 --- a/test/add_campsite_type_carousel_slide.sql +++ b/test/add_campsite_type_carousel_slide.sql @@ -50,9 +50,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (6, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', false) ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/add_campsite_type_feature.sql b/test/add_campsite_type_feature.sql index 754c947..b367ca1 100644 --- a/test/add_campsite_type_feature.sql +++ b/test/add_campsite_type_feature.sql @@ -42,9 +42,9 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4, '[1, 7]') - , (4, 1, '9ae5cf87-cd69-4541-b5a5-75f937cc9e58', 2, 'Type B', 'B
', true, false, 5, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, 4, '[1, 7]') + , (4, 1, '9ae5cf87-cd69-4541-b5a5-75f937cc9e58', 2, 'Type B', 'B
', true, 5, '[2, 6]') ; select lives_ok( diff --git a/test/add_campsite_type_option.sql b/test/add_campsite_type_option.sql index 592e765..3ecbdc4 100644 --- a/test/add_campsite_type_option.sql +++ b/test/add_campsite_type_option.sql @@ -42,9 +42,9 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4, '[1, 7]') - , (4, 1, '9ae5cf87-cd69-4541-b5a5-75f937cc9e58', 2, 'Type B', 'B
', true, false, 5, '[1, 6]') +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, 4, '[1, 7]') + , (4, 1, '9ae5cf87-cd69-4541-b5a5-75f937cc9e58', 2, 'Type B', 'B
', true, 5, '[1, 6]') ; select lives_ok( diff --git a/test/booking.sql b/test/booking.sql index 6330d0e..19622f5 100644 --- a/test/booking.sql +++ b/test/booking.sql @@ -125,9 +125,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (10, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (12, 4, 'Bungalow', 8, false, 6, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (10, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (12, 4, 'Bungalow', 8, 6, '[2, 6]') ; insert into booking (company_id, campsite_type_id, holder_name, arrival_date, departure_date, number_dogs, acsi_card) diff --git a/test/campsite.sql b/test/campsite.sql index 850efb1..21a3f80 100644 --- a/test/campsite.sql +++ b/test/campsite.sql @@ -102,9 +102,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers, bookable_nights) -values (22, 2, 6, 'Wooden lodge', true, 5, '[1, 7]') - , (44, 4, 8, 'Bungalow', false, 4, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, max_campers, bookable_nights) +values (22, 2, 6, 'Wooden lodge', 5, '[1, 7]') + , (44, 4, 8, 'Bungalow', 4, '[2, 6]') ; insert into campsite (company_id, campsite_type_id, label) diff --git a/test/campsite_carousel.sql b/test/campsite_carousel.sql index 54c3594..8f6612d 100644 --- a/test/campsite_carousel.sql +++ b/test/campsite_carousel.sql @@ -93,9 +93,9 @@ values ( 6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff"," , (11, 4, 'text5.txt', sha256('content5')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (21, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (22, 4, 'Bungalow', 9, false, 6, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (21, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (22, 4, 'Bungalow', 9, 6, '[2, 6]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/campsite_feature.sql b/test/campsite_feature.sql index 6ad978c..747bfdc 100644 --- a/test/campsite_feature.sql +++ b/test/campsite_feature.sql @@ -89,9 +89,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, 6, '[2, 6]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/campsite_type.sql b/test/campsite_type.sql index 550fe0f..96a1c65 100644 --- a/test/campsite_type.sql +++ b/test/campsite_type.sql @@ -5,7 +5,7 @@ reset client_min_messages; begin; -select plan(112); +select plan(108); set search_path to camper, public; @@ -83,11 +83,6 @@ select col_type_is('campsite_type', 'max_campers', 'integer'); select col_not_null('campsite_type', 'max_campers'); select col_hasnt_default('campsite_type', 'max_campers'); -select has_column('campsite_type', 'dogs_allowed'); -select col_type_is('campsite_type', 'dogs_allowed', 'boolean'); -select col_not_null('campsite_type', 'dogs_allowed'); -select col_hasnt_default('campsite_type', 'dogs_allowed'); - select has_column('campsite_type', 'overflow_allowed'); select col_type_is('campsite_type', 'overflow_allowed', 'boolean'); select col_not_null('campsite_type', 'overflow_allowed'); @@ -169,9 +164,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (4, 'Bungalow', 8, false, 6, '[2, 6]') +insert into campsite_type (company_id, name, media_id, max_campers, bookable_nights) +values (2, 'Wooden lodge', 6, 7, '[1, 7]') + , (4, 'Bungalow', 8, 6, '[2, 6]') ; prepare campsite_type_data as @@ -192,7 +187,7 @@ reset role; select set_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog', 'co2'); select lives_ok( - $$ insert into campsite_type(company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, 'Another type', 6, true, 7, '[1, 7]') $$, + $$ insert into campsite_type(company_id, name, media_id, max_campers, bookable_nights) values (2, 'Another type', 6, 7, '[1, 7]') $$, 'Admin from company 2 should be able to insert a new campsite type to that company.' ); @@ -233,7 +228,7 @@ select bag_eq( ); select throws_ok( - $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (4, 'Another type', 6, true, 6, '[1, 7]') $$, + $$ insert into campsite_type (company_id, name, media_id, max_campers, bookable_nights) values (4, 'Another type', 6, 6, '[1, 7]') $$, '42501', 'new row violates row-level security policy for table "campsite_type"', 'Admin from company 2 should NOT be able to insert new campsite types to company 4.' ); @@ -271,25 +266,25 @@ select bag_eq( ); select throws_ok( - $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, ' ', 6, false, 5, '[1, 7]') $$, + $$ insert into campsite_type (company_id, name, media_id, max_campers, bookable_nights) values (2, ' ', 6, 5, '[1, 7]') $$, '23514', 'new row for relation "campsite_type" violates check constraint "name_not_empty"', 'Should not be able to insert campsite types with a blank name.' ); select throws_ok( - $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, 'Name', 6, false, 0, '[1, 7]') $$, + $$ insert into campsite_type (company_id, name, media_id, max_campers, bookable_nights) values (2, 'Name', 6, 0, '[1, 7]') $$, '23514', 'new row for relation "campsite_type" violates check constraint "at_least_one_camper"', 'Should not be able to insert campsite types with no campers allowed.' ); select throws_ok( - $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, 'Name', 6, false, 1, '[0, 7]') $$, + $$ insert into campsite_type (company_id, name, media_id, max_campers, bookable_nights) values (2, 'Name', 6, 1, '[0, 7]') $$, '23514', 'new row for relation "campsite_type" violates check constraint "at_least_one_night"', 'Should not be able to insert campsite types that allows to book zero nights.' ); select throws_ok( - $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, 'Name', 6, false, 1, '[1, 1)') $$, + $$ insert into campsite_type (company_id, name, media_id, max_campers, bookable_nights) values (2, 'Name', 6, 1, '[1, 1)') $$, '23514', 'new row for relation "campsite_type" violates check constraint "at_least_one_night"', 'Should not be able to insert campsite types with no bookable nights.' ); diff --git a/test/campsite_type_carousel.sql b/test/campsite_type_carousel.sql index 82c6d2a..b6d4fdb 100644 --- a/test/campsite_type_carousel.sql +++ b/test/campsite_type_carousel.sql @@ -92,9 +92,9 @@ values ( 6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff"," , (11, 4, 'text5.txt', sha256('content5')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (21, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (22, 4, 'Bungalow', 9, false, 6, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (21, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (22, 4, 'Bungalow', 9, 6, '[2, 6]') ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/campsite_type_cost.sql b/test/campsite_type_cost.sql index 87b1b10..0702a49 100644 --- a/test/campsite_type_cost.sql +++ b/test/campsite_type_cost.sql @@ -93,9 +93,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, 6, '[2, 6]') ; insert into season (season_id, company_id, name) diff --git a/test/campsite_type_feature.sql b/test/campsite_type_feature.sql index e11b38c..70557ae 100644 --- a/test/campsite_type_feature.sql +++ b/test/campsite_type_feature.sql @@ -88,9 +88,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, 6, '[2, 6]') ; insert into campsite_type_feature (campsite_type_id, icon_name, name) diff --git a/test/campsite_type_option.sql b/test/campsite_type_option.sql index 37840b8..f0780f8 100644 --- a/test/campsite_type_option.sql +++ b/test/campsite_type_option.sql @@ -86,9 +86,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, 6, '[2, 6]') ; insert into campsite_type_option (campsite_type_id, name, range) diff --git a/test/campsite_type_option_cost.sql b/test/campsite_type_option_cost.sql index 0c48e94..d5c4736 100644 --- a/test/campsite_type_option_cost.sql +++ b/test/campsite_type_option_cost.sql @@ -79,9 +79,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') - , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, 6, '[2, 6]') ; insert into season (season_id, company_id, name) diff --git a/test/campsite_type_pet_cost.sql b/test/campsite_type_pet_cost.sql new file mode 100644 index 0000000..87ecf83 --- /dev/null +++ b/test/campsite_type_pet_cost.sql @@ -0,0 +1,195 @@ +-- Test campsite_type_pet_cost +set client_min_messages to warning; +create extension if not exists pgtap; +reset client_min_messages; + +begin; + +select plan(31); + +set search_path to camper, public; + +select has_table('campsite_type_pet_cost'); +select has_pk('campsite_type_pet_cost'); +select table_privs_are('campsite_type_pet_cost', 'guest', array['SELECT']); +select table_privs_are('campsite_type_pet_cost', 'employee', array['SELECT']); +select table_privs_are('campsite_type_pet_cost', 'admin', array['SELECT', 'INSERT', 'UPDATE', 'DELETE']); +select table_privs_are('campsite_type_pet_cost', 'authenticator', array[]::text[]); + +select has_column('campsite_type_pet_cost', 'campsite_type_id'); +select col_is_pk('campsite_type_pet_cost', 'campsite_type_id'); +select col_is_fk('campsite_type_pet_cost', 'campsite_type_id'); +select fk_ok('campsite_type_pet_cost', 'campsite_type_id', 'campsite_type', 'campsite_type_id'); +select col_type_is('campsite_type_pet_cost', 'campsite_type_id', 'integer'); +select col_not_null('campsite_type_pet_cost', 'campsite_type_id'); +select col_hasnt_default('campsite_type_pet_cost', 'campsite_type_id'); + +select has_column('campsite_type_pet_cost', 'cost_per_night'); +select col_type_is('campsite_type_pet_cost', 'cost_per_night', 'integer'); +select col_not_null('campsite_type_pet_cost', 'cost_per_night'); +select col_hasnt_default('campsite_type_pet_cost', 'cost_per_night'); + + +set client_min_messages to warning; +truncate campsite_type_pet_cost cascade; +truncate campsite_type cascade; +truncate media cascade; +truncate media_content cascade; +truncate company_host cascade; +truncate company_user cascade; +truncate company cascade; +truncate auth."user" cascade; +reset client_min_messages; + +insert into auth."user" (user_id, email, name, password, cookie, cookie_expires_at) +values (1, 'demo@tandem.blog', 'Demo', 'test', '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e', current_timestamp + interval '1 month') + , (5, 'admin@tandem.blog', 'Demo', 'test', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') +; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, rtc_number, tourist_tax, country_code, currency_code, default_lang_tag) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 60, 'ES', 'EUR', 'ca') + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', '', 60, 'FR', 'USD', 'ca') +; + +insert into company_user (company_id, user_id, role) +values (2, 1, 'admin') + , (4, 5, 'admin') +; + +insert into company_host (company_id, host) +values (2, 'co2') + , (4, 'co4') +; + +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 (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) + , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) +; + +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, 7, '[1, 7]') + , (17, 2, 'Another lodge', 6, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, 6, '[2, 6]') + , (19, 4, 'Bungalow Premium', 8, 6, '[2, 6]') +; + +insert into campsite_type_pet_cost (campsite_type_id, cost_per_night) +values (16, 2) + , (18, 4) +; + +prepare campsite_cost_data as +select campsite_type_id, cost_per_night +from campsite_type_pet_cost +; + +set role guest; +select bag_eq( + 'campsite_cost_data', + $$ values (16, 2) + , (18, 4) + $$, + 'Everyone should be able to list all campsite type pet costs across all companies' +); +reset role; + +select set_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog', 'co2'); + +select lives_ok( + $$ insert into campsite_type_pet_cost(campsite_type_id, cost_per_night) values (17, 3) $$, + 'Admin from company 2 should be able to insert a new pet cost to that company.' +); + +select bag_eq( + 'campsite_cost_data', + $$ values (16, 2) + , (17, 3) + , (18, 4) + $$, + 'The new row should have been added' +); + +select lives_ok( + $$ update campsite_type_pet_cost set cost_per_night = 6 where campsite_type_id = 17 $$, + 'Admin from company 2 should be able to update pet cost of that company.' +); + +select bag_eq( + 'campsite_cost_data', + $$ values (16, 2) + , (17, 6) + , (18, 4) + $$, + 'The row should have been updated.' +); + +select lives_ok( + $$ delete from campsite_type_pet_cost where campsite_type_id = 17 $$, + 'Admin from company 2 should be able to delete campsite type season from that company.' +); + +select bag_eq( + 'campsite_cost_data', + $$ values (16, 2) + , (18, 4) + $$, + 'The row should have been deleted.' +); + +select throws_ok( + $$ insert into campsite_type_pet_cost (campsite_type_id, cost_per_night) values (19, 5) $$, + '42501', 'new row violates row-level security policy for table "campsite_type_pet_cost"', + 'Admin from company 2 should NOT be able to insert new pet costs to company 4.' +); + +select lives_ok( + $$ update campsite_type_pet_cost set cost_per_night = 1 where campsite_type_id = 18 $$, + 'Admin from company 2 should not be able to update pet costs of company 4, but no error if campsite_type_id is not changed.' +); + +select bag_eq( + 'campsite_cost_data', + $$ values (16, 2) + , (18, 4) + $$, + 'No row should have been changed.' +); + +select throws_ok( + $$ update campsite_type_pet_cost set campsite_type_id = 19 where campsite_type_id = 16 $$, + '42501', 'new row violates row-level security policy for table "campsite_type_pet_cost"', + 'Admin from company 2 should NOT be able to move pet costs to one of company 4' +); + +select lives_ok( + $$ delete from campsite_type_pet_cost where campsite_type_id = 18 $$, + 'Admin from company 2 should NOT be able to delete pet costs from company 4, but not error is thrown' +); + +select bag_eq( + 'campsite_cost_data', + $$ values (16, 2) + , (18, 4) + $$, + 'No row should have been changed' +); + +select throws_ok( + $$ insert into campsite_type_pet_cost (campsite_type_id, cost_per_night) values (17, -1) $$, + '23514', 'new row for relation "campsite_type_pet_cost" violates check constraint "cost_not_negative"', + 'Should not be able to insert negative pet costs.' +); + + +reset role; + + +select * +from finish(); + +rollback; + diff --git a/test/edit_campsite.sql b/test/edit_campsite.sql index d7d9f95..a81f780 100644 --- a/test/edit_campsite.sql +++ b/test/edit_campsite.sql @@ -40,10 +40,10 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers, bookable_nights) -values (11, 1, 3, 'Type A', false, 5, '[1, 7]') - , (12, 1, 3, 'Type B', false, 5, '[2, 6]') - , (13, 1, 3, 'Type C', false, 5, '[3, 5]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, max_campers, bookable_nights) +values (11, 1, 3, 'Type A', 5, '[1, 7]') + , (12, 1, 3, 'Type B', 5, '[2, 6]') + , (13, 1, 3, 'Type C', 5, '[3, 5]') ; insert into campsite (campsite_id, company_id, campsite_type_id, label, info1, info2, active) diff --git a/test/edit_campsite_feature.sql b/test/edit_campsite_feature.sql index 0be57bc..c39bba6 100644 --- a/test/edit_campsite_feature.sql +++ b/test/edit_campsite_feature.sql @@ -42,8 +42,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, 4, '[1, 7]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/edit_campsite_type.sql b/test/edit_campsite_type.sql index eb56572..ecdd7a8 100644 --- a/test/edit_campsite_type.sql +++ b/test/edit_campsite_type.sql @@ -9,15 +9,15 @@ set search_path to camper, public; select plan(12); -select has_function('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean']); -select function_lang_is('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'sql'); -select function_returns('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'uuid'); -select isnt_definer('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean']); -select volatility_is('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'volatile'); -select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'guest', array[]::text[]); -select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'employee', array[]::text[]); -select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'admin', array['EXECUTE']); -select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'authenticator', array[]::text[]); +select has_function('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean']); +select function_lang_is('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'sql'); +select function_returns('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'uuid'); +select isnt_definer('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean']); +select volatility_is('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'volatile'); +select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'guest', array[]::text[]); +select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'employee', array[]::text[]); +select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'admin', array['EXECUTE']); +select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'authenticator', array[]::text[]); set client_min_messages to warning; truncate campsite_type cascade; @@ -43,25 +43,25 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (4, 1, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffff00","a"};')) ; -insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences, active) -values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'info 1
', 'facilities A
', 'A
', 'Additional A
', '', '', 5, '[1, 7]', false, true, false, true) - , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'info 2
', 'facilities B
', 'B
', 'Additional B
', '', '', 4, '[2, 6]', true, false, true, false) +insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, bookable_nights, overflow_allowed, ask_zone_preferences, active) +values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'info 1
', 'facilities A
', 'A
', 'Additional A
', '', '', 5, '[1, 7]', true, false, true) + , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'info 2
', 'facilities B
', 'B
', 'Additional B
', '', '', 4, '[2, 6]', false, true, false) ; select lives_ok( - $$ select edit_campsite_type('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 'Type 1', 'Features A
', 'Pricing 1
', '1
', 'Additional 1
', 'Check-in 1', 'Check-out 1', 2, '(1, 7)', true, false, true, false) $$, + $$ select edit_campsite_type('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 'Type 1', 'Features A
', 'Pricing 1
', '1
', 'Additional 1
', 'Check-in 1', 'Check-out 1', 2, '(1, 7)', false, true, false) $$, 'Should be able to edit the first type' ); select lives_ok( - $$ select edit_campsite_type('9b6370f7-f941-46f2-bc6e-de455675bd0a', null, 'Type 2', 'Features B
', 'Pricing 2
', '2
', 'Additional 2
', 'Check-in 2', 'Check-out 2', 9, '(2, 6)', false, true, false, true) $$, + $$ select edit_campsite_type('9b6370f7-f941-46f2-bc6e-de455675bd0a', null, 'Type 2', 'Features B
', 'Pricing 2
', '2
', 'Additional 2
', 'Check-in 2', 'Check-out 2', 9, '(2, 6)', true, false, true) $$, 'Should be able to edit the second type' ); select bag_eq( - $$ select slug::text, media_id, name, spiel::text, info::text, facilities::text, description::text, additional_info::text, check_in, check_out, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences, active from campsite_type $$, - $$ values ('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 'Type 1', 'Features A
', 'Pricing 1
', '1
', 'Additional 1
', 'Check-in 1', 'Check-out 1', 2, int4range(2, 7), true, false, true, false) - , ('9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type 2', 'Features B
', 'Pricing 2
', '2
', 'Additional 2
', 'Check-in 2', 'Check-out 2', 9, int4range(3, 6), false, true, false, true) + $$ select slug::text, media_id, name, spiel::text, info::text, facilities::text, description::text, additional_info::text, check_in, check_out, max_campers, bookable_nights, overflow_allowed, ask_zone_preferences, active from campsite_type $$, + $$ values ('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 'Type 1', 'Features A
', 'Pricing 1
', '1
', 'Additional 1
', 'Check-in 1', 'Check-out 1', 2, int4range(2, 7), false, true, false) + , ('9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type 2', 'Features B
', 'Pricing 2
', '2
', 'Additional 2
', 'Check-in 2', 'Check-out 2', 9, int4range(3, 6), true, false, true) $$, 'Should have updated all campsite types.' ); diff --git a/test/edit_campsite_type_feature.sql b/test/edit_campsite_type_feature.sql index 148c65e..77d9a75 100644 --- a/test/edit_campsite_type_feature.sql +++ b/test/edit_campsite_type_feature.sql @@ -42,8 +42,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, 4, '[1, 7]') ; insert into campsite_type_feature (campsite_type_feature_id, campsite_type_id, icon_name, name) diff --git a/test/edit_campsite_type_option.sql b/test/edit_campsite_type_option.sql index b25d57a..6dae754 100644 --- a/test/edit_campsite_type_option.sql +++ b/test/edit_campsite_type_option.sql @@ -42,8 +42,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, 4, '[1, 7]') ; insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range) diff --git a/test/order_campsite_carousel.sql b/test/order_campsite_carousel.sql index f27c033..c191441 100644 --- a/test/order_campsite_carousel.sql +++ b/test/order_campsite_carousel.sql @@ -56,9 +56,9 @@ values ( 3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff"," , (12, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (13, 1, 3, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (14, 2, 8, 'Type B', 'B
', 4, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, active) +values (13, 1, 3, 'Type A', 'A
', 5, '[1, 7]', true) + , (14, 2, 8, 'Type B', 'B
', 4, '[2, 6]', false) ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/order_campsite_features.sql b/test/order_campsite_features.sql index 19645d3..16c7da5 100644 --- a/test/order_campsite_features.sql +++ b/test/order_campsite_features.sql @@ -42,8 +42,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, 7, '[1, 7]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/order_campsite_type_carousel.sql b/test/order_campsite_type_carousel.sql index 15e9949..70d5e52 100644 --- a/test/order_campsite_type_carousel.sql +++ b/test/order_campsite_type_carousel.sql @@ -50,9 +50,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (6, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', false) ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/order_campsite_type_features.sql b/test/order_campsite_type_features.sql index 12c5e2e..f03dbc0 100644 --- a/test/order_campsite_type_features.sql +++ b/test/order_campsite_type_features.sql @@ -56,8 +56,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) -values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, name, media_id, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, 7, '[1, 7]') ; insert into campsite_type_feature (campsite_type_feature_id, campsite_type_id, icon_name, name) diff --git a/test/order_campsite_type_options.sql b/test/order_campsite_type_options.sql index 2192029..8a6d9f0 100644 --- a/test/order_campsite_type_options.sql +++ b/test/order_campsite_type_options.sql @@ -42,8 +42,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, 4, '[1, 7]') ; insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range) diff --git a/test/order_campsite_types.sql b/test/order_campsite_types.sql index 97ced20..bf1dc22 100644 --- a/test/order_campsite_types.sql +++ b/test/order_campsite_types.sql @@ -40,12 +40,12 @@ 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"};')) ; -insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, max_campers, bookable_nights, dogs_allowed, active) -values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'A', '', '', '', '', 5, '[1, 7]', false, true) - , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 2, 'B', '', '', '', '', 5, '[2, 6]', false, true) - , (1, 'b33cfbc9-fbcc-4aac-8335-e5f94ea7e6b2', 2, 'C', '', '', '', '', 5, '[3, 5]', false, true) - , (1, '8c4465ec-a690-43d7-854b-7fcd35fccb1c', 2, 'D', '', '', '', '', 5, '[4, 8]', false, true) - , (1, 'd28c30fb-57ac-4243-a8c3-ad1a26637f5a', 2, 'E', '', '', '', '', 5, '[5, 9]', false, true) +insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, max_campers, bookable_nights, active) +values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'A', '', '', '', '', 5, '[1, 7]', true) + , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 2, 'B', '', '', '', '', 5, '[2, 6]', true) + , (1, 'b33cfbc9-fbcc-4aac-8335-e5f94ea7e6b2', 2, 'C', '', '', '', '', 5, '[3, 5]', true) + , (1, '8c4465ec-a690-43d7-854b-7fcd35fccb1c', 2, 'D', '', '', '', '', 5, '[4, 8]', true) + , (1, 'd28c30fb-57ac-4243-a8c3-ad1a26637f5a', 2, 'E', '', '', '', '', 5, '[5, 9]', true) ; select lives_ok( diff --git a/test/remove_campsite_carousel_slide.sql b/test/remove_campsite_carousel_slide.sql index 6f70df4..bb3c236 100644 --- a/test/remove_campsite_carousel_slide.sql +++ b/test/remove_campsite_carousel_slide.sql @@ -51,9 +51,9 @@ values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (7, 2, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, 3, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (11, 2, 7, 'Type B', 'B
', 4, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, 3, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 2, 7, 'Type B', 'B
', 4, '[2, 6]', false) ; insert into campsite (campsite_id, label, company_id, campsite_type_id) diff --git a/test/remove_campsite_feature.sql b/test/remove_campsite_feature.sql index f036da6..af62f48 100644 --- a/test/remove_campsite_feature.sql +++ b/test/remove_campsite_feature.sql @@ -47,8 +47,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', true) ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/remove_campsite_type_carousel_slide.sql b/test/remove_campsite_type_carousel_slide.sql index 957028a..aec4133 100644 --- a/test/remove_campsite_type_carousel_slide.sql +++ b/test/remove_campsite_type_carousel_slide.sql @@ -48,9 +48,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (6, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', false) ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/remove_campsite_type_feature.sql b/test/remove_campsite_type_feature.sql index 8b950a3..3a198ee 100644 --- a/test/remove_campsite_type_feature.sql +++ b/test/remove_campsite_type_feature.sql @@ -46,9 +46,9 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', false) ; insert into campsite_type_feature (campsite_type_feature_id, campsite_type_id, icon_name, name) diff --git a/test/remove_campsite_type_option.sql b/test/remove_campsite_type_option.sql index 4216c77..a399ad2 100644 --- a/test/remove_campsite_type_option.sql +++ b/test/remove_campsite_type_option.sql @@ -47,9 +47,9 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', false) ; insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range) diff --git a/test/set_campsite_type_cost.sql b/test/set_campsite_type_cost.sql index 5de7120..a630d19 100644 --- a/test/set_campsite_type_cost.sql +++ b/test/set_campsite_type_cost.sql @@ -41,8 +41,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, '[1, 7]', false, true) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, '[1, 7]', true) ; insert into season (season_id, company_id, name) diff --git a/test/set_campsite_type_option_cost.sql b/test/set_campsite_type_option_cost.sql index 9b60047..3686c3b 100644 --- a/test/set_campsite_type_option_cost.sql +++ b/test/set_campsite_type_option_cost.sql @@ -43,8 +43,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, '[1, 7]', false, true) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, '[1, 7]', true) ; insert into season (season_id, company_id, name) diff --git a/test/set_campsite_type_pet_cost.sql b/test/set_campsite_type_pet_cost.sql new file mode 100644 index 0000000..5ca4096 --- /dev/null +++ b/test/set_campsite_type_pet_cost.sql @@ -0,0 +1,78 @@ +-- Test set_campsite_type_pet_cost +set client_min_messages to warning; +create extension if not exists pgtap; +reset client_min_messages; + +begin; + +select plan(12); + +set search_path to camper, public; + +select has_function('camper', 'set_campsite_type_pet_cost', array['uuid', 'text']); +select function_lang_is('camper', 'set_campsite_type_pet_cost', array['uuid', 'text'], 'sql'); +select function_returns('camper', 'set_campsite_type_pet_cost', array['uuid', 'text'], 'void'); +select isnt_definer('camper', 'set_campsite_type_pet_cost', array['uuid', 'text']); +select volatility_is('camper', 'set_campsite_type_pet_cost', array['uuid', 'text'], 'volatile'); +select function_privs_are('camper', 'set_campsite_type_pet_cost', array ['uuid', 'text'], 'guest', array[]::text[]); +select function_privs_are('camper', 'set_campsite_type_pet_cost', array ['uuid', 'text'], 'employee', array[]::text[]); +select function_privs_are('camper', 'set_campsite_type_pet_cost', array ['uuid', 'text'], 'admin', array['EXECUTE']); +select function_privs_are('camper', 'set_campsite_type_pet_cost', array ['uuid', 'text'], 'authenticator', array[]::text[]); + + +set client_min_messages to warning; +truncate campsite_type_pet_cost 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, country_code, currency_code, default_lang_tag) +values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 60, 'ES', 'EUR', '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 (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) +; + +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, '[1, 7]', true) + , (4, 1, '4ccf62bd-98f3-4239-8f25-a7534363cd98', 2, 'Type B', '', 5, '[1, 7]', true) + , (5, 1, 'b16a8473-c40d-4ab9-b209-6fed03e1d14d', 2, 'Type C', '', 5, '[1, 7]', true) +; + +insert into campsite_type_pet_cost (campsite_type_id, cost_per_night) +values (3, 333) + , (4, 444) +; + +select lives_ok( + $$ select set_campsite_type_pet_cost('87452b88-b48f-48d3-bb6c-0296de64164e', '3.50') $$, + 'Should be able to edit the pet cost for first campsite type' +); + +select lives_ok( + $$ select set_campsite_type_pet_cost('b16a8473-c40d-4ab9-b209-6fed03e1d14d', '12.34') $$, + 'Should be able to add pet cost for third campsite type' +); + +select bag_eq( + $$ select campsite_type_id, cost_per_night from campsite_type_pet_cost $$, + $$ values (3, 350) + , (4, 444) + , (5, 1234) + $$, + 'Should have updated all campsite type pet costs.' +); + + +select * +from finish(); + +rollback; diff --git a/test/translate_campsite.sql b/test/translate_campsite.sql index f6be704..ca2aa2c 100644 --- a/test/translate_campsite.sql +++ b/test/translate_campsite.sql @@ -42,8 +42,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers, bookable_nights) -values (11, 1, 3, 'Type A', false, 5, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, max_campers, bookable_nights) +values (11, 1, 3, 'Type A', 5, '[1, 7]') ; insert into campsite (campsite_id, company_id, campsite_type_id, label, info1, info2, active) diff --git a/test/translate_campsite_carousel_slide.sql b/test/translate_campsite_carousel_slide.sql index f2d6451..988db15 100644 --- a/test/translate_campsite_carousel_slide.sql +++ b/test/translate_campsite_carousel_slide.sql @@ -51,9 +51,9 @@ values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (7, 2, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, 3, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (11, 2, 7, 'Type B', 'B
', 7, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, 3, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 2, 7, 'Type B', 'B
', 7, '[2, 6]', false) ; insert into campsite (campsite_id, label, company_id, campsite_type_id) diff --git a/test/translate_campsite_feature.sql b/test/translate_campsite_feature.sql index b178a95..0bf6568 100644 --- a/test/translate_campsite_feature.sql +++ b/test/translate_campsite_feature.sql @@ -42,8 +42,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, 4, '[1, 7]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/translate_campsite_type.sql b/test/translate_campsite_type.sql index 42c9f07..e412d94 100644 --- a/test/translate_campsite_type.sql +++ b/test/translate_campsite_type.sql @@ -43,9 +43,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (4, 1, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffff00","a"};')) ; -insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, active, dogs_allowed, max_campers, bookable_nights) -values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'Features A
', 'Pricing A
', 'A
', 'Additional A
', '', '', true, false, 4, '[1, 7]') - , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'Features B
', 'Pricing B
', 'B
', 'Additional B
', '', '', false, true, 5, '[2, 6]') +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', 'Features A
', 'Pricing A
', 'A
', 'Additional A
', '', '', true, 4, '[1, 7]') + , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'Features B
', 'Pricing B
', 'B
', 'Additional B
', '', '', false, 5, '[2, 6]') ; insert into campsite_type_i18n (campsite_type_id, lang_tag, name, spiel, info, facilities, description, additional_info, check_in, check_out) diff --git a/test/translate_campsite_type_carousel_slide.sql b/test/translate_campsite_type_carousel_slide.sql index 96c29d0..786ddfd 100644 --- a/test/translate_campsite_type_carousel_slide.sql +++ b/test/translate_campsite_type_carousel_slide.sql @@ -48,9 +48,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (6, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', false) ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/translate_campsite_type_feature.sql b/test/translate_campsite_type_feature.sql index d41412d..a6516ba 100644 --- a/test/translate_campsite_type_feature.sql +++ b/test/translate_campsite_type_feature.sql @@ -41,8 +41,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, 4, '[1, 7]') ; insert into campsite_type_feature (campsite_type_feature_id, campsite_type_id, icon_name, name) diff --git a/test/translate_campsite_type_option.sql b/test/translate_campsite_type_option.sql index c8186f5..9526c5c 100644 --- a/test/translate_campsite_type_option.sql +++ b/test/translate_campsite_type_option.sql @@ -41,8 +41,8 @@ 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"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4, '[1, 7]') +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, max_campers, bookable_nights) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, 4, '[1, 7]') ; insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range) diff --git a/test/unset_campsite_type_pet_cost.sql b/test/unset_campsite_type_pet_cost.sql new file mode 100644 index 0000000..4769098 --- /dev/null +++ b/test/unset_campsite_type_pet_cost.sql @@ -0,0 +1,77 @@ +-- Test unset_campsite_type_pet_cost +set client_min_messages to warning; +create extension if not exists pgtap; +reset client_min_messages; + +begin; + +select plan(12); + +set search_path to camper, public; + +select has_function('camper', 'unset_campsite_type_pet_cost', array['uuid']); +select function_lang_is('camper', 'unset_campsite_type_pet_cost', array['uuid'], 'sql'); +select function_returns('camper', 'unset_campsite_type_pet_cost', array['uuid'], 'void'); +select isnt_definer('camper', 'unset_campsite_type_pet_cost', array['uuid']); +select volatility_is('camper', 'unset_campsite_type_pet_cost', array['uuid'], 'volatile'); +select function_privs_are('camper', 'unset_campsite_type_pet_cost', array ['uuid'], 'guest', array[]::text[]); +select function_privs_are('camper', 'unset_campsite_type_pet_cost', array ['uuid'], 'employee', array[]::text[]); +select function_privs_are('camper', 'unset_campsite_type_pet_cost', array ['uuid'], 'admin', array['EXECUTE']); +select function_privs_are('camper', 'unset_campsite_type_pet_cost', array ['uuid'], 'authenticator', array[]::text[]); + + +set client_min_messages to warning; +truncate campsite_type_pet_cost 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, country_code, currency_code, default_lang_tag) +values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 60, 'ES', 'EUR', '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 (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) +; + +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, active) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, '[1, 7]', true) + , (4, 1, '4ccf62bd-98f3-4239-8f25-a7534363cd98', 2, 'Type B', '', 5, '[1, 7]', true) + , (5, 1, 'b16a8473-c40d-4ab9-b209-6fed03e1d14d', 2, 'Type C', '', 5, '[1, 7]', true) +; + +insert into campsite_type_pet_cost (campsite_type_id, cost_per_night) +values (3, 333) + , (4, 444) + , (5, 555) +; + +select lives_ok( + $$ select unset_campsite_type_pet_cost('87452b88-b48f-48d3-bb6c-0296de64164e') $$, + 'Should be able to unset the pet cost from first campsite type' +); + +select lives_ok( + $$ select unset_campsite_type_pet_cost('b16a8473-c40d-4ab9-b209-6fed03e1d14d') $$, + 'Should be able to unset pet cost for third campsite type' +); + +select bag_eq( + $$ select campsite_type_id, cost_per_night from campsite_type_pet_cost $$, + $$ values (4, 444) + $$, + 'Should have removed campsite type pet costs.' +); + + +select * +from finish(); + +rollback; diff --git a/verify/add_campsite_type.sql b/verify/add_campsite_type.sql index 707916e..2be3afd 100644 --- a/verify/add_campsite_type.sql +++ b/verify/add_campsite_type.sql @@ -2,6 +2,6 @@ begin; -select has_function_privilege('camper.add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean)', 'execute'); +select has_function_privilege('camper.add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean)', 'execute'); rollback; diff --git a/verify/campsite_type__-dogs_allowed.sql b/verify/campsite_type__-dogs_allowed.sql new file mode 100644 index 0000000..4cf1c02 --- /dev/null +++ b/verify/campsite_type__-dogs_allowed.sql @@ -0,0 +1,11 @@ +-- Verify camper:campsite_type__-dogs_allowed on pg + +begin; + +select 1 / (1 - count(*)) +from pg_attribute +where attrelid = 'camper.campsite_type'::regclass + and attname = 'dogs_allowed' +; + +rollback; diff --git a/verify/campsite_type_pet_cost.sql b/verify/campsite_type_pet_cost.sql new file mode 100644 index 0000000..60b5190 --- /dev/null +++ b/verify/campsite_type_pet_cost.sql @@ -0,0 +1,16 @@ +-- Verify camper:campsite_type_pet_cost on pg + +begin; + +select campsite_type_id + , cost_per_night +from camper.campsite_type_pet_cost +where false; + +select 1 / count(*) from pg_class where oid = 'camper.campsite_type_pet_cost'::regclass and relrowsecurity; +select 1 / count(*) from pg_policy where polname = 'guest_ok' and polrelid = 'camper.campsite_type_pet_cost'::regclass; +select 1 / count(*) from pg_policy where polname = 'insert_to_company' and polrelid = 'camper.campsite_type_pet_cost'::regclass; +select 1 / count(*) from pg_policy where polname = 'update_company' and polrelid = 'camper.campsite_type_pet_cost'::regclass; +select 1 / count(*) from pg_policy where polname = 'delete_from_company' and polrelid = 'camper.campsite_type_pet_cost'::regclass; + +rollback; diff --git a/verify/edit_campsite_type.sql b/verify/edit_campsite_type.sql index 71bc5ba..bd67a75 100644 --- a/verify/edit_campsite_type.sql +++ b/verify/edit_campsite_type.sql @@ -2,6 +2,6 @@ begin; -select has_function_privilege('camper.edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean, boolean)', 'execute'); +select has_function_privilege('camper.edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean)', 'execute'); rollback; diff --git a/verify/set_campsite_type_pet_cost.sql b/verify/set_campsite_type_pet_cost.sql new file mode 100644 index 0000000..3d55c00 --- /dev/null +++ b/verify/set_campsite_type_pet_cost.sql @@ -0,0 +1,7 @@ +-- Verify camper:set_campsite_type_pet_cost on pg + +begin; + +select has_function_privilege('camper.set_campsite_type_pet_cost(uuid, text)', 'execute'); + +rollback; diff --git a/verify/unset_campsite_type_pet_cost.sql b/verify/unset_campsite_type_pet_cost.sql new file mode 100644 index 0000000..8150857 --- /dev/null +++ b/verify/unset_campsite_type_pet_cost.sql @@ -0,0 +1,7 @@ +-- Verify camper:unset_campsite_type_pet_cost on pg + +begin; + +select has_function_privilege('camper.unset_campsite_type_pet_cost(uuid)', 'execute'); + +rollback; diff --git a/web/templates/admin/campsite/type/form.gohtml b/web/templates/admin/campsite/type/form.gohtml index c036f39..357034e 100644 --- a/web/templates/admin/campsite/type/form.gohtml +++ b/web/templates/admin/campsite/type/form.gohtml @@ -130,14 +130,24 @@ {{ template "error-message" . }} {{- end }} - {{ with .DogsAllowed -}} - - {{ template "error-message" . }} - {{- end }} + {{ with .Prices }}