Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/env perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Test::More tests => 17; |
6 |
use Test::Mojo; |
7 |
|
8 |
use t::lib::Mocks; |
9 |
use t::lib::TestBuilder; |
10 |
|
11 |
my $schema = Koha::Database->new->schema; |
12 |
my $builder = t::lib::TestBuilder->new; |
13 |
|
14 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
15 |
|
16 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
17 |
|
18 |
$schema->storage->txn_begin; |
19 |
|
20 |
my $patron = $builder->build_object( |
21 |
{ |
22 |
class => 'Koha::Patrons', |
23 |
value => { flags => 0 } |
24 |
} |
25 |
); |
26 |
my $password = 'thePassword123'; |
27 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
28 |
my $userid = $patron->userid; |
29 |
|
30 |
my $biblio = $builder->build_sample_biblio({ |
31 |
title => 'The unbearable lightness of being', |
32 |
author => 'Milan Kundera' |
33 |
}); |
34 |
|
35 |
my $url = "//$userid:$password@/api/v1/biblios"; |
36 |
my $marcxml = $biblio->metadata->record->as_xml_record; |
37 |
|
38 |
$t->post_ok($url, json => { marcxml => $marcxml }) |
39 |
->status_is(403); |
40 |
|
41 |
$patron->flags(4)->store; |
42 |
|
43 |
$t->post_ok($url, { Accept => 'application/weird+format' }, json => { marcxml => $marcxml }) |
44 |
->status_is(406) |
45 |
->json_is( [ "application/json", |
46 |
"application/marcxml+xml", |
47 |
"application/marc-in-json", |
48 |
"application/marc", |
49 |
"text/plain" ] ); |
50 |
|
51 |
$t->post_ok($url, { Accept => 'application/json' }, json => { marcxml => $marcxml }) |
52 |
->status_is(200) |
53 |
->json_is( '/title', 'The unbearable lightness of being' ) |
54 |
->json_is( '/author', 'Milan Kundera' ); |
55 |
|
56 |
$t->post_ok($url, { Accept => 'application/marcxml+xml' }, json => { marcxml => $marcxml }) |
57 |
->status_is(200); |
58 |
|
59 |
$t->post_ok($url, { Accept => 'application/marc-in-json' }, json => { marcxml => $marcxml }) |
60 |
->status_is(200); |
61 |
|
62 |
$t->post_ok($url, { Accept => 'application/marc' }, json => { marcxml => $marcxml }) |
63 |
->status_is(200); |
64 |
|
65 |
$t->post_ok($url, { Accept => 'text/plain' }, json => { marcxml => $marcxml }) |
66 |
->status_is(200); |
67 |
|
68 |
$schema->storage->txn_rollback; |