35 lines
863 B
PL/PgSQL
35 lines
863 B
PL/PgSQL
-- Test discount_rate
|
||
set client_min_messages to warning;
|
||
create extension if not exists pgtap;
|
||
reset client_min_messages;
|
||
|
||
begin;
|
||
|
||
select plan(7);
|
||
|
||
set search_path to camper, public;
|
||
|
||
select has_domain('discount_rate');
|
||
select domain_type_is('discount_rate', 'numeric');
|
||
|
||
select lives_ok($$ select 1::discount_rate $$, 'Should be able to cast valid 100 % to discount rate');
|
||
select lives_ok($$ select 0.21::discount_rate $$, 'Should be able to cast valid positive decimals to discount rate');
|
||
select lives_ok($$ select 0::discount_rate $$, 'Should be able to cast valid zero to discount rate');
|
||
|
||
select throws_ok(
|
||
$$ SELECT (-0.01)::discount_rate $$,
|
||
23514, null,
|
||
'Should reject negative discount rate'
|
||
);
|
||
|
||
select throws_ok(
|
||
$$ SELECT 1.01::discount_rate $$,
|
||
23514, null,
|
||
'Should not allow past the 100 % discount'
|
||
);
|
||
|
||
select *
|
||
from finish();
|
||
|
||
rollback;
|