BEGIN;
/*
Started as a test plan for LP#1588948 (authority edits modify bib record
editor and edit_date), but includes general tests for confirming authority
update propagation to bib records.
*/
SELECT plan(9);
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 authority.record_entry (id, marc, last_xact_id)
VALUES (999999100, $$
nz a22 o 4500999999100LOCAL20160606150106.0 ||||||||||||||||||||||||||||||||||LOCALLOCALDoe, Jane999999100authority
$$, 'test'
);
INSERT INTO biblio.record_entry (id, editor, edit_date, last_xact_id, marc)
VALUES (1234512345, 1, now() - '15 days'::INTERVAL, 'test', $$
00620cam a2200205Ka 45001234512345LOCAL20160606145837.0070101s eng d(LOCAL)999999100Doe, JaneTest Record12345123451234512345biblio
$$);
-- modify the authority record to propagate changes
UPDATE authority.record_entry SET
editor = CURRVAL('actor.usr_id_seq'), -- test user created above
marc = $$
nz a22 o 4500999999100LOCAL20160606150106.0 ||||||||||||||||||||||||||||||||||LOCALLOCALDoe, Jane Smith999999100authority
$$
WHERE id = 999999100;
SELECT is(
(SELECT value FROM metabib.full_rec
WHERE record = 1234512345 AND tag = '100' and subfield = 'a'),
'doe, jane smith',
'Authority field change propagated to bib record'
);
SELECT is(
(SELECT editor FROM biblio.record_entry WHERE id = 1234512345),
CURRVAL('actor.usr_id_seq')::INTEGER,
'Bib editor matches authority editor'
);
SELECT is(
(SELECT DATE(edit_date) FROM biblio.record_entry WHERE id = 1234512345),
CURRENT_DATE,
'Bib edit_date is updated'
);
-- Apply a change to the authority record that has no effect on the bib.
UPDATE biblio.record_entry
SET editor = 1, edit_date = NOW() - '1 week'::INTERVAL
WHERE id = 1234512345;
UPDATE authority.record_entry SET
editor = CURRVAL('actor.usr_id_seq'), -- test user created above
marc = $$
nz a22 o 4500999999100LOCAL20160606150106.0 ||||||||||||||||||||||||||||||||||LOCALLOCALDoe, Jane Smith999999100authoritytest
$$
WHERE id = 999999100;
SELECT isnt(
(SELECT DATE(edit_date) FROM biblio.record_entry WHERE id = 1234512345),
CURRENT_DATE,
'Authority change with no effect does not update bib record'
);
-- Reset the bib data for easier testing
UPDATE biblio.record_entry
SET editor = 1, edit_date = NOW() - '1 week'::INTERVAL
WHERE id = 1234512345;
SELECT is(
(SELECT editor FROM biblio.record_entry WHERE id = 1234512345),
1,
'Bib editor is reset'
);
SELECT is(
(SELECT DATE(edit_date) FROM biblio.record_entry WHERE id = 1234512345),
DATE(NOW() - '1 week'::INTERVAL),
'Bib edit_date is reset'
);
-- Disable bib edit data propagation by enabled the disable flag
UPDATE config.global_flag SET enabled = TRUE
WHERE name = 'ingest.disable_authority_auto_update_bib_meta';
-- modify the authority record to propagate changes
UPDATE authority.record_entry SET
editor = CURRVAL('actor.usr_id_seq'), -- test user created above
marc = $$
nz a22 o 4500999999100LOCAL20160606150106.0 ||||||||||||||||||||||||||||||||||LOCALLOCALDoe, Jane Double-Smith999999100authority
$$
WHERE id = 999999100;
SELECT is(
(SELECT value FROM metabib.full_rec
WHERE record = 1234512345 AND tag = '100' and subfield = 'a'),
'doe, jane double smith',
'Authority field change propagated to bib record'
);
SELECT isnt(
(SELECT editor FROM biblio.record_entry WHERE id = 1234512345),
CURRVAL('actor.usr_id_seq')::INTEGER,
'Bib editor does not match authority editor'
);
SELECT isnt(
(SELECT DATE(edit_date) FROM biblio.record_entry WHERE id = 1234512345),
CURRENT_DATE,
'Bib edit_date is not updated'
);
ROLLBACK;