|
Lines 19-24
use Modern::Perl;
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 1; |
20 |
use Test::More tests => 1; |
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
|
|
22 |
use Test::MockObject; |
| 22 |
use Test::Mojo; |
23 |
use Test::Mojo; |
| 23 |
use Test::Warn; |
24 |
use Test::Warn; |
| 24 |
|
25 |
|
|
Lines 40-50
subtest 'list() tests' => sub {
Link Here
|
| 40 |
|
41 |
|
| 41 |
plan tests => 18; |
42 |
plan tests => 18; |
| 42 |
|
43 |
|
|
|
44 |
# Mock ILLBackend (as object) |
| 45 |
my $backend = Test::MockObject->new; |
| 46 |
$backend->set_isa('Koha::Illbackends::Mock'); |
| 47 |
$backend->set_always('name', 'Mock'); |
| 48 |
$backend->set_always('capabilities', sub { return 'bar'; } ); |
| 49 |
$backend->mock( |
| 50 |
'metadata', |
| 51 |
sub { |
| 52 |
my ( $self, $rq ) = @_; |
| 53 |
return { |
| 54 |
ID => $rq->illrequest_id, |
| 55 |
Title => $rq->patron->borrowernumber |
| 56 |
} |
| 57 |
} |
| 58 |
); |
| 59 |
|
| 60 |
# Mock Koha::Illrequest::load_backend (to load Mocked Backend) |
| 43 |
my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); |
61 |
my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); |
| 44 |
# Mock ->capabilities |
62 |
$illreqmodule->mock( 'load_backend', |
| 45 |
$illreqmodule->mock( 'capabilities', sub { return 'capable'; } ); |
63 |
sub { my $self = shift; $self->{_my_backend} = $backend; return $self } |
| 46 |
# Mock ->metadata |
64 |
); |
| 47 |
$illreqmodule->mock( 'metadata', sub { return 'metawhat?'; } ); |
|
|
| 48 |
|
65 |
|
| 49 |
$schema->storage->txn_begin; |
66 |
$schema->storage->txn_begin; |
| 50 |
|
67 |
|
|
Lines 67-78
subtest 'list() tests' => sub {
Link Here
|
| 67 |
{ |
84 |
{ |
| 68 |
class => 'Koha::Illrequests', |
85 |
class => 'Koha::Illrequests', |
| 69 |
value => { |
86 |
value => { |
| 70 |
backend => 'FreeForm', |
87 |
backend => 'Mock', |
| 71 |
branchcode => $library->branchcode, |
88 |
branchcode => $library->branchcode, |
| 72 |
borrowernumber => $patron->borrowernumber |
89 |
borrowernumber => $patron->borrowernumber |
| 73 |
} |
90 |
} |
| 74 |
} |
91 |
} |
| 75 |
); |
92 |
); |
|
|
93 |
$illrequest->_backend($backend); |
| 76 |
|
94 |
|
| 77 |
# One illrequest created, should get returned |
95 |
# One illrequest created, should get returned |
| 78 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
96 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
|
Lines 86-106
subtest 'list() tests' => sub {
Link Here
|
| 86 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
104 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
| 87 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
105 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
| 88 |
$t->request_ok($tx)->status_is(200) |
106 |
$t->request_ok($tx)->status_is(200) |
| 89 |
->json_has( '/0/patron', $patron->unblessed ) |
107 |
->json_has( '/0/patron', 'patron embedded' ) |
| 90 |
->json_has( '/0/capabilities', 'capable' ) |
108 |
->json_has( '/0/capabilities', 'capabilities embedded' ) |
| 91 |
->json_has( '/0/library', $library->unblessed ) |
109 |
->json_has( '/0/library', 'library embedded' ) |
| 92 |
->json_has( '/0/metadata', 'metawhat?' ); |
110 |
->json_has( '/0/metadata', 'metadata embedded' ); |
| 93 |
|
111 |
|
| 94 |
# Create another ILL request |
112 |
# Create another ILL request |
| 95 |
my $illrequest2 = $builder->build_object( |
113 |
my $illrequest2 = $builder->build_object( |
| 96 |
{ |
114 |
{ |
| 97 |
class => 'Koha::Illrequests', |
115 |
class => 'Koha::Illrequests', |
| 98 |
value => { |
116 |
value => { |
|
|
117 |
backend => 'Mock', |
| 99 |
branchcode => $library->branchcode, |
118 |
branchcode => $library->branchcode, |
| 100 |
borrowernumber => $patron->borrowernumber |
119 |
borrowernumber => $patron->borrowernumber |
| 101 |
} |
120 |
} |
| 102 |
} |
121 |
} |
| 103 |
); |
122 |
); |
|
|
123 |
$illrequest2->_backend($backend); |
| 104 |
|
124 |
|
| 105 |
# Two illrequest created, should get returned |
125 |
# Two illrequest created, should get returned |
| 106 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
126 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
| 107 |
- |
|
|