Something went wrong. Try again.
Perl game server for TLE Community
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455use Test::More tests => 7;use Test::Deep;use Data::Dumper;use 5.010;
use TestClient;TestClient->clear_all_test_empires;
my $tester = TestClient->new->generate_test_empire->build_infrastructure;my $session_id = $tester->session->id;my $home_id = $tester->home_planet_id;my $result;
$result = $tester->post('distributioncenter', 'build', [$session_id, $home_id, 3, 3]);
my $building_id = $result->{result}{building}{id};$tester->finish_building($building_id);
$tester->set_body_resources($home_id, water_stored => 500);
$result = $tester->post('distributioncenter', 'reserve', [$session_id, $building_id, [ { type => 'water', quantity => 10000, },]]);
is($result->{error}{code}, 1009, "can't reserve resources you don't have");
$result = $tester->post('distributioncenter', 'release_reserve', [$session_id, $building_id]);is($result->{error}{code}, 1010, "can't release with nothing in reserve");
$tester->set_body_resources($home_id, water_stored => 20000);
$result = $tester->post('distributioncenter', 'reserve', [$session_id, $building_id, [ { type => 'water', quantity => 10000, },]]);is($result->{result}{reserve}{resources}[0]{type}, 'water', "correct resource reserved");is($result->{result}{reserve}{resources}[0]{quantity}, 10000, "correct amount reserved");# Because the PCC is running, producing resources while the test is running, then the numbers are slightly out# expect a small positive excess (caused by production in the mean time)cmp_ok($result->{result}{status}{body}{water_stored}, '<', 10500, "resources removed from planet");
$result = $tester->post('distributioncenter', 'release_reserve', [$session_id, $building_id]);my $resources_stored = $result->{result}{status}{body}{water_stored};cmp_ok($resources_stored, '>', 20000, "resources added to planet");cmp_ok($resources_stored, '<', 20500, "not too many resources added to planet");
END { TestClient->clear_all_test_empires;}