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

(-)a/api/v1/swagger/x-primitives.json (-1 / +1 lines)
Lines 35-41 Link Here
35
    "description": "primary phone number for patron's primary address"
35
    "description": "primary phone number for patron's primary address"
36
  },
36
  },
37
  "surname": {
37
  "surname": {
38
    "type": "string",
38
    "type": ["string", "null"],
39
    "description": "patron's last name"
39
    "description": "patron's last name"
40
  },
40
  },
41
  "vendor_id": {
41
  "vendor_id": {
(-)a/t/db_dependent/api/v1/acquisitions_orders.t (-9 / +36 lines)
Lines 77-90 subtest 'list() tests' => sub { Link Here
77
77
78
        my $size = keys %{$fields};
78
        my $size = keys %{$fields};
79
79
80
        plan tests => $size * 3;
80
        plan tests => $size * (2 + 2 * $size);
81
81
82
        foreach my $field ( keys %{$fields} ) {
82
        foreach my $field ( keys %{$fields} ) {
83
            my $model_field = $fields->{ $field };
83
            my $model_field = $fields->{ $field };
84
            my $result =
84
            my $result = $t->get_ok("//$userid:$password@/api/v1/acquisitions/orders?$field=" . $order->$model_field)
85
            $t->get_ok("//$userid:$password@/api/v1/acquisitions/orders?$field=" . $order->$model_field)
85
              ->status_is(200);
86
              ->status_is(200)
86
87
              ->json_has( [ $order, $another_order ] );
87
            foreach my $key ( keys %{$fields} ) {
88
              my $key_field = $fields->{ $key };
89
              # Uh oh. We use budget_id in the query but return fund_id.
90
              $key = 'fund_id' if ($key eq 'budget_id');
91
              # Check the result order first since it's not predefined.
92
              if ($result->tx->res->json->[0]->{$key} eq $order->$key_field) {
93
                $result->json_is( "/0/$key", $order->$key_field );
94
                $result->json_is( "/1/$key", $another_order->$key_field );
95
              } else {
96
                $result->json_is( "/0/$key", $another_order->$key_field );
97
                $result->json_is( "/1/$key", $order->$key_field );
98
              }
99
            }
88
        }
100
        }
89
    };
101
    };
90
102
Lines 250-260 subtest 'update() tests' => sub { Link Here
250
        address1 => "New library address",
262
        address1 => "New library address",
251
    };
263
    };
252
264
253
    $t->put_ok( "//$auth_userid:$password@/api/v1/libraries/$library_id" => json => $library_with_missing_field )
265
    my $result = $t->put_ok( "//$auth_userid:$password@/api/v1/libraries/$library_id" => json => $library_with_missing_field )
254
      ->status_is(400)
266
      ->status_is(400);
255
      ->json_has( "/errors" =>
267
    # Check the result order first since it's not predefined.
256
          [ { message => "Missing property.", path => "/body/address2" } ]
268
    if ($result->tx->res->json->{errors}->[0]->{path} eq '/body/name') {
269
      $result->json_is(
270
        "/errors",
271
        [
272
          {message => "Missing property.", path => "/body/name"},
273
          {message => "Missing property.", path => "/body/library_id"}
274
        ]
275
      );
276
    } else {
277
      $result->json_is(
278
        "/errors",
279
        [
280
          {message => "Missing property.", path => "/body/library_id"},
281
          {message => "Missing property.", path => "/body/name"}
282
        ]
257
      );
283
      );
284
    }
258
285
259
    my $deleted_library = $builder->build_object( { class => 'Koha::Libraries' } );
286
    my $deleted_library = $builder->build_object( { class => 'Koha::Libraries' } );
260
    my $library_with_updated_field = $deleted_library->to_api;
287
    my $library_with_updated_field = $deleted_library->to_api;
(-)a/t/db_dependent/api/v1/holds.t (-1 / +5 lines)
Lines 197-206 subtest "Test endpoints with permission" => sub { Link Here
197
      ->json_is('/0/patron_id', $patron_2->borrowernumber)
197
      ->json_is('/0/patron_id', $patron_2->borrowernumber)
198
      ->json_hasnt('/1');
198
      ->json_hasnt('/1');
199
199
200
    # While suspended_until is date-time, it's always set to midnight.
201
    my $expected_suspended_until = $suspended_until->strftime('%FT00:00:00%z');
202
    substr($expected_suspended_until, -2, 0, ':');
203
200
    $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => $put_data )
204
    $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => $put_data )
201
      ->status_is(200)
205
      ->status_is(200)
202
      ->json_is( '/hold_id', $reserve_id )
