summaryrefslogtreecommitdiff
path: root/sql/modules/test/Payment.sql
blob: e8280aa7f310c6a058906bf65864d2adb548afee (plain)
  1. BEGIN;
  2. \i Base.sql
  3. INSERT INTO entity (name, entity_class, control_code)
  4. VALUES ('Testing.....', 3, '_TESTING.....');
  5. DELETE FROM users WHERE username = CURRENT_USER;
  6. INSERT INTO users (entity_id, username)
  7. SELECT currval('entity_id_seq'), CURRENT_USER;
  8. INSERT INTO person(first_name, last_name, entity_id)
  9. VALUES ('test', 'test', currval('entity_id_seq'));
  10. INSERT INTO entity_employee(entity_id, person_id)
  11. VALUES (currval('entity_id_seq'), currval('person_id_seq'));
  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');
  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 ap (invnumber, entity_credit_account, approved, amount, netamount, curr)
  21. values ('test_hide', (select min(id) from entity_credit_account where entity_class = 1), false, '100000', '100000', 'USD');
  22. INSERT INTO voucher (trans_id, batch_class, batch_id)
  23. VALUES (currval('id'), 1, currval('batch_id_seq'));
  24. INSERT INTO test_result(test_name, success)
  25. SELECT 'Payment Batch created', (SELECT batch_create('test', 'test', 'ap', now()::date)) IS NOT NULL;
  26. INSERT INTO ap (invnumber, entity_credit_account, approved, amount, netamount, curr, transdate)
  27. values ('test_show', (select min(id) from entity_credit_account where entity_class = 1), false, '100000', '100000', 'USD', now()::date);
  28. INSERT INTO acc_trans (approved, transdate, amount, trans_id, chart_id)
  29. VALUES (true, now()::date, '100000', currval('id'), (select id from chart where accno = '00001'));
  30. INSERT INTO acc_trans (approved, transdate, amount, trans_id, chart_id)
  31. VALUES (true, now()::date, '-100000', currval('id'), (select id from chart where accno = '00002'));
  32. INSERT INTO voucher (trans_id, batch_class, batch_id)
  33. VALUES (currval('id'), 1, currval('batch_id_seq'));
  34. CREATE FUNCTION test_convert_array(anyarray) RETURNS text AS
  35. '
  36. SELECT array_to_string($1, ''::'');
  37. ' LANGUAGE SQL;
  38. INSERT INTO test_result(test_name, success)
  39. VALUES ('Batch Voucher In Payment Selection',
  40. (SELECT test_convert_array(invoices) LIKE '%::test_show::%'
  41. FROM
  42. (
  43. SELECT invoices FROM payment_get_all_contact_invoices(1, NULL, 'USD', NULL, NULL, currval('batch_id_seq')::int, '00001', (select meta_number from entity_credit_account order by id asc limit 1))
  44. )p));
  45. INSERT INTO test_result(test_name, success)
  46. VALUES ('Non-Batch Voucher Not In Payment Selection',
  47. (SELECT test_convert_array(invoices) NOT LIKE '%::test_hide::%'
  48. FROM
  49. (SELECT invoices FROM payment_get_all_contact_invoices(1, NULL, 'USD', NULL, NULL, currval('batch_id_seq')::int, '00001', (select meta_number from entity_credit_account order by id asc limit 1)))p ));
  50. SELECT * FROM TEST_RESULT;
  51. SELECT (select count(*) from test_result where success is true)
  52. || ' tests passed and '
  53. || (select count(*) from test_result where success is not true)
  54. || ' failed' as message;
  55. ROLLBACK;