Bugzilla – Attachment 159030 Details for
Bug 30070
Performance issues with edifactmsgs when you have a large number of messages
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30070: Add unit tests
Bug-30070-Add-unit-tests.patch (text/plain), 6.68 KB, created by
Martin Renvoize
on 2023-11-16 09:43:22 UTC
(
hide
)
Description:
Bug 30070: Add unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2023-11-16 09:43:22 UTC
Size:
6.68 KB
patch
obsolete
>From 8cd87344cba95f29ac0665c9b1c2ee7fa1d29fce Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 14 Nov 2023 09:49:47 +0000 >Subject: [PATCH] Bug 30070: Add unit tests > >--- > t/db_dependent/Koha/Edifact/File.t | 72 +++++++++++++++++ > t/db_dependent/api/v1/edifact_files.t | 110 ++++++++++++++++++++++++++ > 2 files changed, 182 insertions(+) > create mode 100755 t/db_dependent/Koha/Edifact/File.t > create mode 100755 t/db_dependent/api/v1/edifact_files.t > >diff --git a/t/db_dependent/Koha/Edifact/File.t b/t/db_dependent/Koha/Edifact/File.t >new file mode 100755 >index 00000000000..0792994d129 >--- /dev/null >+++ b/t/db_dependent/Koha/Edifact/File.t >@@ -0,0 +1,72 @@ >+#!/usr/bin/perl >+ >+# Copyright 2023 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses> >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+ >+use Koha::Edifact::Files; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'vendor() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $file = $builder->build_object( { class => 'Koha::Edifact::Files' } ); >+ >+ my $vendor = $file->vendor; >+ is( >+ ref($vendor), 'Koha::Acquisition::Bookseller', >+ 'Koha::Edifact::File->vendor should return a Koha::Acquisition::Bookseller' >+ ); >+ >+ $file->vendor_id(undef)->store; >+ is( $file->vendor, undef, 'Koha::Edifact::File->vendor should return undef if no vendor linked' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'basket() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $file = $builder->build_object( { class => 'Koha::Edifact::Files' } ); >+ >+ my $basket = $file->basket; >+ is( >+ ref($basket), 'Koha::Acquisition::Basket', >+ 'Koha::Edifact::File->basket should return a Koha::Acquisition::Basket' >+ ); >+ >+ $file->basketno(undef)->store; >+ is( $file->basket, undef, 'Koha::Edifact::File->basket should return undef if no basket linked' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+1; >diff --git a/t/db_dependent/api/v1/edifact_files.t b/t/db_dependent/api/v1/edifact_files.t >new file mode 100755 >index 00000000000..5f85920ce84 >--- /dev/null >+++ b/t/db_dependent/api/v1/edifact_files.t >@@ -0,0 +1,110 @@ >+#!/usr/bin/env perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use JSON qw(encode_json); >+ >+use Koha::Edifact::Files; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+my $t = Test::Mojo->new('Koha::REST::V1'); >+t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+subtest 'list() tests' => sub { >+ >+ plan tests => 20; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::Edifact::Files->search->delete; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**11 } #acquisition >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ ## Authorized user tests >+ # No acquisitions\/edifiles, so empty array should be returned >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is( [] ); >+ >+ my $file = $builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'ORDER' } } ); >+ >+ # One file created, should get returned >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is( [ $file->to_api ] ); >+ >+ my $another_file_ORDER = >+ $builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'ORDER' } } ); >+ my $another_file_QUOTE = >+ $builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'QUOTE' } } ); >+ >+ # Two files created, they should both be returned >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is( >+ [ >+ $file->to_api, >+ $another_file_ORDER->to_api, >+ $another_file_QUOTE->to_api >+ ] >+ ); >+ >+ # Filtering works, two files sharing type >+ my $api_filter = encode_json( { 'me.type' => ['ORDER'] } ); >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?q=$api_filter")->status_is(200)->json_is( >+ [ >+ $file->to_api, >+ $another_file_ORDER->to_api >+ ] >+ ); >+ >+ $api_filter = encode_json( { 'me.filename' => $file->filename } ); >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?q=$api_filter")->status_is(200) >+ ->json_is( [ $file->to_api ] ); >+ >+ # Warn on unsupported query parameter >+ $api_filter = encode_json( { 'me.file_blah' => 'blah' } ); >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?file_blah=blah")->status_is(400) >+ ->json_is( [ { path => '/query/file_blah', message => 'Malformed query string' } ] ); >+ >+ # Unauthorized access >+ $t->get_ok("//$unauth_userid:$password@/api/v1/acquisitions/edifiles")->status_is(403); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.41.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 30070
:
158808
|
158809
|
158810
|
158887
|
158903
|
158904
|
158905
|
158906
|
158907
|
158908
|
158909
|
158910
|
158911
|
158912
|
158913
|
158914
|
158915
|
158918
|
158920
|
158922
|
158923
|
158924
|
158925
|
158926
|
158927
|
158928
|
158929
|
158930
|
158931
|
158932
|
158933
|
158934
|
158935
|
158936
|
158937
|
158938
|
158939
|
158940
|
158941
|
158942
|
158943
|
158944
|
158945
|
158946
|
158947
|
158948
|
158949
|
158950
|
158951
|
158952
|
158953
|
158954
|
158955
|
158963
|
158964
|
158965
|
158966
|
158967
|
158968
|
158969
|
158970
|
158971
|
158972
|
158973
|
158974
|
158975
|
159026
|
159027
|
159028
|
159029
|
159030
|
159031
|
159032
|
159033
|
159034
|
159035
|
159036
|
160336
|
160337
|
160338
|
160339
|
160340
|
160341
|
160342
|
160343
|
160344
|
160345
|
160346
|
160347
|
160348