This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/admin/040-functions/040-empire/019-resprio-update-apply.sql
Emmanuel BENOîT 1dcde71dff Research priorities
* Added stored procedures meant to update research priorities.
2012-03-01 10:52:52 +01:00

82 lines
No EOL
2.5 KiB
PL/PgSQL

/*
* Unit tests for emp.resprio_update_apply()
*/
BEGIN;
\i utils/strings.sql
\i utils/accounts.sql
\i utils/naming.sql
/* Create a pair of empires, a technology, and some empire
* research & technology records.
*/
SELECT _create_emp_names( 2 , 'emp' );
INSERT INTO emp.empires ( name_id , cash )
SELECT id , 200.0 FROM naming.empire_names;
ALTER TABLE defs.technologies
ALTER technology_category_id DROP NOT NULL ,
ALTER technology_discovery_id DROP NOT NULL ,
ALTER technology_description_id DROP NOT NULL ,
ALTER technology_price DROP NOT NULL ,
ALTER technology_points DROP NOT NULL;
SELECT _create_test_strings( 1 , 'tech' );
INSERT INTO defs.technologies ( technology_name_id )
VALUES ( _get_string( 'tech1' ) );
INSERT INTO emp.technologies_v2(
empire_id , technology_name_id ,
emptech_state , emptech_points , emptech_priority
) VALUES (
_get_emp_name( 'emp1' ) , _get_string( 'tech1' ) ,
'RESEARCH' , 12 , 2
) , (
_get_emp_name( 'emp2' ) , _get_string( 'tech1' ) ,
'RESEARCH' , 12 , 2
);
/* Create a fake temporary table */
CREATE TEMPORARY TABLE rprio_update(
_empire_id INT ,
_technology_name_id INT ,
_emptech_id TEXT ,
_emptech_priority INT
) ON COMMIT DROP;
-- ***** TESTS BEGIN HERE *****
SELECT plan( 4 );
INSERT INTO rprio_update
VALUES ( _get_emp_name( 'emp1' ) , _get_string( 'tech1' ) , 'ignored' , 1 );
SELECT diag_test_name( 'emp.resprio_update_apply() - Applying a valid update - Return value' );
SELECT ok( emp.resprio_update_apply( ) );
SELECT diag_test_name( 'emp.resprio_update_apply() - Applying a valid update - Table contents' );
SELECT set_eq( $$
SELECT empire_id , emptech_priority
FROM emp.technologies_v2
WHERE technology_name_id = _get_string( 'tech1' );
$$ , $$ VALUES(
_get_emp_name( 'emp1' ) , 1
) , (
_get_emp_name( 'emp2' ) , 2
) $$ );
DELETE FROM rprio_update;
UPDATE emp.technologies_v2
SET emptech_priority = 2
WHERE technology_name_id = _get_string( 'tech1' );
INSERT INTO rprio_update
VALUES ( _get_emp_name( 'emp1' ) , _get_string( 'tech1' ) , 'ignored' , 15 );
SELECT diag_test_name( 'emp.resprio_update_apply() - Applying an invalid update - Return value' );
SELECT ok( NOT emp.resprio_update_apply( ) );
SELECT diag_test_name( 'emp.resprio_update_apply() - Applying an invalid update - Table contents' );
SELECT set_eq( $$
SELECT empire_id , emptech_priority
FROM emp.technologies_v2
$$ , $$ VALUES(
_get_emp_name( 'emp1' ) , 2
) , (
_get_emp_name( 'emp2' ) , 2
) $$ );
SELECT * FROM finish( );
ROLLBACK;