Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/env perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Test::More tests => 17; |
6 |
use Test::Mojo; |
7 |
|
8 |
use C4::Context; |
9 |
|
10 |
use Koha::Database; |
11 |
use Koha::Borrower; |
12 |
|
13 |
my $dbh = C4::Context->dbh; |
14 |
$dbh->{AutoCommit} = 0; |
15 |
$dbh->{RaiseError} = 1; |
16 |
|
17 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
18 |
|
19 |
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); |
20 |
my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); |
21 |
|
22 |
my $borrower = Koha::Borrower->new; |
23 |
$borrower->categorycode( $categorycode ); |
24 |
$borrower->branchcode( $branchcode ); |
25 |
$borrower->surname("Test Surname"); |
26 |
$borrower->store; |
27 |
my $borrowernumber = $borrower->borrowernumber; |
28 |
|
29 |
$dbh->do(q| DELETE FROM accountlines |); |
30 |
$dbh->do(q| |
31 |
INSERT INTO accountlines (borrowernumber, amount, accounttype) |
32 |
VALUES (?, 20, 'A'), (?, 40, 'F'), (?, 80, 'F') |
33 |
|, undef, $borrowernumber, $borrowernumber, $borrowernumber); |
34 |
|
35 |
$t->get_ok("/v1/borrowers/$borrowernumber/accountlines") |
36 |
->status_is(200); |
37 |
my $json = $t->tx->res->json; |
38 |
ok(ref $json eq 'ARRAY', 'response is a JSON array'); |
39 |
ok(scalar @$json == 3, 'response array contains 3 elements'); |
40 |
|
41 |
$t->get_ok("/v1/borrowers/$borrowernumber/accountlines?accounttype=A") |
42 |
->status_is(200); |
43 |
$json = $t->tx->res->json; |
44 |
ok(ref $json eq 'ARRAY', 'response is a JSON array'); |
45 |
ok(scalar @$json == 1, 'response array contains 1 element'); |
46 |
is($json->[0]->{amount}, '20.000000', 'right amount returned'); |
47 |
|
48 |
$t->get_ok("/v1/borrowers/$borrowernumber/accountlines?accounttype=F") |
49 |
->status_is(200); |
50 |
$json = $t->tx->res->json; |
51 |
ok(ref $json eq 'ARRAY', 'response is a JSON array'); |
52 |
ok(scalar @$json == 2, 'response array contains 2 elements'); |
53 |
|
54 |
$t->get_ok("/v1/borrowers/$borrowernumber/accountlines?accounttype=Pay") |
55 |
->status_is(200); |
56 |
$json = $t->tx->res->json; |
57 |
ok(ref $json eq 'ARRAY', 'response is a JSON array'); |
58 |
ok(scalar @$json == 0, 'response array is empty'); |
59 |
|
60 |
$dbh->rollback; |