BEGIN;
SELECT plan(8);
-------------------------
-- 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, update_bib_source)
VALUES (1, 'TEST', '901c', TRUE);
--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',
'00374nam a22001212 4500A101401-214316420140506000000.09780199588480 (Trade Paper)USD 11.95 ListHaigh, JohnAuthorProbabilityOxford University Press, Incorporated2012-05-04144 p.16..84 l. X 11..63 w. in.biblio');
INSERT INTO vandelay.queued_bib_record (queue, bib_source, purpose, marc)
SELECT CURRVAL('vandelay.queue_id_seq'), 2, 'overlay',
'00374nam a22001212 4500A101401-214316420140506000000.09780199588480 (Trade Paper)USD 11.95 ListHaigh, JohnAuthorProbabilityOxford University Press, Incorporated2012-05-04144 p.16..84 l. X 11..63 w. in.biblio1234512345'
|| barcode || ''
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'
);
--------------------------------
-- Set up test to verify a false
-- update_bib_source flag will
-- not update editor, edit date
-- and source
--------------------------------
UPDATE vandelay.merge_profile
SET update_bib_source = FALSE
WHERE name = 'TEST';
INSERT INTO biblio.record_entry (id, source, edit_date, last_xact_id, marc)
VALUES (9876598764, 1, now() - '15 days'::INTERVAL, 'TEST',
'01047cam a22003498a 4500339CONS20090505140900.0001129s2001 ctu c 001 0 eng 00065571 0761322507 (lib. bdg.)(MAnMC)807579(OCoLC)ocm45661816DLCDLCDPLMRQUtOrBLWpcclcacMRQA523.421JFarndon, JohnPlanets and their moons /John Farndon.Brookfield, CT :Copper Beech Books,c2001.32 p. :col. ill. ;27 cm.biblio');
INSERT INTO vandelay.queued_bib_record (queue, bib_source, purpose, marc)
SELECT CURRVAL('vandelay.queue_id_seq'), 2, 'overlay',
'01047cam a22003498a 4500339CONS20090505140900.0001129s2001 ctu c 001 0 eng 00065571 0761322507 (lib. bdg.)(MAnMC)807579(OCoLC)ocm45661816DLCDLCDPLMRQUtOrBLWpcclcacMRQA523.421JFarndon, JohnPlanets and their moons /John Farndon.Brookfield, CT :Copper Beech Books,c2001.32 p. :col. ill. ;27 cm.biblio9876598764'
|| barcode || ''
FROM actor.card
WHERE id = CURRVAL('actor.card_id_seq');
------------------------
-- Import the new 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 no new values of editor,
-- edit date, and source
------------------------------------
SELECT isnt(
(SELECT editor::bigint FROM biblio.record_entry ORDER BY id DESC LIMIT 1),
CURRVAL('actor.usr_id_seq'),
'Editor was not updated'
);
SELECT isnt(
(SELECT edit_date::date FROM biblio.record_entry ORDER BY id DESC LIMIT 1),
CURRENT_DATE,
'Edit Date was not updated'
);
SELECT isnt(
(SELECT source FROM biblio.record_entry ORDER BY id DESC LIMIT 1),
2,
'Record source was not updated'
);
ROLLBACK;