From 0e20eab46a8ad5cc459aa4ecefea07142655e977 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Wed, 7 Jun 2023 13:17:57 +0200 Subject: [PATCH] Add test for invoice_number_counter counter_zero_or_positive constraint --- test/invoice_number_counter.sql | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/invoice_number_counter.sql b/test/invoice_number_counter.sql index 955c7a0..1bdaafe 100644 --- a/test/invoice_number_counter.sql +++ b/test/invoice_number_counter.sql @@ -5,7 +5,7 @@ reset client_min_messages; begin; -select plan(27); +select plan(28); set search_path to numerus, auth, public; @@ -116,11 +116,19 @@ reset role; select lives_ok( $$ insert into invoice_number_counter (company_id, year, currval) - values (2, 2008, 0) + values (2, 2009, 0) $$, 'Should allow starting a counter from zero' ); +select throws_ok( $$ + insert into invoice_number_counter (company_id, year, currval) + values (2, 2008, -1) + $$, + '23514', 'new row for relation "invoice_number_counter" violates check constraint "counter_zero_or_positive"', + 'Should not allow starting a counter from a negative value' +); + select throws_ok( $$ insert into invoice_number_counter (company_id, year, currval) values (2, -2008, 1)