Lines 97-165
subtest 'relationships_debt() tests' => sub {
Link Here
|
97 |
is( $parent_1->guarantee_relationships->guarantees->count, 2, 'Parent 1 has correct number of guarantors' ); |
97 |
is( $parent_1->guarantee_relationships->guarantees->count, 2, 'Parent 1 has correct number of guarantors' ); |
98 |
is( $parent_2->guarantee_relationships->guarantees->count, 2, 'Parent 2 has correct number of guarantors' ); |
98 |
is( $parent_2->guarantee_relationships->guarantees->count, 2, 'Parent 2 has correct number of guarantors' ); |
99 |
|
99 |
|
100 |
# 3 params, count from 0 to 7 in binary ( 3 places ) to get the set of switches, then do that 4 times, one for each parent and child |
100 |
# 3 params, count from 0 to 6 in binary ( 3 places ) to get the set of switches, then do that 4 times, one for each parent and child |
101 |
for my $i ( 0 .. 7 ) { |
101 |
for my $i ( 0 .. 7 ) { |
102 |
my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) = split '', sprintf( "%03b", $i ); |
102 |
my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) = split '', sprintf( "%03b", $i ); |
103 |
for my $patron ( $parent_1, $parent_2, $child_1, $child_2 ) { |
103 |
for my $patron ( $child_1, $child_2, $parent_1, $parent_2 ) { |
104 |
is( |
104 |
is( $patron->relationships_debt( { only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron } ), 0, 'Family debt is correct' ); |
105 |
$patron->relationships_debt( |
|
|
106 |
{ |
107 |
only_this_guarantor => $only_this_guarantor, |
108 |
include_guarantors => $include_guarantors, |
109 |
include_this_patron => $include_this_patron |
110 |
} |
111 |
), 0, 'Family debt is correct' |
112 |
); |
113 |
} |
105 |
} |
114 |
} |
106 |
} |
115 |
|
107 |
|
116 |
|
108 |
$child_2->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); |
117 |
my $child_2_debt = 10; |
|
|
118 |
$child_2->account->add_debit({ type => 'ACCOUNT', amount => $child_2_debt, interface => 'commandline' }); |
119 |
is( $child_2->account->non_issues_charges, 10, 'Child 2 owes correct amount' ); |
109 |
is( $child_2->account->non_issues_charges, 10, 'Child 2 owes correct amount' ); |
|
|
110 |
|
120 |
for my $i ( 0 .. 7 ) { |
111 |
for my $i ( 0 .. 7 ) { |
121 |
my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) = split '', sprintf( "%03b", $i ); |
112 |
my ( $only_this_guarantor, $include_guarantors, $include_this_patron ) = split '', sprintf( "%03b", $i ); |
122 |
is( |
113 |
for my $patron ( $child_1, $child_2, $parent_1, $parent_2 ) { |
123 |
$parent_1->relationships_debt( |
114 |
my $amount = 10; |
124 |
{ |
115 |
$amount = 0 if ( $patron->id == $child_1->id && $i > 3 ); |
125 |
only_this_guarantor => $only_this_guarantor, |
116 |
$amount = 0 if ( $patron->id == $child_2->id && ( $i == 0 || $i == 2 || $i == 4 || $i == 5 || $i == 6 ) ); |
126 |
include_guarantors => $include_guarantors, |
117 |
is( $patron->relationships_debt( { only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron } ), $amount, 'Family debt is correct' ); |
127 |
include_this_patron => $include_this_patron |
118 |
} |
128 |
} |
|
|
129 |
), |
130 |
$child_2_debt, "parent 1 debt is correct (only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron" |
131 |
); |
132 |
is( |
133 |
$parent_2->relationships_debt( |
134 |
{ |
135 |
only_this_guarantor => $only_this_guarantor, |
136 |
include_guarantors => $include_guarantors, |
137 |
include_this_patron => $include_this_patron |
138 |
} |
139 |
), |
140 |
$child_2_debt, "parent 2 debt is correct (only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron" |
141 |
); |
142 |
is( |
143 |
$child_1->relationships_debt( |
144 |
{ |
145 |
only_this_guarantor => $only_this_guarantor, |
146 |
include_guarantors => $include_guarantors, |
147 |
include_this_patron => $include_this_patron |
148 |
} |
149 |
), |
150 |
$child_2_debt, "child 1 debt is correct (only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron" |
151 |
); |
152 |
|
153 |
is( |
154 |
$child_2->relationships_debt( |
155 |
{ |
156 |
only_this_guarantor => $only_this_guarantor, |
157 |
include_guarantors => $include_guarantors, |
158 |
include_this_patron => $include_this_patron |
159 |
} |
160 |
), |
161 |
( $include_this_patron && $child_2_debt ) ? $child_2_debt : 0, "child 2 debt is correct (only_this_guarantor => $only_this_guarantor, include_guarantors => $include_guarantors, include_this_patron => $include_this_patron" |
162 |
); |
163 |
} |
119 |
} |
164 |
|
120 |
|
165 |
$parent_1->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); |
121 |
$parent_1->account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); |
166 |
- |
|
|