summaryrefslogtreecommitdiff
path: root/sql/modules/test/Payment.sql
blob: b74269e35d83657ea11ec218e3cee33bc6bf8382 (plain)
  1. BEGIN;
  2. \i Base.sql
  3. INSERT INTO entity (id, name, entity_class, control_code)
  4. VALUES (-100, 'Testing.....', 3, '_TESTING.....');
  5. DELETE FROM users WHERE username = CURRENT_USER;
  6. INSERT INTO users (entity_id, username)
  7. SELECT -100, CURRENT_USER;
  8. INSERT INTO person(first_name, last_name, entity_id, id)
  9. VALUES ('test', 'test', -100, -100);
  10. INSERT INTO entity_employee(entity_id, person_id)
  11. VALUES (-100, -100);
  12. INSERT INTO chart (accno, description, charttype, category, link)
  13. VALUES ('00001', 'testing', 'A', 'L', 'AP');
  14. INSERT INTO chart (accno, description, charttype, category, link)
  15. VALUES ('00002', 'testing2', 'A', 'E', 'AP_expense');
  16. INSERT INTO session (users_id, last_used, token, transaction_id)
  17. values (currval('users_id_seq'), now(), md5('test2'), 2);
  18. INSERT INTO test_result(test_name, success)
  19. SELECT 'AP Batch created', (SELECT batch_create('test', 'test', 'ap', now()::date)) IS NOT NULL;
  20. INSERT INTO entity (id, entity_class, name, control_code)
  21. VALUES (-101, 1, 'TEST VENDOR', 'TEST 2');
  22. INSERT INTO company (id, legal_name, entity_id)
  23. VALUES (-101, 'TEST', -101);
  24. INSERT INTO business (id, description)
  25. values (-101, 'test');
  26. INSERT INTO entity_credit_account (id, meta_number, threshold, entity_id, entity_class, business_id)
  27. values (-101, 'TEST1', 100000, -101, 1, -101);
  28. INSERT INTO ap (invnumber, entity_credit_account, approved, amount, netamount, curr)
  29. values ('test_hide', -101, false, '1', '1', 'USD');
  30. INSERT INTO voucher (trans_id, batch_class, batch_id)
  31. VALUES (currval('id'), 1, currval('batch_id_seq'));
  32. INSERT INTO test_result(test_name, success)
  33. SELECT 'Payment Batch created', (SELECT batch_create('test', 'test', 'ap', now()::date)) IS NOT NULL;
  34. INSERT INTO ap (invnumber, entity_credit_account, approved, amount, netamount, curr, transdate, paid)
  35. VALUES ('test_show2', -101, true, 100000, 100000, 'USD', now()::date, 0);
  36. INSERT INTO acc_trans (approved, transdate, amount, trans_id, chart_id)
  37. VALUES (true, now()::date, '100000', currval('id'), (select id from chart where accno = '00001'));
  38. INSERT INTO acc_trans (approved, transdate, amount, trans_id, chart_id)
  39. VALUES (true, now()::date, '-100000', currval('id'), (select id from chart where accno = '00002'));
  40. INSERT INTO ap (invnumber, entity_credit_account, approved, amount, netamount, curr, transdate, paid)
  41. values ('test_show', -101, false, '1', '1', 'USD', now()::date, 0);
  42. INSERT INTO acc_trans (approved, transdate, amount, trans_id, chart_id)
  43. VALUES (true, now()::date, '1', currval('id'), (select id from chart where accno = '00001'));
  44. INSERT INTO acc_trans (approved, transdate, amount, trans_id, chart_id)
  45. VALUES (true, now()::date, '-1', currval('id'), (select id from chart where accno = '00002'));
  46. INSERT INTO voucher (trans_id, batch_class, batch_id)
  47. VALUES (currval('id'), 1, currval('batch_id_seq'));
  48. CREATE FUNCTION test_convert_array(anyarray) RETURNS text AS
  49. '
  50. SELECT array_to_string($1, ''::'');
  51. ' LANGUAGE SQL;
  52. INSERT INTO test_result(test_name, success)
  53. VALUES ('Batch Voucher In Payment Selection',
  54. (SELECT test_convert_array(invoices) LIKE '%::test_show::%'
  55. FROM
  56. (
  57. SELECT invoices FROM payment_get_all_contact_invoices(1, NULL, 'USD', NULL, NULL, currval('batch_id_seq')::int, '00001', 'TEST1')
  58. )p));
  59. INSERT INTO test_result(test_name, success)
  60. VALUES ('Threshold met',
  61. (SELECT test_convert_array(invoices) LIKE '%::test_show2::%'
  62. FROM
  63. (
  64. SELECT invoices FROM payment_get_all_contact_invoices(1, NULL, 'USD', NULL, NULL, NULL, '00001', 'TEST1')
  65. )p));
  66. SELECT invoices FROM payment_get_all_contact_invoices(1, NULL, 'USD', NULL, NULL, NULL, '00002', 'TEST1');
  67. INSERT INTO test_result(test_name, success)
  68. VALUES ('Non-Batch Voucher Not In Payment Selection',
  69. (SELECT test_convert_array(invoices) NOT LIKE '%::test_hide::%'
  70. FROM
  71. (SELECT invoices FROM payment_get_all_contact_invoices(1, NULL, 'USD', NULL, NULL, currval('batch_id_seq')::int, '00001', 'TEST1'))p ));
  72. SELECT * FROM TEST_RESULT;
  73. SELECT (select count(*) from test_result where success is true)
  74. || ' tests passed and '
  75. || (select count(*) from test_result where success is not true)
  76. || ' failed' as message;
  77. ROLLBACK;