Bug 39900: (QA follow-up): Add translated_contents to tests

Also add tests to searching for specific language code

prove t/db_dependent/api/v1/additional_contents.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 7c6ad4bbe3)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Pedro Amorim 2025-08-01 10:52:58 +00:00 committed by Paul Derscheid
parent 41b3dc9a99
commit f1d771f131
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 68 additions and 2 deletions

View File

@ -235,5 +235,11 @@ __PACKAGE__->belongs_to(
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0w/fOUAy+4V4aVls/i7Wig
# You can replace this text with custom code or comments, and it will be preserved on regeneration
__PACKAGE__->has_many(
"translated_contents",
"Koha::Schema::Result::AdditionalContentsLocalization",
{ "foreign.additional_content_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
1;

View File

@ -35,7 +35,7 @@ my $t = Test::Mojo->new('Koha::REST::V1');
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
subtest 'anonymous access' => sub {
plan tests => 9;
plan tests => 17;
$schema->storage->txn_begin;
@ -80,6 +80,26 @@ subtest 'anonymous access' => sub {
}
);
$builder->build_object(
{
class => 'Koha::AdditionalContentsLocalizations',
value => {
additional_content_id => $public_additional_contents->id,
lang => 'pt-PT',
}
}
);
$builder->build_object(
{
class => 'Koha::AdditionalContentsLocalizations',
value => {
additional_content_id => $public_additional_contents->id,
lang => 'es-ES',
}
}
);
$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' );
@ -92,6 +112,46 @@ subtest 'anonymous access' => sub {
}
);
my $second_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,
}
}
);
$builder->build_object(
{
class => 'Koha::AdditionalContentsLocalizations',
value => {
additional_content_id => $second_public_additional_contents->id,
lang => 'fr-FR',
}
}
);
$t->get_ok( "/api/v1/public/additional_contents?q={\"translated_contents.lang\": \"pt-PT\"}" =>
{ '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 } )
}
)->json_hasnt('/1');
$t->get_ok( "/api/v1/public/additional_contents?q={\"translated_contents.lang\": \"fr-FR\"}" =>
{ 'x-koha-embed' => 'translated_contents' } )->status_is(200)->json_is(
'/0' => {
%{ $second_public_additional_contents->to_api( { public => 1 } ) },
translated_contents => $second_public_additional_contents->translated_contents->to_api( { public => 1 } )
}
)->json_hasnt('/1');
$schema->storage->txn_rollback;
};