View | Details | Raw Unified | Return to bug 14697
Collapse All | Expand All

(-)a/Koha/REST/V1/ReturnClaims.pm (+257 lines)
Line 0 Link Here
1
package Koha::REST::V1::ReturnClaims;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Try::Tiny;
23
24
use Koha::Checkouts::ReturnClaims;
25
use Koha::Checkouts;
26
use Koha::DateUtils qw( dt_from_string output_pref );
27
28
=head1 NAME
29
30
Koha::REST::V1::ReturnClaims
31
32
=head2 Operations
33
34
=head3 claim_returned
35
36
Claim that a checked out item was returned.
37
38
=cut
39
40
sub claim_returned {
41
    my $c    = shift->openapi->valid_input or return;
42
    my $body = $c->validation->param('body');
43
44
    return try {
45
        my $itemnumber      = $body->{item_id};
46
        my $charge_lost_fee = $body->{charge_lost_fee} ? 1 : 0;
47
        my $created_by      = $body->{created_by};
48
        my $notes           = $body->{notes};
49
50
        my $user = $c->stash('koha.user');
51
        $created_by //= $user->borrowernumber;
52
53
        my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } );
54
55
        return $c->render(
56
            openapi => { error => "Not found - Checkout not found" },
57
            status  => 404
58
        ) unless $checkout;
59
60
        my $claim = Koha::Checkouts::ReturnClaims->find(
61
            {
62
                issue_id => $checkout->id
63
            }
64
        );
65
        return $c->render(
66
            openapi => { error => "Bad request - claim exists" },
67
            status  => 400
68
        ) if $claim;
69
70
        $claim = $checkout->claim_returned(
71
            {
72
                charge_lost_fee => $charge_lost_fee,
73
                created_by      => $created_by,
74
                notes           => $notes,
75
            }
76
        );
77
78
        $c->res->headers->location($c->req->url->to_string . '/' . $claim->id );
79
        return $c->render(
80
            status  => 201,
81
            openapi => $claim->to_api
82
        );
83
    }
84
    catch {
85
        if ( $_->isa('Koha::Exceptions::Checkouts::ReturnClaims') ) {
86
            return $c->render(
87
                status  => 500,
88
                openapi => { error => "$_" }
89
            );
90
        }
91
        else {
92
            return $c->render(
93
                status  => 500,
94
                openapi => { error => "Something went wrong, check the logs." }
95
            );
96
        }
97
    };
