Lines 20-26
use Modern::Perl;
Link Here
|
20 |
use utf8; |
20 |
use utf8; |
21 |
use Encode; |
21 |
use Encode; |
22 |
|
22 |
|
23 |
use Test::More tests => 2; |
23 |
use Test::More tests => 3; |
24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
25 |
use Test::Mojo; |
25 |
use Test::Mojo; |
26 |
use Test::Warn; |
26 |
use Test::Warn; |
Lines 152-154
subtest 'delete() tests' => sub {
Link Here
|
152 |
|
152 |
|
153 |
$schema->storage->txn_rollback; |
153 |
$schema->storage->txn_rollback; |
154 |
}; |
154 |
}; |
155 |
- |
155 |
|
|
|
156 |
subtest 'post() tests' => sub { |
157 |
|
158 |
plan tests => 14; |
159 |
|
160 |
$schema->storage->txn_begin; |
161 |
|
162 |
Koha::Authorities->delete; |
163 |
|
164 |
my $patron = $builder->build_object( |
165 |
{ |
166 |
class => 'Koha::Patrons', |
167 |
value => { flags => 0 } # no permissions |
168 |
} |
169 |
); |
170 |
my $password = 'thePassword123'; |
171 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
172 |
my $userid = $patron->userid; |
173 |
|
174 |
my $marcxml = q|<?xml version="1.0" encoding="UTF-8"?> |
175 |
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> |
176 |
<controlfield tag="001">1001</controlfield> |
177 |
<datafield tag="110" ind1=" " ind2=" "> |
178 |
<subfield code="9">102</subfield> |
179 |
<subfield code="a">My Corporation</subfield> |
180 |
</datafield> |
181 |
</record>|; |
182 |
|
183 |
my $mij = '{"fields":[{"001":"1001"},{"110":{"subfields":[{"9":"102"},{"a":"My Corporation"}],"ind1":" ","ind2":" "}}],"leader":" "}'; |
184 |
my $marc = '00079 2200049 45000010005000001100024000051001 9102aMy Corporation'; |
185 |
my $json = { |
186 |
authtypecode => "CORPO_NAME", |
187 |
marcxml => $marcxml |
188 |
}; |
189 |
|
190 |
$t->post_ok("//$userid:$password@/api/v1/authorities") |
191 |
->status_is(403, 'Not enough permissions makes it return the right code'); |
192 |
|
193 |
# Add permissions |
194 |
$builder->build( |
195 |
{ |
196 |
source => 'UserPermission', |
197 |
value => { |
198 |
borrowernumber => $patron->borrowernumber, |
199 |
module_bit => 9, |
200 |
code => 'edit_catalogue' |
201 |
} |
202 |
} |
203 |
); |
204 |
|
205 |
$t->post_ok("//$userid:$password@/api/v1/authorities" => json => $json) |
206 |
->status_is(200) |
207 |
->json_has('/id'); |
208 |
|
209 |
$t->post_ok("//$userid:$password@/api/v1/authorities" => {'Content-Type' => 'application/marcxml+xml', 'x-authority-type' => 'CORPO_NAME'} => $marcxml) |
210 |
->status_is(200) |
211 |
->json_has('/id'); |
212 |
|
213 |
$t->post_ok("//$userid:$password@/api/v1/authorities" => {'Content-Type' => 'application/marc-in-json', 'x-authority-type' => 'CORPO_NAME'} => $mij) |
214 |
->status_is(200) |
215 |
->json_has('/id'); |
216 |
|
217 |
$t->post_ok("//$userid:$password@/api/v1/authorities" => {'Content-Type' => 'application/marc', 'x-authority-type' => 'CORPO_NAME'} => $marc) |
218 |
->status_is(200) |
219 |
->json_has('/id'); |
220 |
|
221 |
$schema->storage->txn_rollback; |
222 |
}; |