numerus/test/bic.sql
jordi fita mas 20827b2cfb Add IBAN and BIC fields to contacts
These two fields are just for information purposes, as Numerus does not
have any way to wire transfer using these, but people might want to keep
these in the contact’s info as a convenience.

Since not every contact should have an IBAN, e.g., customers, and inside
SEPA (European Union and some more countries) the BIC is not required,
they are in two different relations in order to be optional without
using NULL.

For the IBAN i found an already made PostgreSQL module, but for BIC i
had to write a regular expression based on the information i gathered
from Wikipedia, because the ISO standard is not free.

These two parameters for the add_contact and edit_contact functions are
TEXT because i realized that these functions are intended to be used
from the web application, that only deals with texts, so the
ValueOrNil() function was unnecessarily complex and PostreSQL’s
functions were better suited to “convert” from TEXT to IBAN or BIC.
The same is true for EMAIL and URI domains, so i changed their parameter
types to TEXT too.

Closes #54.
2023-07-02 02:08:45 +02:00

107 lines
2.1 KiB
PL/PgSQL

-- Test bic
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(18);
set search_path to numerus, public;
select has_domain('bic');
select domain_type_is('bic', 'text');
select lives_ok($$ select 'BBVAESMM'::bic $$, 'Should be able to cast strings without department to bic');
select lives_ok($$ select 'LOYDCHGGZCH'::bic $$, 'Should be able to cast strings with department to bic');
select throws_ok(
$$ SELECT 'loydchggzch'::bic $$,
23514, null,
'Should reject BIC with lowercase'
);
select throws_ok(
$$ SELECT ' LOYDCHGGZCH'::bic $$,
23514, null,
'Should reject BIC with heading spaces'
);
select throws_ok(
$$ SELECT 'LOYDCHGGZCH '::bic $$,
23514, null,
'Should reject BIC with trailing spaces'
);
select throws_ok(
$$ SELECT 'LOYD CH GG ZCH'::bic $$,
23514, null,
'Should reject BIC with middle spaces'
);
select throws_ok(
$$ SELECT '1OYDCHGGZCH'::bic $$,
23514, null,
'Should reject BIC with numbers at first position'
);
select throws_ok(
$$ SELECT 'L2YDCHGGZCH'::bic $$,
23514, null,
'Should reject BIC with numbers at second position'
);
select throws_ok(
$$ SELECT 'LO3DCHGGZCH'::bic $$,
23514, null,
'Should reject BIC with numbers at third position'
);
select throws_ok(
$$ SELECT 'LOY4CHGGZCH'::bic $$,
23514, null,
'Should reject BIC with numbers at fourth position'
);
select throws_ok(
$$ SELECT 'LOYD5HGGZCH'::bic $$,
23514, null,
'Should reject BIC with numbers at fifth position'
);
select throws_ok(
$$ SELECT 'LOYDC6GGZCH'::bic $$,
23514, null,
'Should reject BIC with numbers at sixth position'
);
select throws_ok(
$$ SELECT 'LOYDCHG'::bic $$,
23514, null,
'Should reject BIC with 7 characters'
);
select throws_ok(
$$ SELECT 'LOYDCHGGZ'::bic $$,
23514, null,
'Should reject BIC with 9 characters'
);
select throws_ok(
$$ SELECT 'LOYDCHGGZC'::bic $$,
23514, null,
'Should reject BIC with 10 characters'
);
select throws_ok(
$$ SELECT 'LOYDCHGGZCHH'::bic $$,
23514, null,
'Should reject BIC with 12 characters'
);
select *
from finish();
rollback;