Lines 31-36
my $builder = t::lib::TestBuilder->new;
Link Here
|
31 |
|
31 |
|
32 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
32 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
33 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
33 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
|
|
34 |
t::lib::Mocks::mock_preference( 'NotifyPasswordChange', 0 ); |
34 |
|
35 |
|
35 |
subtest 'list_updates() tests' => sub { |
36 |
subtest 'list_updates() tests' => sub { |
36 |
|
37 |
|
Lines 117-123
subtest 'list_updates() tests' => sub {
Link Here
|
117 |
|
118 |
|
118 |
subtest 'add_update() tests' => sub { |
119 |
subtest 'add_update() tests' => sub { |
119 |
|
120 |
|
120 |
plan tests => 17; |
121 |
plan tests => 34; |
121 |
|
122 |
|
122 |
$schema->storage->txn_begin; |
123 |
$schema->storage->txn_begin; |
123 |
|
124 |
|
Lines 141-147
subtest 'add_update() tests' => sub {
Link Here
|
141 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
142 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
142 |
my $unauth_userid = $patron->userid; |
143 |
my $unauth_userid = $patron->userid; |
143 |
|
144 |
|
144 |
my $ticket = $builder->build_object( { class => 'Koha::Tickets' } ); |
145 |
my $ticket = $builder->build_object( |
|
|
146 |
{ |
147 |
class => 'Koha::Tickets', |
148 |
value => { reporter_id => $patron->id } |
149 |
} |
150 |
); |
145 |
my $ticket_id = $ticket->id; |
151 |
my $ticket_id = $ticket->id; |
146 |
|
152 |
|
147 |
my $update = { |
153 |
my $update = { |
Lines 165-170
subtest 'add_update() tests' => sub {
Link Here
|
165 |
->json_is( '/public' => $update->{public} ) |
171 |
->json_is( '/public' => $update->{public} ) |
166 |
->json_is( '/user_id' => $librarian->id )->tx->res->json->{update_id}; |
172 |
->json_is( '/user_id' => $librarian->id )->tx->res->json->{update_id}; |
167 |
|
173 |
|
|
|
174 |
# Check that notice trigger didn't fire for non-public update |
175 |
my $notices = |
176 |
Koha::Notice::Messages->search( { borrowernumber => $patron->id } ); |
177 |
is( $notices->count, 0, |
178 |
'No notices queued when the update is marked as not public' ); |
179 |
|
168 |
# Authorized attempt to create with null id |
180 |
# Authorized attempt to create with null id |
169 |
$update->{update_id} = undef; |
181 |
$update->{update_id} = undef; |
170 |
$t->post_ok( |
182 |
$t->post_ok( |
Lines 183-188
subtest 'add_update() tests' => sub {
Link Here
|
183 |
} |
195 |
} |
184 |
] |
196 |
] |
185 |
); |
197 |
); |
|
|
198 |
delete $update->{update_id}; |
186 |
|
199 |
|
187 |
# Authorized attempt to write missing data |
200 |
# Authorized attempt to write missing data |
188 |
my $update_with_missing_field = { message => "Another ticket update" }; |
201 |
my $update_with_missing_field = { message => "Another ticket update" }; |
Lines 198-202
subtest 'add_update() tests' => sub {
Link Here
|
198 |
] |
211 |
] |
199 |
); |
212 |
); |
200 |
|
213 |
|
|
|
214 |
# Check that notice trigger fired for public update |
215 |
$update->{public} = Mojo::JSON->true; |
216 |
$update_id = |
217 |
$t->post_ok( |
218 |
"//$userid:$password@/api/v1/tickets/$ticket_id/updates" => json => |
219 |
$update )->status_is( 201, 'SWAGGER3.2.1' )->header_like( |
220 |
Location => qr|^\/api\/v1\/tickets/\d*|, |
221 |
'SWAGGER3.4.1' |
222 |
)->json_is( '/message' => $update->{message} ) |
223 |
->json_is( '/public' => $update->{public} ) |
224 |
->json_is( '/user_id' => $librarian->id )->tx->res->json->{update_id}; |
225 |
|
226 |
$notices = |
227 |
Koha::Notice::Messages->search( { borrowernumber => $patron->id } ); |
228 |
is( $notices->count, 1, |
229 |
'One notice queued when the update is marked as public' ); |
230 |
my $THE_notice = $notices->next; |
231 |
is( $THE_notice->letter_code, 'TICKET_UPDATE', |
232 |
'Notice queued was a TICKET_UPDATE for non-status changing update' |
233 |
); |
234 |
$THE_notice->delete; |
235 |
|
236 |
$update->{state} = 'resolved'; |
237 |
$update_id = |
238 |
$t->post_ok( |
239 |
"//$userid:$password@/api/v1/tickets/$ticket_id/updates" => json => |
240 |
$update )->status_is( 201, 'SWAGGER3.2.1' )->header_like( |
241 |
Location => qr|^\/api\/v1\/tickets/\d*|, |
242 |
'SWAGGER3.4.1' |
243 |
)->json_is( '/message' => $update->{message} ) |
244 |
->json_is( '/public' => $update->{public} ) |
245 |
->json_is( '/user_id' => $librarian->id )->tx->res->json->{update_id}; |
246 |
|
247 |
$notices = |
248 |
Koha::Notice::Messages->search( { borrowernumber => $patron->id } ); |
249 |
is( $notices->count, 1, |
250 |
'One notice queued when the update is marked as public' ); |
251 |
$THE_notice = $notices->next; |
252 |
is( $THE_notice->letter_code, 'TICKET_RESOLVE', |
253 |
'Notice queued was a TICKET_RESOLVED for status changing update' |
254 |
); |
255 |
|
201 |
$schema->storage->txn_rollback; |
256 |
$schema->storage->txn_rollback; |
202 |
}; |
257 |
}; |
203 |
- |
|
|