diff options
Diffstat (limited to 't/app/controller/report_new_open311.t')
-rw-r--r-- | t/app/controller/report_new_open311.t | 101 |
1 files changed, 58 insertions, 43 deletions
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index e9ada9f41..e3a464f88 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -3,44 +3,46 @@ use warnings; use Test::More; use FixMyStreet::TestMech; +use FixMyStreet::App; use Web::Scraper; +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + my $mech = FixMyStreet::TestMech->new; -FixMyStreet::App->model('DB::Body')->find_or_create( { - area_id => 2651, - endpoint => 'http://example.com/open311', - jurisdiction => 'mySociety', - api_key => 'apikey', -} ); - -my %contact_params = ( - confirmed => 1, - deleted => 0, - editor => 'Test', - whenedited => \'current_timestamp', - note => 'Created for test', -); +my $body = $mech->create_body_ok(2245, 'Wiltshire Council'); +$body->update({ + endpoint => 'http://example.com/open311', + jurisdiction => 'mySociety', + api_key => 'apikey', +}); + # Let's make some contacts to send things to! -my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, - body_id => 2651, # Edinburgh +my $contact1 = $mech->create_contact_ok( + body_id => $body->id, # Edinburgh category => 'Street lighting', email => '100', extra => [ { description => 'Lamppost number', code => 'number', required => 'True' }, { description => 'Lamppost type', code => 'type', required => 'False', values => { value => [ { name => ['Gas'], key => ['old'] }, { name => [ 'Yellow' ], key => [ 'modern' ] } ] } - } + } + ], +); +my $contact1b = $mech->create_contact_ok( + body_id => $body->id, # Edinburgh + category => 'Moon lighting', + email => '100b', + extra => [ { description => 'Moon type', code => 'type', required => 'False', values => + [ { name => 'Full', key => 'full' }, { name => 'New', key => 'new' } ] } ], -} ); -my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, - body_id => 2651, # Edinburgh +); +my $contact2 = $mech->create_contact_ok( + body_id => $body->id, # Edinburgh category => 'Graffiti Removal', email => '101', -} ); -ok $contact1, "created test contact 1"; -ok $contact2, "created test contact 2"; +); # test that the various bit of form get filled in and errors correctly # generated. @@ -51,7 +53,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -66,9 +70,9 @@ foreach my $test ( type => 'old', }, errors => [ + 'This information is required', 'Please enter a subject', 'Please enter some details', - 'This information is required', 'Please enter your email', 'Please enter your name', ], @@ -111,17 +115,22 @@ foreach my $test ( $mech->get_ok('/around'); # submit initial pc form - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "submit location" ); - is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; - - # click through to the report page - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); - - # submit the main form - $mech->submit_form_ok( { with_fields => $test->{fields} }, - "submit form" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "submit location" ); + is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + # submit the main form + $mech->submit_form_ok( { with_fields => $test->{fields} }, + "submit form" ); + }; # check that we got the errors expected is_deeply $mech->page_errors, $test->{errors}, "check errors"; @@ -147,21 +156,27 @@ foreach my $test ( %{ $test->{fields} }, %{ $test->{submit_with} }, }; - $mech->submit_form_ok( { with_fields => $new_values } ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->submit_form_ok( { with_fields => $new_values } ); + }; $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); ok $user, 'created user'; my $prob = $user->problems->first; ok $prob, 'problem created'; - is_deeply $prob->extra, $test->{extra}, 'extra open311 data added to problem'; + is_deeply $prob->get_extra_fields, $test->{extra}, 'extra open311 data added to problem'; $user->problems->delete; $user->delete; }; } -$contact1->delete; -$contact2->delete; - done_testing(); + +END { + $mech->delete_body($body); +} |