From 005c3a531061011c51bc95ef792bae28e7d5bc0b Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Fri, 9 Oct 2020 11:53:43 -0300 Subject: [PATCH] Bug 26636: Add tests [20.11.x] This patch adds tests for the new objects.find helper. Sponsored-by: Virginia Polytechnic Institute and State University Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/REST/Plugin/Objects.t | 60 ++++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t index af656f32d5..6155e58f57 100755 --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ b/t/db_dependent/Koha/REST/Plugin/Objects.t @@ -38,6 +38,13 @@ get '/cities' => sub { $c->render( status => 200, json => $cities ); }; +get '/cities/:city_id' => sub { + my $c = shift; + my $id = $c->stash("city_id"); + my $city = $c->objects->find(Koha::Cities->new, $id); + $c->render( status => 200, json => $city ); +}; + get '/orders' => sub { my $c = shift; $c->stash('koha.embed', ( { fund => {} } ) ); @@ -56,6 +63,14 @@ get '/patrons/:patron_id/holds' => sub { $c->render( status => 200, json => {count => scalar(@$holds)} ); }; +get '/orders/:order_id' => sub { + my $c = shift; + $c->stash('koha.embed', ( { fund => {} } ) ); + my $id = $c->stash("order_id"); + my $order = $c->objects->find(Koha::Acquisition::Orders->new, $id); + $c->render( status => 200, json => $order ); +}; + get '/biblios' => sub { my $c = shift; my $output = $c->req->params->to_hash; @@ -77,7 +92,7 @@ get '/biblios' => sub { # The tests -use Test::More tests => 10; +use Test::More tests => 12; use Test::Mojo; use t::lib::Mocks; @@ -444,8 +459,11 @@ subtest 'object.search helper with all query methods' => sub { }; subtest 'object.search helper order by embedded columns' => sub { + plan tests => 3; + $schema->storage->txn_begin; + my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron1'} } ); my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron2'} } ); my $biblio1 = $builder->build_sample_biblio; @@ -458,5 +476,43 @@ subtest 'object.search helper order by embedded columns' => sub { ->json_is('/biblios/0/biblio_id' => $biblio2->biblionumber, 'Biblio 2 should be first') ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second'); + $schema->storage->txn_rollback; +}; + +subtest 'objects.find helper' => sub { + + plan tests => 6; + + my $t = Test::Mojo->new; + $schema->storage->txn_begin; -} + + my $city_1 = $builder->build_object( { class => 'Koha::Cities' } ); + my $city_2 = $builder->build_object( { class => 'Koha::Cities' } ); + + $t->get_ok( '/cities/' . $city_1->id ) + ->status_is(200) + ->json_is( $city_1->to_api ); + + $t->get_ok( '/cities/' . $city_2->id ) + ->status_is(200) + ->json_is( $city_2->to_api ); + + $schema->storage->txn_rollback; +}; + +subtest 'objects.find helper, embed' => sub { + + plan tests => 2; + + my $t = Test::Mojo->new; + + $schema->storage->txn_begin; + + my $order = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); + + $t->get_ok( '/orders/' . $order->ordernumber ) + ->json_is( $order->to_api( { embed => ( { fund => {} } ) } ) ); + + $schema->storage->txn_rollback; +}; -- 2.33.1