102 lines
5.0 KiB
PL/PgSQL
102 lines
5.0 KiB
PL/PgSQL
-- Test edit_contact
|
|
set client_min_messages to warning;
|
|
create extension if not exists pgtap;
|
|
reset client_min_messages;
|
|
|
|
begin;
|
|
|
|
select plan(14);
|
|
|
|
set search_path to auth, numerus, public;
|
|
|
|
select has_function('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]']);
|
|
select function_lang_is('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]'], 'plpgsql');
|
|
select function_returns('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]'], 'uuid');
|
|
select isnt_definer('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]']);
|
|
select volatility_is('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]'], 'volatile');
|
|
select function_privs_are('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]'], 'guest', array []::text[]);
|
|
select function_privs_are('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]'], 'invoicer', array ['EXECUTE']);
|
|
select function_privs_are('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]'], 'admin', array ['EXECUTE']);
|
|
select function_privs_are('numerus', 'edit_contact', array ['uuid', 'text', 'text', 'text', 'text', 'email', 'uri', 'text', 'text', 'text', 'text', 'country_code', 'tag_name[]'], 'authenticator', array []::text[]);
|
|
|
|
|
|
set client_min_messages to warning;
|
|
truncate contact_tag cascade;
|
|
truncate tag cascade;
|
|
truncate contact cascade;
|
|
truncate payment_method cascade;
|
|
truncate company cascade;
|
|
reset client_min_messages;
|
|
|
|
|
|
set constraints "company_default_payment_method_id_fkey" deferred;
|
|
|
|
insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id)
|
|
values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111)
|
|
;
|
|
|
|
insert into payment_method (payment_method_id, company_id, name, instructions)
|
|
values (111, 1, 'cash', 'cash')
|
|
, (112, 1, 'bank', 'send money to my bank account')
|
|
;
|
|
|
|
set constraints "company_default_payment_method_id_fkey" immediate;
|
|
|
|
insert into tag (tag_id, company_id, name)
|
|
values (10, 1, 'tag1')
|
|
, (11, 1, 'tag2')
|
|
;
|
|
-- edit_contact uses the sequence and sometimes it would confict
|
|
alter sequence tag_tag_id_seq restart with 15;
|
|
|
|
insert into contact (contact_id, company_id, slug, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code)
|
|
values (12, 1, '7ac3ae0e-b0c1-4206-a19b-0be20835edd4', 'Contact 1', 'XX555', '', '777-777-777', 'c@c', '', '', '', '', '', 'ES')
|
|
, (13, 1, 'b57b980b-247b-4be4-a0b7-03a7819c53ae', 'Contact 2', 'XX666', '', '888-888-888', 'd@d', '', '', '', '', '', 'ES')
|
|
;
|
|
|
|
insert into contact_tag (contact_id, tag_id)
|
|
values (12, 10)
|
|
, (13, 11)
|
|
;
|
|
|
|
select lives_ok(
|
|
$$ select edit_contact('7ac3ae0e-b0c1-4206-a19b-0be20835edd4', 'Contact 2.1', '40404040D', 'Trade Contact 2.1', '999-999-999', 'c1@c1', 'https://c', 'Fake St., 123', 'City 2.1', 'Province 2.1', '19486', 'ES', array['tag1']) $$,
|
|
'Should be able to edit the first contact'
|
|
);
|
|
|
|
select lives_ok(
|
|
$$ select edit_contact('b57b980b-247b-4be4-a0b7-03a7819c53ae', 'Contact 2.2', '41414141L', 'Trade Contact 2.2', '111-111-111', 'd2@d2', 'https://d', 'Another Fake St., 123', 'City 2.2', 'Province 2.2', '17417', 'ES', array['tag1', 'tag3']) $$,
|
|
'Should be able to edit the second contact'
|
|
);
|
|
|
|
select bag_eq(
|
|
$$ select company_id, business_name, vatin::text, trade_name, phone::text, email::text, web::text, address, city, province, postal_code, country_code::text, created_at from contact $$,
|
|
$$ values (1, 'Contact 2.1', 'ES40404040D', 'Trade Contact 2.1', '+34 999 99 99 99', 'c1@c1', 'https://c', 'Fake St., 123', 'City 2.1', 'Province 2.1', '19486', 'ES', CURRENT_TIMESTAMP)
|
|
, (1, 'Contact 2.2', 'ES41414141L', 'Trade Contact 2.2', '+34 111111111', 'd2@d2', 'https://d', 'Another Fake St., 123', 'City 2.2', 'Province 2.2', '17417', 'ES', CURRENT_TIMESTAMP)
|
|
$$,
|
|
'Should have updated all contacts'
|
|
);
|
|
|
|
select bag_eq(
|
|
$$ select company_id, name from tag $$,
|
|
$$ values (1, 'tag1')
|
|
, (1, 'tag2')
|
|
, (1, 'tag3')
|
|
$$,
|
|
'Should have added all new tags'
|
|
);
|
|
|
|
select bag_eq(
|
|
$$ select business_name, tag.name from contact_tag join contact using (contact_id) join tag using (tag_id) $$,
|
|
$$ values ('Contact 2.1', 'tag1')
|
|
, ('Contact 2.2', 'tag1')
|
|
, ('Contact 2.2', 'tag3')
|
|
$$,
|
|
'Should have assigned the tags to contacts'
|
|
);
|
|
|
|
select *
|
|
from finish();
|
|
|
|
rollback;
|