From: a. bellenir <ab@grpl.org>
Date: Fri, 8 Jun 2018 14:29:59 +0000 (-0400)
Subject: LP#1775216: adding a pgtap test for inconsistent availability counts
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fe474209a567559491343dd6d8bccc8c3f2d9a2d;p=evergreen%2Fequinox.git

LP#1775216: adding a pgtap test for inconsistent availability counts

Signed-off-by: a. bellenir <ab@grpl.org>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
---

diff --git a/Open-ILS/src/sql/Pg/t/lp1775216-inconsistent-available-counts.pg b/Open-ILS/src/sql/Pg/t/lp1775216-inconsistent-available-counts.pg
new file mode 100644
index 0000000000..36b06b95f7
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/t/lp1775216-inconsistent-available-counts.pg
@@ -0,0 +1,35 @@
+BEGIN;
+
+select plan(2);
+
+--consider all statuses to be "available" and "opac visible"
+update config.copy_status set opac_visible = 't', is_available = 't';
+
+-- consider all copies / locations to be opac visible 
+-- (since we're comparing staff copy counts with opac counts)
+update asset.copy_location set opac_visible = 't';
+update asset.copy set opac_visible = 't';
+
+-- the lp bug started because of a hardcoded status list.
+-- make sure we have at least some items with other statuses.
+select isnt_empty(
+    'select id from asset.copy where status not in (0,7,12) and not deleted',
+    'cannot test: no suitable copies for comparison'
+);
+
+select is_empty(
+    '
+    with min_ou as (select min(id) as id from actor.org_unit)
+    select distinct(record)
+    from min_ou,
+        asset.copy cpy join asset.call_number cn on cpy.call_number = cn.id
+    where not cpy.deleted and cpy.status not in (0,7,12)
+        and (select available from asset.staff_ou_record_copy_count(min_ou.id, cn.record))
+            !=
+            (select available from asset.opac_ou_record_copy_count(min_ou.id, cn.record))
+    ','inconsistent available copy counts between staff client and opac'
+);
+
+SELECT * FROM finish();
+ROLLBACK;
+