Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/WalletTest.php
<?php | <?php | ||||
namespace Tests\Feature; | namespace Tests\Feature; | ||||
use App\Discount; | |||||
use App\Payment; | use App\Payment; | ||||
use App\Package; | use App\Package; | ||||
use App\Plan; | use App\Plan; | ||||
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 App\VatRate; | use App\VatRate; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | class WalletTest extends TestCase | ||||
{ | { | ||||
foreach ($this->users as $user) { | foreach ($this->users as $user) { | ||||
$this->deleteTestUser($user); | $this->deleteTestUser($user); | ||||
} | } | ||||
Sku::select()->update(['fee' => 0]); | Sku::select()->update(['fee' => 0]); | ||||
Payment::query()->delete(); | Payment::query()->delete(); | ||||
VatRate::query()->delete(); | VatRate::query()->delete(); | ||||
Plan::withEnvTenantContext()->where('title', 'individual')->update(['months' => 1]); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test that turning wallet balance from negative to positive | * Test that turning wallet balance from negative to positive | ||||
* unsuspends and undegrades the account | * unsuspends and undegrades the account | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | /* | ||||
} | } | ||||
); | ); | ||||
*/ | */ | ||||
} | } | ||||
/** | /** | ||||
* Verify a wallet can be assigned a controller. | * Verify a wallet can be assigned a controller. | ||||
*/ | */ | ||||
public function testAddWalletController(): void | public function testAddController(): void | ||||
{ | { | ||||
$userA = $this->getTestUser('WalletControllerA@WalletController.com'); | $userA = $this->getTestUser('WalletControllerA@WalletController.com'); | ||||
$userB = $this->getTestUser('WalletControllerB@WalletController.com'); | $userB = $this->getTestUser('WalletControllerB@WalletController.com'); | ||||
$userA->wallets()->each( | $userA->wallets()->each( | ||||
function ($wallet) use ($userB) { | function ($wallet) use ($userB) { | ||||
$wallet->addController($userB); | $wallet->addController($userB); | ||||
} | } | ||||
); | ); | ||||
$this->assertCount(1, $userB->accounts); | $this->assertCount(1, $userB->accounts); | ||||
$aWallet = $userA->wallets()->first(); | $aWallet = $userA->wallets()->first(); | ||||
$bAccount = $userB->accounts()->first(); | $bAccount = $userB->accounts()->first(); | ||||
$this->assertTrue($bAccount->id === $aWallet->id); | $this->assertTrue($bAccount->id === $aWallet->id); | ||||
} | } | ||||
/** | /** | ||||
* Test Wallet::getMinMandateAmount() | |||||
*/ | |||||
public function testGetMinMandateAmount(): void | |||||
{ | |||||
$user = $this->getTestUser('WalletControllerA@WalletController.com'); | |||||
$user->setSetting('plan_id', null); | |||||
$wallet = $user->wallets()->first(); | |||||
// No plan assigned | |||||
$this->assertSame(Payment::MIN_AMOUNT, $wallet->getMinMandateAmount()); | |||||
// Plan assigned | |||||
$plan = Plan::withEnvTenantContext()->where('title', 'individual')->first(); | |||||
$plan->months = 12; | |||||
$plan->save(); | |||||
$user->setSetting('plan_id', $plan->id); | |||||
$this->assertSame(990 * 12, $wallet->getMinMandateAmount()); | |||||
// Plan and discount | |||||
$discount = Discount::where('discount', 30)->first(); | |||||
$wallet->discount()->associate($discount); | |||||
$wallet->save(); | |||||
$this->assertSame((int) (990 * 12 * 0.70), $wallet->getMinMandateAmount()); | |||||
} | |||||
/** | |||||
* Test Wallet::isController() | * Test Wallet::isController() | ||||
*/ | */ | ||||
public function testIsController(): void | public function testIsController(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$ned = $this->getTestUser('ned@kolab.org'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
▲ Show 20 Lines • Show All 331 Lines • Show Last 20 Lines |