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

(-)a/t/db_dependent/api/v1/patrons_accounts.t (-5 / +14 lines)
Lines 46-53 subtest 'get_balance() tests' => sub { Link Here
46
    $schema->storage->txn_begin;
46
    $schema->storage->txn_begin;
47
47
48
    my ( $patron, $session_id ) = create_user_and_session({ authorized => 0 });
48
    my ( $patron, $session_id ) = create_user_and_session({ authorized => 0 });
49
    my $patron_id  = $patron->id;
49
    my $library   = $builder->build_object({ class => 'Koha::Libraries' });
50
    my $account = $patron->account;
50
    my $patron_id = $patron->id;
51
    my $account   = $patron->account;
51
52
52
    my $tx = $t->ua->build_tx(GET => "/api/v1/patrons/$patron_id/account");
53
    my $tx = $t->ua->build_tx(GET => "/api/v1/patrons/$patron_id/account");
53
    $tx->req->cookies({ name => 'CGISESSID', value => $session_id });
54
    $tx->req->cookies({ name => 'CGISESSID', value => $session_id });
Lines 68-73 subtest 'get_balance() tests' => sub { Link Here
68
            accounttype       => "N", # New card
69
            accounttype       => "N", # New card
69
            amountoutstanding => 50,
70
            amountoutstanding => 50,
70
            manager_id        => $patron->borrowernumber,
71
            manager_id        => $patron->borrowernumber,
72
            branchcode        => $library->id
71
        }
73
        }
72
    )->store();
74
    )->store();
73
    $account_line_1->discard_changes;
75
    $account_line_1->discard_changes;
Lines 81-86 subtest 'get_balance() tests' => sub { Link Here
81
            accounttype       => "N", # New card
83
            accounttype       => "N", # New card
82
            amountoutstanding => 50.01,
84
            amountoutstanding => 50.01,
83
            manager_id        => $patron->borrowernumber,
85
            manager_id        => $patron->borrowernumber,
86
            branchcode        => $library->id
84
        }
87
        }
85
    )->store();
88
    )->store();
86
    $account_line_2->discard_changes;
89
    $account_line_2->discard_changes;
Lines 125-131 subtest 'get_balance() tests' => sub { Link Here
125
    );
128
    );
126
129
127
    # add a credit
130
    # add a credit
128
    my $credit_line = $account->add_credit({ amount => 10, user_id => $patron->id });
131
    my $credit_line = $account->add_credit(
132
        { amount => 10, user_id => $patron->id, library_id => $library->id } );
129
    # re-read from the DB
133
    # re-read from the DB
130
    $credit_line->discard_changes;
134
    $credit_line->discard_changes;
131
    $tx = $t->ua->build_tx( GET => "/api/v1/patrons/$patron_id/account" );
135
    $tx = $t->ua->build_tx( GET => "/api/v1/patrons/$patron_id/account" );
Lines 149-159 subtest 'get_balance() tests' => sub { Link Here
149
153
150
subtest 'add_credit() tests' => sub {
154
subtest 'add_credit() tests' => sub {
151
155
152
    plan tests => 17;
156
    plan tests => 18;
153
157
154
    $schema->storage->txn_begin;
158
    $schema->storage->txn_begin;
155
159
156
    my ( $patron, $session_id ) = create_user_and_session( { authorized => 1 } );
160
    my ( $patron, $session_id ) = create_user_and_session( { authorized => 1 } );
161
    my $library   = $builder->build_object({ class => 'Koha::Libraries' });
157
    my $patron_id = $patron->id;
162
    my $patron_id = $patron->id;
158
    my $account   = $patron->account;
163
    my $account   = $patron->account;
159
164
Lines 194-205 subtest 'add_credit() tests' => sub { Link Here
194
    )->store();
199
    )->store();
195
200
196
    is( $account->outstanding_debits->total_outstanding, 25 );
201
    is( $account->outstanding_debits->total_outstanding, 25 );
202
    $credit->{library_id} = $library->id;
197
    $tx = $t->ua->build_tx(
203
    $tx = $t->ua->build_tx(
198
        POST => "/api/v1/patrons/$patron_id/account/credits" => json => $credit );
204
        POST => "/api/v1/patrons/$patron_id/account/credits" => json => $credit );
199
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
205
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
200
    $tx->req->env( { REMOTE_ADDR => '127.0.0.1' } );
206
    $tx->req->env( { REMOTE_ADDR => '127.0.0.1' } );
201
    $t->request_ok($tx)->status_is(200)->json_has('/account_line_id');
207
    $t->request_ok($tx)->status_is(200)->json_has('/account_line_id');
202
208
209
    my $account_line_id = $tx->res->json->{account_line_id};
210
    is( Koha::Account::Lines->find($account_line_id)->branchcode,
211
        $library->id, 'Library id is sored correctly' );
212
203
    is( $account->outstanding_debits->total_outstanding,
213
    is( $account->outstanding_debits->total_outstanding,
204
        0, "Debits have been cancelled automatically" );
214
        0, "Debits have been cancelled automatically" );
205
215
206
- 

Return to bug 21786