|
Lines 20-27
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
use FindBin qw( $Bin ); |
21 |
use FindBin qw( $Bin ); |
| 22 |
|
22 |
|
| 23 |
use Test::More tests => 1; |
23 |
use Test::More tests => 2; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
|
|
25 |
use Test::MockModule; |
| 25 |
|
26 |
|
| 26 |
use t::lib::Mocks; |
27 |
use t::lib::Mocks; |
| 27 |
use t::lib::TestBuilder; |
28 |
use t::lib::TestBuilder; |
|
Lines 123-125
subtest 'process_quote' => sub {
Link Here
|
| 123 |
|
124 |
|
| 124 |
$schema->storage->txn_rollback; |
125 |
$schema->storage->txn_rollback; |
| 125 |
}; |
126 |
}; |
|
|
127 |
|
| 128 |
subtest '_handle_008_field' => sub { |
| 129 |
plan tests => 4; |
| 130 |
|
| 131 |
$schema->storage->txn_begin; |
| 132 |
|
| 133 |
# Add our test quote file to the database for testing against |
| 134 |
my $account = $builder->build( |
| 135 |
{ |
| 136 |
source => 'VendorEdiAccount', |
| 137 |
value => { |
| 138 |
description => 'test vendor', transport => 'FILE', |
| 139 |
} |
| 140 |
} |
| 141 |
); |
| 142 |
my $dirname = ( $Bin =~ /^(.*\/t\/)/ ? $1 . 'edi_testfiles/' : q{} ); |
| 143 |
my $filename = 'QUOTES_SMALL.CEQ'; |
| 144 |
ok( -e $dirname . $filename, 'File QUOTES_SMALL.CEQ found' ); |
| 145 |
|
| 146 |
my $trans = Koha::Edifact::Transport->new( $account->{id} ); |
| 147 |
$trans->working_directory($dirname); |
| 148 |
|
| 149 |
my $mhash = $trans->message_hash(); |
| 150 |
$mhash->{message_type} = 'QUOTE'; |
| 151 |
$trans->ingest( $mhash, $filename ); |
| 152 |
|
| 153 |
my $quote = $schema->resultset('EdifactMessage')->find( { filename => $filename } ); |
| 154 |
|
| 155 |
# Test quote expects REF to be a valid and active fund code |
| 156 |
my $active_period = $builder->build( |
| 157 |
{ |
| 158 |
source => 'Aqbudgetperiod', |
| 159 |
value => { budget_period_active => 1 } |
| 160 |
} |
| 161 |
); |
| 162 |
my $fund = $builder->build( |
| 163 |
{ |
| 164 |
source => 'Aqbudget', |
| 165 |
value => { |
| 166 |
budget_code => 'REF', |
| 167 |
budget_period_id => $active_period->{budget_period_id} |
| 168 |
} |
| 169 |
} |
| 170 |
); |
| 171 |
|
| 172 |
# The quote expects a ROT1 stock rotation roata to exist |
| 173 |
my $rota = $builder->build_object( |
| 174 |
{ |
| 175 |
class => 'Koha::StockRotationRotas', |
| 176 |
value => { title => 'ROT1' } |
| 177 |
} |
| 178 |
); |
| 179 |
$builder->build( |
| 180 |
{ |
| 181 |
source => 'Stockrotationstage', |
| 182 |
value => { rota_id => $rota->rota_id }, |
| 183 |
} |
| 184 |
); |
| 185 |
|
| 186 |
# Process the test quote file |
| 187 |
process_quote($quote); |
| 188 |
|
| 189 |
$quote->get_from_storage; |
| 190 |
|
| 191 |
# Tests for generated basket for passed quote file |
| 192 |
my $baskets = Koha::Acquisition::Baskets->search( { booksellerid => $account->{vendor_id} } ); |
| 193 |
my $basket = $baskets->next; |
| 194 |
|
| 195 |
my $orders = $basket->orders; |
| 196 |
my $order = $orders->next; |
| 197 |
|
| 198 |
my $biblio = $order->biblio; |
| 199 |
my $record = $biblio->record; |
| 200 |
my $record_field = $record->field('008'); |
| 201 |
|
| 202 |
is(exists($record_field->{_data}), 1, 'Field has been added'); |
| 203 |
|
| 204 |
# Test without calling the 008 handler |
| 205 |
$account = $builder->build( |
| 206 |
{ |
| 207 |
source => 'VendorEdiAccount', |
| 208 |
value => { |
| 209 |
description => 'test vendor', transport => 'FILE', |
| 210 |
} |
| 211 |
} |
| 212 |
); |
| 213 |
$dirname = ( $Bin =~ /^(.*\/t\/)/ ? $1 . 'edi_testfiles/' : q{} ); |
| 214 |
$filename = 'QUOTES_SMALL_2.CEQ'; |
| 215 |
ok( -e $dirname . $filename, 'File QUOTES_SMALL_2.CEQ found' ); |
| 216 |
|
| 217 |
$trans = Koha::Edifact::Transport->new( $account->{id} ); |
| 218 |
$trans->working_directory($dirname); |
| 219 |
|
| 220 |
$mhash = $trans->message_hash(); |
| 221 |
$mhash->{message_type} = 'QUOTE'; |
| 222 |
$trans->ingest( $mhash, $filename ); |
| 223 |
|
| 224 |
$quote = $schema->resultset('EdifactMessage')->find( { filename => $filename } ); |
| 225 |
|
| 226 |
# Test quote expects REF to be a valid and active fund code |
| 227 |
$active_period = $builder->build( |
| 228 |
{ |
| 229 |
source => 'Aqbudgetperiod', |
| 230 |
value => { budget_period_active => 1 } |
| 231 |
} |
| 232 |
); |
| 233 |
$fund = $builder->build( |
| 234 |
{ |
| 235 |
source => 'Aqbudget', |
| 236 |
value => { |
| 237 |
budget_code => 'REF2', |
| 238 |
budget_period_id => $active_period->{budget_period_id} |
| 239 |
} |
| 240 |
} |
| 241 |
); |
| 242 |
|
| 243 |
# The quote expects a ROT1 stock rotation roata to exist |
| 244 |
$rota = $builder->build_object( |
| 245 |
{ |
| 246 |
class => 'Koha::StockRotationRotas', |
| 247 |
value => { title => 'ROT2' } |
| 248 |
} |
| 249 |
); |
| 250 |
$builder->build( |
| 251 |
{ |
| 252 |
source => 'Stockrotationstage', |
| 253 |
value => { rota_id => $rota->rota_id }, |
| 254 |
} |
| 255 |
); |
| 256 |
|
| 257 |
# Process the test quote file |
| 258 |
my $edi_module = Test::MockModule->new('Koha::EDI'); |
| 259 |
$edi_module->mock( |
| 260 |
'_check_for_existing_bib', |
| 261 |
sub { |
| 262 |
my $bib_record = shift; |
| 263 |
return undef; |
| 264 |
} |
| 265 |
); |
| 266 |
$edi_module->mock( |
| 267 |
'_handle_008_field', |
| 268 |
sub { |
| 269 |
my $bib_record = shift; |
| 270 |
return $bib_record; |
| 271 |
} |
| 272 |
); |
| 273 |
process_quote($quote); |
| 274 |
|
| 275 |
$quote->get_from_storage; |
| 276 |
|
| 277 |
# Tests for generated basket for passed quote file |
| 278 |
$baskets = Koha::Acquisition::Baskets->search( { booksellerid => $account->{vendor_id} } ); |
| 279 |
$basket = $baskets->next; |
| 280 |
|
| 281 |
$orders = $basket->orders; |
| 282 |
$order = $orders->next; |
| 283 |
|
| 284 |
$biblio = $order->biblio; |
| 285 |
$record = $biblio->record; |
| 286 |
$record_field = $record->field('008'); |
| 287 |
|
| 288 |
is( $record_field->{_data}, undef, 'Field has not been added' ); |
| 289 |
|
| 290 |
$schema->storage->txn_rollback; |
| 291 |
} |