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

(-)a/t/db_dependent/api/v1/patrons_accounts.t (-64 / +45 lines)
Lines 63-97 subtest 'get_balance() tests' => sub { Link Here
63
        }
63
        }
64
    );
64
    );
65
65
66
    my $account_line_1 = Koha::Account::Line->new(
66
    my $debit_1 = $account->add_debit(
67
        {
67
        {
68
            borrowernumber    => $patron->borrowernumber,
68
            amount       => 50,
69
            date              => \'NOW()',
69
            description  => "A description",
70
            amount            => 50,
70
            type         => "NEW_CARD",
71
            description       => "A description",
71
            user_id      => $patron->borrowernumber,
72
            debit_type_code   => "NEW_CARD", # New card
72
            library_id   => $library->id,
73
            amountoutstanding => 50,
73
            interface    => 'test',
74
            manager_id        => $patron->borrowernumber,
75
            branchcode        => $library->id,
76
            interface         => 'test',
77
        }
74
        }
78
    )->store();
75
    )->store();
79
    $account_line_1->discard_changes;
76
    $debit_1->discard_changes;
80
77
81
    my $account_line_2 = Koha::Account::Line->new(
78
    my $debit_2 = $account->add_debit(
82
        {
79
        {
83
            borrowernumber    => $patron->borrowernumber,
80
            amount      => 50.01,
84
            date              => \'NOW()',
81
            description => "A description",
85
            amount            => 50.01,
82
            type        => "NEW_CARD", # New card
86
            description       => "A description",
83
            user_id     => $patron->borrowernumber,
87
            debit_type_code   => "NEW_CARD", # New card
84
            library_id  => $library->id,
88
            amountoutstanding => 50.01,
85
            interface   => 'test',
89
            manager_id        => $patron->borrowernumber,
90
            branchcode        => $library->id,
91
            interface         => 'test',
92
        }
86
        }
93
    )->store();
87
    )->store();
94
    $account_line_2->discard_changes;
88
    $debit_2->discard_changes;
95
89
96
    $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account")
90
    $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account")
97
      ->status_is(200)
91
      ->status_is(200)
Lines 100-107 subtest 'get_balance() tests' => sub { Link Here
100
            outstanding_debits => {
94
            outstanding_debits => {
101
                total => 100.01,
95
                total => 100.01,
102
                lines => [
96
                lines => [
103
                    $account_line_1->to_api,
97
                    $debit_1->to_api,
104
                    $account_line_2->to_api
98
                    $debit_2->to_api
105
                ]
99
                ]
106
            },
100
            },
107
            outstanding_credits => {
101
            outstanding_credits => {
Lines 152-171 subtest 'get_balance() tests' => sub { Link Here
152
    );
146
    );
153
147
154
    # Accountline without manager_id (happens with fines.pl cron for example)
148
    # Accountline without manager_id (happens with fines.pl cron for example)
155
    my $account_line_3 = Koha::Account::Line->new(
149
    my $debit_3 = $account->add_debit(
156
        {
150
        {
157
            borrowernumber    => $patron->borrowernumber,
151
            amount      => 50,
158
            date              => \'NOW()',
152
            description => "A description",
159
            amount            => 50,
153
            type        => "NEW_CARD", # New card
160
            description       => "A description",
154
            user_id     => undef,
161
            debit_type_code   => "NEW_CARD", # New card
155
            library_id  => $library->id,
162
            amountoutstanding => 50,
156
            interface   => 'test',
163
            manager_id        => undef,
164
            branchcode        => $library->id,
165
            interface         => 'test',
166
        }
157
        }
167
    )->store();
158
    )->store();
168
    $account_line_3->discard_changes;
159
    $debit_3->discard_changes;
169
160
170
    $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account")
161
    $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account")
171
      ->status_is(200)
162
      ->status_is(200)
Lines 174-180 subtest 'get_balance() tests' => sub { Link Here
174
            outstanding_debits => {
165
            outstanding_debits => {
175
                total => 50.00,
166
                total => 50.00,
176
                lines => [
167
                lines => [
177
                    $account_line_3->to_api
168
                    $debit_3->to_api
178
                ]
169
                ]
179
            },
170
            },
180
            outstanding_credits => {
171
            outstanding_credits => {
Lines 219-244 subtest 'add_credit() tests' => sub { Link Here
219
    is( $outstanding_credits->count,             1 );
210
    is( $outstanding_credits->count,             1 );
220
    is( $outstanding_credits->total_outstanding, -100 );
211
    is( $outstanding_credits->total_outstanding, -100 );
221
212
222
    my $debit_1 = Koha::Account::Line->new(
213
    my $debit_1 = $account->add_debit(
223
        {   borrowernumber    => $patron->borrowernumber,
214
        {   amount      => 10,
224
            date              => \'NOW()',
215
            description => "A description",
225
            amount            => 10,
216
            type        => "NEW_CARD",
226
            description       => "A description",
217
            user_id     => $patron->borrowernumber,
227
            debit_type_code   => "NEW_CARD",                       # New card
218
            interface   => 'test',
228
            amountoutstanding => 10,
229
            manager_id        => $patron->borrowernumber,
230
            interface         => 'test',
231
        }
219
        }
232
    )->store();
220
    )->store();
233
    my $debit_2 = Koha::Account::Line->new(
221
    my $debit_2 = $account->add_debit(
234
        {   borrowernumber    => $patron->borrowernumber,
222
        {   amount      => 15,
235
            date              => \'NOW()',
223
            description => "A description",
236
            amount            => 15,
224
            type        => "NEW_CARD",
237
            description       => "A description",
225
            user_id     => $patron->borrowernumber,
238
            debit_type_code   => "NEW_CARD",                       # New card
226
            interface   => 'test',
239
            amountoutstanding => 15,
240
            manager_id        => $patron->borrowernumber,
241
            interface         => 'test',
242
        }
227
        }
243
    )->store();
228
    )->store();
244
229
Lines 258-272 subtest 'add_credit() tests' => sub { Link Here
258
    is( $account->outstanding_debits->total_outstanding,
243
    is( $account->outstanding_debits->total_outstanding,
259
        0, "Debits have been cancelled automatically" );
244
        0, "Debits have been cancelled automatically" );
260
245
261
    my $debit_3 = Koha::Account::Line->new(
246
    my $debit_3 = $account->add_debit(
262
        {   borrowernumber    => $patron->borrowernumber,
247
        {   amount      => 100,
263
            date              => \'NOW()',
248
            description => "A description",
264
            amount            => 100,
249
            type        => "NEW_CARD",
265
            description       => "A description",
250
            user_id     => $patron->borrowernumber,
266
            debit_type_code   => "NEW_CARD",                       # New card
251
            interface   => 'test',
267
            amountoutstanding => 100,
268
            manager_id        => $patron->borrowernumber,
269
            interface         => 'test',
270
        }
252
        }
271
    )->store();
253
    )->store();
272
254
273
- 

Return to bug 28424