Bugzilla – Attachment 149532 Details for
Bug 33105
Add vendor issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33105: Add tests
Bug-33105-Add-tests.patch (text/plain), 6.58 KB, created by
Jonathan Druart
on 2023-04-12 11:56:54 UTC
(
hide
)
Description:
Bug 33105: Add tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-04-12 11:56:54 UTC
Size:
6.58 KB
patch
obsolete
>From 74b451765e08255cbd9f934b1cff4cd5bc40a189 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 12 Apr 2023 10:45:33 +0200 >Subject: [PATCH] Bug 33105: Add tests > >--- > Koha/REST/V1/Acquisitions/Vendor/Issues.pm | 72 ++++++++++++++++ > t/db_dependent/Koha/Acquisition/Booksellers.t | 30 ++++++- > .../api/v1/acquisitions_vendor_issues.t | 82 +++++++++++++++++++ > 3 files changed, 183 insertions(+), 1 deletion(-) > create mode 100644 Koha/REST/V1/Acquisitions/Vendor/Issues.pm > create mode 100755 t/db_dependent/api/v1/acquisitions_vendor_issues.t > >diff --git a/Koha/REST/V1/Acquisitions/Vendor/Issues.pm b/Koha/REST/V1/Acquisitions/Vendor/Issues.pm >new file mode 100644 >index 00000000000..683d52ae793 >--- /dev/null >+++ b/Koha/REST/V1/Acquisitions/Vendor/Issues.pm >@@ -0,0 +1,72 @@ >+package Koha::REST::V1::Acquisitions::Vendor::Issues; >+ >+# 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 Mojo::Base 'Mojolicious::Controller'; >+ >+use Try::Tiny qw( catch try ); >+ >+=head1 NAME >+ >+Koha::REST::V1::Acquisitions::Vendor::Issues >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 list >+ >+Controller function that handles vendor issues >+ >+=cut >+ >+=head3 list >+ >+Return the list of issues for a given vendor >+ >+=cut >+ >+sub list { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ >+ my $vendor_id = $c->validation->param('vendor_id'); >+ my $vendor = Koha::Acquisition::Booksellers->find($vendor_id); >+ >+ unless ($vendor) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Vendor not found." } >+ ); >+ } >+ >+ my $issues_rs = $vendor->issues; >+ my $issues = $c->objects->search( $issues_rs ); >+ >+ return $c->render( >+ status => 200, >+ openapi => $issues, >+ ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+1; >diff --git a/t/db_dependent/Koha/Acquisition/Booksellers.t b/t/db_dependent/Koha/Acquisition/Booksellers.t >index 32106b86c13..3f9b8a6c871 100755 >--- a/t/db_dependent/Koha/Acquisition/Booksellers.t >+++ b/t/db_dependent/Koha/Acquisition/Booksellers.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > > use t::lib::TestBuilder; > >@@ -225,3 +225,31 @@ subtest 'interfaces' => sub { > > $schema->storage->txn_rollback(); > }; >+ >+subtest 'issues' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin(); >+ >+ my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); >+ >+ is( $vendor->issues->count, 0, 'Vendor has no issues' ); >+ >+ Koha::Acquisition::Bookseller::Issue->new( >+ { >+ vendor_id => $vendor->id, >+ type => 'MAINTENANCE', >+ notes => 'a vendor issue' >+ } >+ )->store; >+ >+ $vendor = $vendor->get_from_storage; >+ my $issues = $vendor->issues; >+ is( $issues->count, 1, '1 issue stored' ); >+ is( ref($issues), 'Koha::Acquisition::Bookseller::Issues', 'Type is correct' ); >+ >+ is( $issues->next->strings_map->{type}->{str}, 'Maintenance' ); >+ >+ $schema->storage->txn_rollback(); >+}; >diff --git a/t/db_dependent/api/v1/acquisitions_vendor_issues.t b/t/db_dependent/api/v1/acquisitions_vendor_issues.t >new file mode 100755 >index 00000000000..7c0d8e973eb >--- /dev/null >+++ b/t/db_dependent/api/v1/acquisitions_vendor_issues.t >@@ -0,0 +1,82 @@ >+#!/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 Koha::Acquisition::Booksellers; >+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 => 11; >+ >+ $schema->storage->txn_begin; >+ >+ my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); >+ my $vendor_id = $vendor->id; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2 ** 11 } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ # No issues, so empty array should be returned >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues") >+ ->status_is(200) >+ ->json_is( [] ); >+ >+ my $issue = Koha::Acquisition::Bookseller::Issue->new( >+ { >+ vendor_id => $vendor_id, >+ type => 'MAINTENANCE', >+ notes => 'a vendor issue' >+ } >+ )->store; >+ # One issue created, should get returned >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues") >+ ->status_is(200) >+ ->json_is( [$issue->to_api] ); >+ # Embed the AV description >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues" >+ => { 'x-koha-embed' => '+strings' }) >+ ->status_is(200) >+ ->json_is( [$issue->to_api({ strings => 1 })] ); >+ >+ $vendor->delete; >+ # No vendor, should get 404 >+ $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues") >+ ->status_is(404); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.25.1
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 33105
:
149509
|
149510
|
149511
|
149512
|
149513
|
149514
|
149515
|
149530
|
149531
|
149532
|
149556
|
149557
|
149558
|
149559
|
149560
|
149561
|
149562
|
152894
|
152895
|
152896
|
152897
|
152898
|
152899
|
152900
|
153117
|
153118
|
153119
|
153122
|
153123
|
153125
|
153126
|
153127
|
153128
|
153129
|
153130
|
153131
|
153132
|
153133
|
153134
|
153135
|
153136
|
153137
|
153730
|
153731