Bugzilla – Attachment 182891 Details for
Bug 39900
Add public REST endpoint for additional_contents
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39900: Add tests
Bug-39900-Add-tests.patch (text/plain), 3.76 KB, created by
David Nind
on 2025-06-01 20:08:16 UTC
(
hide
)
Description:
Bug 39900: Add tests
Filename:
MIME Type:
Creator:
David Nind
Created:
2025-06-01 20:08:16 UTC
Size:
3.76 KB
patch
obsolete
>From ba7e43c3269c7a1384f16474439c6e5660566507 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@openfifth.co.uk> >Date: Wed, 14 May 2025 12:19:55 +0000 >Subject: [PATCH] Bug 39900: Add tests > >prove t/db_dependent/api/v1/additional_contents.t > >Signed-off-by: David Nind <david@davidnind.com> >--- > t/db_dependent/api/v1/additional_contents.t | 97 +++++++++++++++++++++ > 1 file changed, 97 insertions(+) > create mode 100755 t/db_dependent/api/v1/additional_contents.t > >diff --git a/t/db_dependent/api/v1/additional_contents.t b/t/db_dependent/api/v1/additional_contents.t >new file mode 100755 >index 0000000000..3d1b4ef369 >--- /dev/null >+++ b/t/db_dependent/api/v1/additional_contents.t >@@ -0,0 +1,97 @@ >+#!/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::NoWarnings; >+use Test::More tests => 2; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use Koha::AdditionalContents; >+use Koha::Database; >+use Koha::DateUtils qw( dt_from_string ); >+ >+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 'anonymous access' => sub { >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::AdditionalContents->search->delete; >+ >+ my $today = dt_from_string; >+ my $yesterday = dt_from_string->add( days => -1 ); >+ my $tomorrow = dt_from_string->add( days => 1 ); >+ my $res; >+ >+ $builder->build_object( >+ { >+ class => 'Koha::AdditionalContents', >+ value => { >+ expirationdate => $tomorrow, >+ published_on => $tomorrow, >+ category => 'news', >+ location => 'staff_and_opac', >+ branchcode => undef, >+ number => 3, >+ } >+ } >+ ); >+ >+ t::lib::Mocks::mock_preference( 'RESTPublicAnonymousRequests', 1 ); >+ >+ $res = $t->get_ok("/api/v1/public/additional_contents")->status_is(200)->tx->res->json; >+ >+ is( scalar @{$res}, 0, 'The only additional content is not active and not public' ); >+ >+ my $public_additional_contents = $builder->build_object( >+ { >+ class => 'Koha::AdditionalContents', >+ value => { >+ expirationdate => $tomorrow, >+ published_on => $yesterday, >+ category => 'news', >+ location => 'staff_and_opac', >+ branchcode => undef, >+ number => 3, >+ } >+ } >+ ); >+ >+ $res = $t->get_ok("/api/v1/public/additional_contents")->status_is(200)->tx->res->json; >+ >+ is( scalar @{$res}, 1, 'There is now one active and public additional content' ); >+ >+ $t->get_ok( "/api/v1/public/additional_contents" => { 'x-koha-embed' => 'translated_contents' } )->status_is(200) >+ ->json_is( >+ '/0' => { >+ %{ $public_additional_contents->to_api( { public => 1 } ) }, >+ translated_contents => $public_additional_contents->translated_contents->to_api( { public => 1 } ) >+ } >+ ); >+ >+ $schema->storage->txn_rollback; >+ >+}; >-- >2.39.5
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 39900
:
182439
|
182440
|
182441
|
182442
|
182443
|
182887
|
182888
|
182889
|
182890
| 182891