summaryrefslogtreecommitdiff
path: root/sql/modules/test/Draft.sql
blob: a5f799c68274e99cf36cd9c10aa34f481fd0016b (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. SELECT *
  52. FROM draft__search('gl', NULL, NULL, NULL, NULL, NULL);
  53. INSERT INTO test_result(test_name, success)
  54. SELECT '"gl" search successful', count(*) = 1
  55. FROM draft__search('gl', NULL, NULL, NULL, NULL, NULL)
  56. WHERE reference = '_TEST GL';
  57. INSERT INTO test_result(test_name, success)
  58. SELECT '"GL" search successful', count(*) = 1
  59. FROM draft__search('GL', NULL, NULL, NULL, NULL, NULL)
  60. WHERE reference = '_TEST GL';
  61. SELECT * FROM test_result;
  62. SELECT (select count(*) from test_result where success is true)
  63. || ' tests passed and '
  64. || (select count(*) from test_result where success is not true)
  65. || ' failed' as message;
  66. ROLLBACK;