diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-03-13 18:04:55 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-03-13 21:54:29 +0000 |
commit | 76e533bd318cb4208faa1bf5cd0c00bde9e08e6c (patch) | |
tree | 7ada0b46c3e75b4d3977ca27960638c191354cc7 /t/app/controller | |
parent | e22563a5c8fde74a8a6f1de29948eb45487e9597 (diff) |
Factor out test contact creation to function.
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/my.t | 3 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 4 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 73 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 26 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 1 |
5 files changed, 37 insertions, 70 deletions
diff --git a/t/app/controller/my.t b/t/app/controller/my.t index da509e8ed..b723e537e 100644 --- a/t/app/controller/my.t +++ b/t/app/controller/my.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 11; +use Test::More; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -17,3 +17,4 @@ is $mech->uri->path, '/my', "stayed on '/my/' page"; # cleanup $mech->delete_user( $user ); +done_testing(); diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index e5e9e2899..0631b4209 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -372,3 +372,7 @@ subtest "Submit a correct entry (with location) to cobrand" => sub { }; done_testing(); + +END { + $mech->delete_body($body); +} diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 49ff7b69e..761fdad30 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -2,7 +2,6 @@ use strict; use utf8; # sign in error message has – in it use warnings; use Test::More; -use utf8; use FixMyStreet::TestMech; use FixMyStreet::App; @@ -35,15 +34,8 @@ subtest "test that bare requests to /report/new get redirected" => sub { "pc correctly transferred"; }; -my %contact_params = ( - confirmed => 1, - deleted => 0, - editor => 'Test', - whenedited => \'current_timestamp', - note => 'Created for test', -); - my %body_ids; +my @bodies; for my $body ( { area_id => 2651, name => 'City of Edinburgh Council' }, { area_id => 2226, name => 'Gloucestershire County Council' }, @@ -56,62 +48,46 @@ for my $body ( { area_id => 2333, name => 'Hart Council', id => 2333 }, ) { my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name}, id => $body->{id}); + push @bodies, $body_obj; $body_ids{$body->{area_id}} = $body_obj->id; } # Let's make some contacts to send things to! -FixMyStreet::App->model('DB::Contact')->search( { - email => { 'like', '%example.com' }, -} )->delete; -my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +my $contact1 = $mech->create_contact_ok( body_id => $body_ids{2651}, # Edinburgh category => 'Street lighting', email => 'highways@example.com', -} ); -my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact2 = $mech->create_contact_ok( body_id => $body_ids{2226}, # Gloucestershire category => 'Potholes', email => 'potholes@example.com', -} ); -my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact3 = $mech->create_contact_ok( body_id => $body_ids{2326}, # Cheltenham category => 'Trees', email => 'trees@example.com', -} ); -my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact4 = $mech->create_contact_ok( body_id => $body_ids{2482}, # Bromley category => 'Trees', email => 'trees@example.com', -} ); -my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact5 = $mech->create_contact_ok( body_id => $body_ids{2651}, # Edinburgh category => 'Trees', email => 'trees@example.com', -} ); -my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact6 = $mech->create_contact_ok( body_id => $body_ids{2333}, # Hart category => 'Trees', email => 'trees@example.com', -} ); -my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +my $contact7 = $mech->create_contact_ok( body_id => $body_ids{2227}, # Hampshire category => 'Street lighting', email => 'highways@example.com', -} ); -ok $contact1, "created test contact 1"; -ok $contact2, "created test contact 2"; -ok $contact3, "created test contact 3"; -ok $contact4, "created test contact 4"; -ok $contact5, "created test contact 5"; -ok $contact6, "created test contact 6"; -ok $contact7, "created test contact 7"; +); # test that the various bit of form get filled in and errors correctly # generated. @@ -1356,13 +1332,12 @@ subtest "test SeeSomething" => sub { my $cobrand = FixMyStreet::Cobrand::SeeSomething->new(); my $body_ss = $mech->create_body_ok(2535, 'Sandwell Borough Council', id => 2535); - my $bus_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, + my $bus_contact = $mech->create_contact_ok( body_id => $body_ss->id, category => 'Bus', email => 'bus@example.com', non_public => 1, - } ); + ); for my $test ( { desc => 'report with no user details works', @@ -1597,12 +1572,8 @@ subtest "extra google analytics code displayed on email confirmation problem cre }; }; -$contact1->delete; -$contact2->delete; -$contact3->delete; -$contact4->delete; -$contact5->delete; -$contact6->delete; -$contact7->delete; - done_testing(); + +END { + $mech->delete_body($_) foreach @bodies; +} diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index a274d918b..15ccef493 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -19,16 +19,8 @@ $body->update({ api_key => 'apikey', }); -my %contact_params = ( - confirmed => 1, - deleted => 0, - editor => 'Test', - whenedited => \'current_timestamp', - note => 'Created for test', -); # Let's make some contacts to send things to! -my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +my $contact1 = $mech->create_contact_ok( body_id => $body->id, # Edinburgh category => 'Street lighting', email => '100', @@ -37,15 +29,12 @@ my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { { value => [ { name => ['Gas'], key => ['old'] }, { name => [ 'Yellow' ], key => [ 'modern' ] } ] } } ], -} ); -my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +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. @@ -176,7 +165,8 @@ foreach my $test ( }; } -$contact1->delete; -$contact2->delete; - done_testing(); + +END { + $mech->delete_body($body); +} diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 58d9eff86..fa6c44292 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -789,6 +789,7 @@ subtest "check comment with no status change has not status in meta" => sub { }, 'submit update' ); + $mech->get_ok("/report/$report_id"); $report->discard_changes; my @updates = $report->comments->all; |