generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PO-1010 Deploy the interface files scripts from Capita (#650)
Co-authored-by: DeclanClarkeCGI <[email protected]>
- Loading branch information
1 parent
25fd202
commit bb723a0
Showing
17 changed files
with
1,828 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/dbUnitTest/interfaceFiles/p_int_payment_card_requests_unit_tests.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--Test 1. Run interface for all accounts and check format of JSON | ||
|
||
DO $$ | ||
BEGIN | ||
delete from public.payment_card_requests; | ||
insert into public.payment_card_requests | ||
select defendant_account_id from public.defendant_accounts; | ||
CALL public.p_run_interface_job('PAYMENT_CARD_REQUESTS',4::smallint); | ||
|
||
END | ||
$$; | ||
|
||
|
||
SELECT * | ||
FROM interface_jobs ij1 | ||
WHERE ij1.interface_name = 'PAYMENT_CARD_REQUESTS' | ||
AND ij1.interface_job_id = ( | ||
SELECT max(ij2.interface_job_id) | ||
FROM interface_jobs ij2 | ||
WHERE ij2.interface_name = ij1.interface_name | ||
); | ||
|
||
SELECT * | ||
FROM interface_files if | ||
WHERE if.interface_job_id = ( | ||
SELECT max(ij2.interface_job_id) | ||
FROM interface_jobs ij2 | ||
WHERE ij2.interface_name = 'PAYMENT_CARD_REQUESTS' | ||
); | ||
|
||
--Test 2. Verify that the payment_card_requests table is empty after running the interface. | ||
|
||
SELECT count(*) FROM payment_card_requests; | ||
|
||
|
||
--Test 3. Verify that special characters are removed from a string. | ||
-- Apply following SQL and the rerun test1 | ||
update parties | ||
set surname = 'TestName1%()*+<=>?[]{}Ā' | ||
WHERE party_id = 10600000001596; | ||
|
||
--Test 4. Verify that a company name appears in the JSON. | ||
-- Apply following SQL and the rerun test1 | ||
|
||
update parties | ||
set surname = NULL, title = null, | ||
organisation_name = 'Bob Wright Extreme Tours Ltd', | ||
organisation = true | ||
WHERE party_id = 11060000004428; | ||
|
487 changes: 487 additions & 0 deletions
487
src/dbUnitTest/interfaceFiles/p_int_payments_in_unit_tests.sql
Large diffs are not rendered by default.
Oops, something went wrong.
135 changes: 135 additions & 0 deletions
135
src/dbUnitTest/interfaceFiles/p_int_presented_cheques_unit_tests.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
DO $$ | ||
DECLARE | ||
test_result integer := 0; | ||
|
||
BEGIN | ||
--Script to test Presented Cheques interface | ||
-- clear down jobs | ||
DELETE FROM interface_messages; | ||
DELETE FROM interface_files; | ||
DELETE FROM interface_jobs; | ||
|
||
|
||
--cheques / creditor_transactions / defendant_accounts | ||
DELETE FROM cheques WHERE cheque_id < 100000; | ||
DELETE FROM creditor_transactions WHERE creditor_transaction_id < 1000000; | ||
|
||
|
||
-- Cheque 1 (should get status P) | ||
INSERT INTO public.creditor_transactions( | ||
creditor_transaction_id, creditor_account_id, posted_date, posted_by, posted_by_user_id, transaction_type, transaction_amount, imposition_result_id, | ||
payment_processed, payment_reference, status, status_date, associated_record_type, associated_record_id) | ||
VALUES (1000, 20040000000001, (CURRENT_TIMESTAMP-INTERVAL '60 days'), 'DRJ', null, 'C', 5000, 1, null, 976, null, (CURRENT_TIMESTAMP+INTERVAL '60 days'), null, null); | ||
INSERT INTO public.cheques( | ||
cheque_id, business_unit_id, cheque_number, issue_date, creditor_transaction_id, defendant_transaction_id, amount, allocation_type, reminder_date, status) | ||
VALUES (01, 4, 8888, (CURRENT_TIMESTAMP-INTERVAL '60 days'), 1000, null, 5000, 'A', (CURRENT_TIMESTAMP+INTERVAL '60 days'), 'U'); | ||
|
||
|
||
-- Cheque 2(Query amount) | ||
INSERT INTO public.creditor_transactions( | ||
creditor_transaction_id, creditor_account_id, posted_date, posted_by, posted_by_user_id, transaction_type, transaction_amount, imposition_result_id, | ||
payment_processed, payment_reference, status, status_date, associated_record_type, associated_record_id) | ||
VALUES (1050, 20040000000370, (CURRENT_TIMESTAMP-INTERVAL '60 days'), 'DRJ2', null, 'C', 1050, 1, null, 976, null, (CURRENT_TIMESTAMP+INTERVAL '60 days'), null, null); | ||
INSERT INTO public.cheques( | ||
cheque_id, business_unit_id, cheque_number, issue_date, creditor_transaction_id, defendant_transaction_id, amount, allocation_type, reminder_date, status) | ||
VALUES (02, 4, 7777, (CURRENT_TIMESTAMP-INTERVAL '60 days'), 1050, null, 1050, 'A', (CURRENT_TIMESTAMP+INTERVAL '60 days'), 'U'); | ||
|
||
-- Cheque 3 (is not entered to test Cheque not found) | ||
|
||
-- Cheque 4 (awaiting deletion) | ||
INSERT INTO public.cheques( | ||
cheque_id, business_unit_id, cheque_number, issue_date, creditor_transaction_id, defendant_transaction_id, amount, allocation_type, reminder_date, status) | ||
VALUES (04, 4, 5555, (CURRENT_TIMESTAMP-INTERVAL '60 days'), 20040000000052, null, 300, 'A', (CURRENT_TIMESTAMP+INTERVAL '60 days'), 'X'); | ||
-- Cheque 5 (cheque destroyed) | ||
INSERT INTO public.cheques( | ||
cheque_id, business_unit_id, cheque_number, issue_date, creditor_transaction_id, defendant_transaction_id, amount, allocation_type, reminder_date, status) | ||
VALUES (05, 4, 4444, (CURRENT_TIMESTAMP-INTERVAL '60 days'), 20040000002535, null, 300, 'A', (CURRENT_TIMESTAMP+INTERVAL '60 days'), 'D'); | ||
-- Cheque 6 (cheque withdrawn) | ||
INSERT INTO public.cheques( | ||
cheque_id, business_unit_id, cheque_number, issue_date, creditor_transaction_id, defendant_transaction_id, amount, allocation_type, reminder_date, status) | ||
VALUES (06, 4, 3333, (CURRENT_TIMESTAMP-INTERVAL '60 days'), 20040000002499, null, 300, 'A', (CURRENT_TIMESTAMP+INTERVAL '60 days'), 'W'); | ||
-- Cheque 7 (cheque presented) | ||
INSERT INTO public.cheques( | ||
cheque_id, business_unit_id, cheque_number, issue_date, creditor_transaction_id, defendant_transaction_id, amount, allocation_type, reminder_date, status) | ||
VALUES (07, 4, 2222, (CURRENT_TIMESTAMP-INTERVAL '60 days'), 20040000002466, null, 300, 'A', (CURRENT_TIMESTAMP+INTERVAL '60 days'), 'P'); | ||
-- jobs | ||
INSERT INTO interface_jobs(interface_job_id,business_unit_id,interface_name) | ||
VALUES (99,4,'presented_cheques'); | ||
INSERT INTO interface_files(interface_file_id, interface_job_id,file_name,records) | ||
VALUES (66, 99,'test-presented-cheques', | ||
'[{"account_number":"24000001A","receiving_sort_code":"27049027","receiving_bank_account_number":"27049027","cheque_number":"8888","transaction_code":"11","amount_pence":"5000","entry_date":"311024","originator_reference":"24000001A"}, | ||
{"account_number":"24000002A","receiving_sort_code":"27049027","receiving_bank_account_number":"27049027","cheque_number":"7777","transaction_code":"11","amount_pence":"1000","entry_date":"311024","originator_reference":"24000002A"}, | ||
{"account_number":"24000003A","receiving_sort_code":"27049027","receiving_bank_account_number":"27049027","cheque_number":"6666","transaction_code":"11","amount_pence":"6666","entry_date":"311024","originator_reference":"24000003A"}, | ||
{"account_number":"24000004A","receiving_sort_code":"27049027","receiving_bank_account_number":"27049027","cheque_number":"5555","transaction_code":"11","amount_pence":"5555","entry_date":"311024","originator_reference":"24000004A"}, | ||
{"account_number":"24000005A","receiving_sort_code":"27049027","receiving_bank_account_number":"27049027","cheque_number":"4444","transaction_code":"11","amount_pence":"4444","entry_date":"311024","originator_reference":"24000005A"}, | ||
{"account_number":"24000006A","receiving_sort_code":"27049027","receiving_bank_account_number":"27049027","cheque_number":"3333","transaction_code":"11","amount_pence":"3333","entry_date":"311024","originator_reference":"24000006A"}, | ||
{"account_number":"24000007A","receiving_sort_code":"27049027","receiving_bank_account_number":"27049027","cheque_number":"2222","transaction_code":"11","amount_pence":"3333","entry_date":"311024","originator_reference":"24000007A"}]'); | ||
RAISE NOTICE 'Data setup. Beginning job...'; | ||
|
||
-- Now run all the cheques via the sp and check the results | ||
--call p_run_interface_job('presented_cheques'::text, 4::smallint); -- Job Id , Business Unit | ||
call p_int_presented_cheques(99); | ||
|
||
-- Check the results | ||
BEGIN | ||
|
||
-- Test 1 - Good cheque (should be presented) | ||
test_result := (select count(*) from creditor_transactions ct | ||
left join cheques c on ct.creditor_transaction_id = c.creditor_transaction_Id | ||
where ct.creditor_transaction_id = 1000 and ct.status = 'C' and c.status = 'P')::integer ; | ||
RAISE NOTICE 'Test 1: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
--Test 2 - Cheque not presented - should mark Cheque as Query and leave Creditor_Transaction status null | ||
test_result := (select count(*) from creditor_transactions ct | ||
left join cheques c on ct.creditor_transaction_id = c.creditor_transaction_Id | ||
where ct.creditor_transaction_id = 1050 and ct.status is null and c.status = 'Q')::integer ; | ||
RAISE NOTICE 'Test 2: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
--Test 3 - Cheque not found - cheque number doesn't exist in DB and interface message written | ||
test_result := (select count(*) from interface_Messages | ||
where message_text = 'Cheque not found' AND record_detail like '%6666%' and | ||
0 = (select count(*) from cheques where cheque_number = 6666))::integer ; | ||
RAISE NOTICE 'Test 3: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
--Test 4 - Cheque awaiting deletion (not processed - status remains X) | ||
test_result := (select count(*) from cheques where cheque_number = 5555 and status = 'X')::integer ; | ||
RAISE NOTICE 'Test 4: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
-- Test 5 - Cheque marked for deletion not processed - marked in Interface Messages | ||
test_result := (select count(*) from interface_messages where message_text = 'Cheque not found' AND record_detail like '%5555%')::integer ; | ||
RAISE NOTICE 'Test 5: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
--Test 6 - Cheque destroyed (not processed - status remains D) | ||
test_result := (select count(*) from cheques where cheque_number = 4444 and status = 'D')::integer ; | ||
RAISE NOTICE 'Test 6: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
-- Test 7 - Cheque destroyed not processed - marked in Interface Messages | ||
test_result := (select count(*) from interface_messages where message_text = 'Cheque destroyed' AND record_detail like '%4444%')::integer ; | ||
RAISE NOTICE 'Test 7: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
--Test 8 - Cheque widthdrawn (not processed - status remains W) | ||
test_result := (select count(*) from cheques where cheque_number = 3333 and status = 'W')::integer ; | ||
RAISE NOTICE 'Test 8: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
-- Test 9 - Cheque withdrawn not processed - marked in Interface Messages | ||
test_result := (select count(*) from interface_messages where message_text = 'Cheque withdrawn' AND record_detail like '%3333%')::integer ; | ||
RAISE NOTICE 'Test 9: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
--Test 10 - Cheque already presented (not processed - status remains P) | ||
test_result := (select count(*) from cheques where cheque_number = 2222 and status = 'P')::integer ; | ||
RAISE NOTICE 'Test 10: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
-- Test 11 - Cheque already presented - not processed - marked in Interface Messages | ||
test_result := (select count(*) from interface_messages where message_text = 'Cheque already presented' AND record_detail like '%2222%')::integer ; | ||
RAISE NOTICE 'Test 11: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
--Test 12 - Check the total presented interface message is correct | ||
test_result := (select count(*) from interface_messages where message_text = 'Cheques presented: 1, value: £50.00')::integer ; | ||
RAISE NOTICE 'Test 12: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
|
||
--Test 13 - Check the total not presented interface message is correct | ||
test_result := (select count(*) from interface_messages where message_text = 'Cheques not presented: 6, value: £243.31')::integer ; | ||
RAISE NOTICE 'Test 13: %', CASE WHEN test_result = 1 THEN 'Passed' ELSE 'Failed' END; | ||
END; | ||
END; | ||
$$; |
74 changes: 74 additions & 0 deletions
74
src/dbUnitTest/interfaceFiles/p_run_interface_job_unit_test_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
p_run_interface_job_unit_test_data.sql - Test Data Script | ||
Test to validate old completed jobs are created | ||
The procedure p_run_interface_job performs commit/rollback there cannot be a single process to commit | ||
test data and then run the procedure. | ||
So this test must be run manually as it is in 2 parts: | ||
Part 1 Test data - this script creates the following | ||
19 interface jobs created: | ||
1 new PAYMENTS_IN | ||
1 new PRESENTED_CHEQUES | ||
Note: payment card requests interface creates its own job | ||
8 old jobs for deletion as they are > 100 days (4 payments in, 2 pres cheques, 2 pcr) | ||
3 old jobs that should not be deleted as they are not the status completed/failed (1 of each interface) | ||
6 jobs that should not be deleted as they are 100 days old exactly (2 of each interface) | ||
Part 2 execute p_run_interface_job_unit_tests.sql | ||
Test runs each interface in turn and validates results | ||
*/ | ||
SET SCHEMA 'public'; | ||
|
||
BEGIN; | ||
|
||
-- clear existing data | ||
DELETE FROM interface_messages; | ||
DELETE FROM interface_files; | ||
DELETE FROM interface_jobs; | ||
|
||
-- new jobs to be run | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status) | ||
VALUES (nextval('interface_job_id_seq'), 4, 'PAYMENTS_IN', 'Created'); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status) | ||
VALUES (nextval('interface_job_id_seq'), 4, 'PRESENTED_CHEQUES', 'Created'); | ||
|
||
/* jobs for deletion */ | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PAYMENTS_IN', 'Failed',CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PAYMENTS_IN', 'Failed',CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PAYMENTS_IN', 'Completed',CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PAYMENTS_IN', 'Completed',CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PRESENTED_CHEQUES', 'Completed',CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PRESENTED_CHEQUES', 'Failed',CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), NULL, 'PAYMENT_CARD_REQUESTS', 'Completed',CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), NULL, 'PAYMENT_CARD_REQUESTS', 'Failed',CURRENT_DATE-101); | ||
-- not old enough | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PAYMENTS_IN', 'Failed',CURRENT_DATE-100); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PAYMENTS_IN', 'Completed',CURRENT_DATE-100); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PRESENTED_CHEQUES', 'Failed',CURRENT_DATE-100); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PRESENTED_CHEQUES', 'Completed',CURRENT_DATE-100); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), NULL, 'PAYMENT_CARD_REQUESTS', 'Failed',CURRENT_DATE-100); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), NULL, 'PAYMENT_CARD_REQUESTS', 'Completed',CURRENT_DATE-100); | ||
-- not completed/failed | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PAYMENTS_IN', 'Created', CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), 18, 'PRESENTED_CHEQUES', 'Created', CURRENT_DATE-101); | ||
INSERT INTO interface_jobs (interface_job_id, business_unit_id, interface_name, status, completed_datetime) | ||
VALUES (nextval('interface_job_id_seq'), NULL, 'PAYMENT_CARD_REQUESTS', 'Written', CURRENT_DATE-101); | ||
|
||
END; |
Oops, something went wrong.