summaryrefslogtreecommitdiff
path: root/sql/modules/test/Draft.sql
blob: 53db5349316d8ea5a50a2f39d58d0cae8b16cbbf (plain)
  1. BEGIN;
  2. \i Base.sql
  3. INSERT INTO entity_credit_account (id, entity_id, entity_class, meta_number)
  4. SELECT '-1', min(id), 1, '_test vendor'
  5. FROM entity;
  6. INSERT INTO entity_credit_account (id, entity_id, entity_class, meta_number)
  7. SELECT '-2', min(id), 2, '_test customer'
  8. FROM entity;
  9. INSERT INTO chart (accno, description, charttype, category, link)
  10. VALUES ('00001', 'AP Test', 'A', 'L', 'AP');
  11. INSERT INTO chart (accno, description, charttype, category, link)
  12. VALUES ('00002', 'AR Test', 'A', 'A', 'AP');
  13. INSERT INTO ap (invnumber, entity_credit_account, amount, netamount, paid,
  14. approved, curr)
  15. select '_TEST AP', min(id), '100', '100', '0', FALSE, 'USD'
  16. FROM entity_credit_account WHERE entity_class = 1;
  17. INSERT INTO acc_trans (chart_id, trans_id, amount, approved)
  18. SELECT id, currval('id'), '100', TRUE FROM chart WHERE accno = '00001';
  19. INSERT INTO acc_trans (chart_id, trans_id, amount, approved)
  20. SELECT id, currval('id'), '-100', TRUE FROM chart WHERE accno = '00002';
  21. INSERT INTO ar (invnumber, entity_credit_account, amount, netamount, paid,
  22. approved, curr)
  23. select '_TEST AR', min(id), '100', '100', '0', FALSE, 'USD'
  24. FROM entity_credit_account WHERE entity_class = 2;
  25. INSERT INTO acc_trans (chart_id, trans_id, amount, approved)
  26. SELECT id, currval('id'), '-100', TRUE FROM chart WHERE accno = '00001';
  27. INSERT INTO acc_trans (chart_id, trans_id, amount, approved)
  28. SELECT id, currval('id'), '100', TRUE FROM chart WHERE accno = '00002';
  29. INSERT INTO gl (reference, description, approved)
  30. VALUES ('_TEST GL', 'Testing GL Drafts', false);
  31. INSERT INTO acc_trans (chart_id, trans_id, amount, approved)
  32. SELECT id, currval('id'), '-100', TRUE FROM chart WHERE accno = '00001';
  33. INSERT INTO acc_trans (chart_id, trans_id, amount, approved)
  34. SELECT id, currval('id'), '100', TRUE FROM chart WHERE accno = '00002';
  35. INSERT INTO test_result(test_name, success)
  36. SELECT '"ap" search successful', count(*) = 1
  37. FROM draft__search('ap', NULL, NULL, NULL, NULL, NULL)
  38. WHERE reference = '_TEST AP';
  39. INSERT INTO test_result(test_name, success)
  40. SELECT '"AP" search successful', count(*) = 1
  41. FROM draft__search('AP', NULL, NULL, NULL, NULL, NULL)
  42. WHERE reference = '_TEST AP';
  43. INSERT INTO test_result(test_name, success)
  44. SELECT '"ar" search successful', count(*) = 1
  45. FROM draft__search('ar', NULL, NULL, NULL, NULL, NULL)
  46. WHERE reference = '_TEST AR';
  47. INSERT INTO test_result(test_name, success)
  48. SELECT '"AR" search successful', count(*) = 1
  49. FROM draft__search('AR', NULL, NULL, NULL, NULL, NULL)
  50. WHERE reference = '_TEST AR';
  51. INSERT INTO test_result(test_name, success)
  52. SELECT '"gl" search successful', count(*) = 1
  53. FROM draft__search('gl', NULL, NULL, NULL, NULL, NULL)
  54. WHERE reference = '_TEST GL';
  55. INSERT INTO test_result(test_name, success)
  56. SELECT '"GL" search successful', count(*) = 1
  57. FROM draft__search('GL', NULL, NULL, NULL, NULL, NULL)
  58. WHERE reference = '_TEST GL';
  59. INSERT INTO test_result(test_name, success)
  60. SELECT 'gl draft deletion', draft_delete(currval('id')::int);
  61. INSERT INTO test_result(test_name, success)
  62. SELECT 'gl table cleanup', count(*) = 0 from gl where id = currval('id');
  63. INSERT INTO test_result(test_name, success)
  64. SELECT 'acc_trans table cleanup', count(*) = 0 from acc_trans where trans_id = currval('id');
  65. SELECT * FROM test_result;
  66. SELECT (select count(*) from test_result where success is true)
  67. || ' tests passed and '
  68. || (select count(*) from test_result where success is not true)
  69. || ' failed' as message;
  70. ROLLBACK;