LP#957466: Added pgTAP test for db function change
authorRemington Steed <rjs7@calvin.edu>
Thu, 19 Feb 2015 15:03:18 +0000 (10:03 -0500)
committerDan Wells <dbw2@calvin.edu>
Tue, 24 Feb 2015 18:59:57 +0000 (13:59 -0500)
Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/sql/Pg/t/regress/lp957466_update_date_and_source.pg [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/t/regress/lp957466_update_date_and_source.pg b/Open-ILS/src/sql/Pg/t/regress/lp957466_update_date_and_source.pg
new file mode 100644 (file)
index 0000000..969c31b
--- /dev/null
@@ -0,0 +1,80 @@
+BEGIN;
+
+SELECT plan(4);
+
+-------------------------
+-- Setup test environment
+--   User w/ library card
+--   Vandelay settings (merge profile, queue)
+--   "Pre-loaded" bib record to be overlayed
+--   Matching bib record added to Vandelay queue
+--     including 905u with user barcode
+-------------------------
+
+INSERT INTO actor.usr (profile, ident_type, usrname, home_ou, family_name,
+            passwd, first_given_name, expire_date, dob, suffix)
+    VALUES (13, 1, 'TEST_USER', 1, 'TESTER', 'TEST1234', 'TEST',
+            NOW() + '3 years'::INTERVAL, NULL, NULL);
+
+INSERT INTO actor.card (barcode, usr)
+    VALUES ('TEST_BARCODE', CURRVAL('actor.usr_id_seq'));
+
+UPDATE actor.usr
+    SET card = CURRVAL('actor.card_id_seq')
+    WHERE id = CURRVAL('actor.usr_id_seq');
+
+INSERT INTO vandelay.merge_profile (owner, name, preserve_spec)
+    VALUES (1, 'TEST', '901c');
+
+--XXX: Do we need to create a custom item_attr_def?
+--     If def 1 was deleted from an install, this will break
+INSERT INTO vandelay.bib_queue (owner, name, item_attr_def)
+    VALUES (CURRVAL('actor.usr_id_seq'), 'TEST', 1);
+
+INSERT INTO biblio.record_entry (id, edit_date, last_xact_id, marc)
+    VALUES (1234512345, now() - '15 days'::INTERVAL, 'TEST',
+            '<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"><leader>00374nam a22001212  4500</leader><controlfield tag="001">A101401-2143164</controlfield><controlfield tag="005">20140506000000.0</controlfield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9780199588480 (Trade Paper)</subfield><subfield code="c">USD 11.95 List</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Haigh, John</subfield><subfield code="e">Author</subfield></datafield><datafield tag="245" ind1="1" ind2="0"><subfield code="a">Probability</subfield></datafield><datafield tag="260" ind1=" " ind2=" "><subfield code="b">Oxford University Press, Incorporated</subfield><subfield code="c">2012-05-04</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">144 p.</subfield><subfield code="c">16..84 l. X 11..63 w. in.</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="t">biblio</subfield></datafield></record>');
+
+INSERT INTO vandelay.queued_bib_record (queue, bib_source, purpose, marc)
+    SELECT CURRVAL('vandelay.queue_id_seq'), 2, 'overlay',
+            '<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"><leader>00374nam a22001212  4500</leader><controlfield tag="001">A101401-2143164</controlfield><controlfield tag="005">20140506000000.0</controlfield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9780199588480 (Trade Paper)</subfield><subfield code="c">USD 11.95 List</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Haigh, John</subfield><subfield code="e">Author</subfield></datafield><datafield tag="245" ind1="1" ind2="0"><subfield code="a">Probability</subfield></datafield><datafield tag="260" ind1=" " ind2=" "><subfield code="b">Oxford University Press, Incorporated</subfield><subfield code="c">2012-05-04</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">144 p.</subfield><subfield code="c">16..84 l. X 11..63 w. in.</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="t">biblio</subfield><subfield code="c">1234512345</subfield></datafield><datafield tag="905" ind1=" " ind2=" "><subfield code="u">'
+            || barcode || '</subfield></datafield></record>'
+    FROM actor.card
+    WHERE id = CURRVAL('actor.card_id_seq');
+
+-----------------------
+-- Import the record --
+-----------------------
+SELECT ok(
+    (
+        SELECT vandelay.overlay_bib_record( queued_record, eg_record,
+            CURRVAL('vandelay.merge_profile_id_seq')::int )
+        FROM vandelay.bib_match
+        WHERE queued_record = CURRVAL('vandelay.queued_record_id_seq')
+    ),
+    'Function call succeeded'
+);
+
+---------------------------------
+-- Test for new values of editor,
+-- edit date, and source
+---------------------------------
+SELECT is(
+    (SELECT editor::bigint FROM biblio.record_entry ORDER BY id DESC LIMIT 1),
+    CURRVAL('actor.usr_id_seq'),
+    'Editor was updated'
+);
+
+SELECT is(
+    (SELECT edit_date::date FROM biblio.record_entry ORDER BY id DESC LIMIT 1),
+    CURRENT_DATE,
+    'Edit Date was updated'
+);
+
+SELECT is(
+    (SELECT source FROM biblio.record_entry ORDER BY id DESC LIMIT 1),
+    2,
+    'Record source was updated'
+);
+
+ROLLBACK;