98
}
99
100
=head3 update_notes
101
102
Update the notes of an existing claim
103
104
=cut
105
106
sub update_notes {
107
    my $c     = shift->openapi->valid_input or return;
108
    my $input = $c->validation->output;
109
    my $body  = $c->validation->param('body');
110
111
    return try {
112
        my $id         = $input->{claim_id};
113
        my $updated_by = $body->{updated_by};
114
        my $notes      = $body->{notes};
115
116
        $updated_by ||=
117
          C4::Context->userenv ? C4::Context->userenv->{number} : undef;
118
119
        my $claim = Koha::Checkouts::ReturnClaims->find($id);
120
121
        return $c->render(
122
            openapi => { error => "Not found - Claim not found" },
123
            status  => 404
124
        ) unless $claim;
125
126
        $claim->set(
127
            {
128
                notes      => $notes,
129
                updated_by => $updated_by,
130
                updated_on => dt_from_string(),
131
            }
132
        );
133
        $claim->store();
134
135
        my $data = $claim->unblessed;
136
137
        my $c_dt = dt_from_string( $data->{created_on} );
138
        my $u_dt = dt_from_string( $data->{updated_on} );
139
140
        $data->{created_on_formatted} = output_pref( { dt => $c_dt } );
141
        $data->{updated_on_formatted} = output_pref( { dt => $u_dt } );
142
143
        $data->{created_on} = $c_dt->iso8601;
144
        $data->{updated_on} = $u_dt->iso8601;
145
146
        return $c->render( openapi => $data, status => 200 );
147
    }
148
    catch {
149
        if ( $_->isa('DBIx::Class::Exception') ) {
150
            return $c->render(
151
                status  => 500,
152
                openapi => { error => $_->{msg} }
153
            );
154
        }
155
        else {
156
            return $c->render(
157
                status  => 500,
158
                openapi => { error => "Something went wrong, check the logs." }
159
            );
160
        }
161
    };
162
}
163
164
=head3 resolve_claim
165
166
Marks a claim as resolved
167
168
=cut
169
170
sub resolve_claim {
171
    my $c     = shift->openapi->valid_input or return;
172
    my $input = $c->validation->output;
173
    my $body  = $c->validation->param('body');
174
175
    return try {
176
        my $id          = $input->{claim_id};
177
        my $resolved_by = $body->{updated_by};
178
        my $resolution  = $body->{resolution};
179
180
        $resolved_by ||=
181
          C4::Context->userenv ? C4::Context->userenv->{number} : undef;
182
183
        my $claim = Koha::Checkouts::ReturnClaims->find($id);
184
185
        return $c->render(
186
            openapi => { error => "Not found - Claim not found" },
187
            status  => 404
188
        ) unless $claim;
189
190
        $claim->set(
191
            {
192
                resolution  => $resolution,
193
                resolved_by => $resolved_by,
194
                resolved_on => dt_from_string(),
195
            }
196
        );
197
        $claim->store();
198
199
        return $c->render( openapi => $claim, status => 200 );
200
    }
201
    catch {
202
        if ( $_->isa('DBIx::Class::Exception') ) {
203
            return $c->render(
204
                status  => 500,
205
                openapi => { error => $_->{msg} }
206
            );
207
        }
208
        else {
209
            return $c->render(
210
                status  => 500,
211
                openapi => { error => "Something went wrong, check the logs." }
212
            );
213
        }
214
    };
215
}
216
217
=head3 delete_claim
218
219
Deletes the claim from the database
220
221
=cut
222
223
sub delete_claim {
224
    my $c     = shift->openapi->valid_input or return;
225
    my $input = $c->validation->output;
226
227
    return try {
228
        my $id = $input->{claim_id};
229
230
        my $claim = Koha::Checkouts::ReturnClaims->find($id);
231
232
        return $c->render(
233
            openapi => { error => "Not found - Claim not found" },
234
            status  => 404
235
        ) unless $claim;
236
237
        $claim->delete();
238
239
        return $c->render( openapi => $claim, status => 200 );
240
    }
241
    catch {
242
        if ( $_->isa('DBIx::Class::Exception') ) {
243
            return $c->render(
244
                status  => 500,
245
                openapi => { error => $_->{msg} }
246
            );
247
        }
248
        else {
249
            return $c->render(
250
                status  => 500,
251
                openapi => { error => "Something went wrong, check the logs." }
252
            );
253
        }
254
    };
255
}
256
257
1;
(-)a/api/v1/swagger/definitions.json (+3 lines)
Lines 43-47 Link Here
43
  },
43
  },
44
  "fund": {
44
  "fund": {
45
    "$ref": "definitions/fund.json"
45
    "$ref": "definitions/fund.json"
46
  },
47
  "return_claim": {
48
    "$ref": "definitions/return_claim.json"
46
  }
49
  }
