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

begin;

select plan(78);

set search_path to camper, public;

select has_table('booking_guest');
select has_pk('booking_guest');
select col_is_unique('booking_guest', array['booking_id', 'id_document_type_id', 'id_document_number']);
select table_privs_are('booking_guest', 'guest', array[]::text[]);
select table_privs_are('booking_guest', 'employee', array['SELECT', 'INSERT', 'UPDATE', 'DELETE']);
select table_privs_are('booking_guest', 'admin', array['SELECT', 'INSERT', 'UPDATE', 'DELETE']);
select table_privs_are('booking_guest', 'authenticator', array[]::text[]);

select has_column('booking_guest', 'booking_guest_id');
select col_is_pk('booking_guest', 'booking_guest_id');
select col_type_is('booking_guest', 'booking_guest_id', 'integer');
select col_not_null('booking_guest', 'booking_guest_id');
select col_hasnt_default('booking_guest', 'booking_guest_id');

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

select has_column('booking_guest', 'id_document_type_id');
select col_is_fk('booking_guest', 'id_document_type_id');
select fk_ok('booking_guest', 'id_document_type_id', 'id_document_type', 'id_document_type_id');
select col_type_is('booking_guest', 'id_document_type_id', 'character varying(1)');
select col_not_null('booking_guest', 'id_document_type_id');
select col_hasnt_default('booking_guest', 'id_document_type_id');

select has_column('booking_guest', 'id_document_number');
select col_type_is('booking_guest', 'id_document_number', 'text');
select col_not_null('booking_guest', 'id_document_number');
select col_hasnt_default('booking_guest', 'id_document_number');

select has_column('booking_guest', 'id_document_issue_date');
select col_type_is('booking_guest', 'id_document_issue_date', 'date');
select col_is_null('booking_guest', 'id_document_issue_date');
select col_hasnt_default('booking_guest', 'id_document_issue_date');

select has_column('booking_guest', 'given_name');
select col_type_is('booking_guest', 'given_name', 'text');
select col_not_null('booking_guest', 'given_name');
select col_hasnt_default('booking_guest', 'given_name');

select has_column('booking_guest', 'first_surname');
select col_type_is('booking_guest', 'first_surname', 'text');
select col_not_null('booking_guest', 'first_surname');
select col_hasnt_default('booking_guest', 'first_surname');

select has_column('booking_guest', 'second_surname');
select col_type_is('booking_guest', 'second_surname', 'text');
select col_not_null('booking_guest', 'second_surname');
select col_hasnt_default('booking_guest', 'second_surname');

select has_column('booking_guest', 'sex_id');
select col_is_fk('booking_guest', 'sex_id');
select fk_ok('booking_guest', 'sex_id', 'sex', 'sex_id');
select col_type_is('booking_guest', 'sex_id', 'character varying(1)');
select col_not_null('booking_guest', 'sex_id');
select col_hasnt_default('booking_guest', 'sex_id');

select has_column('booking_guest', 'birthdate');
select col_type_is('booking_guest', 'birthdate', 'date');
select col_not_null('booking_guest', 'birthdate');
select col_hasnt_default('booking_guest', 'birthdate');

select has_column('booking_guest', 'country_code');
select col_is_fk('booking_guest', 'country_code');
select fk_ok('booking_guest', 'country_code', 'country', 'country_code');
select col_type_is('booking_guest', 'country_code', 'country_code');
select col_not_null('booking_guest', 'country_code');
select col_hasnt_default('booking_guest', 'country_code');

select has_column('booking_guest', 'phone');
select col_type_is('booking_guest', 'phone', 'packed_phone_number');
select col_is_null('booking_guest', 'phone');
select col_hasnt_default('booking_guest', 'phone');

select has_column('booking_guest', 'address');
select col_type_is('booking_guest', 'address', 'text');
select col_not_null('booking_guest', 'address');
select col_hasnt_default('booking_guest', 'address');

select has_column('booking_guest', 'created_at');
select col_type_is('booking_guest', 'created_at', 'timestamp with time zone');
select col_not_null('booking_guest', 'created_at');
select col_has_default('booking_guest', 'created_at');
select col_default_is('booking_guest', 'created_at', 'CURRENT_TIMESTAMP');

select has_column('booking_guest', 'updated_at');
select col_type_is('booking_guest', 'updated_at', 'timestamp with time zone');
select col_not_null('booking_guest', 'updated_at');
select col_has_default('booking_guest', 'updated_at');
select col_default_is('booking_guest', 'updated_at', 'CURRENT_TIMESTAMP');


select *
from finish();

rollback;

