Lines 27-33
use t::lib::TestBuilder;
Link Here
|
27 |
use t::lib::Mocks; |
27 |
use t::lib::Mocks; |
28 |
|
28 |
|
29 |
use C4::Auth; |
29 |
use C4::Auth; |
30 |
use Koha::ImportSources; |
30 |
use Koha::RecordSources; |
31 |
use Koha::Database; |
31 |
use Koha::Database; |
32 |
|
32 |
|
33 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
Lines 45-51
subtest 'list() tests' => sub {
Link Here
|
45 |
|
45 |
|
46 |
my $source = $builder->build_object( |
46 |
my $source = $builder->build_object( |
47 |
{ |
47 |
{ |
48 |
class => 'Koha::ImportSources' |
48 |
class => 'Koha::RecordSources' |
49 |
} |
49 |
} |
50 |
); |
50 |
); |
51 |
my $patron = $builder->build_object( |
51 |
my $patron = $builder->build_object( |
Lines 58-64
subtest 'list() tests' => sub {
Link Here
|
58 |
for ( 1..10 ) { |
58 |
for ( 1..10 ) { |
59 |
$builder->build_object( |
59 |
$builder->build_object( |
60 |
{ |
60 |
{ |
61 |
class => 'Koha::ImportSources' |
61 |
class => 'Koha::RecordSources' |
62 |
} |
62 |
} |
63 |
); |
63 |
); |
64 |
} |
64 |
} |
Lines 76-82
subtest 'list() tests' => sub {
Link Here
|
76 |
{ password => $password, skip_validation => 1 } ); |
76 |
{ password => $password, skip_validation => 1 } ); |
77 |
my $userid = $nonprivilegedpatron->userid; |
77 |
my $userid = $nonprivilegedpatron->userid; |
78 |
|
78 |
|
79 |
$t->get_ok( "//$userid:$password@/api/v1/import_sources" ) |
79 |
$t->get_ok( "//$userid:$password@/api/v1/record_sources" ) |
80 |
->status_is(403) |
80 |
->status_is(403) |
81 |
->json_is( |
81 |
->json_is( |
82 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
82 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
Lines 84-104
subtest 'list() tests' => sub {
Link Here
|
84 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
84 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
85 |
$userid = $patron->userid; |
85 |
$userid = $patron->userid; |
86 |
|
86 |
|
87 |
$t->get_ok( "//$userid:$password@/api/v1/import_sources?_per_page=10" ) |
87 |
$t->get_ok( "//$userid:$password@/api/v1/record_sources?_per_page=10" ) |
88 |
->status_is( 200, 'SWAGGER3.2.2' ); |
88 |
->status_is( 200, 'SWAGGER3.2.2' ); |
89 |
|
89 |
|
90 |
my $response_count = scalar @{ $t->tx->res->json }; |
90 |
my $response_count = scalar @{ $t->tx->res->json }; |
91 |
|
91 |
|
92 |
is( $response_count, 10, 'The API returns 10 sources' ); |
92 |
is( $response_count, 10, 'The API returns 10 sources' ); |
93 |
|
93 |
|
94 |
my $id = $source->import_source_id; |
94 |
my $id = $source->record_source_id; |
95 |
$t->get_ok( "//$userid:$password@/api/v1/import_sources?q={\"import_source_id\": $id}" ) |
95 |
$t->get_ok( "//$userid:$password@/api/v1/record_sources?q={\"record_source_id\": $id}" ) |
96 |
->status_is(200) |
96 |
->status_is(200) |
97 |
->json_is( '' => [ $source->to_api ], 'SWAGGER3.3.2'); |
97 |
->json_is( '' => [ $source->to_api ], 'SWAGGER3.3.2'); |
98 |
|
98 |
|
99 |
$source->delete; |
99 |
$source->delete; |
100 |
|
100 |
|
101 |
$t->get_ok( "//$userid:$password@/api/v1/import_sources?q={\"import_source_id\": $id}" ) |
101 |
$t->get_ok( "//$userid:$password@/api/v1/record_sources?q={\"record_source_id\": $id}" ) |
102 |
->status_is(200) |
102 |
->status_is(200) |
103 |
->json_is( '' => [] ); |
103 |
->json_is( '' => [] ); |
104 |
|
104 |
|
Lines 114-120
subtest 'get() tests' => sub {
Link Here
|
114 |
|
114 |
|
115 |
my $source = $builder->build_object( |
115 |
my $source = $builder->build_object( |
116 |
{ |
116 |
{ |
117 |
class => 'Koha::ImportSources' |
117 |
class => 'Koha::RecordSources' |
118 |
} |
118 |
} |
119 |
); |
119 |
); |
120 |
my $patron = $builder->build_object( |
120 |
my $patron = $builder->build_object( |
Lines 137-145
subtest 'get() tests' => sub {
Link Here
|
137 |
{ password => $password, skip_validation => 1 } ); |
137 |
{ password => $password, skip_validation => 1 } ); |
138 |
my $userid = $nonprivilegedpatron->userid; |
138 |
my $userid = $nonprivilegedpatron->userid; |
139 |
|
139 |
|
140 |
my $id = $source->import_source_id; |
140 |
my $id = $source->record_source_id; |
141 |
|
141 |
|
142 |
$t->get_ok( "//$userid:$password@/api/v1/import_sources/$id" ) |
142 |
$t->get_ok( "//$userid:$password@/api/v1/record_sources/$id" ) |
143 |
->status_is(403) |
143 |
->status_is(403) |
144 |
->json_is( |
144 |
->json_is( |
145 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
145 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
Lines 147-161
subtest 'get() tests' => sub {
Link Here
|
147 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
147 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
148 |
$userid = $patron->userid; |
148 |
$userid = $patron->userid; |
149 |
|
149 |
|
150 |
$t->get_ok( "//$userid:$password@/api/v1/import_sources/$id" ) |
150 |
$t->get_ok( "//$userid:$password@/api/v1/record_sources/$id" ) |
151 |
->status_is( 200, 'SWAGGER3.2.2' ) |
151 |
->status_is( 200, 'SWAGGER3.2.2' ) |
152 |
->json_is( '' => $source->to_api, 'SWAGGER3.3.2' ); |
152 |
->json_is( '' => $source->to_api, 'SWAGGER3.3.2' ); |
153 |
|
153 |
|
154 |
$source->delete; |
154 |
$source->delete; |
155 |
|
155 |
|
156 |
$t->get_ok( "//$userid:$password@/api/v1/import_sources/$id" ) |
156 |
$t->get_ok( "//$userid:$password@/api/v1/record_sources/$id" ) |
157 |
->status_is(404) |
157 |
->status_is(404) |
158 |
->json_is( '/error' => 'Import source not found' ); |
158 |
->json_is( '/error' => 'Record source not found' ); |
159 |
|
159 |
|
160 |
$schema->storage->txn_rollback; |
160 |
$schema->storage->txn_rollback; |
161 |
|
161 |
|
Lines 169-175
subtest 'delete() tests' => sub {
Link Here
|
169 |
|
169 |
|
170 |
my $source = $builder->build_object( |
170 |
my $source = $builder->build_object( |
171 |
{ |
171 |
{ |
172 |
class => 'Koha::ImportSources' |
172 |
class => 'Koha::RecordSources' |
173 |
} |
173 |
} |
174 |
); |
174 |
); |
175 |
my $patron = $builder->build_object( |
175 |
my $patron = $builder->build_object( |
Lines 192-200
subtest 'delete() tests' => sub {
Link Here
|
192 |
{ password => $password, skip_validation => 1 } ); |
192 |
{ password => $password, skip_validation => 1 } ); |
193 |
my $userid = $nonprivilegedpatron->userid; |
193 |
my $userid = $nonprivilegedpatron->userid; |
194 |
|
194 |
|
195 |
my $id = $source->import_source_id; |
195 |
my $id = $source->record_source_id; |
196 |
|
196 |
|
197 |
$t->delete_ok( "//$userid:$password@/api/v1/import_sources/$id" ) |
197 |
$t->delete_ok( "//$userid:$password@/api/v1/record_sources/$id" ) |
198 |
->status_is(403) |
198 |
->status_is(403) |
199 |
->json_is( |
199 |
->json_is( |
200 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
200 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
Lines 202-213
subtest 'delete() tests' => sub {
Link Here
|
202 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
202 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
203 |
$userid = $patron->userid; |
203 |
$userid = $patron->userid; |
204 |
|
204 |
|
205 |
$t->delete_ok( "//$userid:$password@/api/v1/import_sources/$id" ) |
205 |
$t->delete_ok( "//$userid:$password@/api/v1/record_sources/$id" ) |
206 |
->status_is( 204, 'SWAGGER3.2.2' ); |
206 |
->status_is( 204, 'SWAGGER3.2.2' ); |
207 |
|
207 |
|
208 |
my $deleted_source = Koha::ImportSources->search({import_source_id => $id}); |
208 |
my $deleted_source = Koha::RecordSources->search({record_source_id => $id}); |
209 |
|
209 |
|
210 |
is($deleted_source->count, 0, 'No import source found'); |
210 |
is($deleted_source->count, 0, 'No record source found'); |
211 |
|
211 |
|
212 |
$schema->storage->txn_rollback; |
212 |
$schema->storage->txn_rollback; |
213 |
|
213 |
|
Lines 219-225
subtest 'add() tests' => sub {
Link Here
|
219 |
|
219 |
|
220 |
$schema->storage->txn_begin; |
220 |
$schema->storage->txn_begin; |
221 |
|
221 |
|
222 |
Koha::ImportSources->delete; |
222 |
Koha::RecordSources->delete; |
223 |
|
223 |
|
224 |
my $patron = $builder->build_object( |
224 |
my $patron = $builder->build_object( |
225 |
{ |
225 |
{ |
Lines 242-248
subtest 'add() tests' => sub {
Link Here
|
242 |
my $userid = $nonprivilegedpatron->userid; |
242 |
my $userid = $nonprivilegedpatron->userid; |
243 |
my $patron_id = $nonprivilegedpatron->borrowernumber; |
243 |
my $patron_id = $nonprivilegedpatron->borrowernumber; |
244 |
|
244 |
|
245 |
$t->post_ok( "//$userid:$password@/api/v1/import_sources" => json => { name => 'test1', patron_id => $patron_id }) |
245 |
$t->post_ok( "//$userid:$password@/api/v1/record_sources" => json => { name => 'test1', patron_id => $patron_id }) |
246 |
->status_is(403) |
246 |
->status_is(403) |
247 |
->json_is( |
247 |
->json_is( |
248 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
248 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
Lines 250-263
subtest 'add() tests' => sub {
Link Here
|
250 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
250 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
251 |
$userid = $patron->userid; |
251 |
$userid = $patron->userid; |
252 |
|
252 |
|
253 |
$t->post_ok( "//$userid:$password@/api/v1/import_sources" => json => { name => 'test1', patron_id => $patron_id }) |
253 |
$t->post_ok( "//$userid:$password@/api/v1/record_sources" => json => { name => 'test1', patron_id => $patron_id }) |
254 |
->status_is( 201, 'SWAGGER3.2.2' ) |
254 |
->status_is( 201, 'SWAGGER3.2.2' ) |
255 |
->json_is('/name', 'test1') |
255 |
->json_is('/name', 'test1') |
256 |
->json_is('/patron_id', $patron_id); |
256 |
->json_is('/patron_id', $patron_id); |
257 |
|
257 |
|
258 |
my $created_source = Koha::ImportSources->search->next; |
258 |
my $created_source = Koha::RecordSources->search->next; |
259 |
|
259 |
|
260 |
is($created_source->name, 'test1', 'Import source found'); |
260 |
is($created_source->name, 'test1', 'Record source found'); |
261 |
|
261 |
|
262 |
$schema->storage->txn_rollback; |
262 |
$schema->storage->txn_rollback; |
263 |
|
263 |
|
Lines 271-277
subtest 'update() tests' => sub {
Link Here
|
271 |
|
271 |
|
272 |
my $source = $builder->build_object( |
272 |
my $source = $builder->build_object( |
273 |
{ |
273 |
{ |
274 |
class => 'Koha::ImportSources', |
274 |
class => 'Koha::RecordSources', |
275 |
value => { name => 'Oldname' } |
275 |
value => { name => 'Oldname' } |
276 |
} |
276 |
} |
277 |
); |
277 |
); |
Lines 295-303
subtest 'update() tests' => sub {
Link Here
|
295 |
{ password => $password, skip_validation => 1 } ); |
295 |
{ password => $password, skip_validation => 1 } ); |
296 |
my $userid = $nonprivilegedpatron->userid; |
296 |
my $userid = $nonprivilegedpatron->userid; |
297 |
|
297 |
|
298 |
my $id = $source->import_source_id; |
298 |
my $id = $source->record_source_id; |
299 |
|
299 |
|
300 |
$t->put_ok( "//$userid:$password@/api/v1/import_sources/$id" => json => { name => 'Newname', patron_id => $source->patron_id } ) |
300 |
$t->put_ok( "//$userid:$password@/api/v1/record_sources/$id" => json => { name => 'Newname', patron_id => $source->patron_id } ) |
301 |
->status_is(403) |
301 |
->status_is(403) |
302 |
->json_is( |
302 |
->json_is( |
303 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
303 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
Lines 305-318
subtest 'update() tests' => sub {
Link Here
|
305 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
305 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
306 |
$userid = $patron->userid; |
306 |
$userid = $patron->userid; |
307 |
|
307 |
|
308 |
$t->put_ok( "//$userid:$password@/api/v1/import_sources/$id" => json => { name => 'Newname', patron_id => $source->patron_id } ) |
308 |
$t->put_ok( "//$userid:$password@/api/v1/record_sources/$id" => json => { name => 'Newname', patron_id => $source->patron_id } ) |
309 |
->status_is( 200, 'SWAGGER3.2.2' ) |
309 |
->status_is( 200, 'SWAGGER3.2.2' ) |
310 |
->json_is('/name', 'Newname'); |
310 |
->json_is('/name', 'Newname'); |
311 |
|
311 |
|
312 |
my $updated_source = Koha::ImportSources->find($id); |
312 |
my $updated_source = Koha::RecordSources->find($id); |
313 |
|
313 |
|
314 |
is($updated_source->name, 'Newname', 'Import source updated'); |
314 |
is($updated_source->name, 'Newname', 'Record source updated'); |
315 |
|
315 |
|
316 |
$schema->storage->txn_rollback; |
316 |
$schema->storage->txn_rollback; |
317 |
|
317 |
|
318 |
}; |
318 |
}; |