From b35427fdfdbdd2e4c2e6ed6670b7788c63c4e23f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 26 Apr 2024 17:01:43 +0100 Subject: [PATCH] Bug 35657: Unit test for addition to tickets endpoint This patch adds a unit test for the additional option of now setting the assignee from the tickets update endpoint. --- t/db_dependent/api/v1/tickets.t | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/api/v1/tickets.t b/t/db_dependent/api/v1/tickets.t index dcb68df109c..05a2d6d2777 100755 --- a/t/db_dependent/api/v1/tickets.t +++ b/t/db_dependent/api/v1/tickets.t @@ -252,7 +252,7 @@ subtest 'add() tests' => sub { subtest 'update() tests' => sub { - plan tests => 15; + plan tests => 20; $schema->storage->txn_begin; @@ -276,7 +276,8 @@ subtest 'update() tests' => sub { $patron->set_password( { password => $password, skip_validation => 1 } ); my $unauth_userid = $patron->userid; - my $ticket_id = $builder->build_object( { class => 'Koha::Tickets' } )->id; + my $ticket = $builder->build_object( { class => 'Koha::Tickets' } ); + my $ticket_id = $ticket->id; # Unauthorized attempt to update $t->put_ok( @@ -305,6 +306,16 @@ subtest 'update() tests' => sub { $ticket_with_updated_field )->status_is(200) ->json_is( '/title' => 'Test ticket update' ); + # Set the assignee on PUT + $ticket_with_updated_field->{assignee_id} = $librarian->id; + $t->put_ok( "//$userid:$password@/api/v1/tickets/$ticket_id" => json => + $ticket_with_updated_field )->status_is(200) + ->json_is( '/title' => 'Test ticket update' ) + ->json_is( '/assignee_id' => $librarian->id ); + + my $updates = $ticket->updates; + is( $updates->count, 1, "Ticket update added for assignee change" ); + # Authorized attempt to write invalid data my $ticket_with_invalid_field = { blah => "Ticket Blah", -- 2.44.0