aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/report_import.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/report_import.t')
-rw-r--r--t/app/controller/report_import.t298
1 files changed, 178 insertions, 120 deletions
diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t
index eb686b44e..b956b61ae 100644
--- a/t/app/controller/report_import.t
+++ b/t/app/controller/report_import.t
@@ -3,8 +3,13 @@ use warnings;
use Test::More;
use FixMyStreet::TestMech;
+use FixMyStreet::App;
use Web::Scraper;
use Path::Class;
+use LWP::Protocol::PSGI;
+use t::Mock::MapItZurich;
+
+LWP::Protocol::PSGI->register(t::Mock::MapItZurich->to_psgi_app, host => 'mapit.zurich');
my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/import');
@@ -12,6 +17,22 @@ $mech->get_ok('/import');
my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify;
ok -e $sample_file, "sample file $sample_file exists";
+# disable info logs for this test run
+FixMyStreet::App->log->disable('info');
+END { FixMyStreet::App->log->enable('info'); }
+
+my $body = $mech->create_body_ok(2245, 'Wiltshire Council');
+$mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Street lighting',
+ email => 'streetlighting@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Potholes',
+ email => 'highways@example.com',
+);
+
# submit an empty report to import - check we get all errors
subtest "Test creating bad partial entries" => sub {
@@ -58,10 +79,14 @@ subtest "Test creating bad partial entries" => sub {
{
$mech->get_ok('/import');
- $mech->submit_form_ok( #
- { with_fields => $test->{fields} },
- "fill in form"
- );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ }, sub {
+ $mech->submit_form_ok( #
+ { with_fields => $test->{fields} },
+ "fill in form"
+ );
+ };
is_deeply( $mech->import_errors, $test->{errors}, "expected errors" );
}
@@ -69,7 +94,6 @@ subtest "Test creating bad partial entries" => sub {
};
subtest "Submit a correct entry" => sub {
-
$mech->get_ok('/import');
$mech->submit_form_ok( #
@@ -90,15 +114,16 @@ subtest "Submit a correct entry" => sub {
is $mech->content, 'SUCCESS', "Got success response";
# check that we have received the email
- $mech->email_count_is(1);
- my $email = $mech->get_email;
+ my $token_url = $mech->get_link_from_email;
$mech->clear_emails_ok;
-
- my ($token_url) = $email->body =~ m{(http://\S+)};
ok $token_url, "Found a token url $token_url";
# go to the token url
- $mech->get_ok($token_url);
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->get_ok($token_url);
+ };
# check that we are on '/around'
is $mech->uri->path, '/around', "sent to /around";
@@ -107,10 +132,15 @@ subtest "Submit a correct entry" => sub {
is_deeply $mech->visible_form_values, { pc => '' },
"check only pc field is shown";
- $mech->submit_form_ok( #
- { with_fields => { pc => 'SW1A 1AA' } },
- "fill in postcode"
- );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok(
+ { with_fields => { pc => 'SN15 5NG' } },
+ "fill in postcode"
+ );
+ };
is $mech->uri->path, '/report/new', "sent to report page";
@@ -120,7 +150,9 @@ subtest "Submit a correct entry" => sub {
name => 'Test User',
title => 'Test report',
detail => 'This is a test report',
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
phone => '',
may_show_name => '1',
category => '-- Pick a category --',
@@ -129,19 +161,24 @@ subtest "Submit a correct entry" => sub {
# Check photo present, and still there after map submission (testing bug #18)
$mech->content_contains( '<img align="right" src="/photo/' );
- $mech->content_contains('latitude" value="51.50101"', 'Check latitude');
- $mech->content_contains('longitude" value="-0.141587"', 'Check longitude');
- $mech->submit_form_ok(
- {
- button => 'tile_32742.21793',
- x => 10,
- y => 10,
- },
- "New map location"
- );
+ $mech->content_contains('latitude" value="51.5"', 'Check latitude');
+ $mech->content_contains('longitude" value="-2.1"', 'Check longitude');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok(
+ {
+ button => 'tile_16192.10896',
+ x => 10,
+ y => 10,
+ },
+ "New map location"
+ );
+ };
$mech->content_contains( '<img align="right" src="/photo/' );
- $mech->content_contains('latitude" value="51.50519"', 'Check latitude');
- $mech->content_contains('longitude" value="-0.142608"', 'Check longitude');
+ $mech->content_contains('latitude" value="51.508475"', 'Check latitude');
+ $mech->content_contains('longitude" value="-2.108946"', 'Check longitude');
# check that fields haven't changed at all
is_deeply $mech->visible_form_values,
@@ -149,7 +186,9 @@ subtest "Submit a correct entry" => sub {
name => 'Test User',
title => 'Test report',
detail => 'This is a test report',
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
phone => '',
may_show_name => '1',
category => '-- Pick a category --',
@@ -157,19 +196,24 @@ subtest "Submit a correct entry" => sub {
"check imported fields are shown";
# change the details
- $mech->submit_form_ok( #
- {
- with_fields => {
- name => 'New Test User',
- title => 'New Test report',
- detail => 'This is a test report',
- phone => '01234 567 890',
- may_show_name => '1',
- category => 'Street lighting',
- }
- },
- "Update details and save"
- );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ name => 'New Test User',
+ title => 'New Test report',
+ detail => 'This is a test report',
+ phone => '01234 567 890',
+ may_show_name => '1',
+ category => 'Street lighting',
+ }
+ },
+ "Update details and save"
+ );
+ };
# check that report has been created
my $user =
@@ -192,8 +236,8 @@ subtest "Submit a correct entry (with location)" => sub {
{
with_fields => {
service => 'test-script',
- lat => '51.5010096115539', # SW1A 1AA
- lon => '-0.141587067110009',
+ lat => '51.5',
+ lon => '-2.1',
name => 'Test User ll',
email => 'test-ll@example.com',
subject => 'Test report ll',
@@ -208,15 +252,17 @@ subtest "Submit a correct entry (with location)" => sub {
is $mech->content, 'SUCCESS', "Got success response";
# check that we have received the email
- $mech->email_count_is(1);
- my $email = $mech->get_email;
+ my $token_url = $mech->get_link_from_email;
$mech->clear_emails_ok;
-
- my ($token_url) = $email->body =~ m{(http://\S+)};
ok $token_url, "Found a token url $token_url";
# go to the token url
- $mech->get_ok($token_url);
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->get_ok($token_url);
+ };
# check that we are on '/report/new'
is $mech->uri->path, '/report/new', "sent to /report/new";
@@ -227,7 +273,9 @@ subtest "Submit a correct entry (with location)" => sub {
name => 'Test User ll',
title => 'Test report ll',
detail => 'This is a test report ll',
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
phone => '',
may_show_name => '1',
category => '-- Pick a category --',
@@ -235,19 +283,24 @@ subtest "Submit a correct entry (with location)" => sub {
"check imported fields are shown";
# change the details
- $mech->submit_form_ok( #
- {
- with_fields => {
- name => 'New Test User ll',
- title => 'New Test report ll',
- detail => 'This is a test report ll',
- phone => '01234 567 890',
- may_show_name => '1',
- category => 'Street lighting',
- }
- },
- "Update details and save"
- );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( #
+ {
+ with_fields => {
+ name => 'New Test User ll',
+ title => 'New Test report ll',
+ detail => 'This is a test report ll',
+ phone => '01234 567 890',
+ may_show_name => '1',
+ category => 'Street lighting',
+ }
+ },
+ "Update details and save"
+ );
+ };
# check that report has been created
my $user =
@@ -263,72 +316,77 @@ subtest "Submit a correct entry (with location)" => sub {
};
subtest "Submit a correct entry (with location) to cobrand" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ MAPIT_URL => 'http://mapit.zurich/',
+ MAPIT_TYPES => [ 'O08' ],
+ MAPIT_ID_WHITELIST => [],
+ MAP_TYPE => 'Zurich,OSM',
+ }, sub {
+ ok $mech->host("zurich.example.org"), 'change host to zurich';
- SKIP: {
- skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 20 )
- unless FixMyStreet::Cobrand->exists('fiksgatami');
- mySociety::MaPit::configure('http://mapit.nuug.no/');
- ok $mech->host("fiksgatami.no"), 'change host to fiksgatami';
+ $mech->get_ok('/import');
- $mech->get_ok('/import');
+ $mech->submit_form_ok( #
+ {
+ with_fields => {
+ service => 'test-script',
+ lat => '47.4',
+ lon => '8.5',
+ name => 'Test User ll',
+ email => 'test-ll@example.com',
+ subject => 'Test report ll',
+ detail => 'This is a test report ll',
+ photo => $sample_file,
+ }
+ },
+ "fill in form"
+ );
- $mech->submit_form_ok( #
- {
- with_fields => {
- service => 'test-script',
- lat => '59',
- lon => '10',
- name => 'Test User ll',
- email => 'test-ll@example.com',
- subject => 'Test report ll',
- detail => 'This is a test report ll',
- photo => $sample_file,
- }
- },
- "fill in form"
- );
+ is_deeply( $mech->import_errors, [], "got no errors" );
+ is $mech->content, 'SUCCESS', "Got success response";
- is_deeply( $mech->import_errors, [], "got no errors" );
- is $mech->content, 'SUCCESS', "Got success response";
+ # check that we have received the email
+ my $token_url = $mech->get_link_from_email;
+ $mech->clear_emails_ok;
+ ok $token_url, "Found a token url $token_url";
- # check that we have received the email
- $mech->email_count_is(1);
- my $email = $mech->get_email;
- $mech->clear_emails_ok;
+ # go to the token url
+ $mech->get_ok($token_url);
- my ($token_url) = $email->body =~ m{(http://\S+)};
- ok $token_url, "Found a token url $token_url";
+ # check that we are on '/report/new'
+ is $mech->uri->path, '/report/new', "sent to /report/new";
- # go to the token url
- $mech->get_ok($token_url);
+ # check that fields are prefilled for us
+ is_deeply $mech->visible_form_values,
+ {
+ name => 'Test User ll',
+ detail => 'This is a test report ll',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ phone => '',
+ email => 'test-ll@example.com',
+ },
+ "check imported fields are shown"
+ or diag Dumper( $mech->visible_form_values ); use Data::Dumper;
- # check that we are on '/report/new'
- is $mech->uri->path, '/report/new', "sent to /report/new";
-
- # check that fields are prefilled for us
- is_deeply $mech->visible_form_values,
- {
- name => 'Test User ll',
- title => 'Test report ll',
- detail => 'This is a test report ll',
- photo => '',
- phone => '',
- may_show_name => '1',
- },
- "check imported fields are shown";
-
- my $user =
- FixMyStreet::App->model('DB::User')
- ->find( { email => 'test-ll@example.com' } );
- ok $user, "Found a user";
-
- my $report = $user->problems->first;
- is $report->state, 'partial', 'is still partial';
- is $report->title, 'Test report ll', 'title is correct';
- is $report->lang, 'nb', 'language is correct';
-
- $mech->delete_user($user);
- }
+ my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find( { email => 'test-ll@example.com' } );
+ ok $user, "Found a user";
+
+ my $report = $user->problems->first;
+ is $report->state, 'partial', 'is still partial';
+ is $report->title, 'Test report ll', 'title is correct';
+ is $report->lang, 'de-ch', 'language is correct';
+
+ $mech->delete_user($user);
+ };
};
done_testing();
+
+END {
+ $mech->delete_body($body);
+}