47
}
50
}
(-)a/api/v1/swagger/definitions/return_claim.json (+93 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "claim_id": {
5
      "type": [
6
        "integer"
7
      ],
8
      "description": "internally assigned return claim identifier"
9
    },
10
    "item_id": {
11
      "type": [
12
        "integer"
13
      ],
14
      "description": "internal identifier of the claimed item"
15
    },
16
    "issue_id": {
17
      "type": [
18
        "integer",
19
        "null"
20
      ],
21
      "description": "internal identifier of the claimed checkout if still checked out"
22
    },
23
    "old_issue_id": {
24
      "type": [
25
        "integer",
26
        "null"
27
      ],
28
      "description": "internal identifier of the claimed checkout if not longer checked out"
29
    },
30
    "patron_id": {
31
      "$ref": "../x-primitives.json#/patron_id"
32
    },
33
    "notes": {
34
      "type": [
35
        "string",
36
        "null"
37
      ],
38
      "description": "notes about this claim"
39
    },
40
    "created_on": {
41
      "type": [
42
        "string",
43
        "null"
44
      ],
45
      "format": "date-time",
46
      "description": "date of claim creation"
47
    },
48
    "created_by": {
49
      "type": [
50
        "integer",
51
        "null"
52
      ],
53
      "description": "patron id of librarian who made the claim"
54
    },
55
    "updated_on": {
56
      "type": [
57
        "string",
58
        "null"
59
      ],
60
      "format": "date-time",
61
      "description": "date the claim was last updated"
62
    },
63
    "updated_by": {
64
      "type": [
65
        "integer",
66
        "null"
67
      ],
68
      "description": "patron id of librarian who last updated the claim"
69
    },
70
    "resolution": {
71
      "type": [
72
        "string",
73
        "null"
74
      ],
75
      "description": "code of resolution type for this claim"
76
    },
77
    "resolved_on": {
78
      "type": [
79
        "string",
80
        "null"
81
      ],
82
      "format": "date-time",
83
      "description": "date the claim was resolved"
84
    },
85
    "resolved_by": {
86
      "type": [
87
        "integer",
88
        "null"
89
      ],
90
      "description": "patron id of librarian who resolved this claim"
91
    }
92
  }
93
}
(-)a/api/v1/swagger/paths.json (+12 lines)
Lines 88-92 Link Here
88
  },
88
  },
89
  "/public/patrons/{patron_id}/guarantors/can_see_checkouts": {
89
  "/public/patrons/{patron_id}/guarantors/can_see_checkouts": {
90
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_checkouts"
90
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_checkouts"
91
  },
92
  "/return_claims": {
93
    "$ref": "paths/return_claims.json#/~1return_claims"
94
  },
95
  "/return_claims/{claim_id}/notes": {
96
    "$ref": "paths/return_claims.json#/~1return_claims~1{claim_id}~1notes"
97
  },
98
  "/return_claims/{claim_id}/resolve": {
99
    "$ref": "paths/return_claims.json#/~1return_claims~1{claim_id}~1resolve"
100
  },
101
  "/return_claims/{claim_id}": {
102
    "$ref": "paths/return_claims.json#/~1return_claims~1{claim_id}"
91
  }
103
  }
