Bug 32353: Fix erm_agreements.t

Agreement.vendor_id has a default value defined in TestBuilder, but here
we were assuming there was one.
We should then generate it and pass the value when building the
agreement objects.

The failure was:
koha_1       |     #   Failed test '200 OK'
koha_1       |     #   at t/db_dependent/api/v1/erm_agreements.t line 95.
koha_1       |     #          got: '400'
koha_1       |     #     expected: '200'
koha_1       |
koha_1       |     #   Failed test 'exact match for JSON Pointer ""'
koha_1       |     #   at t/db_dependent/api/v1/erm_agreements.t line 95.
koha_1       |     #     Structures begin differing at:
koha_1       |     #          $got = HASH(0x55cde781a480)
koha_1       |     #     $expected = ARRAY(0x55cde75af9c8)
koha_1       |     # Looks like you failed 2 tests of 32.

400 because we were calling
http://localhost:8081/api/v1/erm/agreements?vendor_id='
which returns {"errors":[{"message":"Expected integer - got string.","path":"\/vendor_id"}],"status":400}%

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-02-23 09:39:42 +01:00 committed by Tomas Cohen Arazi
parent c500fd3c61
commit e7d40b7a99
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -65,8 +65,13 @@ subtest 'list() tests' => sub {
$t->get_ok("//$userid:$password@/api/v1/erm/agreements")->status_is(200)
->json_is( [] );
my $agreement =
$builder->build_object( { class => 'Koha::ERM::Agreements' } );
my $vendor_1 = $builder->build_object({ class => 'Koha::Acquisition::Booksellers' });
my $agreement = $builder->build_object(
{
class => 'Koha::ERM::Agreements',
value => { vendor_id => $vendor_1->id },
}
);
# One agreement created, should get returned
$t->get_ok("//$userid:$password@/api/v1/erm/agreements")->status_is(200)
@ -75,11 +80,17 @@ subtest 'list() tests' => sub {
my $another_agreement = $builder->build_object(
{
class => 'Koha::ERM::Agreements',
value => { vendor_id => $agreement->vendor_id }
value => { vendor_id => $vendor_1->id }
}
);
my $vendor_2 = $builder->build_object({ class => 'Koha::Acquisition::Booksellers' });
my $agreement_with_another_vendor_id = $builder->build_object(
{
class => 'Koha::ERM::Agreements',
value => { vendor_id => $vendor_2->id },
}
);
my $agreement_with_another_vendor_id =
$builder->build_object( { class => 'Koha::ERM::Agreements' } );
# Two agreements created, they should both be returned
$t->get_ok("//$userid:$password@/api/v1/erm/agreements")->status_is(200)
@ -93,7 +104,7 @@ subtest 'list() tests' => sub {
# Filtering works, two agreements sharing vendor_id
$t->get_ok( "//$userid:$password@/api/v1/erm/agreements?vendor_id="
. $agreement->vendor_id )->status_is(200)
. $vendor_1->id )->status_is(200)
->json_is( [ $agreement->to_api, $another_agreement->to_api ] );
# Attempt to search by name like 'ko'