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

begin;

select plan(63);

set search_path to camper, public;

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

select has_column('payment_redsys_response', 'payment_redsys_response_id');
select col_is_pk('payment_redsys_response', 'payment_redsys_response_id');
select col_type_is('payment_redsys_response', 'payment_redsys_response_id', 'integer');
select col_not_null('payment_redsys_response', 'payment_redsys_response_id');
select col_hasnt_default('payment_redsys_response', 'payment_redsys_response_id');

select has_column('payment_redsys_response', 'payment_id');
select col_is_fk('payment_redsys_response', 'payment_id');
select fk_ok('payment_redsys_response', 'payment_id', 'payment', 'payment_id');
select col_type_is('payment_redsys_response', 'payment_id', 'integer');
select col_not_null('payment_redsys_response', 'payment_id');
select col_hasnt_default('payment_redsys_response', 'payment_id');

select has_column('payment_redsys_response', 'response_code');
select col_type_is('payment_redsys_response', 'response_code', 'integer');
select col_not_null('payment_redsys_response', 'response_code');
select col_hasnt_default('payment_redsys_response', 'response_code');

select has_column('payment_redsys_response', 'date_time');
select col_type_is('payment_redsys_response', 'date_time', 'timestamp without time zone');
select col_not_null('payment_redsys_response', 'date_time');
select col_hasnt_default('payment_redsys_response', 'date_time');

select has_column('payment_redsys_response', 'secure_payment');
select col_type_is('payment_redsys_response', 'secure_payment', 'boolean');
select col_not_null('payment_redsys_response', 'secure_payment');
select col_hasnt_default('payment_redsys_response', 'secure_payment');

select has_column('payment_redsys_response', 'transaction_type');
select col_type_is('payment_redsys_response', 'transaction_type', 'integer');
select col_not_null('payment_redsys_response', 'transaction_type');
select col_hasnt_default('payment_redsys_response', 'transaction_type');

select has_column('payment_redsys_response', 'amount');
select col_type_is('payment_redsys_response', 'amount', 'integer');
select col_not_null('payment_redsys_response', 'amount');
select col_hasnt_default('payment_redsys_response', 'amount');

select has_column('payment_redsys_response', 'currency_code');
select col_is_fk('payment_redsys_response', 'currency_code');
select fk_ok('payment_redsys_response', 'currency_code', 'currency', 'currency_code');
select col_type_is('payment_redsys_response', 'currency_code', 'currency_code');
select col_not_null('payment_redsys_response', 'currency_code');
select col_hasnt_default('payment_redsys_response', 'currency_code');

select has_column('payment_redsys_response', 'order_number');
select col_type_is('payment_redsys_response', 'order_number', 'text');
select col_not_null('payment_redsys_response', 'order_number');
select col_hasnt_default('payment_redsys_response', 'order_number');

select has_column('payment_redsys_response', 'authorization_code');
select col_type_is('payment_redsys_response', 'authorization_code', 'text');
select col_not_null('payment_redsys_response', 'authorization_code');
select col_hasnt_default('payment_redsys_response', 'authorization_code');

select has_column('payment_redsys_response', 'merchant_code');
select col_type_is('payment_redsys_response', 'merchant_code', 'text');
select col_not_null('payment_redsys_response', 'merchant_code');
select col_hasnt_default('payment_redsys_response', 'merchant_code');

select has_column('payment_redsys_response', 'terminal_number');
select col_type_is('payment_redsys_response', 'terminal_number', 'integer');
select col_not_null('payment_redsys_response', 'terminal_number');
select col_hasnt_default('payment_redsys_response', 'terminal_number');

select has_column('payment_redsys_response', 'error_code');
select col_type_is('payment_redsys_response', 'error_code', 'text');
select col_not_null('payment_redsys_response', 'error_code');
select col_hasnt_default('payment_redsys_response', 'error_code');


select *
from finish();

rollback;

