/* * Test the defs.uoc_technology() function for existing technologies */ BEGIN; \i utils/strings.sql /* * We need a few test strings to play with. Each technology definition * uses four strings (name, category, discovery and description) so we'll * create 8. */ SELECT _create_test_strings( 8 , 's' ); /* Insert two entries. */ INSERT INTO defs.technologies ( technology_name_id , technology_category_id , technology_discovery_id , technology_description_id , technology_price , technology_points ) VALUES ( _get_string( 's1' ) , _get_string( 's2' ) , _get_string( 's3' ) , _get_string( 's4' ) , 1 , 1 ) , ( _get_string( 's5' ) , _get_string( 's6' ) , _get_string( 's7' ) , _get_string( 's8' ) , 1 , 1 ); -- ***** TESTS BEGIN HERE ***** SELECT plan( 9 ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Invalid category string' ); SELECT is( defs.uoc_technology( 's1' , 'does not exist' , 's3' , 's4' , 1 , 1 )::TEXT , 'BAD_STRINGS' ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Invalid discovery string' ); SELECT is( defs.uoc_technology( 's1' , 's2' , 'does not exist' , 's4' , 1 , 1 )::TEXT , 'BAD_STRINGS' ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Invalid description string' ); SELECT is( defs.uoc_technology( 's1' , 's2' , 's3' , 'does not exist' , 1 , 1 )::TEXT , 'BAD_STRINGS' ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Invalid price' ); SELECT is( defs.uoc_technology( 's1' , 's2' , 's3' , 's4' , 0 , 1 )::TEXT , 'BAD_VALUE' ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Invalid research points' ); SELECT is( defs.uoc_technology( 's1' , 's2' , 's3' , 's4' , 1 , 0 )::TEXT , 'BAD_VALUE' ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Duplicate description string' ); SELECT is( defs.uoc_technology( 's1' , 's2' , 's7' , 's4' , 1 , 1 )::TEXT , 'DUP_STRING' ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Duplicate discovery string' ); SELECT is( defs.uoc_technology( 's1' , 's2' , 's3' , 's8' , 1 , 1 )::TEXT , 'DUP_STRING' ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Success' ); SELECT is( defs.uoc_technology( 's1' , 's4' , 's2' , 's3' , 2 , 3 )::TEXT , 'UPDATED' ); SELECT diag_test_name( 'defs.uoc_technology() - Update - Row contents after success' ); SELECT set_eq( $$ SELECT * FROM defs.technologies WHERE technology_name_id = _get_string( 's1' ) $$ , $$ VALUES( _get_string( 's1' ) , _get_string( 's4' ) , _get_string( 's2' ) , _get_string( 's3' ) , 2 , 3 ) $$ ); SELECT * FROM finish( ); ROLLBACK;