From edb048de78bccf1bc7b9c9d84284cdb0228ca4be Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 9 Oct 2023 12:23:57 +0000 Subject: [PATCH] Bug 30719: (QA follow-up) Rename illbatches endpoint to ill/batches Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Illbatches.pm | 6 +-- .../{illbatch.yaml => ill_batch.yaml} | 0 .../{illbatches.yaml => ill_batches.yaml} | 2 +- .../{illbatches.yaml => ill_batches.yaml} | 32 +++++++-------- api/v1/swagger/swagger.yaml | 22 +++++----- koha-tmpl/intranet-tmpl/prog/js/ill-batch.js | 2 +- .../api/v1/{illbatches.t => ill_batches.t} | 40 +++++++++---------- 7 files changed, 52 insertions(+), 52 deletions(-) rename api/v1/swagger/definitions/{illbatch.yaml => ill_batch.yaml} (100%) rename api/v1/swagger/definitions/{illbatches.yaml => ill_batches.yaml} (67%) rename api/v1/swagger/paths/{illbatches.yaml => ill_batches.yaml} (90%) rename t/db_dependent/api/v1/{illbatches.t => ill_batches.t} (84%) diff --git a/Koha/REST/V1/Illbatches.pm b/Koha/REST/V1/Illbatches.pm index 6b1fd95570..72efdc3ae8 100644 --- a/Koha/REST/V1/Illbatches.pm +++ b/Koha/REST/V1/Illbatches.pm @@ -106,7 +106,7 @@ Get one batch sub get { my $c = shift->openapi->valid_input; - my $batchid = $c->param('illbatch_id'); + my $batchid = $c->param('ill_batch_id'); my $batch = Koha::Illbatches->find($batchid); @@ -204,7 +204,7 @@ Update a batch sub update { my $c = shift->openapi->valid_input or return; - my $batch = Koha::Illbatches->find( $c->param('illbatch_id') ); + my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') ); if ( not defined $batch ) { return $c->render( @@ -253,7 +253,7 @@ sub delete { my $c = shift->openapi->valid_input or return; - my $batch = Koha::Illbatches->find( $c->param('illbatch_id') ); + my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') ); if ( not defined $batch ) { return $c->render( status => 404, openapi => { error => "ILL batch not found" } ); diff --git a/api/v1/swagger/definitions/illbatch.yaml b/api/v1/swagger/definitions/ill_batch.yaml similarity index 100% rename from api/v1/swagger/definitions/illbatch.yaml rename to api/v1/swagger/definitions/ill_batch.yaml diff --git a/api/v1/swagger/definitions/illbatches.yaml b/api/v1/swagger/definitions/ill_batches.yaml similarity index 67% rename from api/v1/swagger/definitions/illbatches.yaml rename to api/v1/swagger/definitions/ill_batches.yaml index 4db20f480d..616d97bfe5 100644 --- a/api/v1/swagger/definitions/illbatches.yaml +++ b/api/v1/swagger/definitions/ill_batches.yaml @@ -1,5 +1,5 @@ --- type: array items: - $ref: "illbatch.yaml" + $ref: "ill_batch.yaml" additionalProperties: false diff --git a/api/v1/swagger/paths/illbatches.yaml b/api/v1/swagger/paths/ill_batches.yaml similarity index 90% rename from api/v1/swagger/paths/illbatches.yaml rename to api/v1/swagger/paths/ill_batches.yaml index 30a67355d8..c543aaf648 100644 --- a/api/v1/swagger/paths/illbatches.yaml +++ b/api/v1/swagger/paths/ill_batches.yaml @@ -1,10 +1,10 @@ --- -/illbatches: +/ill/batches: get: x-mojo-to: Illbatches#list operationId: listIllbatches tags: - - illbatches + - ill_batches summary: List ILL batches parameters: [] produces: @@ -13,7 +13,7 @@ "200": description: A list of ILL batches schema: - $ref: "../swagger.yaml#/definitions/illbatches" + $ref: "../swagger.yaml#/definitions/ill_batches" "401": description: Authentication required schema: @@ -44,7 +44,7 @@ x-mojo-to: Illbatches#add operationId: addIllbatch tags: - - illbatches + - ill_batches summary: Add ILL batch parameters: - name: body @@ -52,14 +52,14 @@ description: A JSON object containing informations about the new batch required: true schema: - $ref: "../swagger.yaml#/definitions/illbatch" + $ref: "../swagger.yaml#/definitions/ill_batch" produces: - application/json responses: "201": description: Batch added schema: - $ref: "../swagger.yaml#/definitions/illbatch" + $ref: "../swagger.yaml#/definitions/ill_batch" "400": description: Bad request schema: @@ -94,15 +94,15 @@ x-koha-authorization: permissions: ill: "1" -"/illbatches/{illbatch_id}": +"/ill/batches/{ill_batch_id}": get: x-mojo-to: Illbatches#get operationId: getIllbatches tags: - - illbatches + - ill_batches summary: Get ILL batch parameters: - - name: illbatch_id + - name: ill_batch_id in: path description: ILL batch id/name/contents required: true @@ -113,7 +113,7 @@ "200": description: An ILL batch schema: - $ref: "../swagger.yaml#/definitions/illbatch" + $ref: "../swagger.yaml#/definitions/ill_batch" "401": description: Authentication required schema: @@ -144,16 +144,16 @@ x-mojo-to: Illbatches#update operationId: updateIllBatch tags: - - illbatches + - ill_batches summary: Update batch parameters: - - $ref: "../swagger.yaml#/parameters/illbatch_id_pp" + - $ref: "../swagger.yaml#/parameters/ill_batch_id_pp" - name: body in: body description: A JSON object containing information on the batch required: true schema: - $ref: "../swagger.yaml#/definitions/illbatch" + $ref: "../swagger.yaml#/definitions/ill_batch" consumes: - application/json produces: @@ -162,7 +162,7 @@ "200": description: An ILL batch schema: - $ref: "../swagger.yaml#/definitions/illbatch" + $ref: "../swagger.yaml#/definitions/ill_batch" "400": description: Bad request schema: @@ -197,10 +197,10 @@ x-mojo-to: Illbatches#delete operationId: deleteBatch tags: - - illbatches + - ill_batches summary: Delete ILL batch parameters: - - $ref: "../swagger.yaml#/parameters/illbatch_id_pp" + - $ref: "../swagger.yaml#/parameters/ill_batch_id_pp" produces: - application/json responses: diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 1663e04d1c..3a6320528c 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -64,10 +64,10 @@ definitions: $ref: ./definitions/ill_status.yaml ill_request: $ref: ./definitions/ill_request.yaml - illbatch: - $ref: ./definitions/illbatch.yaml - illbatches: - $ref: ./definitions/illbatches.yaml + ill_batch: + $ref: ./definitions/ill_batch.yaml + ill_batches: + $ref: ./definitions/ill_batches.yaml illbatchstatus: $ref: ./definitions/illbatchstatus.yaml illbatchstatuses: @@ -277,10 +277,10 @@ paths: $ref: "./paths/ill_backends.yaml#/~1ill~1backends~1{ill_backend_id}" /ill/requests: $ref: ./paths/ill_requests.yaml#/~1ill~1requests - /illbatches: - $ref: ./paths/illbatches.yaml#/~1illbatches - "/illbatches/{illbatch_id}": - $ref: "./paths/illbatches.yaml#/~1illbatches~1{illbatch_id}" + /ill/batches: + $ref: ./paths/ill_batches.yaml#/~1ill~1batches + "/ill/batches/{ill_batch_id}": + $ref: "./paths/ill_batches.yaml#/~1ill~1batches~1{ill_batch_id}" /illbatchstatuses: $ref: ./paths/illbatchstatuses.yaml#/~1illbatchstatuses "/illbatchstatuses/{illbatchstatus_code}": @@ -537,10 +537,10 @@ parameters: name: hold_id required: true type: integer - illbatch_id_pp: + ill_batch_id_pp: description: Internal ILL batch identifier in: path - name: illbatch_id + name: ill_batch_id required: true type: integer illbatchstatus_code_pp: @@ -880,7 +880,7 @@ tags: name: ill_backends x-displayName: ILL backends - description: "Manage ILL module batches\n" - name: illbatches + name: ill_batches x-displayName: ILL batches - description: "Manage ILL module batch statuses\n" name: illbatchstatuses diff --git a/koha-tmpl/intranet-tmpl/prog/js/ill-batch.js b/koha-tmpl/intranet-tmpl/prog/js/ill-batch.js index 491c0a4374..d670055e4e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/ill-batch.js +++ b/koha-tmpl/intranet-tmpl/prog/js/ill-batch.js @@ -13,7 +13,7 @@ // Make a batch API call, returning the resulting promise window.doBatchApiRequest = function (url, options) { - var batchListApi = '/api/v1/illbatches'; + var batchListApi = '/api/v1/ill/batches'; var fullUrl = batchListApi + (url ? url : ''); return doApiRequest(fullUrl, options); }; diff --git a/t/db_dependent/api/v1/illbatches.t b/t/db_dependent/api/v1/ill_batches.t similarity index 84% rename from t/db_dependent/api/v1/illbatches.t rename to t/db_dependent/api/v1/ill_batches.t index 9ed668ca4b..ad0107f33e 100755 --- a/t/db_dependent/api/v1/illbatches.t +++ b/t/db_dependent/api/v1/ill_batches.t @@ -60,7 +60,7 @@ subtest 'list() tests' => sub { ## Authorized user tests # No batches, so empty array should be returned - $t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_is( [] ); + $t->get_ok("//$userid:$password@/api/v1/ill/batches")->status_is(200)->json_is( [] ); my $batch = $builder->build_object( { @@ -85,7 +85,7 @@ subtest 'list() tests' => sub { ); # One batch created, should get returned - $t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_has( '/0/batch_id', 'Batch ID' ) + $t->get_ok("//$userid:$password@/api/v1/ill/batches")->status_is(200)->json_has( '/0/batch_id', 'Batch ID' ) ->json_has( '/0/name', 'Batch name' )->json_has( '/0/backend', 'Backend name' ) ->json_has( '/0/patron_id', 'Borrowernumber' )->json_has( '/0/library_id', 'Branchcode' ) ->json_has( '/0/patron', 'patron embedded' )->json_has( '/0/branch', 'branch embedded' ) @@ -98,7 +98,7 @@ subtest 'list() tests' => sub { my $batch_with_another_name = $builder->build_object( { class => 'Koha::Illbatches' } ); # Two batches created, they should both be returned - $t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_has( '/0', 'has first batch' ) + $t->get_ok("//$userid:$password@/api/v1/ill/batches")->status_is(200)->json_has( '/0', 'has first batch' ) ->json_has( '/1', 'has second batch' ); my $patron = $builder->build_object( @@ -115,7 +115,7 @@ subtest 'list() tests' => sub { my $unauth_userid = $patron->userid; # Unauthorized access - $t->get_ok("//$unauth_userid:$password@/api/v1/illbatches")->status_is(403); + $t->get_ok("//$unauth_userid:$password@/api/v1/ill/batches")->status_is(403); $schema->storage->txn_rollback; }; @@ -160,19 +160,19 @@ subtest 'get() tests' => sub { $patron->set_password( { password => $password, skip_validation => 1 } ); my $unauth_userid = $patron->userid; - $t->get_ok( "//$userid:$password@/api/v1/illbatches/" . $batch->id )->status_is(200) + $t->get_ok( "//$userid:$password@/api/v1/ill/batches/" . $batch->id )->status_is(200) ->json_has( '/batch_id', 'Batch ID' )->json_has( '/name', 'Batch name' ) ->json_has( '/backend', 'Backend name' )->json_has( '/patron_id', 'Borrowernumber' ) ->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' ) ->json_has( '/branch', 'branch embedded' )->json_has( '/requests_count', 'request count' ); - $t->get_ok( "//$unauth_userid:$password@/api/v1/illbatches/" . $batch->id )->status_is(403); + $t->get_ok( "//$unauth_userid:$password@/api/v1/ill/batches/" . $batch->id )->status_is(403); my $batch_to_delete = $builder->build_object( { class => 'Koha::Illbatches' } ); my $non_existent_id = $batch_to_delete->id; $batch_to_delete->delete; - $t->get_ok("//$userid:$password@/api/v1/illbatches/$non_existent_id")->status_is(404) + $t->get_ok("//$userid:$password@/api/v1/ill/batches/$non_existent_id")->status_is(404) ->json_is( '/error' => 'ILL batch not found' ); $schema->storage->txn_rollback; @@ -217,7 +217,7 @@ subtest 'add() tests' => sub { }; # Unauthorized attempt to write - $t->post_ok( "//$unauth_userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(403); + $t->post_ok( "//$unauth_userid:$password@/api/v1/ill/batches" => json => $batch_metadata )->status_is(403); # Authorized attempt to write invalid data my $batch_with_invalid_field = { @@ -225,7 +225,7 @@ subtest 'add() tests' => sub { doh => 1 }; - $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_with_invalid_field )->status_is(400) + $t->post_ok( "//$userid:$password@/api/v1/ill/batches" => json => $batch_with_invalid_field )->status_is(400) ->json_is( "/errors" => [ { @@ -237,7 +237,7 @@ subtest 'add() tests' => sub { # Authorized attempt to write my $batch_id = - $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(201) + $t->post_ok( "//$userid:$password@/api/v1/ill/batches" => json => $batch_metadata )->status_is(201) ->json_is( '/name' => $batch_metadata->{name} )->json_is( '/backend' => $batch_metadata->{backend} ) ->json_is( '/patron_id' => $librarian->borrowernumber ) ->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/statuscode' => $batch_status->code ) @@ -245,7 +245,7 @@ subtest 'add() tests' => sub { # Authorized attempt to create with null id $batch_metadata->{id} = undef; - $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(400) + $t->post_ok( "//$userid:$password@/api/v1/ill/batches" => json => $batch_metadata )->status_is(400) ->json_has('/errors'); $schema->storage->txn_rollback; @@ -282,7 +282,7 @@ subtest 'update() tests' => sub { my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id; # Unauthorized attempt to update - $t->put_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" => json => + $t->put_ok( "//$unauth_userid:$password@/api/v1/ill/batches/$batch_id" => json => { name => 'These are not the droids you are looking for' } )->status_is(403); my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } ); @@ -295,7 +295,7 @@ subtest 'update() tests' => sub { statuscode => $batch_status->code }; - $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_missing_field ) + $t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_missing_field ) ->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] ); # Full object update on PUT @@ -307,7 +307,7 @@ subtest 'update() tests' => sub { statuscode => $batch_status->code }; - $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field ) + $t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_updated_field ) ->status_is(200)->json_is( '/name' => 'Master Ploo Koon' ); # Authorized attempt to write invalid data @@ -317,7 +317,7 @@ subtest 'update() tests' => sub { backend => "Mock" }; - $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_invalid_field ) + $t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_invalid_field ) ->status_is(400)->json_is( "/errors" => [ { @@ -331,13 +331,13 @@ subtest 'update() tests' => sub { my $non_existent_id = $batch_to_delete->id; $batch_to_delete->delete; - $t->put_ok( "//$userid:$password@/api/v1/illbatches/$non_existent_id" => json => $batch_with_updated_field ) + $t->put_ok( "//$userid:$password@/api/v1/ill/batches/$non_existent_id" => json => $batch_with_updated_field ) ->status_is(404); # Wrong method (POST) $batch_with_updated_field->{id} = 2; - $t->post_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field ) + $t->post_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_updated_field ) ->status_is(404); $schema->storage->txn_rollback; @@ -372,11 +372,11 @@ subtest 'delete() tests' => sub { my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id; # Unauthorized attempt to delete - $t->delete_ok("//$unauth_userid:$password@/api/v1/illbatches/$batch_id")->status_is(403); + $t->delete_ok("//$unauth_userid:$password@/api/v1/ill/batches/$batch_id")->status_is(403); - $t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")->status_is(204); + $t->delete_ok("//$userid:$password@/api/v1/ill/batches/$batch_id")->status_is(204); - $t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")->status_is(404); + $t->delete_ok("//$userid:$password@/api/v1/ill/batches/$batch_id")->status_is(404); $schema->storage->txn_rollback; }; -- 2.20.1