numerus/test/discount_rate.sql

35 lines
864 B
PL/PgSQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 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 numerus, 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;