From cad95e5feab789ebfcd7806187359f7e4f0412ca Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 31 Jul 2023 14:00:36 -0300 Subject: [PATCH] Bug 34024: Unit tests --- api/v1/swagger/paths/holds.yaml | 14 ++++++++++---- t/db_dependent/api/v1/holds.t | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/api/v1/swagger/paths/holds.yaml b/api/v1/swagger/paths/holds.yaml index 528656748b4..fefdddc0982 100644 --- a/api/v1/swagger/paths/holds.yaml +++ b/api/v1/swagger/paths/holds.yaml @@ -680,13 +680,19 @@ schema: $ref: "../swagger.yaml#/definitions/error" "409": - description: Unable to perform action on hold + description: | + Unable to perform action on hold. Possible `error_code` attribute values: + + * `hold_waiting` + * `hold_in_transit` + * `hold_in_processing` schema: $ref: "../swagger.yaml#/definitions/error" "500": - description: Internal error - schema: - $ref: "../swagger.yaml#/definitions/error" + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` "503": description: Under maintenance schema: diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index adc54296605..bf58edc7535 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -1270,7 +1270,7 @@ subtest 'add() tests' => sub { subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { - plan tests => 28; + plan tests => 37; $schema->storage->txn_begin; @@ -1403,6 +1403,25 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'invalid pickup library not used, even if x-koha-override is passed' ); + my $waiting_hold = $builder->build_object( { class => 'Koha::Holds', value => { found => 'W' } } ); + my $in_processing_hold = $builder->build_object( { class => 'Koha::Holds', value => { found => 'P' } } ); + my $in_transit_hold = $builder->build_object( { class => 'Koha::Holds', value => { found => 'T' } } ); + + $t->put_ok( "//$userid:$password@/api/v1/holds/" + . $waiting_hold->id + . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )->status_is(409) + ->json_is( { error => q{Cannot change pickup location}, error_code => 'hold_waiting' } ); + + $t->put_ok( "//$userid:$password@/api/v1/holds/" + . $in_processing_hold->id + . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )->status_is(409) + ->json_is( { error => q{Cannot change pickup location}, error_code => 'hold_in_processing' } ); + + $t->put_ok( "//$userid:$password@/api/v1/holds/" + . $in_transit_hold->id + . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )->status_is(409) + ->json_is( { error => q{Cannot change pickup location}, error_code => 'hold_in_transit' } ); + $schema->storage->txn_rollback; }; -- 2.41.0