206
      ->json_is( '/hold_id', $reserve_id )
203
      ->json_is( '/suspended_until', output_pref({ dt => $suspended_until, dateformat => 'rfc3339' }) )
207
      ->json_is( '/suspended_until', $expected_suspended_until )
204
      ->json_is( '/priority', 2 );
208
      ->json_is( '/priority', 2 );
205
209
206
    $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" )
210
    $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" )
(-)a/t/db_dependent/api/v1/libraries.t (-5 / +8 lines)
Lines 85-98 subtest 'list() tests' => sub { Link Here
85
85
86
        my $size = keys %{$fields};
86
        my $size = keys %{$fields};
87
87
88
        plan tests => $size * 3;
88
        plan tests => $size * (2 + 2 * $size);
89
89
90
        foreach my $field ( keys %{$fields} ) {
90
        foreach my $field ( keys %{$fields} ) {
91
            my $model_field = $fields->{ $field };
91
            my $model_field = $fields->{ $field };
92
            my $result =
92
            my $result = $t->get_ok("//$userid:$password@/api/v1/libraries?$field=" . $library->$model_field)
93
            $t->get_ok("//$userid:$password@/api/v1/libraries?$field=" . $library->$model_field)
93
              ->status_is(200);
94
              ->status_is(200)
94
            foreach my $key ( keys %{$fields} ) {
95
              ->json_has( [ $library, $another_library ] );
95
              my $key_field = $fields->{ $key };
96
              $result->json_is( "/0/$key", $library->$key_field );
97
              $result->json_is( "/1/$key", $another_library->$key_field );
98
            }
96
        }
99
        }
97
    };
100
    };
98
101
(-)a/t/db_dependent/api/v1/patrons.t (-4 / +10 lines)
Lines 310-316 subtest 'update() tests' => sub { Link Here
310
        warning_like {
310
        warning_like {
311
            $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron )
311
            $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron )
312
              ->status_is(409)
312
              ->status_is(409)
313
              ->json_has( '/error' => "Fails when trying to update to an existing cardnumber or userid")
313
              ->json_has( '/error', "Fails when trying to update to an existing cardnumber or userid")
314
              ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ ); }
314
              ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ ); }
315
            qr/^DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/;
315
            qr/^DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/;
316
316
Lines 318-326 subtest 'update() tests' => sub { Link Here
318
        $newpatron->{ userid }     = "user" . $patron_1->id.$patron_2->id;
318
        $newpatron->{ userid }     = "user" . $patron_1->id.$patron_2->id;
319
        $newpatron->{ surname }    = "user" . $patron_1->id.$patron_2->id;
319
        $newpatron->{ surname }    = "user" . $patron_1->id.$patron_2->id;
320
320
321
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron )
321
        my $result = $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron )
322
          ->status_is(200, 'Patron updated successfully')
322
          ->status_is(200, 'Patron updated successfully');
323
          ->json_has($newpatron);
323
324
        # Put back the RO attributes
325
        $newpatron->{patron_id} = $unauthorized_patron->to_api->{patron_id};
326
        $newpatron->{restricted} = $unauthorized_patron->to_api->{restricted};
327
        $newpatron->{anonymized} = $unauthorized_patron->to_api->{anonymized};
328
        is_deeply($result->tx->res->json, $newpatron, 'Returned patron from update matches expected');
329
324
        is(Koha::Patrons->find( $patron_2->id )->cardnumber,
330
        is(Koha::Patrons->find( $patron_2->id )->cardnumber,
325
           $newpatron->{ cardnumber }, 'Patron is really updated!');
331
           $newpatron->{ cardnumber }, 'Patron is really updated!');
326
332
(-)a/t/db_dependent/api/v1/patrons_password.t (-4 / +1 lines)
Lines 175-183 subtest 'set_public() (unprivileged user tests)' => sub { Link Here
175
    $tx->req->env( { REMOTE_ADDR => '127.0.0.1' } );
175
    $tx->req->env( { REMOTE_ADDR => '127.0.0.1' } );
176
    $t->request_ok($tx)
176
    $t->request_ok($tx)
177
      ->status_is(403)
177
      ->status_is(403)
178
      ->json_has({
178
      ->json_is('/error', "Authorization failure. Missing required permission(s).");
179
          error => "Authorization failure. Missing required permission(s)."
180
        });
181
179
182
    $tx = $t->ua->build_tx(
180
    $tx = $t->ua->build_tx(
183
              POST => "/api/v1/public/patrons/"
181
              POST => "/api/v1/public/patrons/"
184
- 

Return to bug 22522