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\User; | use App\User; | ||||
use App\Sku; | |||||
use App\Wallet; | use App\Wallet; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
use Illuminate\Foundation\Testing\WithFaker; | use Illuminate\Foundation\Testing\WithFaker; | ||||
use Illuminate\Foundation\Testing\RefreshDatabase; | use Illuminate\Foundation\Testing\RefreshDatabase; | ||||
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', | ||||
'UserWallet4@UserWallet.com', | 'UserWallet4@UserWallet.com', | ||||
'UserWallet5@UserWallet.com', | 'UserWallet5@UserWallet.com', | ||||
'WalletControllerA@WalletController.com', | 'WalletControllerA@WalletController.com', | ||||
'WalletControllerB@WalletController.com', | 'WalletControllerB@WalletController.com', | ||||
'WalletController2A@WalletController.com', | 'WalletController2A@WalletController.com', | ||||
'WalletController2B@WalletController.com', | 'WalletController2B@WalletController.com', | ||||
'jane@kolabnow.com' | |||||
]; | ]; | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
foreach ($this->users as $user) { | foreach ($this->users as $user) { | ||||
$this->deleteTestUser($user); | $this->deleteTestUser($user); | ||||
} | } | ||||
} | } | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
foreach ($this->users as $user) { | foreach ($this->users as $user) { | ||||
$this->deleteTestUser($user); | $this->deleteTestUser($user); | ||||
} | } | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
public function testBalanceLastsUntil(): void | |||||
{ | |||||
$user = $this->getTestUser('jane@kolabnow.com'); | |||||
$package = Package::where('title', 'kolab')->first(); | |||||
$mailbox = Sku::where('title', 'mailbox')->first(); | |||||
$user->assignPackage($package); | |||||
$wallet = $user->wallets()->first(); | |||||
$until = $wallet->balanceLastsUntil(); | |||||
// TODO: Test this for typical cases | |||||
// TODO: Test this for a user with no entitlements | |||||
// TODO: Test this for a user with 100% discount | |||||
$this->markTestIncomplete(); | |||||
} | |||||
public function testCostsPerDay(): void | |||||
{ | |||||
// 999 | |||||
// 28 days: 35.68 | |||||
// 31 days: 32.22 | |||||
$user = $this->getTestUser('jane@kolabnow.com'); | |||||
$package = Package::where('title', 'kolab')->first(); | |||||
$mailbox = Sku::where('title', 'mailbox')->first(); | |||||
$user->assignPackage($package); | |||||
$wallet = $user->wallets()->first(); | |||||
$costsPerDay = $wallet->costsPerDay(); | |||||
$this->assertTrue($costsPerDay < 35.68); | |||||
$this->assertTrue($costsPerDay > 32.22); | |||||
} | |||||
/** | /** | ||||
* Verify a wallet is created, when a user is created. | * Verify a wallet is created, when a user is created. | ||||
*/ | */ | ||||
public function testCreateUserCreatesWallet(): void | public function testCreateUserCreatesWallet(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UserWallet1@UserWallet.com'); | $user = $this->getTestUser('UserWallet1@UserWallet.com'); | ||||
$this->assertCount(1, $user->wallets); | $this->assertCount(1, $user->wallets); | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |