From fe474209a567559491343dd6d8bccc8c3f2d9a2d Mon Sep 17 00:00:00 2001
From: "a. bellenir" <ab@grpl.org>
Date: Fri, 8 Jun 2018 10:29:59 -0400
Subject: [PATCH] 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>
---
 .../t/lp1775216-inconsistent-available-counts.pg   | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Open-ILS/src/sql/Pg/t/lp1775216-inconsistent-available-counts.pg

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;
+
-- 
2.11.0