@@ -, +, @@ /suggestions --- api/v1/swagger/paths/suggestions.yaml | 10 ++++++ t/db_dependent/api/v1/suggestions.t | 46 ++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) --- a/api/v1/swagger/paths/suggestions.yaml +++ a/api/v1/swagger/paths/suggestions.yaml @@ -53,6 +53,16 @@ required: true schema: $ref: ../definitions.yaml#/suggestion + - name: x-koha-override + in: header + required: false + description: | + Overrides list sent as a request header + Valid values: + * any + * max_total + * max_pending + type: string produces: - application/json responses: --- a/t/db_dependent/api/v1/suggestions.t +++ a/t/db_dependent/api/v1/suggestions.t @@ -149,7 +149,7 @@ subtest 'get() tests' => sub { subtest 'add() tests' => sub { - plan tests => 15; + plan tests => 16; $schema->storage->txn_begin; @@ -237,6 +237,50 @@ subtest 'add() tests' => sub { ] ); + subtest 'x-koha-override tests' => sub { + + plan tests => 14; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + t::lib::Mocks::mock_preference( 'MaxTotalSuggestions', 4 ); + t::lib::Mocks::mock_preference( 'MaxOpenSuggestions', 2 ); + t::lib::Mocks::mock_preference( 'NumberOfSuggestionDays', 2 ); + + my $suggestion = $builder->build_object( + { class => 'Koha::Suggestions', + value => { suggestedby => $patron->id, STATUS => 'ACCEPTED' } + } + ); + + my $suggestion_data = $suggestion->to_api; + delete $suggestion_data->{suggestion_id}; + delete $suggestion_data->{status}; + + $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) + ->status_is( 201, 'First pending suggestion' ); + + $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) + ->status_is( 201, 'Second pending suggestion' ); + + $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) + ->status_is(400) + ->json_is( '/error_code' => 'max_pending_reached' ); + + $t->post_ok( "//$userid:$password@/api/v1/suggestions" + => { 'x-koha-override' => 'max_pending' } + => json => $suggestion_data ) + ->status_is( 201, 'max_pending override does the job' ); + + $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) + ->status_is(400) + ->json_is( '/error_code' => 'max_total_reached' ); + + $t->post_ok( + "//$userid:$password@/api/v1/suggestions" => { 'x-koha-override' => 'any' } => json => $suggestion_data ) + ->status_is( 201, 'any overrides anything' ); + }; + $schema->storage->txn_rollback; }; --