Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/WalletTest.php
<?php | <?php | ||||
namespace Tests\Feature; | namespace Tests\Feature; | ||||
use App\Package; | use App\Package; | ||||
use App\User; | use App\User; | ||||
use App\Sku; | use App\Sku; | ||||
use App\Transaction; | use App\Transaction; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
use Illuminate\Support\Facades\Queue; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class WalletTest extends TestCase | class WalletTest extends TestCase | ||||
{ | { | ||||
private $users = [ | private $users = [ | ||||
'UserWallet1@UserWallet.com', | 'UserWallet1@UserWallet.com', | ||||
'UserWallet2@UserWallet.com', | 'UserWallet2@UserWallet.com', | ||||
'UserWallet3@UserWallet.com', | 'UserWallet3@UserWallet.com', | ||||
Show All 23 Lines | public function tearDown(): void | ||||
Sku::select()->update(['fee' => 0]); | Sku::select()->update(['fee' => 0]); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test that turning wallet balance from negative to positive | * Test that turning wallet balance from negative to positive | ||||
* unsuspends the account | * unsuspends and undegrades the account | ||||
*/ | */ | ||||
public function testBalancePositiveUnsuspend(): void | public function testBalanceTurnsPositive(): void | ||||
{ | { | ||||
Queue::fake(); | |||||
$user = $this->getTestUser('UserWallet1@UserWallet.com'); | $user = $this->getTestUser('UserWallet1@UserWallet.com'); | ||||
$user->suspend(); | $user->suspend(); | ||||
$user->degrade(); | |||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->balance = -100; | $wallet->balance = -100; | ||||
$wallet->save(); | $wallet->save(); | ||||
$this->assertTrue($user->isSuspended()); | $this->assertTrue($user->isSuspended()); | ||||
$this->assertTrue($user->isDegraded()); | |||||
$this->assertNotNull($wallet->getSetting('balance_negative_since')); | $this->assertNotNull($wallet->getSetting('balance_negative_since')); | ||||
$wallet->balance = 100; | $wallet->balance = 100; | ||||
$wallet->save(); | $wallet->save(); | ||||
$this->assertFalse($user->fresh()->isSuspended()); | $user->refresh(); | ||||
$this->assertFalse($user->isSuspended()); | |||||
$this->assertFalse($user->isDegraded()); | |||||
$this->assertNull($wallet->getSetting('balance_negative_since')); | $this->assertNull($wallet->getSetting('balance_negative_since')); | ||||
// TODO: Test group account and unsuspending domain/members | // TODO: Test group account and unsuspending domain/members/groups | ||||
} | } | ||||
/** | /** | ||||
* Test for Wallet::balanceLastsUntil() | * Test for Wallet::balanceLastsUntil() | ||||
*/ | */ | ||||
public function testBalanceLastsUntil(): void | public function testBalanceLastsUntil(): void | ||||
{ | { | ||||
// Monthly cost of all entitlements: 990 | // Monthly cost of all entitlements: 990 | ||||
▲ Show 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | public function testChargeAndDeleteEntitlements(): void | ||||
$this->assertSame(Transaction::WALLET_DEBIT, $trans->type); | $this->assertSame(Transaction::WALLET_DEBIT, $trans->type); | ||||
$trans = $transactions[1]; | $trans = $transactions[1]; | ||||
$this->assertSame('', $trans->description); | $this->assertSame('', $trans->description); | ||||
$this->assertSame(-11, $trans->amount); | $this->assertSame(-11, $trans->amount); | ||||
$this->assertSame(Transaction::WALLET_DEBIT, $trans->type); | $this->assertSame(Transaction::WALLET_DEBIT, $trans->type); | ||||
// TODO: Test entitlement transaction records | // TODO: Test entitlement transaction records | ||||
} | } | ||||
/** | |||||
* Tests for updateEntitlements() | |||||
*/ | |||||
public function testUpdateEntitlements(): void | |||||
{ | |||||
$this->markTestIncomplete(); | |||||
} | |||||
} | } |