View | Details | Raw Unified | Return to bug 36066
Collapse All | Expand All

(-)a/Koha/REST/V1/Acquisitions/Orders.pm (-1 / +9 lines)
Lines 183-189 sub update { Link Here
183
183
184
=head3 delete
184
=head3 delete
185
185
186
Controller function that handles deleting a Koha::Patron object
186
Controller function that handles deleting a Koha::Acquisition::Order object
187
188
Note that we only allow deletion when the status is cancelled.
187
189
188
=cut
190
=cut
189
191
Lines 197-202 sub delete { Link Here
197
            status  => 404,
199
            status  => 404,
198
            openapi => { error => 'Order not found' }
200
            openapi => { error => 'Order not found' }
199
        );
201
        );
202
    } elsif ( ( $order->orderstatus && $order->orderstatus ne 'cancelled' ) || !$order->datecancellationprinted ) {
203
        # Koha may (historically) have inconsistent order data here (e.g. cancelled without date)
204
        return $c->render(
205
            status  => 403,
206
            openapi => { error => 'Order status must be cancelled' }
207
        );
200
    }
208
    }
201
209
202
    return try {
210
    return try {
(-)a/t/db_dependent/api/v1/acquisitions_orders.t (-4 / +8 lines)
Lines 72-80 subtest 'list() tests' => sub { Link Here
72
    $another_order = $builder->build_object({ class => 'Koha::Acquisition::Orders', value => $another_order });
72
    $another_order = $builder->build_object({ class => 'Koha::Acquisition::Orders', value => $another_order });
73
73
74
    ## Authorized user tests
74
    ## Authorized user tests
75
    my $count_of_orders = Koha::Acquisition::Orders->search->count;
75
    my $count_of_orders = Koha::Acquisition::Orders->search( { orderstatus => 'new' } )->count;
76
    # Make sure we are returned with the correct amount of orders
76
    # Make sure we are returned with the correct amount of orders
77
    $t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?_per_page=-1" )
77
    $t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?status=new&_per_page=-1" )
78
      ->status_is( 200, 'SWAGGER3.2.2' )
78
      ->status_is( 200, 'SWAGGER3.2.2' )
79
      ->json_has('/'.($count_of_orders-1).'/order_id')
79
      ->json_has('/'.($count_of_orders-1).'/order_id')
80
      ->json_hasnt('/'.($count_of_orders).'/order_id');
80
      ->json_hasnt('/'.($count_of_orders).'/order_id');
Lines 449-455 subtest 'update() tests' => sub { Link Here
449
};
449
};
450
450
451
subtest 'delete() tests' => sub {
451
subtest 'delete() tests' => sub {
452
    plan tests => 7;
452
    plan tests => 9;
453
453
454
    $schema->storage->txn_begin;
454
    $schema->storage->txn_begin;
455
455
Lines 474-479 subtest 'delete() tests' => sub { Link Here
474
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )
474
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )
475
      ->status_is(403);
475
      ->status_is(403);
476
476
477
    # Check if status is cancelled?
478
    $order->orderstatus('new')->store;
479
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )->status_is(403);
480
481
    $order->orderstatus('cancelled')->store;
477
    $t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )
482
    $t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )
478
      ->status_is(204, 'SWAGGER3.2.4')
483
      ->status_is(204, 'SWAGGER3.2.4')
479
      ->content_is('', 'SWAGGER3.3.4');
484
      ->content_is('', 'SWAGGER3.3.4');
480
- 

Return to bug 36066