campingmontagut/test/percentage.sql
jordi fita mas bd84df8169 Add down payment
Customer wants to require a down payment of 30 % for bookings made
one week or more before the actual date, and to make the full payment
otherwise.

This would require yet another relation to keep these values. Fuck it;
i added them to the function, as they are very unlikely to change.

That forced me to change the test for draft_payment to use relative
dates, otherwise there is no way i can have stable results in the
future.
2024-02-13 23:45:25 +01:00

44 lines
850 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 percentage
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(10);
set search_path to camper, public;
select has_domain('percentage');
select domain_type_is('percentage', 'numeric');
select lives_ok($$ select 1.0::percentage $$);
select lives_ok($$ select 0.0::percentage $$);
select lives_ok($$ select 0.5::percentage $$);
select lives_ok($$ select 0.33::percentage $$);
select lives_ok($$ select 0.89::percentage $$);
select throws_ok(
$$ select 1.01::percentage $$,
23514, null,
'Maximum percentage is 100 %'
);
select throws_ok(
$$ select (-0.01)::percentage $$,
23514, null,
'Minimum percentage is 0 %'
);
select is(
0.001::percentage,
0.00::percentage,
'Percentage precission is 1 % (i.e., no decimals)'
);
select *
from finish();
rollback;