-- Test booking_option
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;

begin;

select plan(27);

set search_path to camper, public;

select has_table('booking_option');
select has_pk('booking_option');
select col_is_pk('booking_option', array['booking_id', 'campsite_type_option_id']);
select table_privs_are('booking_option', 'guest', array[]::text[]);
select table_privs_are('booking_option', 'employee', array['SELECT', 'INSERT', 'UPDATE', 'DELETE']);
select table_privs_are('booking_option', 'admin', array['SELECT', 'INSERT', 'UPDATE', 'DELETE']);
select table_privs_are('booking_option', 'authenticator', array[]::text[]);

select has_column('booking_option', 'booking_id');
select col_is_fk('booking_option', 'booking_id');
select fk_ok('booking_option', 'booking_id', 'booking', 'booking_id');
select col_type_is('booking_option', 'booking_id', 'integer');
select col_not_null('booking_option', 'booking_id');
select col_hasnt_default('booking_option', 'booking_id');

select has_column('booking_option', 'campsite_type_option_id');
select col_is_fk('booking_option', 'campsite_type_option_id');
select fk_ok('booking_option', 'campsite_type_option_id', 'campsite_type_option', 'campsite_type_option_id');
select col_type_is('booking_option', 'campsite_type_option_id', 'integer');
select col_not_null('booking_option', 'campsite_type_option_id');
select col_hasnt_default('booking_option', 'campsite_type_option_id');

select has_column('booking_option', 'units');
select col_type_is('booking_option', 'units', 'positive_integer');
select col_not_null('booking_option', 'units');
select col_hasnt_default('booking_option', 'units');

select has_column('booking_option', 'subtotal');
select col_type_is('booking_option', 'subtotal', 'nonnegative_integer');
select col_not_null('booking_option', 'subtotal');
select col_hasnt_default('booking_option', 'subtotal');


select *
from finish();

rollback;

