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 / +34 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_is( [ $order->to_api, $another_order->to_api ] );
87
            foreach my $key ( keys %{$fields} ) {
88
              my $key_field = $fields->{ $key };
89
              # Check the result order first since it's not predefined.
90
              if ($result->tx->res->json->[0]->{$key} eq $order->$key_field) {
91
                $result->json_is( "/0/$key", $order->$key_field );
92
                $result->json_is( "/1/$key", $another_order->$key_field );
93
              } else {
94
                $result->json_is( "/0/$key", $another_order->$key_field );
95
                $result->json_is( "/1/$key", $order->$key_field );
96
              }
97
            }
88
        }
98
        }
89
    };
99
    };
90
100
Lines 250-260 subtest 'update() tests' => sub { Link Here
250
        address1 => "New library address",
260
        address1 => "New library address",
251
    };
261
    };
252
262
253
    $t->put_ok( "//$auth_userid:$password@/api/v1/libraries/$library_id" => json => $library_with_missing_field )
263
    my $result = $t->put_ok( "//$auth_userid:$password@/api/v1/libraries/$library_id" => json => $library_with_missing_field )
254
      ->status_is(400)
264
      ->status_is(400);
255
      ->json_has( "/errors" =>
265
    # Check the result order first since it's not predefined.
256
          [ { message => "Missing property.", path => "/body/address2" } ]
266
    if ($result->tx->res->json->{errors}->[0]->{path} eq '/body/name') {
267
      $result->json_is(
268
        "/errors",
269
        [
270
          {message => "Missing property.", path => "/body/name"},
271
          {message => "Missing property.", path => "/body/library_id"}
272
        ]
273
      );
274
    } else {
275
      $result->json_is(
276
        "/errors",
277
        [
278
          {message => "Missing property.", path => "/body/library_id"},
279
          {message => "Missing property.", path => "/body/name"}
280
        ]
257
      );
281
      );
282
    }
258
283
259
    my $deleted_library = $builder->build_object( { class => 'Koha::Libraries' } );
284
    my $deleted_library = $builder->build_object( { class => 'Koha::Libraries' } );
260
    my $library_with_updated_field = $deleted_library->to_api;
285
    my $library_with_updated_field = $deleted_library->to_api;
(-)a/t/db_dependent/api/v1/holds.t (-1 / +5 lines)
Lines 211-220 subtest "Test endpoints with permission" => sub { Link Here
211
      ->json_is('/0/patron_id', $patron_2->borrowernumber)
211
      ->json_is('/0/patron_id', $patron_2->borrowernumber)
212
      ->json_hasnt('/1');
212
      ->json_hasnt('/1');
213
213
214
    # While suspended_until is date-time, it's always set to midnight.
215
    my $expected_suspended_until = $suspended_until->strftime('%FT00:00:00%z');
216
    substr($expected_suspended_until, -2, 0, ':');
217
214
    $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => $put_data )
218
    $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => $put_data )
215
      ->status_is(200)
219
      ->status_is(200)
216
      ->json_is( '/hold_id', $reserve_id )
220
      ->json_is( '/hold_id', $reserve_id )
217
      ->json_is( '/suspended_until', output_pref({ dt => $suspended_until, dateformat => 'rfc3339' }) )
221
      ->json_is( '/suspended_until', $expected_suspended_until )
218
      ->json_is( '/priority', 2 );
222
      ->json_is( '/priority', 2 );
219
223
220
    $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" )
224
    $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