Bugzilla – Attachment 111418 Details for
Bug 26636
Add objects.find Mojolicious helper
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26636: Add tests
Bug-26636-Add-tests.patch (text/plain), 5.31 KB, created by
Agustín Moyano
on 2020-10-09 17:24:18 UTC
(
hide
)
Description:
Bug 26636: Add tests
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2020-10-09 17:24:18 UTC
Size:
5.31 KB
patch
obsolete
>From 1059935e725a81a0eb5a2720fefb8623f7b0c20a Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Fri, 9 Oct 2020 11:53:43 -0300 >Subject: [PATCH] Bug 26636: Add tests > >Add tests in t/db_dependent/Koha/REST/Plugin/Objects.t >--- > t/db_dependent/Koha/REST/Plugin/Objects.t | 106 +++++++++++++++++++++- > 1 file changed, 105 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t >index 362618aa39..1877fd1200 100755 >--- a/t/db_dependent/Koha/REST/Plugin/Objects.t >+++ b/t/db_dependent/Koha/REST/Plugin/Objects.t >@@ -40,6 +40,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 => {} } ) ); >@@ -48,6 +55,14 @@ get '/orders' => sub { > $c->render( status => 200, json => $orders ); > }; > >+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 '/patrons/:patron_id/holds' => sub { > my $c = shift; > my $params = $c->req->params->to_hash; >@@ -79,7 +94,7 @@ get '/biblios' => sub { > > > # The tests >-use Test::More tests => 11; >+use Test::More tests => 14; > use Test::Mojo; > > use t::lib::Mocks; >@@ -209,6 +224,28 @@ subtest 'objects.search helper' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'objects.find helper' => sub { >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::Cities->delete; >+ >+ my $city1 = $builder->build_object({ class => 'Koha::Cities' }); >+ my $city2 = $builder->build_object({ class => 'Koha::Cities' }); >+ >+ $t->get_ok('/cities/'.$city1->cityid) >+ ->status_is(200) >+ ->json_is('/name' => $city1->city_name); >+ >+ $t->get_ok('/cities/'.$city2->cityid) >+ ->status_is(200) >+ ->json_is('/name' => $city2->city_name); >+ >+ $schema->storage->txn_rollback; >+ >+}; >+ > subtest 'objects.search helper, sorting on mapped column' => sub { > > plan tests => 14; >@@ -274,6 +311,20 @@ subtest 'objects.search helper, embed' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'objects.find helper, embed' => sub { >+ >+ plan tests => 2; >+ >+ $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; >+}; >+ > subtest 'objects.search helper, with path parameters and _match' => sub { > plan tests => 8; > >@@ -471,5 +522,58 @@ subtest 'objects.search helper with expanded authorised values' => sub { > ->json_has('/1/_authorised_values') > ->json_is('/1/_authorised_values/country/lib' => $us->lib); > >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'objects.find helper with expanded authorised values' => sub { >+ plan tests => 10; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::AuthorisedValues->search({category => 'Countries'})->delete; >+ Koha::AuthorisedValueCategories->search({category_name =>'Countries'})->delete; >+ >+ my $cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories', value => {category_name =>'Countries'} }); >+ my $fr = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'FR', lib=>'France', category=>$cat->category_name} }); >+ my $us = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'US', lib=>'United States of America', category=>$cat->category_name} }); >+ my $ar = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'AR', lib=>'Argentina', category=>$cat->category_name} }); >+ >+ my $city_class = Test::MockModule->new('Koha::City'); >+ $city_class->mock( '_fetch_authorised_values', >+ sub { >+ my ($self) = @_; >+ use Koha::AuthorisedValues; >+ my $av = Koha::AuthorisedValues->find({authorised_value => $self->city_country, category => 'Countries'}); >+ return {country => $av->unblessed}; >+ } >+ ); >+ >+ my $manuel = $builder->build_object({ >+ class => 'Koha::Cities', >+ value => { >+ city_name => 'Manuel', >+ city_country => 'AR' >+ } >+ }); >+ my $manuela = $builder->build_object({ >+ class => 'Koha::Cities', >+ value => { >+ city_name => 'Manuela', >+ city_country => 'US' >+ } >+ }); >+ >+ $t->get_ok('/cities/'.$manuel->cityid => { 'x-koha-av' => 1 }) >+ ->status_is(200) >+ ->json_is('/name' => 'Manuel') >+ ->json_has('/_authorised_values') >+ ->json_is('/_authorised_values/country/lib' => $ar->lib); >+ >+ $t->get_ok('/cities/'.$manuela->cityid => { 'x-koha-av' => 1 }) >+ ->status_is(200) >+ ->json_is('/name' => 'Manuela') >+ ->json_has('/_authorised_values') >+ ->json_is('/_authorised_values/country/lib' => $us->lib); >+ > $schema->storage->txn_rollback; > }; >\ No newline at end of file >-- >2.25.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26636
:
111418
|
111419
|
116222
|
116223
|
116224
|
116225
|
116226
|
116227
|
116228
|
116229
|
116230
|
116231
|
116594
|
116595
|
116596
|
116597
|
116598
|
117669
|
117670
|
117671
|
117672
|
117673
|
127528
|
127529
|
127530
|
127531
|
127532