+subtest 'suspend and resume tests' => sub {
+
+ plan tests => 21;
+
+ $schema->storage->txn_begin;
+
+ my $password = 'AbcdEFG123';
+
+ my $patron = $builder->build_object(
+ { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 1 } } );
+ $patron->set_password({ password => $password, skip_validation => 1 });
+ my $userid = $patron->userid;
+
+ # Disable logging
+ t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
+ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
+
+ my $hold = $builder->build_object(
+ { class => 'Koha::Holds',
+ value => { suspend => 0, suspend_until => undef, waitingdate => undef }
+ }
+ );
+
+ ok( !$hold->is_suspended, 'Hold is not suspended' );
+ $t->post_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
+ ->status_is( 201, 'Hold suspension created' );
+
+ $hold->discard_changes; # refresh object
+
+ ok( $hold->is_suspended, 'Hold is suspended' );
+ $t->json_is(
+ '/end_date',
+ output_pref(
+ { dt => dt_from_string( $hold->suspend_until ),
+ dateformat => 'rfc3339',
+ dateonly => 1
+ }
+ )
+ );
+
+ $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
+ ->status_is( 204, "Correct status when deleting a resource" )
+ ->json_is( undef );
+
+ # Pass a an expiration date for the suspension
+ my $date = dt_from_string()->add( days => 5 );
+ $t->post_ok(
+ "//$userid:$password@/api/v1/holds/"
+ . $hold->id
+ . "/suspension" => json => {
+ end_date =>
+ output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } )
+ }
+ )->status_is( 201, 'Hold suspension created' )
+ ->json_is( '/end_date',
+ output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } ) )
+ ->header_is( Location => "/api/v1/holds/" . $hold->id . "/suspension", 'The Location header is set' );
+
+ $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
+ ->status_is( 204, "Correct status when deleting a resource" )
+ ->json_is( undef );
+
+ $hold->set_waiting->discard_changes;
+
+ $t->post_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
+ ->status_is( 400, 'Cannot suspend waiting hold' )
+ ->json_is( '/error', 'Found hold cannot be suspended. Status=W' );
+
+ $hold->set_waiting(1)->discard_changes;
+
+ $t->post_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
+ ->status_is( 400, 'Cannot suspend waiting hold' )
+ ->json_is( '/error', 'Found hold cannot be suspended. Status=T' );
+
+ $schema->storage->txn_rollback;
+};
+