View | Details | Raw Unified | Return to bug 36641
Collapse All | Expand All

(-)a/Koha/REST/Plugin/Responses.pm (+30 lines)
Lines 77-82 Provides a generic method rendering the standard response for resource not found Link Here
77
            );
77
            );
78
        }
78
        }
79
    );
79
    );
80
81
=head3 render_invalid_parameter_value
82
83
    $c->render_invalid_parameter_value
84
85
Provides a generic method rendering the standard response for invalid parameter value passed.
86
87
=cut
88
89
    $app->helper(
90
        'render_invalid_parameter_value' => sub {
91
            my ( $c, $opts ) = @_;
92
            my $path   = $opts->{path};
93
            my $values = $opts->{values};
94
95
            $c->render(
96
                status  => 400,
97
                openapi => {
98
                    error      => "Invalid parameter value",
99
                    error_code => 'invalid_parameter_value',
100
                    path       => $path,
101
                    (
102
                        $values
103
                        ? ( values => { uri => $values->{uri}, field => $values->{field} } )
104
                        : ()
105
                    )
106
                },
107
            );
108
        }
109
    );
80
}
110
}
81
111
82
1;
112
1;
(-)a/t/db_dependent/api/v1/responses.t (-2 / +54 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 3;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Mojo;
22
use Test::Mojo;
23
23
Lines 115-117 subtest 'render_resource_deleted() tests' => sub { Link Here
115
115
116
    $schema->storage->txn_rollback;
116
    $schema->storage->txn_rollback;
117
};
117
};
118
- 
118
119
subtest 'render_invalid_parameter_value() tests' => sub {
120
121
    plan tests => 3;
122
123
    $schema->storage->txn_begin;
124
125
    my $authorized_patron = $builder->build_object(
126
        {
127
            class => 'Koha::Patrons',
128
            value => { flags => 1 },
129
        }
130
    );
131
    my $password = 'thePassword123';
132
    $authorized_patron->set_password( { password => $password, skip_validation => 1 } );
133
    my $userid = $authorized_patron->userid;
134
135
    my $path        = '/query/library';
136
    my $uri         = '/api/v1/libraries';
137
    my $field       = 'library_id';
138
    my $mock_cities = Test::MockModule->new('Koha::REST::V1::CirculationRules');
139
    $mock_cities->mock(
140
        'list_effective_rules',
141
        sub {
142
            my $c = shift->openapi->valid_input or return;
143
            return $c->render_invalid_parameter_value(
144
                {
145
                    path   => $path,
146
                    values => {
147
                        uri   => $uri,
148
                        field => $field
149
                    }
150
                }
151
            );
152
        }
153
    );
154
155
    my $t = Test::Mojo->new('Koha::REST::V1');
156
157
    $t->get_ok("//$userid:$password@/api/v1/circulation_rules?library=SOMETHING")->status_is('400')->json_is(
158
        {
159
            error      => 'Invalid parameter value',
160
            error_code => 'invalid_parameter_value',
161
            path       => $path,
162
            values     => {
163
                uri   => $uri,
164
                field => $field
165
            }
166
        }
167
    );
168
169
    $schema->storage->txn_rollback;
170
};

Return to bug 36641