92
}
104
}
(-)a/api/v1/swagger/paths/return_claims.json (+355 lines)
Line 0 Link Here
1
{
2
  "/return_claims": {
3
    "post": {
4
      "x-mojo-to": "ReturnClaims#claim_returned",
5
      "operationId": "claimReturned",
6
      "tags": [
7
        "claims",
8
        "returned",
9
        "return",
10
        "claim"
11
      ],
12
      "parameters": [
13
        {
14
          "name": "body",
15
          "in": "body",
16
          "description": "A JSON object containing fields to modify",
17
          "required": true,
18
          "schema": {
19
            "type": "object",
20
            "properties": {
21
              "item_id" : {
22
                "description": "Internal item id to claim as returned",
23
                "type": "integer"
24
              },
25
              "notes": {
26
                "description": "Notes about this return claim",
27
                "type": "string"
28
              },
29
              "created_by": {
30
                "description": "User id for the librarian submitting this claim",
31
                "type": "string"
32
              },
33
              "charge_lost_fee": {
34
                "description": "Charge a lost fee if true and Koha is set to allow a choice. Ignored otherwise.",
35
                "type": "boolean"
36
              }
37
            }
38
          }
39
        }
40
      ],
41
      "produces": [
42
        "application/json"
43
      ],
44
      "responses": {
45
        "201": {
46
          "description": "Created claim",
47
          "schema": {
48
            "$ref": "../definitions.json#/return_claim"
49
          }
50
        },
51
        "400": {
52
          "description": "Bad request",
53
          "schema": {
54
            "$ref": "../definitions.json#/error"
55
          }
56
        },
57
        "401": {
58
          "description": "Authentication required",
59
          "schema": {
60
            "$ref": "../definitions.json#/error"
61
          }
62
        },
63
        "403": {
64
          "description": "Access forbidden",
65
          "schema": {
66
            "$ref": "../definitions.json#/error"
67
          }
68
        },
69
        "404": {
70
          "description": "Checkout not found",
71
          "schema": {
72
            "$ref": "../definitions.json#/error"
73
          }
74
        },
75
        "500": {
76
          "description": "Internal server error",
77
          "schema": {
78
            "$ref": "../definitions.json#/error"
79
          }
80
        },
81
        "503": {
82
          "description": "Under maintenance",
83
          "schema": {
84
            "$ref": "../definitions.json#/error"
85
          }
86
        }
87
      },
88
      "x-koha-authorization": {
89
        "permissions": {
90
          "circulate": "circulate_remaining_permissions"
91
        }
92
      }
93
    }
94
  },
95
  "/return_claims/{claim_id}/notes": {
96
    "put": {
97
      "x-mojo-to": "ReturnClaims#update_notes",
98
      "operationId": "updateClaimNotes",
99
      "tags": [
100
        "claims",
101
        "returned",
102
        "return",
103
        "claim",
104
        "notes"
105
      ],
106
      "parameters": [
107
        {
108
          "name": "claim_id",
109
          "in": "path",
110
          "required": true,
111
          "description": "Unique identifier for the claim whose notes are to be updated",
112
          "type": "integer"
113
        },
114
        {
115
          "name": "body",
116
          "in": "body",
117
          "description": "A JSON object containing fields to modify",
118
          "required": true,
119
          "schema": {
120
            "type": "object",
121
            "properties": {
122
              "notes": {
123
                "description": "Notes about this return claim",
124
                "type": "string"
125
              },
126
              "updated_by": {
127
                "description": "User id for the librarian updating the claim notes",
128
                "type": "string"
129
              }
130
            }
131
          }
132
        }
133
      ],
134
      "produces": [
135
        "application/json"
136
      ],
137
      "responses": {
138
        "200": {
139
          "description": "Claim notes updated",
140
          "schema": {
141
            "$ref": "../definitions.json#/return_claim"
142
          }
143
        },
144
        "400": {
145
          "description": "Bad request",
146
          "schema": {
147
            "$ref": "../definitions.json#/error"
148
          }
149
        },
150
        "401": {
151
          "description": "Authentication required",
152
          "schema": {
153
            "$ref": "../definitions.json#/error"
154
          }
155
        },
156
        "403": {
157
          "description": "Access forbidden",
158
          "schema": {
159
            "$ref": "../definitions.json#/error"
160
          }
161
        },
162
        "404": {
163
          "description": "Claim not found",
164
          "schema": {
165
            "$ref": "../definitions.json#/error"
166
          }
167
        },
168
        "500": {
169
          "description": "Internal server error",
170
          "schema": {
171
            "$ref": "../definitions.json#/error"
172
          }
173
        },
174
        "503": {
175
          "description": "Under maintenance",
176
          "schema": {
177
            "$ref": "../definitions.json#/error"
178
          }
179
        }
180
      },
181
      "x-koha-authorization": {
182
        "permissions": {
183
          "circulate": "circulate_remaining_permissions"
184
        }
185
      }
186
    }
187
  },
188
  "/return_claims/{claim_id}": {
189
    "delete": {
190
      "x-mojo-to": "ReturnClaims#delete_claim",
191
      "operationId": "deletedClaim",
192
      "tags": [
193
        "claims",
194
        "returned",
195
        "return",
196
        "claim",
197
        "delete"
198
      ],
199
      "parameters": [
200
        {
201
          "name": "claim_id",
202
          "in": "path",
203
          "required": true,
204
          "description": "Unique identifier for the claim to be deleted",
205
          "type": "integer"
206
        }
207
      ],
208
      "produces": [
209
        "application/json"
210
      ],
211
      "responses": {
212
        "200": {
213
          "description": "Claim deleted",
214
          "schema": {
215
            "$ref": "../definitions.json#/return_claim"
216
          }
217
        },
218
        "400": {
219
          "description": "Bad request",
220
          "schema": {
221
            "$ref": "../definitions.json#/error"
222
          }
223
        },
224
        "401": {
225
          "description": "Authentication required",
226
          "schema": {
227
            "$ref": "../definitions.json#/error"
228
          }
229
        },
230
        "403": {
231
          "description": "Access forbidden",
232
          "schema": {
233
            "$ref": "../definitions.json#/error"
234
          }
235
        },
236
        "404": {
237
          "description": "Claim not found",
238
          "schema": {
239
            "$ref": "../definitions.json#/error"
240
          }
241
        },
242
        "500": {
243
          "description": "Internal server error",
244
          "schema": {
245
            "$ref": "../definitions.json#/error"
246
          }
247
        },
248
        "503": {
249
          "description": "Under maintenance",
250
          "schema": {
251
            "$ref": "../definitions.json#/error"
252
          }
253
        }
254
      },
255
      "x-koha-authorization": {
256
        "permissions": {
257
          "circulate": "circulate_remaining_permissions"
258
        }
259
      }
260
    }
261
  },
262
  "/return_claims/{claim_id}/resolve": {
263
    "put": {
264
      "x-mojo-to": "ReturnClaims#resolve_claim",
265
      "operationId": "updateClaimResolve",
266
      "tags": [
267
        "claims",
268
        "returned",
269
        "return",
270
        "claim",
271
        "notes"
272
      ],
273
      "parameters": [
274
        {
275
          "name": "claim_id",
276
          "in": "path",
277
          "required": true,
278
          "description": "Unique identifier for the claim to be resolved",
279
          "type": "integer"
280
        },
281
        {
282
          "name": "body",
283
          "in": "body",
284
          "description": "A JSON object containing fields to modify",
285
          "required": true,
286
          "schema": {
287
            "type": "object",
288
            "properties": {
289
              "resolution": {
290
                "description": "The RETURN_CLAIM_RESOLUTION code to be used to resolve the calim",
291
                "type": "string"
292
              },
293
              "resolved_by": {
294
                "description": "User id for the librarian resolving the claim",
295
                "type": "string"
296
              }
297
            }
298
          }
299
        }
300
      ],
301
      "produces": [
302
        "application/json"
303
      ],
304
      "responses": {
305
        "200": {
306
          "description": "Claim resolved",
307
          "schema": {
308
            "$ref": "../definitions.json#/return_claim"
309
          }
310
        },
311
        "400": {
312
          "description": "Bad request",
313
          "schema": {
314
            "$ref": "../definitions.json#/error"
315
          }
316
        },
317
        "401": {
318
          "description": "Authentication required",
319
          "schema": {
320
            "$ref": "../definitions.json#/error"
321
          }
322
        },
323
        "403": {
324
          "description": "Access forbidden",
325
          "schema": {
326
            "$ref": "../definitions.json#/error"
327
          }
328
        },
329
        "404": {
330
          "description": "Claim not found",
331
          "schema": {
332
            "$ref": "../definitions.json#/error"
333
          }
334
        },
335
        "500": {
336
          "description": "Internal server error",
337
          "schema": {
338
            "$ref": "../definitions.json#/error"
339
          }
340
        },
341
        "503": {
342
          "description": "Under maintenance",
343
          "schema": {
344
            "$ref": "../definitions.json#/error"
345
          }
346
        }
347
      },
348
      "x-koha-authorization": {
349
        "permissions": {
350
          "circulate": "circulate_remaining_permissions"
351
        }
352
      }
353
    }
354
  }
355
}
(-)a/t/db_dependent/api/v1/return_claims.t (-1 / +162 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Test::More tests => 25;
21
use Test::MockModule;
22
use Test::Mojo;
23
use t::lib::Mocks;
24
use t::lib::TestBuilder;
25
26
use DateTime;
27
28
use C4::Context;
29
use C4::Circulation;
30
31
use Koha::Checkouts::ReturnClaims;
32
use Koha::Database;
33
use Koha::DateUtils;
34
35
my $schema  = Koha::Database->schema;
36
my $builder = t::lib::TestBuilder->new;
37
38
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
39
my $t = Test::Mojo->new('Koha::REST::V1');
40
41
$schema->storage->txn_begin;
42
43
my $dbh = C4::Context->dbh;
44
45
my $librarian = $builder->build_object(
46
    {
47
        class => 'Koha::Patrons',
48
        value => { flags => 1 }
49
    }
50
);
51
my $password = 'thePassword123';
52
$librarian->set_password( { password => $password, skip_validation => 1 } );
53
my $userid = $librarian->userid;
54
55
my $patron = $builder->build_object(
56
    {
57
        class => 'Koha::Patrons',
58
        value => { flags => 0 }
59
    }
60
);
61
my $unauth_password = 'thePassword000';
62
$patron->set_password(
63
    { password => $unauth_password, skip_validattion => 1 } );
64
my $unauth_userid = $patron->userid;
65
my $patron_id     = $patron->borrowernumber;
66
67
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
68
my $module     = new Test::MockModule('C4::Context');
69
$module->mock( 'userenv', sub { { branch => $branchcode } } );
70
71
my $item1       = $builder->build_sample_item;
72
my $itemnumber1 = $item1->itemnumber;
73
74
my $date_due = DateTime->now->add( weeks => 2 );
75
my $issue1 =
76
  C4::Circulation::AddIssue( $patron->unblessed, $item1->barcode, $date_due );
77
78
t::lib::Mocks::mock_preference( 'ClaimReturnedChargeFee', 'ask' );
79
t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', '99' );
80
81
# Test creating a return claim
82
## Invalid id
83
$t->post_ok(
84
    "//$userid:$password@/api/v1/return_claims" => json => {
85
        item_id         => 1,
86
        charge_lost_fee => Mojo::JSON->false,
87
        created_by      => $librarian->id,
88
        notes           => "This is a test note."
89
    }
90
)->status_is(404);
91
92
## Valid id
93
$t->post_ok(
94
    "//$userid:$password@/api/v1/return_claims" => json => {
95
        item_id         => $itemnumber1,
96
        charge_lost_fee => Mojo::JSON->false,
97
        created_by      => $librarian->id,
98
        notes           => "This is a test note."
99
    }
100
)->status_is(201);
101
my $claim_id = $t->tx->res->json->{claim_id};
102
103
## Duplicate id
104
$t->post_ok(
105
    "//$userid:$password@/api/v1/return_claims" => json => {
106
        item_id         => $itemnumber1,
107
        charge_lost_fee => Mojo::JSON->false,
108
        created_by      => $librarian->id,
109
        notes           => "This is a test note."
110
    }
111
)->status_is(400);
112
113
# Test editing a claim note
114
## Valid claim id
115
$t->put_ok(
116
    "//$userid:$password@/api/v1/return_claims/$claim_id/notes" => json => {
117
        notes      => "This is a different test note.",
118
        updated_by => $librarian->id,
119
    }
120
)->status_is(200);
121
my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
122
is( $claim->notes,      "This is a different test note." );
123
is( $claim->updated_by, $librarian->id );
124
ok( $claim->updated_on );
125
126
## Bad claim id
127
$t->put_ok(
128
    "//$userid:$password@/api/v1/return_claims/99999999999/notes" => json => {
129
        notes      => "This is a different test note.",
130
        updated_by => $librarian->id,
131
    }
132
)->status_is(404);
133
134
# Resolve a claim
135
## Valid claim id
136
$t->put_ok(
137
    "//$userid:$password@/api/v1/return_claims/$claim_id/resolve" => json => {
138
        resolved_by => $librarian->id,
139
        resolution  => "FOUNDINLIB",
140
    }
141
)->status_is(200);
142
$claim = Koha::Checkouts::ReturnClaims->find($claim_id);
143
is( $claim->resolution, "FOUNDINLIB" );
144
is( $claim->updated_by, $librarian->id );
145
ok( $claim->resolved_on );
146
147
## Invalid claim id
148
$t->put_ok(
149
    "//$userid:$password@/api/v1/return_claims/999999999999/resolve" => json => {
150
        resolved_by => $librarian->id,
151
        resolution  => "FOUNDINLIB",
152
    }
153
)->status_is(404);
154
155
# Test deleting a return claim
156
$t = $t->delete_ok("//$userid:$password@/api/v1/return_claims/$claim_id")
157
  ->status_is(200);
158
$claim = Koha::Checkouts::ReturnClaims->find($claim_id);
159
isnt( $claim, "Return claim was deleted" );
160
161
$t->delete_ok("//$userid:$password@/api/v1/return_claims/$claim_id")
162
  ->status_is(404);

Return to bug 14697