Bug 29668: Move tests

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2025-11-05 13:47:59 -03:00 committed by Lucas Gass
parent 5e0a72f8a8
commit ca8134f85d
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 51 additions and 64 deletions

View File

@ -18,7 +18,7 @@
use Modern::Perl;
use Test::NoWarnings;
use Test::More tests => 3;
use Test::More tests => 4;
use Test::Mojo;
use t::lib::TestBuilder;
@ -97,3 +97,53 @@ subtest 'list() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'add() tests' => sub {
plan tests => 14;
$schema->storage->txn_begin;
my $vendor = $builder->build_object(
{
class => 'Koha::Acquisition::Booksellers',
}
);
my $patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => { flags => 0 }
}
);
my $password = 'thePassword123';
$patron->set_password( { password => $password, skip_validation => 1 } );
my $userid = $patron->userid;
my $url = "//$userid:$password@/api/v1/acquisitions/baskets";
$t->post_ok( $url, json => {} )->status_is(403);
$schema->resultset('UserPermission')->create(
{
borrowernumber => $patron->borrowernumber,
module_bit => 11,
code => 'order_manage',
}
);
$t->post_ok( $url, json => {} )->status_is(400);
$t->post_ok( $url, json => { vendor_id => $vendor->id } )->status_is(201)->json_has('/basket_id')
->json_is( '/vendor_id', $vendor->id );
my $basket = {
vendor_id => $vendor->id,
name => 'Basket #1',
vendor_note => 'Vendor note',
};
$t->post_ok( $url, json => $basket )->status_is(201)->json_has('/basket_id')
->json_is( '/vendor_id', $basket->{vendor_id} )->json_is( '/name', $basket->{name} )
->json_is( '/vendor_note', $basket->{vendor_note} );
$schema->storage->txn_rollback;
};

View File

@ -1,63 +0,0 @@
#!/usr/bin/env perl
use Modern::Perl;
use Test::More tests => 14;
use Test::Mojo;
use t::lib::Mocks;
use t::lib::TestBuilder;
use Koha::Database;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
my $t = Test::Mojo->new('Koha::REST::V1');
$schema->storage->txn_begin;
my $bookseller = $builder->build_object(
{
class => 'Koha::Acquisition::Booksellers',
}
);
my $patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => { flags => 0 }
}
);
my $password = 'thePassword123';
$patron->set_password( { password => $password, skip_validation => 1 } );
my $userid = $patron->userid;
my $url = "//$userid:$password@/api/v1/acquisitions/baskets";
$t->post_ok( $url, json => {} )->status_is(403);
$schema->resultset('UserPermission')->create(
{
borrowernumber => $patron->borrowernumber,
module_bit => 11,
code => 'order_manage',
}
);
$t->post_ok( $url, json => {} )->status_is(400);
$t->post_ok( $url, json => { vendor_id => $bookseller->id } )->status_is(201)->json_has('/basket_id')
->json_is( '/vendor_id', $bookseller->id );
my $basket = {
vendor_id => $bookseller->id,
name => 'Basket #1',
vendor_note => 'Vendor note',
};
$t->post_ok( $url, json => $basket )->status_is(201)->json_has('/basket_id')
->json_is( '/vendor_id', $basket->{vendor_id} )->json_is( '/name', $basket->{name} )
->json_is( '/vendor_note', $basket->{vendor_note} );
$schema->storage->txn_rollback;