aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/report_interest_count.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/report_interest_count.t')
-rw-r--r--t/app/controller/report_interest_count.t75
1 files changed, 35 insertions, 40 deletions
diff --git a/t/app/controller/report_interest_count.t b/t/app/controller/report_interest_count.t
index 0a8a5ac0b..3cb80ea5f 100644
--- a/t/app/controller/report_interest_count.t
+++ b/t/app/controller/report_interest_count.t
@@ -1,5 +1,16 @@
use strict;
use warnings;
+
+package FixMyStreet::Cobrand::Tester;
+
+use parent 'FixMyStreet::Cobrand::Default';
+
+sub can_support_problems {
+ return 1;
+}
+
+package main;
+
use Test::More;
use FixMyStreet::TestMech;
@@ -11,15 +22,7 @@ my $mech = FixMyStreet::TestMech->new;
# create a test user and report
$mech->delete_user('test@example.com');
-my $user =
- FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
-ok $user, "created test user";
-
-my $user2 =
- FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'test2@example.com', name => 'Other User' } );
-ok $user2, "created test user";
+my $user = $mech->create_user_ok('test@example.com', name => 'Test User');
my $dt = DateTime->new(
year => 2011,
@@ -33,7 +36,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -56,37 +59,38 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
my $report_id = $report->id;
ok $report, "created test report - $report_id";
-SKIP: {
- skip( "Need 'fixmybarangay' in ALLOWED_COBRANDS config", 29 )
- unless FixMyStreet::Cobrand->exists('fixmybarangay');
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tester' ],
+}, sub {
+ my $body = $mech->create_body_ok(2504, 'Westminster City Council');
+
for my $test (
{
- desc => 'if not from council then no supporter button',
- from_body => 0,
+ desc => 'if not from body then no supporter button',
+ from_body => undef,
support_string => 'No supporters',
},
{
- desc => 'from council user can increment supported count',
- from_body => 2504,
+ desc => 'from body user can increment supported count',
+ from_body => $body->id,
support_string => 'No supporters',
updated_support => '1 supporter'
},
{
desc => 'correct grammar for more than one supporter',
- from_body => 2504,
+ from_body => $body->id,
support_string => '1 supporter',
updated_support => '2 supporters'
},
) {
subtest $test->{desc} => sub {
- ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
$mech->log_in_ok( $user->email );
$user->from_body( $test->{from_body} );
$user->update;
- $report->discard_changes;
- $report->council( $test->{report_council} );
- $report->update;
+ $report->update( {
+ bodies_str => $test->{report_council}
+ } );
$mech->get_ok("/report/$report_id");
$mech->content_contains( $test->{support_string} );
@@ -95,7 +99,7 @@ SKIP: {
$mech->content_contains('Add support');
$mech->submit_form_ok( { form_number => 1 } );
- is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
+ is $mech->uri->path, "/report/$report_id", 'add support redirects to report page';
$mech->content_contains($test->{updated_support});
} else {
@@ -104,29 +108,23 @@ SKIP: {
};
}
- subtest 'check non council user cannot increment support count' => sub {
- ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
- $report->discard_changes;
- $report->interest_count(1);
- ok $report->update(), 'updated interest count';
-
- $report->discard_changes;
+ subtest 'check non body user cannot increment support count' => sub {
+ ok $report->update({ interest_count => 1 }), 'updated interest count';
is $report->interest_count, 1, 'correct interest count';
$mech->get_ok("/report/$report_id");
$mech->content_contains( '1 supporter' );
+ $mech->log_out_ok( $user->email );
$mech->post_ok("/report/support", { id => $report_id } );
- is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
+ is $mech->uri->path, "/report/$report_id", 'add support redirects to report page';
$mech->content_contains( '1 supporter' );
};
};
subtest 'check support details not shown if not enabled in cobrand' => sub {
- ok $mech->host('fixmystreet.com'), 'changed to fixmystreet';
-
$report->interest_count(1);
ok $report->update, 'updated interest count';
@@ -134,10 +132,7 @@ subtest 'check support details not shown if not enabled in cobrand' => sub {
$mech->content_lacks( '1 supporter' );
};
-$report->discard_changes;
-$report->council( 2504 );
-$report->update;
-
-# tidy up
-$mech->delete_user('test@example.com');
-done_testing();
+END {
+ $mech->delete_user('test@example.com');
+ done_testing();
+}