Skip to content

Commit

Permalink
[EastSussex] optionally set a sort order on question answers
Browse files Browse the repository at this point in the history
if the question has an order key then use that to sort the list of
answers
  • Loading branch information
struan committed Apr 29, 2020
1 parent 4c11ded commit 2ba2363
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions perllib/Open311/Endpoint/Integration/SalesForceRest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ sub service {
if ($q->{answers}) {
$attribs->{datatype} = 'singlevaluelist';
$attribs->{values} = { map { ref $_ eq 'ARRAY' ? ( $_->[0] => $_->[1] ) : ( $_ => $_ ) } @{ $q->{answers} } };
$attribs->{values_sorted} = [ map { ref $_ eq 'ARRAY' ? $_->[0] : $_ } @{ $q->{answers} } ] if $q->{maintain_order};
}

push @{ $service->attributes }, Open311::Endpoint::Service::Attribute->new($attribs);
Expand Down
8 changes: 4 additions & 4 deletions t/open311/endpoint/eastsussex.t
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,14 @@ subtest "check fetch service description with questions" => sub {
order => 4,
description => "What is the problem with the sign?",
values => [
{
name => "broken",
key => "broken",
},
{
name => "dirty",
key => "dirty",
},
{
name => "broken",
key => "broken",
},
{
name => "sign is incorrect",
key => "incorrect",
Expand Down
1 change: 1 addition & 0 deletions t/open311/endpoint/eastsussex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"signQuestions": [
{
question: "What is the problem with the sign?",
maintain_order: 1,
answers: [
"dirty",
"broken",
Expand Down

0 comments on commit 2ba2363

Please sign in to comment.