Something went wrong. Try again.
Perl game server for TLE Community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354# Verifies the dev-only /test setup API (lib/Lacuna/Web/TestSetup.pm): the things# it creates must be real and usable over the normal JSON-RPC API. This file is# also the reference for the "converted" style -- no `use lib`, no `use Lacuna`,# just TestClient.
use strict;use warnings;use Test::More tests => 12;use 5.010;
use TestClient;
TestClient->clear_all_test_empires;
my $tester = TestClient->new->generate_test_empire;
ok($tester->empire_id, 'generate_empire returned an empire_id');ok($tester->session_id, 'generate_empire returned a session_id');ok($tester->home_planet_id, 'generate_empire returned a home_planet_id');is($tester->empire_name, 'TLE Test Empire', 'empire has the default test name');
# The session works against the real Empire RPC.my $status = $tester->post('empire', 'get_status', [$tester->session_id]);is($status->{result}{empire}{id}, $tester->empire_id, 'get_status resolves the session to our empire');
# The empire is real enough to log into with its password.my $login = $tester->post('empire', 'login', [$tester->empire_name, $tester->empire_password, 'Anonymous']);ok($login->{result}{session_id}, 'can log into the generated empire with its password');
# Infrastructure build-out ticks resources onto the home planet.$tester->build_infrastructure;my $body = $tester->post('body', 'get_status', [$tester->session_id, $tester->home_planet_id]);ok(exists $body->{result}{body}{food_capacity}, 'body get_status has resource fields after build_infrastructure');cmp_ok($body->{result}{body}{energy_capacity}, '>', 0, 'build_infrastructure gave the planet energy capacity');
# build_building + finish_building produce a finished, viewable building.my $shipyard = $tester->build_building('Lacuna::DB::Result::Building::Shipyard', 1);ok($shipyard->id, 'build_building returned a building id');$shipyard->finish_upgrade;my $view = $tester->post('shipyard', 'view', [$tester->session_id, $shipyard->id]);is($view->{result}{building}{level}, 1, 'finished building is level 1 via the Shipyard RPC');
# set_body_resources pokes whitelisted columns.$tester->set_body_resources($tester->home_planet_id, energy_stored => 12345, tick => 1);$body = $tester->post('body', 'get_status', [$tester->session_id, $tester->home_planet_id]);cmp_ok($body->{result}{body}{energy_stored}, '>=', 0, 'set_body_resources kept the planet in a sane state');
# clear_empires really deletes it.TestClient->clear_all_test_empires;my $after = $tester->post('empire', 'login', [$tester->empire_name, $tester->empire_password, 'Anonymous']);ok($after->{error}, 'login fails after clear_empires deleted the empire');