diff options
Diffstat (limited to 't/app/model')
-rw-r--r-- | t/app/model/alert_type.t | 6 | ||||
-rw-r--r-- | t/app/model/defecttype.t | 67 | ||||
-rw-r--r-- | t/app/model/user.t | 4 |
3 files changed, 72 insertions, 5 deletions
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index 4e8817225..5e4fcec0a 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -188,7 +188,7 @@ subtest "correct text for title after URL" => sub { } )->delete; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; @@ -324,7 +324,7 @@ foreach my $test ( $report->update(); FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; @@ -432,7 +432,7 @@ subtest "check alerts from cobrand send main site url for alerts for different c )->delete; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; diff --git a/t/app/model/defecttype.t b/t/app/model/defecttype.t new file mode 100644 index 000000000..0f66ac684 --- /dev/null +++ b/t/app/model/defecttype.t @@ -0,0 +1,67 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::App; +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237); +my $potholes_contact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' ); +my $traffic_lights_contact =$mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' ); + +my $potholes_defect_type = FixMyStreet::App->model('DB::DefectType')->find_or_create( + { + body_id => 2237, + name => 'Potholes', + description => 'This defect type is to do with potholes' + } +); +$potholes_defect_type->contact_defect_types->find_or_create({ + contact_id => $potholes_contact->id, +}); + +my $general_defect_type = FixMyStreet::App->model('DB::DefectType')->find_or_create( + { + body_id => 2237, + name => 'All categories', + description => 'This defect type is for all categories' + } +); + + +subtest 'for_bodies returns correct results' => sub { + my $defect_types = FixMyStreet::App->model('DB::DefectType')->for_bodies( + [ $oxfordshire->id ], + 'Potholes' + ); + + is $defect_types->count, 2, 'Both defect types are included for Potholes category'; + + $defect_types = FixMyStreet::App->model('DB::DefectType')->for_bodies( + [ $oxfordshire->id ], + 'Traffic lights' + ); + + is $defect_types->count, 1, 'Only 1 defect type is included for Traffic lights category'; + is $defect_types->first->name, $general_defect_type->name, 'Correct defect type is returned for Traffic lights category'; +}; + +subtest 'Problem->defect_types behaves correctly' => sub { + my ($problem) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Test', { + category => 'Potholes', + }); + + is $problem->defect_types->count, 2, 'Both defect types are available for the problem'; + + $problem->update({ category => 'Traffic lights' }); + is $problem->defect_types->count, 1, 'Only 1 defect type is included for Traffic lights category'; + is $problem->defect_types->first->name, $general_defect_type->name, 'Correct defect type is returned for Traffic lights category'; +}; + + +END { + $mech->delete_body( $oxfordshire ); + + done_testing(); +} diff --git a/t/app/model/user.t b/t/app/model/user.t index bf73a9d09..d4115d586 100644 --- a/t/app/model/user.t +++ b/t/app/model/user.t @@ -14,7 +14,7 @@ is $problem->user->latest_anonymity, 0, "User's last report was not anonymous"; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around?pc=sw1a1aa'); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); @@ -32,7 +32,7 @@ is $problem->user->latest_anonymity, 1, "User's last update was anonymous"; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around?pc=sw1a1aa'); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); |