View | Details | Raw Unified | Return to bug 27421
Collapse All | Expand All

(-)a/t/db_dependent/Koha/BackgroundJobs/StageMARCForImport.t (-1 / +132 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2022 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 3;
23
use Test::MockModule;
24
use JSON qw( encode_json decode_json );
25
26
use Koha::Database;
27
use Koha::BackgroundJobs;
28
use Koha::BackgroundJob::StageMARCForImport;
29
use Koha::BackgroundJob::MARCImportCommitBatch;
30
use Koha::BackgroundJob::MARCImportRevertBatch;
31
use Koha::Import::Records;
32
use Koha::Exception;
33
use t::lib::TestBuilder;
34
35
my $schema = Koha::Database->new->schema;
36
37
my $builder = t::lib::TestBuilder->new;
38
39
$schema->storage->txn_begin;
40
41
my $biblio = $builder->build_sample_biblio;
42
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
43
my $import_batch_id;
44
45
subtest 'StageMARCForImport' => sub {
46
47
    plan tests => 4;
48
49
    my $job = Koha::BackgroundJob::StageMARCForImport->new(
50
        {
51
            status         => 'new',
52
            size           => 1,
53
            borrowernumber => $patron->borrowernumber,
54
            type           => 'stage_marc_for_import',
55
        }
56
    )->store;
57
    $job = Koha::BackgroundJobs->find( $job->id );
58
    $job->process(
59
        {
60
            job_id      => $job->id,
61
            record_type => 'biblio',
62
            encoding    => 'UTF-8',
63
            format      => 'ISO2709',
64
            filepath    => 't/db_dependent/data/marc21/zebraexport/biblio/exported_records',
65
            filename    => 'some_records',
66
            parse_items => 1,
67
        }
68
    );
69
70
    my $report = decode_json($job->get_from_storage->data)->{report};
71
    is( $report->{num_items},     138 );
72
    is( $report->{staged},        178 );
73
    is( $report->{total},         179 );
74
    is( $report->{import_errors}, 1 );
75
    $import_batch_id = $report->{import_batch_id};
76
77
};
78
79
subtest 'MARCImportCommitBatch' => sub {
80
81
    plan tests => 2;
82
83
    my $job = Koha::BackgroundJob::MARCImportCommitBatch->new(
84
        {
85
            status         => 'new',
86
            size           => 1,
87
            borrowernumber => $patron->borrowernumber,
88
            type           => 'marc_import_commit_batch'
89
        }
90
    )->store;
91
    $job = Koha::BackgroundJobs->find( $job->id );
92
    $job->process(
93
        {
94
            job_id          => $job->id,
95
            import_batch_id => $import_batch_id,
96
            frameworkcode   => q{},
97
        }
98
    );
99
100
    my $report = decode_json( $job->get_from_storage->data )->{report};
101
    is( $report->{num_added},       178 );
102
    is( $report->{num_items_added}, 138 );
103
104
};
105
106
subtest 'MARCImportRevertBatch' => sub {
107
108
    plan tests => 2;
109
110
    my $job = Koha::BackgroundJob::MARCImportRevertBatch->new(
111
        {
112
            status         => 'new',
113
            size           => 1,
114
            borrowernumber => $patron->borrowernumber,
115
            type           => 'marc_import_revert_batch'
116
        }
117
    )->store;
118
    $job = Koha::BackgroundJobs->find( $job->id );
119
    $job->process(
120
        {
121
            job_id          => $job->id,
122
            import_batch_id => $import_batch_id,
123
        }
124
    );
125
126
    my $report = decode_json( $job->get_from_storage->data )->{report};
127
    is( $report->{num_deleted},       178 );
128
    is( $report->{num_items_deleted}, 138 );
129
130
};
131
132
$schema->storage->txn_rollback;

Return to bug 27421