aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/report_as_other.t
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2020-09-29 14:23:52 +0200
committerMarius Halden <marius.h@lden.org>2020-09-29 14:23:52 +0200
commita27ce1524d801d2742a2bdb6ec1da45126d64353 (patch)
tree64123c4e17dc1776aa0a7cd65ee01d49d3e7d978 /t/app/controller/report_as_other.t
parent377bd96aab7cad3434185c30eb908c9da447fe40 (diff)
parent2773c60226b9370fe8ee00f7b205b571bb87c3b5 (diff)
Merge tag 'v3.0.1' into fiksgatami-dev
Diffstat (limited to 't/app/controller/report_as_other.t')
-rw-r--r--t/app/controller/report_as_other.t62
1 files changed, 47 insertions, 15 deletions
diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t
index 0c8b7d995..377de27bd 100644
--- a/t/app/controller/report_as_other.t
+++ b/t/app/controller/report_as_other.t
@@ -1,5 +1,4 @@
use FixMyStreet::TestMech;
-use FixMyStreet::App;
use FixMyStreet::Script::Reports;
# disable info logs for this test run
@@ -41,7 +40,6 @@ subtest "Body user, has permission to add report as council" => sub {
is $report->anonymous, 0, 'report not anonymous';
};
-my @users;
subtest "Body user, has permission to add report as another user with email" => sub {
my $report = add_report(
'contribute_as_another_user',
@@ -57,7 +55,6 @@ subtest "Body user, has permission to add report as another user with email" =>
is $report->user->email, 'another@example.net', 'user email correct';
isnt $report->user->id, $user->id, 'user does not match';
like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/;
- push @users, $report->user;
};
subtest "Body user, has permission to add report as another user with mobile phone number" => sub {
@@ -78,7 +75,6 @@ subtest "Body user, has permission to add report as another user with mobile pho
is $report->user->email_verified, 0, 'user email not verified';
isnt $report->user->id, $user->id, 'user does not match';
$mech->email_count_is(0);
- push @users, $report->user;
};
subtest "Body user, has permission to add report as another user with landline number" => sub {
@@ -99,14 +95,30 @@ subtest "Body user, has permission to add report as another user with landline n
is $report->user->email_verified, 0, 'user email not verified';
isnt $report->user->id, $user->id, 'user does not match';
$mech->email_count_is(0);
- push @users, $report->user;
+};
+
+subtest "Body user, has permission to add report as another user with only name" => sub {
+ my $report = add_report(
+ 'contribute_as_another_user',
+ form_as => 'another_user',
+ title => "Test Report",
+ detail => 'Test report details.',
+ category => 'Potholes',
+ name => 'Another User',
+ username => '',
+ may_show_name => undef,
+ );
+ is $report->name, 'Another User', 'report name is name given';
+ is $report->user->name, 'Body User', 'user name unchanged';
+ is $report->user->id, $user->id, 'user matches';
+ is $report->anonymous, 1, 'report anonymous';
};
subtest "Body user, has permission to add report as another (existing) user with email" => sub {
FixMyStreet::Script::Reports::send();
$mech->clear_emails_ok;
- $mech->create_user_ok('existing@example.net', name => 'Existing User');
+ my $existing = $mech->create_user_ok('existing@example.net', name => 'Existing User');
my $report = add_report(
'contribute_as_another_user',
form_as => 'another_user',
@@ -114,14 +126,13 @@ subtest "Body user, has permission to add report as another (existing) user with
detail => 'Test report details.',
category => 'Potholes',
name => 'Existing Yooser',
- username => 'existing@example.net',
+ username => $existing->email,
);
is $report->name, 'Existing Yooser', 'report name is given name';
is $report->user->name, 'Existing User', 'user name remains same';
- is $report->user->email, 'existing@example.net', 'user email correct';
+ is $report->user->email, $existing->email, 'user email correct';
isnt $report->user->id, $user->id, 'user does not match';
like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/;
- push @users, $report->user;
my $send_confirmation_mail_override = Sub::Override->new(
"FixMyStreet::Cobrand::Default::report_sent_confirmation_email",
@@ -149,7 +160,6 @@ subtest "Body user, has permission to add report as another (existing) user with
is $report->user->phone, '+447906333333', 'user phone correct';
isnt $report->user->id, $user->id, 'user does not match';
$mech->email_count_is(0);
- push @users, $report->user;
};
subtest "Superuser, can add report as anonymous user" => sub {
@@ -168,6 +178,8 @@ subtest "Superuser, can add report as anonymous user" => sub {
is $report->user->name, 'Super', 'user name unchanged';
is $report->user->id, $user->id, 'user matches';
is $report->anonymous, 1, 'report anonymous';
+ is $report->get_extra_metadata('contributed_as'), 'anonymous_user';
+ is $report->get_extra_metadata('contributed_by'), undef;
my $send_confirmation_mail_override = Sub::Override->new(
"FixMyStreet::Cobrand::Default::report_sent_confirmation_email",
@@ -183,6 +195,28 @@ subtest "Superuser, can add report as anonymous user" => sub {
$mech->log_in_ok($test_email);
};
+subtest "Body user, can add report as anonymous user" => sub {
+ FixMyStreet::Script::Reports::send();
+ $mech->clear_emails_ok;
+
+ my $user = $mech->log_in_ok($user->email);
+ my $report = add_report(
+ 'contribute_as_anonymous_user',
+ form_as => 'anonymous_user',
+ title => "Test Report",
+ detail => 'Test report details.',
+ category => 'Street lighting',
+ );
+ is $report->name, $body->name, 'report name is OK';
+ is $report->user->name, 'Body User', 'user name unchanged';
+ is $report->user->id, $user->id, 'user matches';
+ is $report->anonymous, 1, 'report anonymous';
+ is $report->get_extra_metadata('contributed_as'), 'anonymous_user';
+ is $report->get_extra_metadata('contributed_by'), $user->id;
+
+ $mech->log_in_ok($test_email);
+};
+
subtest "Body user, has permission to add update as council" => sub {
my $update = add_update(
'contribute_as_body',
@@ -208,7 +242,6 @@ subtest "Body user, has permission to add update as another user with email" =>
is $update->user->email, 'another2@example.net', 'user email correct';
isnt $update->user->id, $user->id, 'user does not match';
like $mech->get_text_body_from_email, qr/Your update has been logged/;
- push @users, $update->user;
};
subtest "Body user, has permission to add update as another user with mobile phone" => sub {
@@ -224,7 +257,6 @@ subtest "Body user, has permission to add update as another user with mobile pho
is $update->user->phone, '+447906444444', 'user phone correct';
isnt $update->user->id, $user->id, 'user does not match';
$mech->email_count_is(0);
- push @users, $update->user;
};
subtest "Body user, has permission to add update as another user with landline phone" => sub {
@@ -240,20 +272,20 @@ subtest "Body user, has permission to add update as another user with landline p
is $update->user->phone, '+441685555555', 'user phone correct';
isnt $update->user->id, $user->id, 'user does not match';
$mech->email_count_is(0);
- push @users, $update->user;
};
subtest "Body user, has permission to add update as another (existing) user with email" => sub {
+ my $existing = $mech->create_user_ok('existing@example.net', name => 'Existing User');
my $update = add_update(
'contribute_as_another_user',
form_as => 'another_user',
update => 'Test Update',
name => 'Existing Yooser',
- username => 'existing@example.net',
+ username => $existing->email,
);
is $update->name, 'Existing Yooser', 'update name is given name';
is $update->user->name, 'Existing User', 'user name remains same';
- is $update->user->email, 'existing@example.net', 'user email correct';
+ is $update->user->email, $existing->email, 'user email correct';
isnt $update->user->id, $user->id, 'user does not match';
like $mech->get_text_body_from_email, qr/Your update has been logged/;
};