|
Lines 151-157
subtest 'get() test' => sub {
Link Here
|
| 151 |
|
151 |
|
| 152 |
subtest 'add() tests' => sub { |
152 |
subtest 'add() tests' => sub { |
| 153 |
|
153 |
|
| 154 |
plan tests => 16; |
154 |
plan tests => 17; |
| 155 |
|
155 |
|
| 156 |
$schema->storage->txn_begin; |
156 |
$schema->storage->txn_begin; |
| 157 |
|
157 |
|
|
Lines 220-231
subtest 'add() tests' => sub {
Link Here
|
| 220 |
] |
220 |
] |
| 221 |
); |
221 |
); |
| 222 |
|
222 |
|
|
|
223 |
subtest 'relationships contracts, interfaces, aliases' => sub { |
| 224 |
plan tests => 32; |
| 225 |
my $vendor = { name => 'another vendor', contacts => [], interfaces => [], aliases => [] }; |
| 226 |
my $vendor_id = $t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor ) |
| 227 |
->status_is( 201, 'REST3 .2.1' )->json_is( '/name' => $vendor->{name} ) |
| 228 |
|
| 229 |
# FIXME Maybe we expect instead |
| 230 |
# ->json_is( '/contacts' => [] )->json_is('/interfaces' => [], '/aliases' => [] ); |
| 231 |
->json_hasnt('/contacts')->json_hasnt('/interfaces')->json_hasnt('/aliases')->tx->res->json->{id}; |
| 232 |
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor_id )->status_is(200) |
| 233 |
->json_hasnt('/contacts')->json_hasnt('/interfaces')->json_hasnt('/aliases'); |
| 234 |
|
| 235 |
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" |
| 236 |
. $vendor_id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200) |
| 237 |
->json_is( '/contacts', [] )->json_is( '/interfaces', [] )->json_is( '/aliases', [] ); |
| 238 |
|
| 239 |
$vendor = { |
| 240 |
name => 'yet another vendor', contacts => [ { name => 'contact name' } ], |
| 241 |
interfaces => [ { name => 'interface name' } ], aliases => [ { alias => 'foo' } ] |
| 242 |
}; |
| 243 |
$vendor_id = $t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor ) |
| 244 |
->status_is( 201, 'REST3 .2.1' )->json_is( '/name' => $vendor->{name} ) |
| 245 |
|
| 246 |
# FIXME Maybe we expect instead |
| 247 |
# ->json_is( '/contacts' => [] )->json_is('/interfaces' => [], '/aliases' => [] ); |
| 248 |
->json_hasnt('/contacts')->json_hasnt('/interfaces')->json_hasnt('/aliases')->tx->res->json->{id}; |
| 249 |
|
| 250 |
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor_id )->status_is(200) |
| 251 |
->json_hasnt('/contacts')->json_hasnt('/interfaces')->json_hasnt('/aliases'); |
| 252 |
|
| 253 |
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" |
| 254 |
. $vendor_id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200) |
| 255 |
->json_has('/contacts/0/name')->json_has('/interfaces/0/name')->json_has('/aliases/0/alias'); |
| 256 |
}; |
| 257 |
|
| 223 |
$schema->storage->txn_rollback; |
258 |
$schema->storage->txn_rollback; |
| 224 |
}; |
259 |
}; |
| 225 |
|
260 |
|
| 226 |
subtest 'update() tests' => sub { |
261 |
subtest 'update() tests' => sub { |
| 227 |
|
262 |
|
| 228 |
plan tests => 15; |
263 |
plan tests => 16; |
| 229 |
|
264 |
|
| 230 |
$schema->storage->txn_begin; |
265 |
$schema->storage->txn_begin; |
| 231 |
|
266 |
|
|
Lines 294-305
subtest 'update() tests' => sub {
Link Here
|
| 294 |
$t->put_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" |
329 |
$t->put_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" |
| 295 |
. $non_existent_id => json => $vendor_with_updated_field )->status_is(404); |
330 |
. $non_existent_id => json => $vendor_with_updated_field )->status_is(404); |
| 296 |
|
331 |
|
| 297 |
$schema->storage->txn_rollback; |
|
|
| 298 |
|
| 299 |
# Wrong method (POST) |
332 |
# Wrong method (POST) |
| 300 |
$t->post_ok( |
333 |
$t->post_ok( |
| 301 |
"//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id => json => $vendor_with_updated_field ) |
334 |
"//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id => json => $vendor_with_updated_field ) |
| 302 |
->status_is(404); |
335 |
->status_is(404); |
|
|
336 |
|
| 337 |
subtest 'relationships contracts, interfaces, aliases' => sub { |
| 338 |
plan tests => 30; |
| 339 |
my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); |
| 340 |
$vendor->contacts( [] ); |
| 341 |
$vendor->interfaces( [] ); |
| 342 |
$vendor->aliases( [] ); |
| 343 |
|
| 344 |
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" |
| 345 |
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200) |
| 346 |
->json_is( '/contacts', [] )->json_is( '/interfaces', [] )->json_is( '/aliases', [] ); |
| 347 |
|
| 348 |
my $api_vendor = $vendor->to_api; |
| 349 |
delete $api_vendor->{id}; |
| 350 |
|
| 351 |
$api_vendor->{contacts} = [ { name => 'contact name' } ]; |
| 352 |
$api_vendor->{interfaces} = [ { name => 'interface name' } ]; |
| 353 |
$api_vendor->{aliases} = [ { alias => 'foo' } ]; |
| 354 |
|
| 355 |
$t->put_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id => json => $api_vendor ) |
| 356 |
->status_is( 200, 'REST3 .2.1' )->json_is( '/name' => $vendor->name )->json_hasnt('/contacts') |
| 357 |
->json_hasnt('/interfaces')->json_hasnt('/aliases'); |
| 358 |
|
| 359 |
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" |
| 360 |
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200) |
| 361 |
->json_has('/contacts/0/name')->json_has('/interfaces/0/name')->json_has('/aliases/0/alias'); |
| 362 |
|
| 363 |
delete $api_vendor->{contacts}; |
| 364 |
delete $api_vendor->{interfaces}; |
| 365 |
delete $api_vendor->{aliases}; |
| 366 |
|
| 367 |
$t->put_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id => json => $api_vendor ) |
| 368 |
->status_is( 200, 'REST3 .2.1' ); |
| 369 |
|
| 370 |
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" |
| 371 |
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200) |
| 372 |
->json_has('/contacts/0/name')->json_has('/interfaces/0/name')->json_has('/aliases/0/alias'); |
| 373 |
|
| 374 |
$api_vendor->{contacts} = []; |
| 375 |
$api_vendor->{interfaces} = []; |
| 376 |
$api_vendor->{aliases} = []; |
| 377 |
|
| 378 |
$t->put_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id => json => $api_vendor ) |
| 379 |
->status_is( 200, 'REST3 .2.1' ); |
| 380 |
|
| 381 |
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" |
| 382 |
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200) |
| 383 |
->json_is( '/contacts', [] )->json_is( '/interfaces', [] )->json_is( '/aliases', [] ); |
| 384 |
}; |
| 385 |
|
| 386 |
$schema->storage->txn_rollback; |
| 387 |
|
| 303 |
}; |
388 |
}; |
| 304 |
|
389 |
|
| 305 |
subtest 'delete() tests' => sub { |
390 |
subtest 'delete() tests' => sub { |
| 306 |
- |
|
|