|
Lines 28-33
use t::lib::Mocks;
Link Here
|
| 28 |
|
28 |
|
| 29 |
use C4::Auth; |
29 |
use C4::Auth; |
| 30 |
use Koha::Illrequests; |
30 |
use Koha::Illrequests; |
|
|
31 |
use Koha::DateUtils qw( format_sqldatetime ); |
| 31 |
|
32 |
|
| 32 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
| 33 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $builder = t::lib::TestBuilder->new; |
|
Lines 98-108
subtest 'list() tests' => sub {
Link Here
|
| 98 |
my $response = $illrequest->unblessed; |
99 |
my $response = $illrequest->unblessed; |
| 99 |
$response->{id_prefix} = $illrequest->id_prefix; |
100 |
$response->{id_prefix} = $illrequest->id_prefix; |
| 100 |
|
101 |
|
|
|
102 |
my $req_formatted = add_formatted($illrequest); |
| 103 |
|
| 101 |
# One illrequest created, should get returned |
104 |
# One illrequest created, should get returned |
| 102 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
105 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
| 103 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
106 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
| 104 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
107 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
| 105 |
$t->request_ok($tx)->status_is(200)->json_is( [$response] ); |
108 |
$t->request_ok($tx)->status_is(200)->json_is( [ $req_formatted ] ); |
| 106 |
|
109 |
|
| 107 |
# One illrequest created, returned with augmented data |
110 |
# One illrequest created, returned with augmented data |
| 108 |
$tx = $t->ua->build_tx( GET => |
111 |
$tx = $t->ua->build_tx( GET => |
|
Lines 131-142
subtest 'list() tests' => sub {
Link Here
|
| 131 |
my $response2 = $illrequest2->unblessed; |
134 |
my $response2 = $illrequest2->unblessed; |
| 132 |
$response2->{id_prefix} = $illrequest2->id_prefix; |
135 |
$response2->{id_prefix} = $illrequest2->id_prefix; |
| 133 |
|
136 |
|
|
|
137 |
my $req2_formatted = add_formatted($illrequest2); |
| 138 |
|
| 134 |
# Two illrequest created, should get returned |
139 |
# Two illrequest created, should get returned |
| 135 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
140 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
| 136 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
141 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
| 137 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
142 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
| 138 |
$t->request_ok($tx)->status_is(200) |
143 |
$t->request_ok($tx)->status_is(200) |
| 139 |
->json_is( [ $response, $response2 ] ); |
144 |
->json_is( [ $req_formatted, $req2_formatted ] ); |
| 140 |
|
145 |
|
| 141 |
# Warn on unsupported query parameter |
146 |
# Warn on unsupported query parameter |
| 142 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests?request_blah=blah' ); |
147 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests?request_blah=blah' ); |
|
Lines 149-154
subtest 'list() tests' => sub {
Link Here
|
| 149 |
$schema->storage->txn_rollback; |
154 |
$schema->storage->txn_rollback; |
| 150 |
}; |
155 |
}; |
| 151 |
|
156 |
|
|
|
157 |
sub add_formatted { |
| 158 |
my $req = shift; |
| 159 |
my @format_dates = ( 'placed', 'updated' ); |
| 160 |
# We need to embellish the request with properties that the API |
| 161 |
# controller calculates on the fly |
| 162 |
my $req_unblessed = $req->unblessed; |
| 163 |
# Create new "formatted" columns for each date column |
| 164 |
# that needs formatting |
| 165 |
foreach my $field(@format_dates) { |
| 166 |
if (defined $req_unblessed->{$field}) { |
| 167 |
$req_unblessed->{$field . "_formatted"} = format_sqldatetime( |
| 168 |
$req_unblessed->{$field}, |
| 169 |
undef, |
| 170 |
undef, |
| 171 |
1 |
| 172 |
); |
| 173 |
} |
| 174 |
} |
| 175 |
return $req_unblessed; |
| 176 |
} |
| 177 |
|
| 152 |
sub create_user_and_session { |
178 |
sub create_user_and_session { |
| 153 |
|
179 |
|
| 154 |
my $args = shift; |
180 |
my $args = shift; |
| 155 |
- |
|
|