Browse Source

Bug 31028: Unit tests for ticket create notice triggers

This patch adds unit tests for the two notices that can be triggered
upon ticket creation.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
23.05.x
Martin Renvoize 1 year ago
committed by Tomas Cohen Arazi
parent
commit
8f185bd330
  1. 84
      t/db_dependent/Koha/Ticket.t

84
t/db_dependent/Koha/Ticket.t

@ -19,8 +19,9 @@
use Modern::Perl;
use Test::More tests => 5;
use Test::More tests => 6;
use t::lib::TestBuilder;
use t::lib::Mocks;
use Koha::Database;
@ -145,3 +146,84 @@ subtest 'add_update() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'store() tests' => sub {
plan tests => 2;
subtest 'acknowledgement notice trigger' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $patron = $builder->build_object( { class => "Koha::Patrons" } );
my $biblio = $builder->build_sample_biblio();
my $new_ticket = Koha::Ticket->new(
{
reporter_id => $patron->id,
title => "Testing ticket",
body => "Testing ticket message",
biblio_id => $biblio->id
}
)->store();
is( ref($new_ticket), 'Koha::Ticket',
'Koha::Ticket->store() returned the Koha::Ticket object' );
my $notices =
Koha::Notice::Messages->search( { borrowernumber => $patron->id } );
is( $notices->count, 1,
'One acknowledgement notice queued for the ticket reporter' );
my $THE_notice = $notices->next;
isnt( $THE_notice->status, 'pending',
'Acknowledgement notice is sent immediately' );
$new_ticket->set( { title => "Changed title" } )->store();
$notices =
Koha::Notice::Messages->search( { borrowernumber => $patron->id } );
is( $notices->count, 1,
'Further acknowledgement notices are not queud on subsequent stores'
);
$schema->storage->txn_rollback;
};
subtest 'cataloger notice trigger' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $catemail = 'catalogers@testmail.com';
t::lib::Mocks::mock_preference( 'CatalogerEmails', $catemail );
my $patron = $builder->build_object( { class => "Koha::Patrons" } );
my $biblio = $builder->build_sample_biblio();
my $new_ticket = Koha::Ticket->new(
{
reporter_id => $patron->id,
title => "Testing ticket",
body => "Testing ticket message",
biblio_id => $biblio->id
}
)->store();
is( ref($new_ticket), 'Koha::Ticket',
'Koha::Ticket->store() returned the Koha::Ticket object' );
my $notices =
Koha::Notice::Messages->search( { to_address => $catemail } );
is( $notices->count, 1,
'One notification notice queued for the catalogers when ticket reported' );
my $THE_notice = $notices->next;
isnt( $THE_notice->status, 'pending',
'Notification notice is sent immediately' );
$new_ticket->set( { title => "Changed title" } )->store();
$notices =
Koha::Notice::Messages->search( { to_address => $catemail } );
is( $notices->count, 1,
'Further notification notices are not queud on subsequent stores'
);
$schema->storage->txn_rollback;
};
};

Loading…
Cancel
Save