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 94-104
subtest 'list() tests' => sub {
Link Here
|
94 |
} |
95 |
} |
95 |
); |
96 |
); |
96 |
|
97 |
|
|
|
98 |
my $req_formatted = add_formatted($illrequest); |
99 |
|
97 |
# One illrequest created, should get returned |
100 |
# One illrequest created, should get returned |
98 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
101 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
99 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
102 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
100 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
103 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
101 |
$t->request_ok($tx)->status_is(200)->json_is( [ $illrequest->unblessed ] ); |
104 |
$t->request_ok($tx)->status_is(200)->json_is( [ $req_formatted ] ); |
102 |
|
105 |
|
103 |
# One illrequest created, returned with augmented data |
106 |
# One illrequest created, returned with augmented data |
104 |
$tx = $t->ua->build_tx( GET => |
107 |
$tx = $t->ua->build_tx( GET => |
Lines 123-134
subtest 'list() tests' => sub {
Link Here
|
123 |
} |
126 |
} |
124 |
); |
127 |
); |
125 |
|
128 |
|
|
|
129 |
my $req2_formatted = add_formatted($illrequest2); |
130 |
|
126 |
# Two illrequest created, should get returned |
131 |
# Two illrequest created, should get returned |
127 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
132 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); |
128 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
133 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
129 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
134 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
130 |
$t->request_ok($tx)->status_is(200) |
135 |
$t->request_ok($tx)->status_is(200) |
131 |
->json_is( [ $illrequest->unblessed, $illrequest2->unblessed ] ); |
136 |
->json_is( [ $req_formatted, $req2_formatted ] ); |
132 |
|
137 |
|
133 |
# Warn on unsupported query parameter |
138 |
# Warn on unsupported query parameter |
134 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests?request_blah=blah' ); |
139 |
$tx = $t->ua->build_tx( GET => '/api/v1/illrequests?request_blah=blah' ); |
Lines 141-146
subtest 'list() tests' => sub {
Link Here
|
141 |
$schema->storage->txn_rollback; |
146 |
$schema->storage->txn_rollback; |
142 |
}; |
147 |
}; |
143 |
|
148 |
|
|
|
149 |
sub add_formatted { |
150 |
my $req = shift; |
151 |
my @format_dates = ( 'placed', 'updated' ); |
152 |
# We need to embellish the request with properties that the API |
153 |
# controller calculates on the fly |
154 |
my $req_unblessed = $req->unblessed; |
155 |
# Create new "formatted" columns for each date column |
156 |
# that needs formatting |
157 |
foreach my $field(@format_dates) { |
158 |
if (defined $req_unblessed->{$field}) { |
159 |
$req_unblessed->{$field . "_formatted"} = format_sqldatetime( |
160 |
$req_unblessed->{$field}, |
161 |
undef, |
162 |
undef, |
163 |
1 |
164 |
); |
165 |
} |
166 |
} |
167 |
return $req_unblessed; |
168 |
} |
169 |
|
144 |
sub create_user_and_session { |
170 |
sub create_user_and_session { |
145 |
|
171 |
|
146 |
my $args = shift; |
172 |
my $args = shift; |
147 |
- |
|
|