aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZarino Zappia <mail@zarino.co.uk>2018-08-23 18:33:32 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-08-29 13:09:54 +0100
commitc255f82085e85cfa520871b80fc70964da3d7015 (patch)
tree8a21fc9def145524726138458e94e84ed9541def
parent60629c93d6f6ebb48ba00e16abffd8df4df79abe (diff)
Move all test endpoints under /_dev.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm5
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm5
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Develop.pm122
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm6
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm26
-rw-r--r--t/app/controller/develop.t45
-rwxr-xr-xtemplates/web/base/develop/index.html41
9 files changed, 200 insertions, 58 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cee2291e5..87ba501a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,7 @@
- Add ability for client to set bodies not to be sent to.
- Make it easier to prevent a form_detail_placeholder being printed.
- Include user agent in contact form emails. #2206
+ - Add /_dev endpoints for previewing confirmation/submission pages.
* v2.3.4 (7th June 2018)
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index 41674e377..9f948e0f9 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -54,11 +54,6 @@ sub general : Path : Args(0) {
}
-sub general_test : Path('_test_') : Args(0) {
- my ( $self, $c ) = @_;
- $c->stash->{template} = 'auth/token.html';
-}
-
sub authenticate : Private {
my ($self, $c, $type, $username, $password) = @_;
return 1 if $type eq 'email' && $c->authenticate({ email => $username, email_verified => 1, password => $password });
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm
index 3a37d9fa9..aabeb650e 100644
--- a/perllib/FixMyStreet/App/Controller/Contact.pm
+++ b/perllib/FixMyStreet/App/Controller/Contact.pm
@@ -42,11 +42,6 @@ Handle contact us form submission
sub submit : Path('submit') : Args(0) {
my ( $self, $c ) = @_;
- if (my $testing = $c->get_param('_test_')) {
- $c->stash->{success} = $c->get_param('success');
- return;
- }
-
$c->res->redirect( '/contact' ) and return unless $c->req->method eq 'POST';
return
diff --git a/perllib/FixMyStreet/App/Controller/Develop.pm b/perllib/FixMyStreet/App/Controller/Develop.pm
index 0bc52883f..b73bbaf86 100755
--- a/perllib/FixMyStreet/App/Controller/Develop.pm
+++ b/perllib/FixMyStreet/App/Controller/Develop.pm
@@ -26,10 +26,21 @@ Makes sure this controller is only available when run in development.
sub auto : Private {
my ($self, $c) = @_;
- $c->detach( '/page_error_404_not_found' ) unless $c->config->{STAGING_SITE};
+ $c->detach( '/page_error_404_not_found' ) unless $c->user_exists && $c->user->is_superuser;
return 1;
}
+=item index
+
+Shows a list of links to preview HTML emails.
+
+=cut
+
+sub index : Path('/_dev') : Args(0) {
+ my ( $self, $c ) = @_;
+ $c->stash->{problem} = $c->model('DB::Problem')->first;
+}
+
=item email_list
Shows a list of links to preview HTML emails.
@@ -130,6 +141,115 @@ sub email_previewer : Path('/_dev/email') : Args(1) {
$c->response->body($html);
}
+=item problem_confirm_previewer
+
+Displays the confirmation page for a given problem.
+
+=back
+
+=cut
+
+sub problem_confirm_previewer : Path('/_dev/confirm_problem') : Args(1) {
+ my ( $self, $c, $id ) = @_;
+
+ $c->log->info('Previewing confirmation page for problem ' . $id);
+
+ my $problem = $c->model('DB::Problem')->find( { id => $id } )
+ || $c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] );
+ $c->stash->{report} = $problem;
+
+ $c->log->info('Problem ' . $id . ' found: ' . $problem->title);
+ $c->stash->{template} = 'tokens/confirm_problem.html';
+}
+
+=item update_confirm_previewer
+
+Displays the confirmation page for an update on the given problem.
+
+=back
+
+=cut
+
+sub update_confirm_previewer : Path('/_dev/confirm_update') : Args(1) {
+ my ( $self, $c, $id ) = @_;
+
+ my $problem = $c->model('DB::Problem')->find( { id => $id } )
+ || $c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] );
+ $c->stash->{problem} = $problem;
+
+ $c->stash->{template} = 'tokens/confirm_update.html';
+}
+
+=item alert_confirm_previewer
+
+Displays the confirmation page for an alert, with the supplied
+confirmation type (ie: subscribed, or unsubscribed).
+
+=back
+
+=cut
+
+sub alert_confirm_previewer : Path('/_dev/confirm_alert') : Args(1) {
+ my ( $self, $c, $confirm_type ) = @_;
+ $c->stash->{confirm_type} = $confirm_type;
+ $c->stash->{template} = 'tokens/confirm_alert.html';
+}
+
+=item contact_submit_previewer
+
+Displays the contact submission page, with success based on the
+truthyness of the supplied argument.
+
+=back
+
+=cut
+
+sub contact_submit_previewer : Path('/_dev/contact_submit') : Args(1) {
+ my ( $self, $c, $success ) = @_;
+ $c->stash->{success} = $success;
+ $c->stash->{template} = 'contact/submit.html';
+}
+
+=item questionnaire_completed_previewer
+
+Displays the questionnaire completed page, with content based on
+the supplied ?new_state and ?been_fixed query params.
+
+=back
+
+=cut
+
+sub questionnaire_completed_previewer : Path('/_dev/questionnaire_completed') : Args(0) {
+ my ( $self, $c ) = @_;
+ $c->stash->{been_fixed} = $c->get_param('been_fixed');
+ $c->stash->{new_state} = $c->get_param('new_state');
+ $c->stash->{template} = 'questionnaire/completed.html';
+}
+
+=item questionnaire_creator_fixed_previewer
+
+Displays the page a user sees after they mark their own report as fixed.
+
+=back
+
+=cut
+
+sub questionnaire_creator_fixed_previewer : Path('/_dev/questionnaire_creator_fixed') : Args(0) {
+ my ( $self, $c ) = @_;
+ $c->stash->{template} = 'questionnaire/creator_fixed.html';
+}
+
+sub auth_preview : Path('/_dev/auth') : Args(0) {
+ my ( $self, $c ) = @_;
+ $c->stash->{template} = 'auth/token.html';
+}
+
+sub report_new_preview : Path('/_dev/report_new') : Args(0) {
+ my ( $self, $c ) = @_;
+ $c->stash->{template} = 'email_sent.html';
+ $c->stash->{email_type} = $c->get_param('email_type');
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index 696529660..d2b0bf3f4 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -65,15 +65,8 @@ sub submit : Path('submit') {
my ( $self, $c ) = @_;
if (my $token = $c->get_param('token')) {
- if ($token eq '_test_') {
- $c->stash->{been_fixed} = $c->get_param('been_fixed');
- $c->stash->{new_state} = $c->get_param('new_state');
- $c->stash->{template} = 'questionnaire/completed.html';
- return;
- }
$c->forward('submit_standard');
} elsif (my $p = $c->get_param('problem')) {
- $c->detach('creator_fixed') if $p eq '_test_';
$c->forward('submit_creator_fixed');
} else {
$c->detach( '/page_error_404_not_found' );
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index a1038e909..14b1029a7 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -118,12 +118,6 @@ sub report_new : Path : Args(0) {
$c->forward('redirect_or_confirm_creation');
}
-sub report_new_test : Path('_test_') : Args(0) {
- my ( $self, $c ) = @_;
- $c->stash->{template} = 'email_sent.html';
- $c->stash->{email_type} = $c->get_param('email_type');
-}
-
# This is for the new phonegap versions of the app. It looks a lot like
# report_new but there's a few workflow differences as we only ever want
# to sent JSON back here
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index bb6140e0a..659d763de 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -28,17 +28,6 @@ problem but are not logged in.
sub confirm_problem : Path('/P') {
my ( $self, $c, $token_code ) = @_;
- if ($token_code eq '_test_') {
- $c->stash->{report} = {
- id => 123,
- title => 'Title of Report',
- bodies_str => '1',
- url => '/report/123',
- service => $c->get_param('service'),
- };
- return;
- }
-
my $auth_token =
$c->forward( 'load_auth_token', [ $token_code, 'problem' ] );
@@ -88,11 +77,6 @@ alert but are not logged in.
sub confirm_alert : Path('/A') {
my ( $self, $c, $token_code ) = @_;
- if ($token_code eq '_test_') {
- $c->stash->{confirm_type} = $c->get_param('confirm_type');
- return;
- }
-
my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'alert' ] );
# Load the alert
@@ -134,16 +118,6 @@ update but are not logged in.
sub confirm_update : Path('/C') {
my ( $self, $c, $token_code ) = @_;
- if ($token_code eq '_test_') {
- $c->stash->{problem} = {
- id => 123,
- title => 'Title of Report',
- bodies_str => '1',
- url => '/report/123',
- };
- return;
- }
-
my $auth_token =
$c->forward( 'load_auth_token', [ $token_code, 'comment' ] );
diff --git a/t/app/controller/develop.t b/t/app/controller/develop.t
index 92aa86721..8f26a9f16 100644
--- a/t/app/controller/develop.t
+++ b/t/app/controller/develop.t
@@ -6,14 +6,20 @@ my ($problem) = $mech->create_problems_for_body(1, 2504, 'title');
my $update = $mech->create_comment_for_problem($problem, $problem->user, 'Name', 'Text', 'f', 'confirmed', 'confirmed');
subtest 'not visible on live site' => sub {
- FixMyStreet::override_config {
- STAGING_SITE => 0
- }, sub {
- $mech->get('/_dev/email/');
- is $mech->res->code, 404;
- $mech->get('/_dev/email/login');
- is $mech->res->code, 404;
- };
+ $mech->get('/_dev/');
+ is $mech->res->code, 404;
+ $mech->get('/_dev/email');
+ is $mech->res->code, 404;
+ $mech->get('/_dev/email/login');
+ is $mech->res->code, 404;
+};
+
+$problem->user->update({ is_superuser => 1 });
+$mech->log_in_ok($problem->user->email);
+
+subtest 'dev index' => sub {
+ $mech->get_ok('/_dev/');
+ $mech->content_contains('<h1>/_dev</h1>');
};
subtest 'dev email index page' => sub {
@@ -30,4 +36,27 @@ subtest 'individual email previews' => sub {
$mech->get_ok('/_dev/email/update-confirm?update=' . $update->id);
};
+subtest 'problem confirmation page preview' => sub {
+ $mech->get_ok('/_dev/confirm_problem/' . $problem->id );
+};
+
+subtest 'update confirmation page preview' => sub {
+ $mech->get_ok('/_dev/confirm_update/' . $problem->id);
+};
+
+subtest 'alert confirmation page preview' => sub {
+ $mech->get_ok('/_dev/confirm_alert/subscribe');
+};
+
+subtest 'contact form submission page preview' => sub {
+ $mech->get_ok('/_dev/contact_submit/1');
+};
+
+subtest 'questionnaire completion page previews' => sub {
+ $mech->get_ok('/_dev/questionnaire_completed?been_fixed=Yes');
+ $mech->get_ok('/_dev/questionnaire_completed?been_fixed=Unknown');
+ $mech->get_ok('/_dev/questionnaire_completed?new_state=confirmed');
+ $mech->get_ok('/_dev/questionnaire_creator_fixed');
+};
+
done_testing();
diff --git a/templates/web/base/develop/index.html b/templates/web/base/develop/index.html
new file mode 100755
index 000000000..56af2319d
--- /dev/null
+++ b/templates/web/base/develop/index.html
@@ -0,0 +1,41 @@
+[% INCLUDE 'header.html' %]
+
+<h1>/_dev</h1>
+
+<p><a href="/_dev/email">Email previews</a></p>
+
+<dl>
+
+<dt>Questionnaire responses</dt>
+<dd><ul>
+<li><a href="/_dev/questionnaire_completed?been_fixed=Yes">Yes</a>
+<li><a href="/_dev/questionnaire_completed?new_state=confirmed">No</a>
+<li><a href="/_dev/questionnaire_completed?been_fixed=Unknown">Unknown</a>
+<li><a href="/_dev/questionnaire_creator_fixed">Mark fixed as part of update by reporter</a>
+</ul></dd>
+
+<dt>Confirmation pages</dt>
+<dd><ul>
+<li><a href="/_dev/confirm_problem/[% problem.id %]">Problem</a>
+<li><a href="/_dev/confirm_update/[% problem.id %]">Update</a>
+<li><a href="/_dev/confirm_alert/subscribe">Alert</a>
+<li><a href="/_dev/confirm_alert/unsubscribe">Alert unsubscribe</a>
+</ul></dd>
+
+<dt>Contact form</dt>
+<dd><ul>
+<li><a href="/_dev/contact_submit/1">Success</a>
+<li><a href="/_dev/contact_submit/0">Failure</a>
+</ul></dd>
+
+<dt>Check email pages</dt>
+<dd><ul>
+<li><a href="/_dev/auth">Auth</a>
+ <li><a href="/_dev/report_new?email_type=problem">New report</a>
+ <li><a href="/_dev/report_new?email_type=update">New update</a>
+ <li><a href="/_dev/report_new?email_type=alert">New alert</a>
+</ul></dd>
+
+</dl>
+
+[% INCLUDE 'footer.html' %]