Bugzilla – Attachment 112538 Details for
Bug 26635
Expand coded values in REST API call
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26635: Add tests
Bug-26635-Add-tests.patch (text/plain), 8.28 KB, created by
Agustín Moyano
on 2020-10-26 19:09:33 UTC
(
hide
)
Description:
Bug 26635: Add tests
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2020-10-26 19:09:33 UTC
Size:
8.28 KB
patch
obsolete
>From 3fc1092d89c2178438e3727e95755807bb83f774 Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Fri, 9 Oct 2020 09:59:46 -0300 >Subject: [PATCH] Bug 26635: Add tests > >Add tests in t/db_dependent/Koha/Object.t and >t/db_dependent/Koha/REST/Plugin/Objects.t >--- > t/db_dependent/Koha/Object.t | 43 +++++++++++++- > t/db_dependent/Koha/REST/Plugin/Objects.t | 71 ++++++++++++++++++++--- > 2 files changed, 106 insertions(+), 8 deletions(-) > >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index b78283ce25..b9c27665d4 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 21; >+use Test::More tests => 22; > use Test::Exception; > use Test::Warn; > use DateTime; >@@ -33,6 +33,8 @@ use Koha::DateUtils qw( dt_from_string ); > use Koha::Libraries; > use Koha::Patrons; > use Koha::ApiKeys; >+use Koha::AuthorisedValueCategories; >+use Koha::AuthorisedValues; > > use JSON; > use Scalar::Util qw( isvstring ); >@@ -896,5 +898,44 @@ subtest 'messages() and add_message() tests' => sub { > isnt( $patron->messages, undef, '->messages initializes the array if required' ); > is( scalar @{ $patron->messages }, 0, '->messages returns an empty arrayref' ); > >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'Authorised values expansion' => sub { >+ plan tests => 4; >+ >+ $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 $marseille = $builder->build_object({ class => 'Koha::Cities', value => {city_country => 'FR', city_name => 'Marseille'} }); >+ my $cordoba = $builder->build_object({ class => 'Koha::Cities', value => {city_country => 'AR', city_name => 'Córdoba'} }); >+ >+ my $mobj = $marseille->to_api({av_expand => 1}); >+ my $cobj = $cordoba->to_api({av_expand => 1}); >+ >+ isnt($mobj->{_authorised_values}, undef, '_authorised_values exists for Marseille'); >+ isnt($cobj->{_authorised_values}, undef, '_authorised_values exists for Córdoba'); >+ >+ is($mobj->{_authorised_values}->{country}->{lib}, $fr->lib, 'Authorised value for country expanded'); >+ is($cobj->{_authorised_values}->{country}->{lib}, $ar->lib, 'Authorised value for country expanded'); >+ >+ > $schema->storage->txn_rollback; > }; >diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t >index d5db5e7c66..362618aa39 100755 >--- a/t/db_dependent/Koha/REST/Plugin/Objects.t >+++ b/t/db_dependent/Koha/REST/Plugin/Objects.t >@@ -21,6 +21,8 @@ use Koha::Acquisition::Orders; > use Koha::Cities; > use Koha::Holds; > use Koha::Biblios; >+use Koha::AuthorisedValueCategories; >+use Koha::AuthorisedValues; > > # Dummy app for testing the plugin > use Mojolicious::Lite; >@@ -77,7 +79,7 @@ get '/biblios' => sub { > > > # The tests >-use Test::More tests => 10; >+use Test::More tests => 11; > use Test::Mojo; > > use t::lib::Mocks; >@@ -305,7 +307,7 @@ subtest 'objects.search helper, with path parameters and _match' => sub { > $schema->storage->txn_rollback; > }; > >-subtest 'object.search helper with query parameter' => sub { >+subtest 'objects.search helper with query parameter' => sub { > plan tests => 4; > > $schema->storage->txn_begin; >@@ -328,7 +330,7 @@ subtest 'object.search helper with query parameter' => sub { > $schema->storage->txn_rollback; > }; > >-subtest 'object.search helper with q parameter' => sub { >+subtest 'objects.search helper with q parameter' => sub { > plan tests => 4; > > $schema->storage->txn_begin; >@@ -351,7 +353,7 @@ subtest 'object.search helper with q parameter' => sub { > $schema->storage->txn_rollback; > }; > >-subtest 'object.search helper with x-koha-query header' => sub { >+subtest 'objects.search helper with x-koha-query header' => sub { > plan tests => 4; > > $schema->storage->txn_begin; >@@ -374,7 +376,7 @@ subtest 'object.search helper with x-koha-query header' => sub { > $schema->storage->txn_rollback; > }; > >-subtest 'object.search helper with all query methods' => sub { >+subtest 'objects.search helper with all query methods' => sub { > plan tests => 6; > > $schema->storage->txn_begin; >@@ -400,9 +402,11 @@ subtest 'object.search helper with all query methods' => sub { > $schema->storage->txn_rollback; > }; > >-subtest 'object.search helper order by embedded columns' => sub { >+subtest 'objects.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; >@@ -414,5 +418,58 @@ 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.search helper with expanded authorised values' => sub { >+ plan tests => 11; >+ > $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}; >+ } >+ ); >+ >+ $builder->build_object({ >+ class => 'Koha::Cities', >+ value => { >+ city_name => 'Manuel', >+ city_country => 'AR' >+ } >+ }); >+ $builder->build_object({ >+ class => 'Koha::Cities', >+ value => { >+ city_name => 'Manuela', >+ city_country => 'US' >+ } >+ }); >+ >+ $t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => { 'x-koha-av' => 1 }) >+ ->status_is(200) >+ ->json_has('/0') >+ ->json_has('/1') >+ ->json_hasnt('/2') >+ ->json_is('/0/name' => 'Manuel') >+ ->json_has('/0/_authorised_values') >+ ->json_is('/0/_authorised_values/country/lib' => $ar->lib) >+ ->json_is('/1/name' => 'Manuela') >+ ->json_has('/1/_authorised_values') >+ ->json_is('/1/_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 26635
:
111400
|
111401
|
111402
|
111411
|
111412
|
111413
|
111414
|
112538
|
112539
|
116232
|
116233
|
116234
|
116235
|
116592
|
116593
|
120698
|
120699
|
120700
|
124268
|
142761
|
142762
|
142763
|
142776
|
142792
|
142793
|
142794
|
142795
|
142796
|
142801
|
142802
|
142803
|
142804
|
142805
|
143039
|
143040
|
143041
|
143042
|
143043
|
143044
|
143073
|
143074
|
143075
|
143076
|
143077
|
143078
|
143079
|
143080
|
143127
|
143128
|
143129
|
143130
|
143131
|
143132
|
143133
|
143134
|
143276
|
143354
|
143355
|
143356
|
143357
|
143358
|
143359
|
143360
|
143361
|
143362