Skip to content

Commit a299de6

Browse files
committed
Melhoria nos testes.
1 parent cffd3e4 commit a299de6

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

t/donor/007-compute-donation.t

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ db_transaction {
5555
my $httpcb_rs = $schema->resultset("HttpCallbackToken");
5656

5757
# Mockando um pagamento para simular o callback de compute donation.
58-
ok (
58+
ok(
5959
my $payment = $schema->resultset("Payment")->create(
6060
{
6161
donor_id => $donor_id,
@@ -67,7 +67,7 @@ db_transaction {
6767
"fake payment",
6868
);
6969

70-
ok (
70+
ok(
7171
my $token = $httpcb_rs->create_for_action(
7272
"payment-success-renewal",
7373
{
@@ -84,8 +84,11 @@ db_transaction {
8484
code => 200,
8585
;
8686

87+
ok( $user_plan->discard_changes, 'user_plan discard changes' );
88+
ok( defined($user_plan->last_close_at), 'user_plan.last_close_at is defined' );
89+
8790
# O jornalista 1 deve receber R$ 13,26.
88-
is (
91+
is(
8992
$schema->resultset("MoneyTransfer")->search(
9093
{
9194
journalist_id => $journalist_ids[0],
@@ -98,7 +101,7 @@ db_transaction {
98101
);
99102

100103
# E o jornalista 2 deve receber R$ 8,84.
101-
is (
104+
is(
102105
$schema->resultset("MoneyTransfer")->search(
103106
{
104107
journalist_id => $journalist_ids[1],
@@ -109,6 +112,50 @@ db_transaction {
109112
"1",
110113
'journalist 2 will receive R$ 8,84',
111114
);
115+
116+
# Se houver um novo callback do compute_donations, não deve criar mais nenhuma transferência pois nenhum libre
117+
# será doado.
118+
use_ok 'Libre::Worker::BankTeller';
119+
my $worker = new_ok( 'Libre::Worker::BankTeller', [ schema => $schema, log => Libre->log ] );
120+
121+
is(
122+
$schema->resultset("MoneyTransfer")->search( { 'me.transferred' => "false" } )->count,
123+
2,
124+
"money_transfer count=2",
125+
);
126+
127+
ok( $worker->run_once(), 'run once' );
128+
ok( $worker->run_once(), 'run once' );
129+
130+
is(
131+
$schema->resultset("MoneyTransfer")->search( { 'me.transferred' => "false" } )->count,
132+
0,
133+
"money_transfer count=0",
134+
);
135+
136+
undef $token;
137+
ok(
138+
$token = $httpcb_rs->create_for_action(
139+
"payment-success-renewal",
140+
{
141+
user_id => $donor_id,
142+
user_plan_id => $user_plan_id,
143+
payment_id => $payment->id,
144+
}
145+
),
146+
"fake http callback of fake payment",
147+
);
148+
149+
rest_post [ "callback-for-token", $token ],
150+
name => "http callback triggered again",
151+
code => 200,
152+
;
153+
154+
is(
155+
$schema->resultset("MoneyTransfer")->search( { 'me.transferred' => "false" } )->count,
156+
0,
157+
"money_transfer count=0",
158+
);
112159
};
113160

114161
done_testing();

0 commit comments

Comments
 (0)