]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/live_t/lp1883171-copy_inventory.pg
LP 2061136 follow-up: ng lint --fix
[working/Evergreen.git] / Open-ILS / src / sql / Pg / live_t / lp1883171-copy_inventory.pg
1 BEGIN;
2
3 SELECT plan(9);
4
5 -- Workstations to use for tests:
6 \set BR1_ws_name 'BR1-lp1883171-pgtap-live_t'
7 \set BR4_ws_name 'BR4-lp1883171-pgtap-live_t'
8
9 -- Fixed timestamp to check for duplicates:
10 \set fixed_ts '2021-10-24 11:52:33.604067-04'
11
12 -- Copy from BR1:
13 \set BR1_copy_id 1
14 -- Copy from BR4
15 \set BR4_copy_id 801
16 -- Copy from BR3 to test floating.
17 \set BR3_copy_id 701
18
19 -- A name for a floating group to test floating.
20 \set SYS2_floating_group_name 'SYS2 Float Group'
21
22 -- Create workstations:
23 INSERT INTO actor.workstation
24 (name, owning_lib)
25 VALUES
26 (:'BR1_ws_name', 4),
27 (:'BR4_ws_name', 7);
28
29 -- Create the floating group and define its members
30 INSERT INTO config.floating_group
31 (name)
32 VALUES (:'SYS2_floating_group_name');
33
34 INSERT INTO config.floating_group_member
35 (floating_group, org_unit, stop_depth)
36 SELECT id, 3, 1
37 FROM config.floating_group
38 WHERE name = :'SYS2_floating_group_name';
39
40 -- Let the copy at BR3 float to SYS2
41 UPDATE asset.copy
42 SET floating = floating_group.id
43 FROM config.floating_group
44 WHERE copy.id = :BR3_copy_id
45 AND floating_group.name = :'SYS2_floating_group_name';
46
47 PREPARE insert_null_all AS INSERT INTO asset.copy_inventory (inventory_workstation, inventory_date, copy)
48 VALUES (NULL, :'fixed_ts', :BR1_copy_id),
49 (NULL, :'fixed_ts', :BR3_copy_id),
50 (NULL, :'fixed_ts', :BR4_copy_id);
51 SELECT lives_ok('insert_null_all', 'NULL workstation should succeed');
52
53 PREPARE insert_br1_br1 AS INSERT INTO asset.copy_inventory(inventory_workstation, copy)
54 SELECT id, :BR1_copy_id
55 FROM actor.workstation
56 WHERE name = :'BR1_ws_name';
57 SELECT lives_ok('insert_br1_br1', 'BR1 at BR1 should succeed');
58
59 PREPARE insert_br1_br4 AS INSERT INTO asset.copy_inventory (inventory_workstation, copy)
60 SELECT id, :BR1_copy_id
61 FROM actor.workstation
62 WHERE name = :'BR4_ws_name';
63 SELECT throws_ok('insert_br1_br4');
64
65 PREPARE insert_br4_br1 AS INSERT INTO asset.copy_inventory (inventory_workstation, copy)
66 SELECT id, :BR4_copy_id
67 FROM actor.workstation
68 WHERE name = :'BR1_ws_name';
69 SELECT throws_ok('insert_br4_br1');
70
71 PREPARE insert_br3_br1 AS INSERT INTO asset.copy_inventory (inventory_workstation, copy)
72 SELECT id, :BR3_copy_id
73 FROM actor.workstation
74 WHERE name = :'BR1_ws_name';
75 SELECT throws_ok('insert_br3_br1');
76
77 PREPARE insert_br4_br4 AS INSERT INTO asset.copy_inventory(inventory_workstation, copy)
78 SELECT id, :BR4_copy_id
79 FROM actor.workstation
80 WHERE name = :'BR4_ws_name';
81 SELECT lives_ok('insert_br4_br4', 'BR4 at BR4 should succeed');
82
83 PREPARE insert_br3_br4 AS INSERT INTO asset.copy_inventory(inventory_workstation, copy)
84 SELECT id, :BR3_copy_id
85 FROM actor.workstation
86 WHERE name = :'BR4_ws_name';
87 SELECT lives_ok('insert_br3_br4', 'BR3 at BR4 should succeed');
88
89 PREPARE dup_insert_br3_br4 AS INSERT INTO asset.copy_inventory (inventory_workstation, inventory_date, copy)
90 SELECT id, :'fixed_ts', :BR3_copy_id
91 FROM actor.workstation
92 WHERE name = :'BR4_ws_name';
93 SELECT throws_ok('dup_insert_br3_br4', 23505);
94
95 SELECT throws_ok('insert_null_all', 23505);
96
97 SELECT * FROM finish();
98 ROLLBACK;