Skip to content

Commit

Permalink
test: espera bastasnte para pegar faturas
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewalkerescavador committed Jun 14, 2024
1 parent cbb30d2 commit ab3342f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/GuPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ class GuPaymentTest extends TestCase

protected $iuguSubscriptionModelPlanColumn;

private function getLastInvoice($user, $subscription, $tries = 0)
{
$invoice = $user->invoices(false, ['subscription_id' => $subscription->id])->first();

if ($invoice) {
return $invoice;
}

if ($tries > 5) {
throw new Exception('Invoice not found.');
}

sleep(pow(3, $tries));

return $this->getLastInvoice($user, $subscription, $tries + 1);
}

public function setUp() : void
{
parent::setUp();
Expand Down Expand Up @@ -143,11 +160,10 @@ public function testSubscriptionsCanBeCreated()
$this->assertEquals('silver', $subscription->{$this->iuguSubscriptionModelPlanColumn});

// Delay, wait for iugu register invoice
sleep(10);
sleep(30);

// Invoice Tests
$invoices = $user->invoices(false, ['subscription_id' => $subscription->id]);
$invoice = $invoices->first();
$invoice = $this->getLastInvoice($user, $subscription);

$this->assertEquals('R$ 5,00', $invoice->total());
$this->assertEquals('Mudança de Plano: [antigo] Silver', $invoice->items[0]->description);
Expand Down

0 comments on commit ab3342f

Please sign in to comment.