numerus/test/discount_rate.sql
jordi fita mas 6bf51d5eeb Add discount_rate domain and invoice_product relation
I store again the product’s name, description, and prices, because they
are bound to change, but the invoice should remain the same always.
That makes me wonder if i should do the same for seller’s and buyer’s
data, but that should be a different commit.

I’ve added the discount_rate domain because then i can test it
independently of the invoice_product relation, moreover i am sure i will
need it for simplified invoices too.
2023-02-10 19:02:04 +01:00

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;