Skip to content

Commit

Permalink
Make sure disable flag for old app is string "1".
Browse files Browse the repository at this point in the history
The old app has a === "1" comparison in it to check for a question
answer disabling, so make sure we output a string.
  • Loading branch information
dracos committed Oct 23, 2023
1 parent fe57e04 commit 65f72af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions perllib/FixMyStreet/App/Controller/Report/New.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,7 @@ sub generate_category_extra_json : Private {
if (($_->{variable} || '') eq 'true' && @{$_->{values} || []}) {
foreach my $opt (@{$_->{values}}) {
if ($opt->{disable}) {
$opt->{disable} = "1";

Check warning on line 2047 in perllib/FixMyStreet/App/Controller/Report/New.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Controller/Report/New.pm#L2047

Added line #L2047 was not covered by tests
my $message = $opt->{disable_message} || $_->{datatype_description};
$data{datatype_description} = $message;
}
Expand Down
16 changes: 16 additions & 0 deletions t/app/controller/report_new_open311.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use FixMyStreet::TestMech;
use Test::LongString;
use JSON::MaybeXS;
use Web::Scraper;

# disable info logs for this test run
Expand Down Expand Up @@ -431,6 +432,21 @@ subtest "Category extras includes form disabling string" => sub {
},
],
};

# The old mobile app has a === comparison for disable with the string "1"
my $J = JSON::MaybeXS->new->allow_nonref->utf8;
$output = $json->{by_category} ? $json->{by_category}{Pothole}{category_extra_json}[3] : $json->{category_extra_json}[3];
is_deeply $output, {
datatype_description => 'Please please ring',
code => 'dangerous',
required => 'false',
values => [
{ 'name' => 'Yes', 'key' => 'yes', 'disable' => "1" },
{ 'name' => 'No', 'key' => 'no' },
],
description => 'Is it dangerous?'
};
is $J->encode($output->{values}[0]{disable}), '"1"';
}

# Test new non-JS form disabling flow
Expand Down

0 comments on commit 65f72af

Please sign in to comment.