|
Lines 37-43
my $t = Test::Mojo->new('Koha::REST::V1');
Link Here
|
| 37 |
|
37 |
|
| 38 |
subtest 'list() and delete() tests | authorized user' => sub { |
38 |
subtest 'list() and delete() tests | authorized user' => sub { |
| 39 |
|
39 |
|
| 40 |
plan tests => 44; |
40 |
plan tests => 39; |
| 41 |
|
41 |
|
| 42 |
$schema->storage->txn_begin; |
42 |
$schema->storage->txn_begin; |
| 43 |
|
43 |
|
|
Lines 92-114
subtest 'list() and delete() tests | authorized user' => sub {
Link Here
|
| 92 |
->json_is( '/0/aliases/0/alias' => 'alias 1', 'alias 1 is embedded' ) |
92 |
->json_is( '/0/aliases/0/alias' => 'alias 1', 'alias 1 is embedded' ) |
| 93 |
->json_is( '/0/aliases/1/alias' => 'alias 2', 'alias 2 is embedded' ); |
93 |
->json_is( '/0/aliases/1/alias' => 'alias 2', 'alias 2 is embedded' ); |
| 94 |
|
94 |
|
|
|
95 |
my @cleanup; |
| 95 |
for ( 0 .. 1 ) { |
96 |
for ( 0 .. 1 ) { |
| 96 |
$builder->build_object( { class => 'Koha::Subscriptions', value => { aqbooksellerid => $vendor->id } } ); |
97 |
push @cleanup, |
|
|
98 |
$builder->build_object( { class => 'Koha::Subscriptions', value => { aqbooksellerid => $vendor->id } } ); |
| 99 |
push @cleanup, |
| 100 |
$builder->build_object( |
| 101 |
{ class => 'Koha::Acquisition::Baskets', value => { booksellerid => $vendor->id } } ); |
| 102 |
push @cleanup, |
| 103 |
$builder->build_object( |
| 104 |
{ class => 'Koha::Acquisition::Invoices', value => { booksellerid => $vendor->id } } ); |
| 97 |
} |
105 |
} |
| 98 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" => { 'x-koha-embed' => 'subscriptions+count' } ) |
106 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" => |
| 99 |
->status_is(200)->json_has( '/0/subscriptions_count', 'subscriptions_count is embedded' ) |
107 |
{ 'x-koha-embed' => 'subscriptions+count,baskets+count,invoices+count' } )->status_is(200) |
| 100 |
->json_is( '/0/subscriptions_count' => '2', 'subscription count is 2' ); |
108 |
->json_is( '/0/subscriptions_count', 2, 'subscriptions_count is 2' ) |
|
|
109 |
->json_is( '/0/baskets_count', 2, 'baskets_count is 2' ) |
| 110 |
->json_is( '/0/invoices_count', 2, 'invoices_count is 2' ); |
| 111 |
|
| 112 |
# FIXME We need to add more tests/code here |
| 113 |
# A vendor deletion should be rejected if it has baskets or subscriptions (or invoices?) linked to it |
| 114 |
$_->delete for @cleanup; |
| 101 |
|
115 |
|
| 102 |
$t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is( 204, 'REST3.2.4' ) |
116 |
$t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is( 204, 'REST3.2.4' ) |
| 103 |
->content_is( '', 'REST3.3.4' ); |
117 |
->content_is( '', 'REST3.3.4' ); |
| 104 |
|
118 |
|
| 105 |
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")->status_is(200) |
119 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $other_vendor->id )->status_is(200); |
| 106 |
->json_like( '/0/name' => qr/$other_vendor_name/ )->json_hasnt( '/1', 'Only one vendor' ); |
120 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is(404); |
| 107 |
|
|
|
| 108 |
$t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $other_vendor->id ) |
| 109 |
->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' ); |
| 110 |
|
| 111 |
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")->status_is(200)->json_is( [] ); |
| 112 |
|
121 |
|
| 113 |
$schema->storage->txn_rollback; |
122 |
$schema->storage->txn_rollback; |
| 114 |
}; |
123 |
}; |
| 115 |
- |
|
|